Skip to content

Commit e63ea11

Browse files
feat(playwright): add Playwright critical path tests for event creation
Also: - Remove use of broken & unused NEXT_PUBLIC_CMS_TERMS_OF_SERVICE_SLUG_(FI|EN|SV) environment variables - This was done because Playwright couldn't run successfully with the import.meta.env.NEXT_PUBLIC_CMS_TERMS_OF_SERVICE_SLUG_* for some reason - Fix / normalize some Swedish translations - Add data-testid-values to EventForm/CreateOccurrencePage/LocationForm parts for ease-of-use in Playwright tests - Regenerate generated GraphQL types and fix their gql imports to work with Playwright - Add mocks for Playwright tests, mostly copy-pasted from actual network traffic and manually modified for test purposes - Remove running Playwright tests from Github actions, as now the tests require a secret and that can't be easily provided in that environment currently i.e. Playwright tests need to be moved to use City of Helsinki's Azure DevOps environment instead refs PT-1920
1 parent c619927 commit e63ea11

55 files changed

Lines changed: 9764 additions & 5936 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.playwright.local.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
VITE_APP_ORIGIN=http://localhost:3000
2+
VITE_APP_API_URI=http://localhost:8081/graphql
3+
BROWSER_TESTS_JWT_SIGN_SECRET=your-256-bit-secret
4+
BROWSER_TESTS_JWT_ISSUER=https://kultus-admin-ui.test.hel.ninja
5+
VITE_APP_OIDC_API_CLIENT_ID=kultus-api-dev
6+
VITE_APP_OIDC_CLIENT_ID=kultus-admin-ui-dev
7+
VITE_APP_OIDC_AUTHORITY=https://tunnistus.test.hel.ninja/auth/realms/helsinki-tunnistus

.github/workflows/playwright.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

codegen.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ generates:
1212
- 'typescript-operations'
1313
- 'typescript-react-apollo'
1414
config:
15+
gqlImport: graphql-tag#gql
1516
withHooks: true
1617
withComponent: false
1718
src/generated/graphql-cms.tsx:
@@ -22,5 +23,6 @@ generates:
2223
- 'typescript-operations'
2324
- 'typescript-react-apollo'
2425
config:
26+
gqlImport: graphql-tag#gql
2527
withHooks: true
2628
withComponent: false

eslint.config.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ export default [
163163
},
164164
},
165165

166+
// Overrides for Playwright related typescript files
167+
{
168+
files: ['src/playwright/**/*.ts', 'src/playwright/**/*.tsx'],
169+
rules: {
170+
'@typescript-eslint/no-unused-vars': [
171+
'error',
172+
{
173+
// Ignore mock arguments, e.g. mocksForSearchPage in Playwright tests.
174+
// This way mock fixtures can be used without having to always disable the rule.
175+
argsIgnorePattern: '^(mock|mocks|mocking|mocked)[A-Z].*$',
176+
},
177+
],
178+
},
179+
},
180+
166181
// Overrides for test files
167182
{
168183
files: ['**/*.test.js', '**/*.test.ts', '**/*.test.jsx', '**/*.test.tsx'],

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444
"To fix https://github.com/City-of-Helsinki/palvelutarjotin-admin/security/dependabot/125",
4545
"NOTE: This can be removed if hds-react starts to depend on >=v1 cookie"
4646
]
47-
}
47+
},
48+
"Why is playwright version 1.52.0 || ^1.54.0?": [
49+
"Playwright 1.53.0 has a regression that causes tests to fail",
50+
"See https://github.com/microsoft/playwright/issues/36307"
51+
]
4852
},
4953
"resolutions": {
5054
"@testing-library/dom": "^10.4.0",
@@ -60,7 +64,7 @@
6064
"@date-fns/tz": "^1.2.0",
6165
"@datepicker-react/hooks": "^2.8.4",
6266
"@faker-js/faker": "^9.7.0",
63-
"@playwright/test": "^1.52.0",
67+
"@playwright/test": "1.52.0 || ^1.54.0",
6468
"@sentry/browser": "^9.15.0",
6569
"@stylistic/eslint-plugin": "^4.2.0",
6670
"@testing-library/jest-dom": "^6.6.3",
@@ -73,6 +77,7 @@
7377
"@types/draftjs-to-html": "^0.8.4",
7478
"@types/file-saver": "^2.0.7",
7579
"@types/html-to-draftjs": "^1.5.0",
80+
"@types/jsonwebtoken": "^9.0.9",
7681
"@types/lodash": "^4.17.16",
7782
"@types/node": "^20.17.43",
7883
"@types/pretty": "^2.0.3",
@@ -119,10 +124,10 @@
119124
"i18next-intervalplural-postprocessor": "^3.0.0",
120125
"ics": "^3.8.1",
121126
"jsdom": "^26.1.0",
127+
"jsonwebtoken": "^9.0.2",
122128
"msw": "^2.7.6",
123129
"oidc-client": "^1.11.5",
124130
"path": "^0.12.7",
125-
"playwright": "^1.52.0",
126131
"react": "^18.3.1",
127132
"react-content-loader": "^7.0.2",
128133
"react-dom": "^18.3.1",
@@ -165,8 +170,10 @@
165170
"typecheck": "tsc --project ./tsconfig.json --noEmit",
166171
"codegen": "cross-env DOTENV_CONFIG_PATH=\"./.env.development.local\" graphql-codegen -r dotenv/config --config codegen.yml",
167172
"codegen:browser": "playwright codegen",
168-
"test:browser": "playwright test",
169-
"test:browser:ci": "yarn test:browser"
173+
"test:browser:install": "playwright install",
174+
"test:browser": "playwright test --ui",
175+
"test:browser:ci": "playwright test",
176+
"test:browser:report": "playwright show-report report/html"
170177
},
171178
"browserslist": {
172179
"production": [
@@ -192,6 +199,7 @@
192199
"doctoc": "^2.2.1",
193200
"husky": "^9.1.7",
194201
"lint-staged": "^15.5.2",
202+
"playwright": "1.52.0 || ^1.54.0",
195203
"postcss-scss": "^4.0.9",
196204
"prettier": "^3.5.3",
197205
"pretty": "^2.0.0"
@@ -203,4 +211,4 @@
203211
"yarn test:staged"
204212
]
205213
}
206-
}
214+
}

playwright.config.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,62 @@ const useDevServer = webServerType == 'development';
2222

2323
// See https://playwright.dev/docs/test-configuration.
2424
export default defineConfig({
25+
// https://playwright.dev/docs/api/class-testconfig#test-config-output-dir
26+
// The output directory for files created during test execution.
27+
outputDir: './report/test-results',
28+
29+
// https://playwright.dev/docs/api/class-testconfig#test-config-test-dir
30+
// Directory that will be recursively scanned for test files.
2531
testDir: './src/playwright/tests',
32+
2633
// Run tests in files in parallel
2734
fullyParallel: true,
35+
2836
// Fail the build on CI if you accidentally left test.only in the source code.
2937
forbidOnly: !!process.env.CI,
38+
3039
// Retry on CI only
3140
retries: process.env.CI ? 3 : 0,
41+
3242
// Opt out of parallel tests on CI.
3343
workers: process.env.CI ? 1 : undefined,
44+
3445
// Reporter to use. See https://playwright.dev/docs/test-reporters
35-
reporter: 'html',
46+
reporter: [
47+
// For CI pipeline:
48+
['junit', { outputFile: 'report/playwright-junit-results.xml' }],
49+
// For local development:
50+
[
51+
'html',
52+
{
53+
open: process.env.CI ? 'never' : 'on-failure',
54+
outputFolder: 'report/html',
55+
},
56+
],
57+
],
58+
3659
// Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions.
3760
use: {
3861
// Base URL to use in actions like `await page.goto('/')`.
3962
baseURL: process.env.VITE_APP_ORIGIN,
63+
4064
// Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer
4165
trace: 'on-first-retry',
4266

67+
// Use Finnish locale and timezone by default.
4368
locale: 'fi-FI',
4469
timezoneId: 'Europe/Helsinki',
70+
71+
// Use no cookies by defaults.
4572
storageState: { cookies: [], origins: [] },
73+
74+
screenshot: {
75+
fullPage: true,
76+
mode: 'only-on-failure',
77+
},
78+
79+
// https://playwright.dev/docs/videos
80+
video: 'on-first-retry',
4681
},
4782

4883
// Test with the following browsers:
@@ -56,6 +91,6 @@ export default defineConfig({
5691
webServer: {
5792
command: useDevServer ? 'yarn dev' : 'yarn serve',
5893
url: process.env.VITE_APP_ORIGIN,
59-
reuseExistingServer: !process.env.CI,
94+
reuseExistingServer: true,
6095
},
6196
});

src/constants.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,13 @@ export const PRIVACY_POLICY_LINKS = {
3232
fi: 'https://hkih.production.geniem.io/uploads/sites/5/2022/11/739f5edc-rekisteriseloste-kultus.fi_.pdf',
3333
en: 'https://hkih.production.geniem.io/uploads/sites/5/2022/11/bf2f8d34-rekisteriseloste-kultus.fi_en.pdf',
3434
sv: 'https://hkih.production.geniem.io/uploads/sites/5/2022/11/0d425f44-rekisteriseloste-kultus.fi_sv.pdf',
35-
};
35+
} as const;
3636

3737
export const TERMS_OF_SERVICE_SLUGS = {
38-
fi: import.meta.env.NEXT_PUBLIC_CMS_TERMS_OF_SERVICE_SLUG_FI ?? 'kayttoehdot',
39-
en:
40-
import.meta.env.NEXT_PUBLIC_CMS_TERMS_OF_SERVICE_SLUG_EN ??
41-
'terms-of-service',
42-
sv:
43-
import.meta.env.NEXT_PUBLIC_CMS_TERMS_OF_SERVICE_SLUG_SV ??
44-
'anvandarvillkor',
45-
};
38+
fi: 'kayttoehdot',
39+
en: 'terms-of-service',
40+
sv: 'anvandarvillkor',
41+
} as const;
4642

4743
export const createEmptyLocalizedObject = (): LocalisedObject => ({
4844
[SUPPORT_LANGUAGES.FI]: '',

src/domain/app/AppConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class AppConfig {
8383
return getEnvAsUrl('VITE_APP_ORIGIN').origin;
8484
}
8585

86-
static get kukkuuApiGraphqlEndpoint() {
86+
static get kultusApiGraphqlEndpoint() {
8787
return getEnvOrError(import.meta.env.VITE_APP_API_URI, 'VITE_APP_API_URI');
8888
}
8989

src/domain/app/apollo/apolloClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let apolloClient: ApolloClient<NormalizedCacheObject> | undefined;
3030
*/
3131
function createApolloClient(): ApolloClient<NormalizedCacheObject> {
3232
const httpLink = createUploadLink({
33-
uri: AppConfig.kukkuuApiGraphqlEndpoint,
33+
uri: AppConfig.kultusApiGraphqlEndpoint,
3434
fetch,
3535
});
3636

src/domain/app/i18n/sv.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@
416416
"descriptionAddImage": "Lägg till en bild för evenemanget. Du behöver också namnet på fotografen och en publiceringslicens. Maximal storlek 2 megabyte. Rekommenderad bildstorlek är 1200 x 800 px.",
417417
"imageAltTextHelp": "Beskrivning av innehållet i bilden. Lägg till licensinformation också.",
418418
"labelDescription": "Beskrivning (SV)",
419-
"labelMandatoryAdditionalInformation": "De som anmäler sig måste ange tilläggsinformation.",
419+
"labelMandatoryAdditionalInformation": "De som anmäler sig måste ange tilläggsinformation",
420420
"guidanceTextMandatoryAdditionalInformation": "Ifall du vill ha tilläggsinformation om gruppen i samband med bokningen meddela om detta i beskrivningen av evenemanget",
421421
"labelEnrolmentEndDays": "Anmälan stänger X dagar före evenemangstiden",
422422
"labelEnrolmentStartDate": "Registrering börjar",
@@ -459,7 +459,7 @@
459459
"offers": {
460460
"title": "Evenemangets prissättning",
461461
"labelIsFree": "Evenemanget är gratis",
462-
"labelPrice": "Pris €",
462+
"labelPrice": "Pris,",
463463
"labelPriceDescription": "Tilläggsinformation (SV)",
464464
"placeholderPriceDescription": "pris per barn/grupp,\nhur man betala (faktura eller bankkort),\navbokningspolicy"
465465
},
@@ -520,7 +520,7 @@
520520
"buttonLoadMore": "Visa mer",
521521
"buttonNewEvent": "Lägg till ett nytt evenemang",
522522
"eventCard": {
523-
"ariaLabelOpenOccurrences": "Gå till evenemangstid av {{eventName}}",
523+
"ariaLabelOpenOccurrences": "Gå till evenemangstid av {{eventName}}",
524524
"textEnrolments": "{{count}} registrerad",
525525
"textEnrolments_other": "{{count}} registrerade",
526526
"textExternalEnrolments": "Anmälan på en annan webbplats",
@@ -855,7 +855,7 @@
855855
"age34": "3-4 åringar",
856856
"other": "Annan grupp"
857857
},
858-
"Evenemangsplats": {
858+
"venue": {
859859
"venueDataFields": {
860860
"helperLocationDescription": "Ytterligare information för att underlätta besöket",
861861
"labelHasClothingStorage": "Förvaring av ytterkläder",

0 commit comments

Comments
 (0)