|
| 1 | +import { ICatalog, IHydraResponse } from '@elastic-suite/gally-admin-shared' |
| 2 | +import { test, expect } from '@playwright/test' |
| 3 | +import { randomUUID } from 'crypto' |
| 4 | +import { login } from '../helper' |
| 5 | + |
| 6 | +test.describe('Boost Page', () => { |
| 7 | + test('Check redirection to boost grid page and presence of "Create a new boost" button', async ({ |
| 8 | + page, |
| 9 | + }) => { |
| 10 | + await login(page) |
| 11 | + |
| 12 | + await page.getByTestId('sidebarMenu').locator('a:has-text("Boost")').click() |
| 13 | + |
| 14 | + await expect(page).toHaveURL('/fr/admin/merchandize/boost/grid') |
| 15 | + |
| 16 | + const createBoostButton = await page.getByTestId('createButtonResourceGrid') |
| 17 | + await expect(createBoostButton).toBeVisible() |
| 18 | + }) |
| 19 | + |
| 20 | + test('Create Boost', async ({ page }) => { |
| 21 | + await page.route('**/*', (route) => { |
| 22 | + const headers = { |
| 23 | + ...route.request().headers(), |
| 24 | + 'Cache-Control': 'no-cache', |
| 25 | + } |
| 26 | + route.continue({ headers }) |
| 27 | + }) |
| 28 | + |
| 29 | + await login(page) |
| 30 | + |
| 31 | + await page.getByTestId('sidebarMenu').locator('a:has-text("Boost")').click() |
| 32 | + |
| 33 | + const catalogs: IHydraResponse<ICatalog> = await ( |
| 34 | + await page.waitForResponse( |
| 35 | + (response) => |
| 36 | + response.url() === `${process.env.API_SERVER_BASE_URL}/catalogs` && |
| 37 | + response.ok() |
| 38 | + ) |
| 39 | + ).json() |
| 40 | + |
| 41 | + await expect(page).toHaveURL('/fr/admin/merchandize/boost/grid') |
| 42 | + await ( |
| 43 | + await page.getByTestId('tablePagination').all() |
| 44 | + )[0] |
| 45 | + |
| 46 | + const createBoostButton = await page.getByTestId('createButtonResourceGrid') |
| 47 | + await createBoostButton.click() |
| 48 | + |
| 49 | + const switchIsActive = await page.getByTestId('isActive') |
| 50 | + |
| 51 | + await expect(await switchIsActive.locator('input')).toBeChecked() |
| 52 | + await switchIsActive.click() |
| 53 | + await expect(await switchIsActive.locator('input')).not.toBeChecked() |
| 54 | + await switchIsActive.click() |
| 55 | + await expect(await switchIsActive.locator('input')).toBeChecked() |
| 56 | + |
| 57 | + const modelInput = await page.getByTestId('modelInputText') |
| 58 | + await expect(await modelInput.getAttribute('placeholder')).toBe( |
| 59 | + 'Sélectionnez un modèle' |
| 60 | + ) |
| 61 | + |
| 62 | + await expect(modelInput).toBeEmpty() |
| 63 | + await modelInput.click() |
| 64 | + await page.getByText('Constante').click() |
| 65 | + await expect(await modelInput.inputValue()).toBe('Constante') |
| 66 | + |
| 67 | + const modelConfig = await page.getByTestId('modelConfig') |
| 68 | + await expect(modelConfig).toBeVisible() |
| 69 | + await expect(await modelConfig.locator('input').inputValue()).toBe('0') |
| 70 | + |
| 71 | + await expect( |
| 72 | + await page.getByText('Veuillez remplir les champs requis') |
| 73 | + ).toBeVisible() |
| 74 | + |
| 75 | + const boostName = randomUUID() |
| 76 | + const nameInput = await page.getByTestId('name') |
| 77 | + await nameInput.fill(boostName) |
| 78 | + |
| 79 | + await expect(await nameInput.inputValue()).toBe(boostName) |
| 80 | + const localizedCatalogsInput = await page.getByTestId( |
| 81 | + 'localizedCatalogsInputText' |
| 82 | + ) |
| 83 | + |
| 84 | + await expect(await localizedCatalogsInput).toBeEmpty() |
| 85 | + await localizedCatalogsInput.click() |
| 86 | + const catalogGroupTitles = await page |
| 87 | + .getByTestId('localizedCatalogsGroupTitle') |
| 88 | + .allInnerTexts() |
| 89 | + await expect(catalogGroupTitles).toEqual( |
| 90 | + catalogs['hydra:member'].map((catalog) => catalog.name) |
| 91 | + ) |
| 92 | + |
| 93 | + const catalogsCheckbox = await page |
| 94 | + .getByTestId('localizedCatalogsCheckbox') |
| 95 | + .all() |
| 96 | + await catalogsCheckbox[0].click() |
| 97 | + await catalogsCheckbox[1].click() |
| 98 | + |
| 99 | + expect( |
| 100 | + await page.getByTestId('localizedCatalogsCheckbox').allInnerTexts() |
| 101 | + ).toEqual( |
| 102 | + catalogs['hydra:member'] |
| 103 | + .map((catalog) => |
| 104 | + catalog.localizedCatalogs.map( |
| 105 | + (localizedCatalog) => localizedCatalog.name |
| 106 | + ) |
| 107 | + ) |
| 108 | + .flat() |
| 109 | + ) |
| 110 | + let catalogsTags = await page |
| 111 | + .getByTestId('localizedCatalogsTag') |
| 112 | + .allInnerTexts() |
| 113 | + |
| 114 | + expect(catalogsTags).toEqual([ |
| 115 | + await catalogsCheckbox[0].innerText(), |
| 116 | + await catalogsCheckbox[1].innerText(), |
| 117 | + ]) |
| 118 | + await catalogsCheckbox[0].click() |
| 119 | + catalogsTags = await page |
| 120 | + .getByTestId('localizedCatalogsTag') |
| 121 | + .allInnerTexts() |
| 122 | + expect(catalogsTags).toEqual([await catalogsCheckbox[1].innerText()]) |
| 123 | + await catalogsCheckbox[0].click() |
| 124 | + |
| 125 | + const requestTypesDropdownInputText = await page.getByTestId( |
| 126 | + 'requestTypesDropdownInputText' |
| 127 | + ) |
| 128 | + await requestTypesDropdownInputText.click() |
| 129 | + |
| 130 | + const requestTypeCheckboxList = await page.getByTestId( |
| 131 | + 'requestTypesDropdownCheckbox' |
| 132 | + ) |
| 133 | + |
| 134 | + for (const tag of await requestTypeCheckboxList.all()) await tag.click() |
| 135 | + |
| 136 | + await expect( |
| 137 | + await page.getByTestId('requestTypesDropdownTag').allInnerTexts() |
| 138 | + ).toEqual(await requestTypeCheckboxList.allInnerTexts()) |
| 139 | + |
| 140 | + const submitButton = await page.getByTestId('submitButtonResourceForm') |
| 141 | + await submitButton.click() |
| 142 | + |
| 143 | + await expect(page).toHaveURL( |
| 144 | + `${process.env.SERVER_BASE_URL}/fr/admin/merchandize/boost/grid` |
| 145 | + ) |
| 146 | + |
| 147 | + const newBoostName = await page.getByText(boostName) |
| 148 | + |
| 149 | + await expect(newBoostName).toBeVisible() |
| 150 | + }) |
| 151 | +}) |
0 commit comments