Skip to content

Commit 294b242

Browse files
feat(#1304624): Add e2e tests and add the service that lauches them in docker compose
1 parent 3a3cbc3 commit 294b242

File tree

13 files changed

+598
-5
lines changed

13 files changed

+598
-5
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ phpunit: ## Run php unit tests, pass the parameter "p=" to launch tests on a spe
146146
jest: ## Run jest unit tests
147147
@$(DOCKER_COMP) exec pwa yarn test
148148

149+
e2e: ## Run e2e tests
150+
@$(DOCKER_COMP) exec e2e yarn test
151+
149152
jest_update: ## Run jest unit tests
150153
@$(DOCKER_COMP) exec pwa yarn test:update
151154

compose.override.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ services:
5757
environment:
5858
- PUBLIC_URL=https://${SERVER_NAME:-gally.localhost}/example
5959
- REACT_APP_API_URL=https://${API_SERVER_NAME:-${SERVER_NAME:-api.gally.localhost}}/${API_ROUTE_PREFIX:-}
60+
e2e:
61+
build:
62+
context: .
63+
dockerfile: ./docker/front/Dockerfile.e2e
64+
environment:
65+
- SERVER_BASE_URL=https://${SERVER_NAME:-gally.localhost}
66+
- API_SERVER_BASE_URL=https://${API_SERVER_NAME:-api.gally.localhost}
67+
depends_on:
68+
- proxy
69+
extra_hosts:
70+
- ${SERVER_NAME:-gally.localhost}:host-gateway
71+
- ${API_SERVER_NAME:-api.gally.localhost}:host-gateway
72+
6073

6174
###> doctrine/doctrine-bundle ###
6275
database:

docker/front/Dockerfile.e2e

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM mcr.microsoft.com/playwright:v1.39.0
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY ./front/e2e/ .
6+
7+
RUN yarn install
8+
9+
RUN npx playwright install chromium
10+
RUN npx playwright install-deps chromium
11+
12+
CMD ["yarn", "test"]

front/e2e/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
/test-results/
3+
/playwright-report/
4+
/blob-report/
5+
/playwright/.cache/

front/e2e/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "e2e",
3+
"private": "false",
4+
"version": "1.0.0",
5+
"main": "index.js",
6+
"license": "MIT",
7+
"devDependencies": {
8+
"@playwright/test": "^1.47.2",
9+
"@types/node": "^22.6.1"
10+
},
11+
"scripts": {
12+
"test": "yarn playwright test",
13+
"test:ci": "yarn playwright test",
14+
"test:standard": "yarn playwright test --grep @standard",
15+
"test:premium": "yarn playwright test --grep @premium"
16+
},
17+
"dependencies": {}
18+
}

front/e2e/playwright.config.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
// import dotenv from 'dotenv'
3+
// import path from 'path'
4+
5+
// Read from ".env" file.
6+
// dotenv.config({ path: path.resolve(__dirname, '.env') })
7+
8+
/**
9+
* Read environment variables from file.
10+
* https://github.com/motdotla/dotenv
11+
*/
12+
// import dotenv from 'dotenv';
13+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
14+
15+
/**
16+
* See https://playwright.dev/docs/test-configuration.
17+
*/
18+
export default defineConfig({
19+
testDir: './tests',
20+
/* Run tests in files in parallel */
21+
fullyParallel: true,
22+
/* Fail the build on CI if you accidentally left test.only in the source code. */
23+
forbidOnly: !!process.env.CI,
24+
/* Retry on CI only */
25+
retries: process.env.CI ? 2 : 0,
26+
/* Opt out of parallel tests on CI. */
27+
workers: process.env.CI ? 1 : undefined,
28+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
29+
reporter: 'html',
30+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
31+
use: {
32+
baseURL: process.env.SERVER_BASE_URL,
33+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
34+
trace: 'on-first-retry',
35+
headless: true, // Exécuter tous les tests en mode headless
36+
ignoreHTTPSErrors: true, // Ignorer les erreurs HTTPS
37+
},
38+
projects: [
39+
{
40+
name: 'chromium',
41+
use: { ...devices['Desktop Chrome'] },
42+
},
43+
],
44+
45+
/* Run your local dev server before starting the tests */
46+
// webServer: {
47+
// command: 'npm run start',
48+
// url: 'http://127.0.0.1:3000',
49+
// reuseExistingServer: !process.env.CI,
50+
// },
51+
})
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
})
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { test, expect } from '@playwright/test'
2+
import { login } from '../helper'
3+
4+
test('Header', async ({ page }) => {
5+
await login(page)
6+
7+
const appBar = await page.getByTestId('appBar')
8+
const breadcrumbs = await appBar.getByTestId('breadcrumbs')
9+
const tooltip = await appBar.getByTestId('helpToolTip')
10+
const tooltipOver = await tooltip.getByTestId('helpOver')
11+
const userMenu = await appBar.getByTestId('userMenu')
12+
13+
// Global Tests
14+
await expect(breadcrumbs).toBeVisible()
15+
await expect(tooltip).toBeVisible()
16+
await expect(tooltipOver).not.toBeVisible()
17+
await expect(userMenu).toBeVisible()
18+
19+
// ToolTip tests
20+
await tooltip.hover()
21+
await expect(tooltipOver).toBeVisible()
22+
23+
// UserMenu tests
24+
const username = await userMenu.getByTestId('username')
25+
const email = await userMenu.getByTestId('userEmail')
26+
const logOutButton = await userMenu.getByTestId('logOutButton')
27+
28+
await expect(username).toBeVisible()
29+
await expect(await username.innerText()).toBe('Admin@example.com')
30+
await expect(email).not.toBeVisible()
31+
await expect(logOutButton).not.toBeVisible()
32+
33+
await userMenu.click()
34+
35+
await expect(email).toBeVisible()
36+
await expect(logOutButton).toBeVisible()
37+
await expect(await email.innerText()).toBe('Admin@example.com')
38+
39+
await logOutButton.click()
40+
41+
await expect(page).toHaveURL(`${process.env.SERVER_BASE_URL}/fr/login`)
42+
await login(page)
43+
})

0 commit comments

Comments
 (0)