Skip to content

Commit 737afa2

Browse files
committed
fix(#1369486): ensure category scope config request is awaited in e2e test
1 parent ed0d05a commit 737afa2

File tree

1 file changed

+75
-32
lines changed

1 file changed

+75
-32
lines changed

front/e2e/src/tests/pages/admin/merchandising/category.spec.ts

Lines changed: 75 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,52 @@ const texts = {
4747
stockStatus: 'Stock status'
4848
} as const
4949

50+
let catalogDropdown: Dropdown = null
51+
let localizedCatalogDropdown: Dropdown = null
52+
53+
function resetDropdowns(): void {
54+
catalogDropdown = null
55+
localizedCatalogDropdown = null
56+
}
57+
58+
// Add this before your test functions
59+
test.beforeEach(() => {
60+
resetDropdowns()
61+
})
62+
63+
function getCatalogDropdown(page: Page): Dropdown {
64+
if (!catalogDropdown) {
65+
catalogDropdown = new Dropdown(page, testIds.catalogSwitcher)
66+
}
67+
return catalogDropdown
68+
}
69+
70+
function getLocalizedCatalogDropdown(page: Page): Dropdown {
71+
if (!localizedCatalogDropdown) {
72+
localizedCatalogDropdown = new Dropdown(
73+
page,
74+
testIds.localizedCatalogSwitcher
75+
)
76+
}
77+
return localizedCatalogDropdown
78+
}
79+
80+
async function changeScopeDropdown(page: Page, dropdown: Dropdown, value: string, waitForRequest = true): Promise<void> {
81+
const catalogInformationsResponse = page.waitForResponse('**/api/category_configurations/category/**')
82+
await dropdown.selectValue(value)
83+
if (waitForRequest) {
84+
await catalogInformationsResponse
85+
}
86+
}
87+
88+
async function selectCatalog(page: Page, catalog: string, waitForRequest = true): Promise<void> {
89+
await changeScopeDropdown(page, getCatalogDropdown(page), catalog, waitForRequest)
90+
}
91+
92+
async function selectLocalizedCatalog(page: Page, localizedCatalog: string, waitForRequest = true): Promise<void> {
93+
await changeScopeDropdown(page, getLocalizedCatalogDropdown(page), localizedCatalog, waitForRequest)
94+
}
95+
5096
async function testCategoriesPage(page: Page, gallyPackage: GallyPackage): Promise<void> {
5197
await test.step('Login and navigate to the Categories page', async () => {
5298
await login(page)
@@ -74,7 +120,6 @@ async function testCategoriesPage(page: Page, gallyPackage: GallyPackage): Promi
74120
}])
75121
})
76122

77-
78123
// Editable configuration fields
79124
const defaultSortingDropdown = new Dropdown(
80125
page,
@@ -85,12 +130,6 @@ async function testCategoriesPage(page: Page, gallyPackage: GallyPackage): Promi
85130
testIds.useNameInProductSearch
86131
)
87132
const isVirtualSwitch = new Switch(page, testIds.isVirtual)
88-
89-
const catalogDropdown = new Dropdown(page, testIds.catalogSwitcher)
90-
const localizedCatalogDropdown = new Dropdown(
91-
page,
92-
testIds.localizedCatalogSwitcher
93-
)
94133
const categoriesProductsSaveButton = page.getByTestId(testIds.categoriesProductsSaveButton)
95134

96135
const alertMessage = new AlertMessage(page)
@@ -105,42 +144,42 @@ async function testCategoriesPage(page: Page, gallyPackage: GallyPackage): Promi
105144
})
106145

107146
await test.step('Open catalog dropdown and choose a value', async () => {
108-
await catalogDropdown.expectToHaveOptions([texts.allCatalog, ...texts.catalogs])
109-
await catalogDropdown.expectToHaveValue(texts.allCatalog)
110-
await localizedCatalogDropdown.expectToBeVisible(false)
111-
await catalogDropdown.selectValue(texts.catalogs[0])
112-
await localizedCatalogDropdown.expectToBeVisible()
147+
await getCatalogDropdown(page).expectToHaveOptions([texts.allCatalog, ...texts.catalogs])
148+
await getCatalogDropdown(page).expectToHaveValue(texts.allCatalog)
149+
await getLocalizedCatalogDropdown(page).expectToBeVisible(false)
150+
await selectCatalog(page, texts.catalogs[0])
151+
await getLocalizedCatalogDropdown(page).expectToBeVisible()
113152
})
114153

115154
await test.step('Open localized catalog dropdown and choose a value', async () => {
116-
await localizedCatalogDropdown.expectToHaveOptions([
155+
await getLocalizedCatalogDropdown(page).expectToHaveOptions([
117156
texts.allLocales,
118157
...texts.locales,
119158
])
120-
await localizedCatalogDropdown.expectToHaveValue(texts.allLocales)
121-
await localizedCatalogDropdown.selectValue(texts.locales[0])
159+
await getLocalizedCatalogDropdown(page).expectToHaveValue(texts.allLocales)
160+
await selectLocalizedCatalog(page, texts.locales[0])
122161
})
123162

124163
await test.step('Select "All catalogs" in catalog dropdown and modify the configuration', async () => {
125-
await catalogDropdown.selectValue(texts.allCatalog)
126-
await localizedCatalogDropdown.expectToBeVisible(false)
164+
await selectCatalog(page, texts.allCatalog)
165+
await getLocalizedCatalogDropdown(page).expectToBeVisible(false)
127166
await defaultSortingDropdown.selectValue(texts.brand)
128167
await expect(categoriesProductsSaveButton).not.toBeDisabled()
129168
await categoriesProductsSaveButton.click()
130169
await alertMessage.expectToHaveText(texts.saveDataMessage, AlertMessageType.SUCCESS)
131170
})
132171

133172
await test.step('Select "COM catalog" in catalog dropdown', async () => {
134-
await catalogDropdown.selectValue(texts.catalogs[0])
173+
await selectCatalog(page, texts.catalogs[0])
135174
await defaultSortingDropdown.expectToHaveValue(texts.brand)
136175
})
137176

138177
await test.step('Reset default sorting values for "All catalogs"', async () => {
139-
await catalogDropdown.selectValue(texts.allCatalog)
178+
await selectCatalog(page, texts.allCatalog)
140179
await defaultSortingDropdown.selectValue(texts.position)
141180
await categoriesProductsSaveButton.click()
142181
await alertMessage.expectToHaveText(texts.saveDataMessage, AlertMessageType.SUCCESS)
143-
await catalogDropdown.selectValue(texts.catalogs[0])
182+
await selectCatalog(page, texts.catalogs[0])
144183
})
145184

146185
const categoryCollapseTreeListButton = await page
@@ -180,39 +219,43 @@ async function testCategoriesPage(page: Page, gallyPackage: GallyPackage): Promi
180219
})
181220

182221
await test.step('Select a locale', async () => {
183-
await localizedCatalogDropdown.selectValue(texts.locales[0])
222+
await selectLocalizedCatalog(page, texts.locales[0])
184223
await defaultSortingDropdown.expectToHaveValue(texts.price)
185224
})
186225

187226
await test.step('Select "All catalogs"', async () => {
188-
await catalogDropdown.selectValue(texts.allCatalog)
227+
await selectCatalog(page, texts.allCatalog)
189228
await defaultSortingDropdown.expectToHaveValue(texts.position)
190229
})
191230

192-
await test.step('Select catalog and localized catalog, modify the configuration and select All locales and All catalog to verify that the configuration is not apply to them', async () => {
193-
await catalogDropdown.selectValue(texts.catalogs[0])
194-
await localizedCatalogDropdown.selectValue(texts.locales[0])
231+
await test.step('Select catalog and localized catalog, modify the configuration and select All locales and All catalog to verify that the configuration is not applied to them', async () => {
232+
await selectCatalog(page, texts.catalogs[0])
233+
await selectLocalizedCatalog(page, texts.locales[0])
195234
await defaultSortingDropdown.selectValue(texts.stockStatus)
196235
await expect(categoriesProductsSaveButton).not.toBeDisabled()
197236
await categoriesProductsSaveButton.click()
198237
await alertMessage.expectToHaveText(texts.saveDataMessage, AlertMessageType.SUCCESS)
199-
await localizedCatalogDropdown.selectValue(texts.allLocales)
238+
await selectLocalizedCatalog(page, texts.allLocales)
200239
await defaultSortingDropdown.expectToHaveValue(texts.price)
201-
await catalogDropdown.selectValue(texts.allCatalog)
240+
await selectCatalog(page, texts.allCatalog)
202241
await defaultSortingDropdown.expectToHaveValue(texts.position)
203242
})
204243

205244
await test.step('Reset default sorting values for "COM Catalog"', async () => {
206245
// Reset default sorting on com_fr for FR_fr locale
207-
await catalogDropdown.selectValue(texts.catalogs[0])
208-
await localizedCatalogDropdown.selectValue(texts.locales[0])
209-
await defaultSortingDropdown.selectValue(texts.position)
246+
await selectCatalog(page, texts.catalogs[0])
247+
await selectLocalizedCatalog(page, texts.locales[0])
248+
// BEWARE: we set price here because we run standard and premium back to back
249+
// AND we can't remove configuration values for localized catalogs once set
250+
await defaultSortingDropdown.selectValue(texts.price)
210251
await categoriesProductsSaveButton.click()
211252
await alertMessage.expectToHaveText(texts.saveDataMessage, AlertMessageType.SUCCESS)
212253

213254
// Reset default sorting on com_fr for all locales
214-
await catalogDropdown.selectValue(texts.catalogs[0])
215-
await localizedCatalogDropdown.selectValue(texts.allLocales)
255+
// No wait for request as the value is the same as the last one for the catalog
256+
// We keep this selection to be consistent with the rest of the test
257+
await selectCatalog(page, texts.catalogs[0], false)
258+
await selectLocalizedCatalog(page, texts.allLocales)
216259
await defaultSortingDropdown.selectValue(texts.position)
217260
await expect(categoriesProductsSaveButton).not.toBeDisabled()
218261
await categoriesProductsSaveButton.click()

0 commit comments

Comments
 (0)