From 3c0b26bca58d74739820d69d389ed8ff6e3ce84e Mon Sep 17 00:00:00 2001 From: Helene Lotsberg Date: Mon, 26 Oct 2026 13:13:14 +0100 Subject: [PATCH 01/22] setup and install Playwright for e2e tests --- .gitignore | 5 +++ e2e/explore-plants.spec.ts | 8 +++++ package-lock.json | 64 ++++++++++++++++++++++++++++++++++++++ package.json | 4 +++ playwright.config.ts | 27 ++++++++++++++++ tsconfig.json | 12 +++++++ 6 files changed, 120 insertions(+) create mode 100644 e2e/explore-plants.spec.ts create mode 100644 playwright.config.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 2d61bff7..0e00e5c3 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,8 @@ lerna-debug.log* *.njsproj *.sln *.sw? + +# Playwright (e2e) +test-results/ +playwright-report/ +playwright/.cache/ \ No newline at end of file diff --git a/e2e/explore-plants.spec.ts b/e2e/explore-plants.spec.ts new file mode 100644 index 00000000..1ff9a6bb --- /dev/null +++ b/e2e/explore-plants.spec.ts @@ -0,0 +1,8 @@ +import { test, expect } from '@playwright/test'; + +test('explore-siden laster og viser planter', async ({ page }) => { + await page.goto(''); // = baseURL (/project2/) + + // Bytt ut med noe som faktisk finnes på siden deres: + await expect(page.getByRole('heading', { level: 1 })).toBeVisible(); +}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f0ec1bd9..04e3acd7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,10 +6,38 @@ "": { "name": "t03-project-2", "devDependencies": { + "@playwright/test": "^1.64.1", + "@types/node": "^26.6.5", "concurrently": "^9.2.1", "prettier": "3.9.10" } }, + "node_modules/@playwright/test": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.64.1.tgz", + "integrity": "sha512-IaYGml/nSOiZWROfPtuIL7neuu9qDOZ3TNvNljUIrhDMxiGTgPjzj/g9p9RxpS2tSepPDRY+UwAaEeiKtUvIAg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.64.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@types/node": { + "version": "26.6.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.5.tgz", + "integrity": "sha512-uMzsv9stDdofIZBx4UGh4Z9ZgXnGC9seRDscilBcTHAeOFk67MZg/k9bWVfO+bk4qZmG+l52hRnLwUiH2LnJTg==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~8.9.0" + } + }, "node_modules/ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -173,6 +201,35 @@ "node": ">=8" } }, + "node_modules/playwright": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.64.1.tgz", + "integrity": "sha512-HCrVhHr5QQuwYoswEUGTb7gGp522yflbv/ST8nF4sFWGuLjQCt17Q/EubpGGSNKYn1tsTCPZxqHhHCfVURu7UA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.64.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/playwright-core": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.1.tgz", + "integrity": "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/prettier": { "version": "3.9.10", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.10.tgz", @@ -283,6 +340,13 @@ "dev": true, "license": "0BSD" }, + "node_modules/undici-types": { + "version": "8.9.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.9.0.tgz", + "integrity": "sha512-KTDyRTYX8sWmKXAikPHHSyc63CRPETMctyjKFupcC6OBLXT3xsN0e9aF7m+mIXutFWpUXuedtowG7iLOzp0kQg==", + "dev": true, + "license": "MIT" + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", diff --git a/package.json b/package.json index 46aa0e83..f2027393 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,14 @@ "build": "npm run build --prefix backend && npm run build --prefix frontend", "lint": "npm run lint --prefix backend && npm run lint --prefix frontend", "test": "npm test --prefix frontend -- --run", + "test:e2e": "playwright test", + "test:e2e:ui": "playwright test --ui", "format": "prettier --write .", "format:check": "prettier --check ." }, "devDependencies": { + "@playwright/test": "^1.64.1", + "@types/node": "^26.6.5", "concurrently": "^9.2.1", "prettier": "3.9.10" } diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 00000000..35bbf6be --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,27 @@ +import { defineConfig, devices } from '@playwright/test'; + +export default defineConfig({ + testDir: './e2e', + workers: 1, + retries: process.env.CI ? 1 : 0, + failOnFlakyTests: !!process.env.CI, + reporter: [ + ['list'], + ['html', { open: 'never' }], + ...(process.env.CI ? [['github'] as const] : []), + ], + use: { + baseURL: 'http://localhost:5173/project2/', + trace: 'retain-on-failure', + }, + projects: [ + { name: 'desktop', use: { ...devices['Desktop Chrome'] } }, + { name: 'mobil', use: { ...devices['Pixel 7'] } }, + ], + webServer: { + command: 'npm run dev', + url: 'http://localhost:5173/project2/', + reuseExistingServer: !process.env.CI, + timeout: 120_000, + }, +}); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..c8e929c1 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "moduleResolution": "bundler", + "strict": true, + "noEmit": true, + "skipLibCheck": true, + "types": ["node"] + }, + "include": ["playwright.config.ts", "e2e"] +} \ No newline at end of file From 2eb48175eb7273f31d5e75f27f32d4cbc9a88d53 Mon Sep 17 00:00:00 2001 From: Helene Lotsberg Date: Mon, 26 Oct 2026 13:49:56 +0100 Subject: [PATCH 02/22] setup test-db --- e2e/fixtures/plants.json | 22 ++ e2e/global-setup.ts | 20 ++ e2e/start-test-db.mjs | 14 + e2e/test-db.ts | 5 + package-lock.json | 691 +++++++++++++++++++++++++++++++++++++++ package.json | 2 + 6 files changed, 754 insertions(+) create mode 100644 e2e/fixtures/plants.json create mode 100644 e2e/global-setup.ts create mode 100644 e2e/start-test-db.mjs create mode 100644 e2e/test-db.ts diff --git a/e2e/fixtures/plants.json b/e2e/fixtures/plants.json new file mode 100644 index 00000000..e65472cf --- /dev/null +++ b/e2e/fixtures/plants.json @@ -0,0 +1,22 @@ +[ + { "perenualId": 1, "commonName": "Aloe Vera", "scientificName": ["Aloe vera"], "watering": "Minimum", "sunlight": ["full sun"], "careLevel": "Low", "description": "A succulent with thick, fleshy leaves.", "imageData": null }, + { "perenualId": 2, "commonName": "Boston Fern", "scientificName": ["Nephrolepis exaltata"], "watering": "Frequent", "sunlight": ["filtered shade"], "careLevel": "Medium", "description": "A fern with long, arching fronds.", "imageData": null }, + { "perenualId": 3, "commonName": "Fiddle Leaf Fig", "scientificName": ["Ficus lyrata"], "watering": "Average", "sunlight": ["full sun", "part shade"], "careLevel": "High", "description": "A tree with large, violin-shaped leaves.", "imageData": null }, + { "perenualId": 4, "commonName": "Jade Plant", "scientificName": ["Crassula ovata"], "watering": "Minimum", "sunlight": ["full sun"], "careLevel": "Low", "description": "A succulent with round, glossy leaves.", "imageData": null }, + { "perenualId": 5, "commonName": "Monstera", "scientificName": ["Monstera deliciosa"], "watering": "Average", "sunlight": ["part shade"], "careLevel": "Moderate", "description": "A climbing plant with split leaves.", "imageData": null }, + { "perenualId": 6, "commonName": "Peace Lily", "scientificName": ["Spathiphyllum wallisii"], "watering": "Frequent", "sunlight": ["part shade", "filtered shade"], "careLevel": "Medium", "description": "A plant with white flowers and dark leaves.", "imageData": null }, + { "perenualId": 7, "commonName": "Pothos", "scientificName": ["Epipremnum aureum"], "watering": "Average", "sunlight": ["part shade"], "careLevel": "Low", "description": "A trailing vine with heart-shaped leaves.", "imageData": null }, + { "perenualId": 8, "commonName": "Snake Plant", "scientificName": ["Dracaena trifasciata"], "watering": "Minimum", "sunlight": ["part shade", "full sun"], "careLevel": null, "description": "A plant with stiff, upright leaves.", "imageData": null }, + { "perenualId": 9, "commonName": "Calathea", "scientificName": ["Goeppertia orbifolia"], "watering": "Average", "sunlight": ["filtered shade"], "careLevel": "High", "description": "A plant with large, striped leaves.", "imageData": null }, + { "perenualId": 10, "commonName": "Chinese Evergreen", "scientificName": ["Aglaonema commutatum"], "watering": "Average", "sunlight": ["part shade"], "careLevel": "Low", "description": "A bushy plant with patterned leaves.", "imageData": null }, + { "perenualId": 11, "commonName": "Dracaena", "scientificName": ["Dracaena fragrans"], "watering": "Average", "sunlight": ["filtered shade"], "careLevel": "Low", "description": "A small tree with long, narrow leaves.", "imageData": null }, + { "perenualId": 12, "commonName": "English Ivy", "scientificName": ["Hedera helix"], "watering": "Average", "sunlight": ["part shade", "full sun"], "careLevel": "Medium", "description": "A climbing vine with lobed leaves.", "imageData": null }, + { "perenualId": 13, "commonName": "Golden Barrel Cactus", "scientificName": ["Echinocactus grusonii"], "watering": "Minimum", "sunlight": ["full sun"], "careLevel": "Low", "description": "A round cactus with golden spines.", "imageData": null }, + { "perenualId": 14, "commonName": "Hoya", "scientificName": ["Hoya carnosa"], "watering": "Average", "sunlight": ["part shade"], "careLevel": "Medium", "description": "A vine with waxy leaves and star-shaped flowers.", "imageData": null }, + { "perenualId": 15, "commonName": "Lavender", "scientificName": ["Lavandula angustifolia"], "watering": "Minimum", "sunlight": ["full sun"], "careLevel": "Moderate", "description": "A fragrant shrub with purple flowers.", "imageData": null }, + { "perenualId": 16, "commonName": "Maidenhair Fern", "scientificName": ["Adiantum raddianum"], "watering": "Frequent", "sunlight": ["filtered shade"], "careLevel": "High", "description": "A fern with delicate, fan-shaped leaves.", "imageData": null }, + { "perenualId": 17, "commonName": "Moth Orchid", "scientificName": ["Phalaenopsis amabilis"], "watering": "Average", "sunlight": ["filtered shade"], "careLevel": "High", "description": "An orchid with long-lasting flowers.", "imageData": null }, + { "perenualId": 18, "commonName": "Rubber Tree", "scientificName": ["Ficus elastica"], "watering": "Average", "sunlight": ["full sun", "part shade"], "careLevel": "Medium", "description": "A tree with large, glossy leaves.", "imageData": null }, + { "perenualId": 19, "commonName": "String of Pearls", "scientificName": ["Curio rowleyanus"], "watering": "Minimum", "sunlight": ["full sun"], "careLevel": "Low", "description": "A trailing succulent with bead-like leaves.", "imageData": null }, + { "perenualId": 20, "commonName": "Zebra Haworthia", "scientificName": ["Haworthiopsis attenuata"], "watering": "Minimum", "sunlight": ["part shade"], "careLevel": "Low", "description": "A small succulent with white-striped leaves.", "imageData": null } +] \ No newline at end of file diff --git a/e2e/global-setup.ts b/e2e/global-setup.ts new file mode 100644 index 00000000..c6adb703 --- /dev/null +++ b/e2e/global-setup.ts @@ -0,0 +1,20 @@ +import { readFile } from 'node:fs/promises'; +import { MongoClient } from 'mongodb'; +import { E2E_DB_NAME, E2E_MONGODB_URI } from './test-db'; + +// Kjøres én gang før alle testene: tømmer testdatabasen og fyller den med faste planter, +// slik at hver testkjøring starter fra nøyaktig samme data. +export default async function globalSetup() { + // Stien er relativ til roten, der Playwright kjøres fra + const plants = JSON.parse(await readFile('e2e/fixtures/plants.json', 'utf8')); + + const client = new MongoClient(E2E_MONGODB_URI); + try { + await client.connect(); + const db = client.db(E2E_DB_NAME); + await db.dropDatabase(); // fjerner også brukere og matcher fra forrige kjøring + await db.collection('plants').insertMany(plants); + } finally { + await client.close(); + } +} \ No newline at end of file diff --git a/e2e/start-test-db.mjs b/e2e/start-test-db.mjs new file mode 100644 index 00000000..7910b5a0 --- /dev/null +++ b/e2e/start-test-db.mjs @@ -0,0 +1,14 @@ +// Starter en MongoDB i minnet for e2e-testene. Playwright kjører dette scriptet +// som en webServer og stopper det når testene er ferdige. +import { MongoMemoryServer } from 'mongodb-memory-server'; + +const port = Number(process.env.E2E_DB_PORT); +const mongod = await MongoMemoryServer.create({ instance: { port } }); +console.log(`Testdatabasen kjører på ${mongod.getUri()}`); + +const stop = async () => { + await mongod.stop(); + process.exit(0); +}; +process.on('SIGINT', stop); +process.on('SIGTERM', stop); \ No newline at end of file diff --git a/e2e/test-db.ts b/e2e/test-db.ts new file mode 100644 index 00000000..1870544d --- /dev/null +++ b/e2e/test-db.ts @@ -0,0 +1,5 @@ +// Felles innstillinger for testdatabasen, brukt av playwright.config.ts og global-setup.ts. +// Port 27018 så den ikke kolliderer med SSH-tunnelen til VM-en på 27017. +export const E2E_DB_PORT = 27018; +export const E2E_MONGODB_URI = `mongodb://127.0.0.1:${E2E_DB_PORT}`; +export const E2E_DB_NAME = 'iloveplants_e2e'; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 04e3acd7..6d9b5e4f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,21 @@ "@playwright/test": "^1.64.1", "@types/node": "^26.6.5", "concurrently": "^9.2.1", + "mongodb": "^7.7.0", + "mongodb-memory-server": "^11.3.0", "prettier": "3.9.10" } }, + "node_modules/@mongodb-js/saslprep": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.6.1.tgz", + "integrity": "sha512-D4CQtk9IwjCLAvCf1xvHEod3960q8XMUzfmdRU9qjUNlHnesGuTOvJcOTaPm9koZ1caUKA2aTbszZiAkcmSgmg==", + "dev": true, + "license": "MIT", + "dependencies": { + "sparse-bitfield": "^3.0.3" + } + }, "node_modules/@playwright/test": { "version": "1.64.1", "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.64.1.tgz", @@ -38,6 +50,33 @@ "undici-types": "~8.9.0" } }, + "node_modules/@types/webidl-conversions": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", + "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/whatwg-url": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-13.0.0.tgz", + "integrity": "sha512-N8WXpbE6Wgri7KUSvrmQcqrMllKZ9uxkYWMt+mCSGwNc0Hsw9VQTW7ApqI4XNrx6/SaM2QQJCzMPDEXE058s+Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/webidl-conversions": "*" + } + }, + "node_modules/agent-base": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", + "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, "node_modules/ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -64,6 +103,139 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/async-mutex": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.5.0.tgz", + "integrity": "sha512-1A94B18jkJ3DYq284ohPxoXbfTA5HsQ7/Mf4DEhcyLx3Bz27Rh59iScbB6EPiP+B+joue6YCxcMXSbFC1tZKwA==", + "dev": true, + "license": "MIT", + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/b4a": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.9.0.tgz", + "integrity": "sha512-dpfcF9fDNR6++cthXR67iyhgqWy9CBouAvIWhIntzBG6cvK/cnIPiZQjBwi/ZqjjBEDGfoNDtmB0kTjroOJ3pQ==", + "dev": true, + "license": "Apache-2.0", + "peerDependencies": { + "react-native-b4a": "*" + }, + "peerDependenciesMeta": { + "react-native-b4a": { + "optional": true + } + } + }, + "node_modules/bare-events": { + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.9.2.tgz", + "integrity": "sha512-AIPKioV7/Y/8KfZ3AAhjPJxLLbY49S64Ym5DakZlUg75qQiTgUq9hEJoEwa4eUezPUlXRy/i5NpsKvo9jgKmoA==", + "dev": true, + "license": "Apache-2.0", + "peerDependencies": { + "bare-abort-controller": "*" + }, + "peerDependenciesMeta": { + "bare-abort-controller": { + "optional": true + } + } + }, + "node_modules/bare-fs": { + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-4.8.4.tgz", + "integrity": "sha512-MPC2eyrpbk3A873sK4y6rk+Iv4o2enxTjHZ8zH3HO0mjrpm5XjnguY2XmfidIsDV6vnjpbMBKUAJpV0ISD2SsQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "bare-events": "^2.5.4", + "bare-path": "^3.0.0", + "bare-stream": "^2.6.4", + "bare-url": "^2.2.2", + "fast-fifo": "^1.3.2" + }, + "engines": { + "bare": ">=1.28.0" + }, + "peerDependencies": { + "bare-buffer": "*" + }, + "peerDependenciesMeta": { + "bare-buffer": { + "optional": true + } + } + }, + "node_modules/bare-path": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bare-path/-/bare-path-3.1.2.tgz", + "integrity": "sha512-ZyKbsuuqK6Ag0K8pX6V5Txq6XeJRvY+wXucnFGRjiyVYP9YWDpIQugk/b+enRYrEYBJaqLzghRQpXPMR7341Nw==", + "dev": true, + "license": "Apache-2.0" + }, + "node_modules/bare-stream": { + "version": "2.13.4", + "resolved": "https://registry.npmjs.org/bare-stream/-/bare-stream-2.13.4.tgz", + "integrity": "sha512-PcrQ8lVLbiJscNm1Kez+Yp4Gy4AHGcN1lzwjvf5NybWen7VvEgUfyfnXYJ2zNqWnzOfCb1Abq6lH8ti0syQszA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "b4a": "^1.8.1", + "streamx": "^2.25.0", + "teex": "^1.0.1" + }, + "peerDependencies": { + "bare-abort-controller": "*", + "bare-buffer": "*", + "bare-events": "*" + }, + "peerDependenciesMeta": { + "bare-abort-controller": { + "optional": true + }, + "bare-buffer": { + "optional": true + }, + "bare-events": { + "optional": true + } + } + }, + "node_modules/bare-url": { + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/bare-url/-/bare-url-2.5.5.tgz", + "integrity": "sha512-iM9qJCruvpt2rPaLsrumVDru9pogI7PHziHIa9kTNRFt8C8HuSa+kI9kFezK+NvHEFnnz71rKGZ1EAilq/3V/Q==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "bare-path": "^3.0.0" + } + }, + "node_modules/bson": { + "version": "7.3.3", + "resolved": "https://registry.npmjs.org/bson/-/bson-7.3.3.tgz", + "integrity": "sha512-oz3LwE3qGEhTCSyhzQRLY3Bj1NLOsjFMf6tcmY5J8M+3R7EVcmoBfSHWvjUK3yXCLDUsGpIuB3aQL4nDZ1EV/g==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -129,6 +301,13 @@ "dev": true, "license": "MIT" }, + "node_modules/commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==", + "dev": true, + "license": "MIT" + }, "node_modules/concurrently": { "version": "9.2.5", "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-9.2.5.tgz", @@ -154,6 +333,24 @@ "url": "https://github.com/open-cli-tools/concurrently?sponsor=1" } }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -171,6 +368,76 @@ "node": ">=6" } }, + "node_modules/events-universal": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/events-universal/-/events-universal-1.0.1.tgz", + "integrity": "sha512-LUd5euvbMLpwOF8m6ivPCbhQeSiYVNb8Vs0fQ8QjXo0JTkEHpz8pxdQf0gStltaPpw0Cca8b39KxvK9cfKRiAw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "bare-events": "^2.7.0" + } + }, + "node_modules/fast-fifo": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.2.tgz", + "integrity": "sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/find-cache-dir": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.2.tgz", + "integrity": "sha512-wXZV5emFEjrridIgED11OoUKLxiYjAcqot/NJdAkOhlJ+vGzwhOAfcG5OX1jP+S0PcjEn8bdMJv+g2jwQ3Onig==", + "dev": true, + "license": "MIT", + "dependencies": { + "commondir": "^1.0.1", + "make-dir": "^3.0.2", + "pkg-dir": "^4.1.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/avajs/find-cache-dir?sponsor=1" + } + }, + "node_modules/find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "dev": true, + "license": "MIT", + "dependencies": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/follow-redirects": { + "version": "1.16.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.2.tgz", + "integrity": "sha512-/kVP2U8z596Ia0gwFrwyIeo74ta5aVmSeU1FfAUMAmcEP5EP7zydmag3SLiN64NaRKef3lxsq7i/g7ltJQDGow==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -191,6 +458,20 @@ "node": ">=8" } }, + "node_modules/https-proxy-agent": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", @@ -201,6 +482,288 @@ "node": ">=8" } }, + "node_modules/locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-locate": "^4.1.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dev": true, + "license": "MIT", + "dependencies": { + "semver": "^6.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/make-dir/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "dev": true, + "license": "MIT" + }, + "node_modules/mongodb": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.7.0.tgz", + "integrity": "sha512-XG1xXEqyouAV8GCb3PuRaujofeXKpAJAPvXYWZgHl6Dz4QHSJ1nRLl0+GpqaLTwKvC0RFE9truOur34RNFY1nw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@mongodb-js/saslprep": "^1.5.0", + "bson": "^7.3.2", + "mongodb-connection-string-url": "^7.0.2" + }, + "engines": { + "node": ">=20.19.0" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.806.0", + "@mongodb-js/zstd": "^7.0.0", + "gcp-metadata": "^7.0.1", + "kerberos": "^7.0.0", + "mongodb-client-encryption": "^7.2.0", + "snappy": "^7.3.2", + "socks": "^2.8.6" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "@mongodb-js/zstd": { + "optional": true + }, + "gcp-metadata": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + }, + "socks": { + "optional": true + } + } + }, + "node_modules/mongodb-connection-string-url": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-7.0.2.tgz", + "integrity": "sha512-ZoS07RoFqpKYQwAk59qmrx8+jJHNHU30UjlU96QktiGn1ltvDr+vCznLX5DiUBLEpMAHatHNWV1nM/74ul66kA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@types/whatwg-url": "^13.0.0", + "whatwg-url": "^14.1.0" + }, + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/mongodb-memory-server": { + "version": "11.3.0", + "resolved": "https://registry.npmjs.org/mongodb-memory-server/-/mongodb-memory-server-11.3.0.tgz", + "integrity": "sha512-8ZCDrraqKqmAikoeKuEq+16jeWdVKwjtEAuMxxeQctHiGSGYt17W9LmoRzV1Nwnz7owyxwDKMhow4IVkNYYRKw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "mongodb-memory-server-core": "11.3.0", + "tslib": "^2.8.1" + }, + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/mongodb-memory-server-core": { + "version": "11.3.0", + "resolved": "https://registry.npmjs.org/mongodb-memory-server-core/-/mongodb-memory-server-core-11.3.0.tgz", + "integrity": "sha512-QBu/RsRpBfcNd5CrBDfCzqcaFPaYpivUzGYUy9YgVc3up78ff0gIHQVD9PLmBLOOxFX6BM9hU6YT0HocZH+s1g==", + "dev": true, + "license": "MIT", + "dependencies": { + "async-mutex": "^0.5.0", + "camelcase": "^6.3.0", + "debug": "^4.4.3", + "find-cache-dir": "^3.3.2", + "follow-redirects": "^1.16.0", + "https-proxy-agent": "^7.0.6", + "mongodb": "~7.5.0", + "new-find-package-json": "^2.0.0", + "semver": "^7.8.5", + "tar-stream": "^3.2.1", + "tslib": "^2.8.1", + "yauzl": "^3.4.0" + }, + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/mongodb-memory-server-core/node_modules/mongodb": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.5.0.tgz", + "integrity": "sha512-5FnrEDLnvp6ycUOGLNLLU33BfCx2qmp2mJjGPDwKLruYsVzXVSK5fsGpoDXvsXJwBfBsD7ebMRdawbDxC2814g==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@mongodb-js/saslprep": "^1.4.11", + "bson": "^7.2.0", + "mongodb-connection-string-url": "^7.0.1" + }, + "engines": { + "node": ">=20.19.0" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.806.0", + "@mongodb-js/zstd": "^7.0.0", + "gcp-metadata": "^7.0.1", + "kerberos": "^7.0.0", + "mongodb-client-encryption": "^7.2.0", + "snappy": "^7.3.2", + "socks": "^2.8.6" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "@mongodb-js/zstd": { + "optional": true + }, + "gcp-metadata": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + }, + "socks": { + "optional": true + } + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/new-find-package-json": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/new-find-package-json/-/new-find-package-json-2.0.0.tgz", + "integrity": "sha512-lDcBsjBSMlj3LXH2v/FW3txlh2pYTjmbOXPYJD93HI5EwuLzI11tdHSIpUMmfq/IOsldj4Ps8M8flhm+pCK4Ew==", + "dev": true, + "license": "MIT", + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">=12.22.0" + } + }, + "node_modules/p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-try": "^2.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-limit": "^2.2.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", + "dev": true, + "license": "MIT" + }, + "node_modules/pkg-dir": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", + "integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "find-up": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/playwright": { "version": "1.64.1", "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.64.1.tgz", @@ -246,6 +809,16 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -266,6 +839,19 @@ "tslib": "^2.1.0" } }, + "node_modules/semver": { + "version": "7.8.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", + "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/shell-quote": { "version": "1.12.0", "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.12.0.tgz", @@ -279,6 +865,28 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "memory-pager": "^1.0.2" + } + }, + "node_modules/streamx": { + "version": "2.28.1", + "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.28.1.tgz", + "integrity": "sha512-zEzXb0s5Cds7tqMH6rhZ05lcJydCWiQPEwiNngVqzsxCc962vLY4Uw+mW7od8kDH258k2Uz/JrOkdIAAhSh9VA==", + "dev": true, + "license": "MIT", + "dependencies": { + "events-universal": "^1.0.0", + "fast-fifo": "^1.3.2", + "text-decoder": "^1.1.0" + } + }, "node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -323,6 +931,52 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, + "node_modules/tar-stream": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.2.2.tgz", + "integrity": "sha512-+8NeqHRjQWH9nYlwo2gamAMImZCVzI4UoEgDpWorBt9OEfppiZn+uSkskzQKPWIZyji/C8fpWO7u69G0DX0tbg==", + "dev": true, + "license": "MIT", + "dependencies": { + "b4a": "^1.9.0", + "bare-fs": "^4.8.2", + "fast-fifo": "^1.3.2", + "streamx": "^2.28.1" + } + }, + "node_modules/teex": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/teex/-/teex-1.0.1.tgz", + "integrity": "sha512-eYE6iEI62Ni1H8oIa7KlDU6uQBtqr4Eajni3wX7rpfXD8ysFx8z0+dri+KWEPWpBsxXfxu58x/0jvTVT1ekOSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "streamx": "^2.12.5" + } + }, + "node_modules/text-decoder": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/text-decoder/-/text-decoder-1.2.7.tgz", + "integrity": "sha512-vlLytXkeP4xvEq2otHeJfSQIRyWxo/oZGEbXrtEEF9Hnmrdly59sUbzZ/QgyWuLYHctCHxFF4tRQZNQ9k60ExQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "b4a": "^1.6.4" + } + }, + "node_modules/tr46": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", + "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", + "dev": true, + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/tree-kill": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", @@ -347,6 +1001,30 @@ "dev": true, "license": "MIT" }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-url": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "dev": true, + "license": "MIT", + "dependencies": { + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -403,6 +1081,19 @@ "engines": { "node": ">=12" } + }, + "node_modules/yauzl": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-3.4.0.tgz", + "integrity": "sha512-jIH9yLR9wqr0wOS0TpBvo/g/2UgZH5qePVbjgRliiF0BYvOZyaBknKsF+x9Iht0O6sqgnB93rCICdOZFecJuDw==", + "dev": true, + "license": "MIT", + "dependencies": { + "pend": "~1.2.0" + }, + "engines": { + "node": ">=12" + } } } } diff --git a/package.json b/package.json index f2027393..3b7ed00c 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,8 @@ "@playwright/test": "^1.64.1", "@types/node": "^26.6.5", "concurrently": "^9.2.1", + "mongodb": "^7.7.0", + "mongodb-memory-server": "^11.3.0", "prettier": "3.9.10" } } From 4a84441b3165fa4d3d2207842b006f73b0c036b0 Mon Sep 17 00:00:00 2001 From: Helene Lotsberg Date: Mon, 26 Oct 2026 14:59:42 +0100 Subject: [PATCH 03/22] created ui and api folders in e2e to seperate the two --- e2e/api/api-explore-page.spec.ts | 107 +++++++++++++++++++++++++++++++ e2e/ui/ui-explore-page.spec.ts | 61 ++++++++++++++++++ playwright.config.ts | 59 ++++++++++++++--- 3 files changed, 217 insertions(+), 10 deletions(-) create mode 100644 e2e/api/api-explore-page.spec.ts create mode 100644 e2e/ui/ui-explore-page.spec.ts diff --git a/e2e/api/api-explore-page.spec.ts b/e2e/api/api-explore-page.spec.ts new file mode 100644 index 00000000..129b5ec1 --- /dev/null +++ b/e2e/api/api-explore-page.spec.ts @@ -0,0 +1,107 @@ +import { test, expect, type APIRequestContext } from '@playwright/test'; + +// Tester explorePlants-queryen direkte mot testbackenden. +// Forventede verdier er basert på de 20 plantene i e2e/fixtures/plants.json. + +const EXPLORE_PLANTS = ` + query ExplorePlants( + $search: String + $sunlight: String + $watering: String + $careLevel: String + $sort: String + $limit: Int + $offset: Int + ) { + explorePlants( + search: $search + sunlight: $sunlight + watering: $watering + careLevel: $careLevel + sort: $sort + limit: $limit + offset: $offset + ) { + totalCount + plants { + name + } + } + } +`; + +interface ExploreResult { + totalCount: number; + plants: { name: string }[]; +} + +// Sender queryen og sjekker at svaret ikke inneholder GraphQL-feil +async function explorePlants( + request: APIRequestContext, + variables: Record = {}, +): Promise { + const res = await request.post('graphql', { + data: { query: EXPLORE_PLANTS, variables }, + }); + expect(res.ok()).toBeTruthy(); + const body = await res.json(); + expect(body.errors).toBeUndefined(); + return body.data.explorePlants; +} + +const names = (result: ExploreResult) => result.plants.map((p) => p.name); + +test.describe('explorePlants', () => { + test('uten argumenter gir første side sortert a–z', async ({ request }) => { + const result = await explorePlants(request); + expect(result.totalCount).toBe(20); + expect(result.plants).toHaveLength(12); + expect(result.plants[0].name).toBe('Aloe Vera'); + }); + + test('offset gir neste side', async ({ request }) => { + const result = await explorePlants(request, { offset: 12 }); + expect(result.totalCount).toBe(20); + expect(result.plants).toHaveLength(8); + expect(result.plants[0].name).toBe('Monstera'); + }); + + test('søk er case-insensitivt', async ({ request }) => { + const result = await explorePlants(request, { search: 'PLANT' }); + expect(result.totalCount).toBe(2); + expect(names(result)).toEqual(['Jade Plant', 'Snake Plant']); + }); + + test('søk med regex-tegn tolkes som vanlig tekst', async ({ request }) => { + const result = await explorePlants(request, { search: '.*' }); + expect(result.totalCount).toBe(0); + }); + + test('care level medium inkluderer Moderate', async ({ request }) => { + const result = await explorePlants(request, { careLevel: 'medium' }); + expect(result.totalCount).toBe(7); + expect(names(result)).toEqual(expect.arrayContaining(['Monstera', 'Lavender'])); + }); + + test('watering-filter', async ({ request }) => { + const result = await explorePlants(request, { watering: 'minimum' }); + expect(result.totalCount).toBe(7); + }); + + test('sortering z–a', async ({ request }) => { + const result = await explorePlants(request, { sort: 'name_desc' }); + expect(result.plants[0].name).toBe('Zebra Haworthia'); + }); + + test('planter uten care level havner sist', async ({ request }) => { + const result = await explorePlants(request, { sort: 'careLevel_asc', limit: 20 }); + expect(result.plants[0].name).toBe('Aloe Vera'); + expect(result.plants.at(-1)?.name).toBe('Snake Plant'); + }); + + // Feiler til sunlight-filteret er implementert i backend (resolveren ignorerer det i dag) + test('sunlight-filter', async ({ request }) => { + const result = await explorePlants(request, { sunlight: 'full_sun' }); + expect(result.totalCount).toBe(9); + }); +}); \ No newline at end of file diff --git a/e2e/ui/ui-explore-page.spec.ts b/e2e/ui/ui-explore-page.spec.ts new file mode 100644 index 00000000..16618918 --- /dev/null +++ b/e2e/ui/ui-explore-page.spec.ts @@ -0,0 +1,61 @@ +import { test, expect } from '@playwright/test'; + +// En sammenhengende brukerreise på ExplorePlants, basert på de 20 plantene i +// e2e/fixtures/plants.json. Locatorene er språkuavhengige (roller, option-verdier og +// CSS-klasser), så testen fungerer både på norsk og engelsk. + +test('bruker blar, filtrerer, søker, sorterer og nullstiller', async ({ page }) => { + const cards = page.locator('.plant-grid > li'); + const searchField = page.getByRole('searchbox'); + // Care level er den eneste select-en med "high" som valg + const careLevelSelect = page.locator('select').filter({ + has: page.locator('option[value="high"]'), + }); + const pagination = page.locator('.pagination'); + const previousButton = pagination.getByRole('button').first(); + const nextButton = pagination.getByRole('button').last(); + + await test.step('første side viser 12 planter sortert a–z', async () => { + await page.goto('explorePlants'); + await expect(cards).toHaveCount(12); + await expect(cards.first()).toContainText('Aloe Vera'); + await expect(previousButton).toBeDisabled(); + }); + + await test.step('neste side viser de 8 siste', async () => { + await nextButton.click(); + await expect(cards).toHaveCount(8); + await expect(cards.first()).toContainText('Monstera'); + await expect(nextButton).toBeDisabled(); + }); + + await test.step('filter fra side 2 sender brukeren tilbake til side 1', async () => { + await careLevelSelect.selectOption('medium'); + await expect(cards).toHaveCount(7); // inkluderer "Moderate" + await expect(cards.first()).toContainText('Boston Fern'); + await expect(previousButton).toBeDisabled(); + }); + + await test.step('søk viser bare treffene', async () => { + await careLevelSelect.selectOption(''); + await expect(cards).toHaveCount(12); + await searchField.fill('plant'); + // expect venter automatisk, så debounce på 800 ms er ikke et problem + await expect(cards).toHaveCount(2); + await expect(cards.nth(0)).toContainText('Jade Plant'); + await expect(cards.nth(1)).toContainText('Snake Plant'); + }); + + await test.step('sortering z–a snur rekkefølgen', async () => { + await page.locator('.sort-button').click(); + await page.locator('.sort-option').nth(1).click(); // name_desc, se SORT_OPTIONS + await expect(cards.first()).toContainText('Snake Plant'); + }); + + await test.step('reset viser alle plantene igjen', async () => { + await page.locator('.reset-button').click(); + await expect(searchField).toHaveValue(''); + await expect(cards).toHaveCount(12); + await expect(cards.first()).toContainText('Aloe Vera'); + }); +}); \ No newline at end of file diff --git a/playwright.config.ts b/playwright.config.ts index 35bbf6be..fc761c80 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,7 +1,13 @@ import { defineConfig, devices } from '@playwright/test'; +import { E2E_DB_NAME, E2E_DB_PORT, E2E_MONGODB_URI } from './e2e/test-db'; + +// Testbackenden kjører på 3002, så den ikke kolliderer med dev-backenden på 3001 +const E2E_BACKEND_PORT = 3002; export default defineConfig({ testDir: './e2e', + // Kjøres etter at webServerne er oppe: tømmer testdatabasen og fyller den med fixtures + globalSetup: './e2e/global-setup.ts', workers: 1, retries: process.env.CI ? 1 : 0, failOnFlakyTests: !!process.env.CI, @@ -11,17 +17,50 @@ export default defineConfig({ ...(process.env.CI ? [['github'] as const] : []), ], use: { - baseURL: 'http://localhost:5173/project2/', + baseURL: 'http://localhost:4173/project2/', trace: 'retain-on-failure', }, - projects: [ - { name: 'desktop', use: { ...devices['Desktop Chrome'] } }, - { name: 'mobil', use: { ...devices['Pixel 7'] } }, + projects: [ + // API-testene sender GraphQL rett til backend og trenger ingen nettleser + { + name: 'api', + testMatch: 'api/**/*.spec.ts', + use: { baseURL: `http://localhost:${E2E_BACKEND_PORT}/` }, + }, + { name: 'desktop', testMatch: 'ui/**/*.spec.ts', use: { ...devices['Desktop Chrome'] } }, + { name: 'mobil', testMatch: 'ui/**/*.spec.ts', use: { ...devices['Pixel 7'] } }, + ], + // Startes i rekkefølge: databasen må være oppe før backend, som kobler til ved oppstart + webServer: [ + { + // MongoDB i minnet, ingen installasjon nødvendig + command: 'node e2e/start-test-db.mjs', + port: E2E_DB_PORT, + env: { E2E_DB_PORT: String(E2E_DB_PORT) }, + reuseExistingServer: !process.env.CI, + timeout: 180_000, // første kjøring laster ned MongoDB + }, + { + // Env-verdiene her vinner over backend/.env, så backend bruker testdatabasen + command: 'npm run build --prefix backend && npm run start --prefix backend', + url: `http://localhost:${E2E_BACKEND_PORT}/graphql?query=%7B__typename%7D`, + env: { + MONGODB_URI: E2E_MONGODB_URI, + DB_NAME: E2E_DB_NAME, + PORT: String(E2E_BACKEND_PORT), + NODE_ENV: 'test', + }, + reuseExistingServer: !process.env.CI, + timeout: 120_000, + }, + { + // Overstyrer VITE_GRAPHQL_URL fra .env.production, så frontend ikke snakker med VM-en + command: + 'npm run build --prefix frontend && npm run preview --prefix frontend -- --port 4173 --strictPort', + url: 'http://localhost:4173/project2/', + env: { VITE_GRAPHQL_URL: `http://localhost:${E2E_BACKEND_PORT}/graphql` }, + reuseExistingServer: !process.env.CI, + timeout: 120_000, + }, ], - webServer: { - command: 'npm run dev', - url: 'http://localhost:5173/project2/', - reuseExistingServer: !process.env.CI, - timeout: 120_000, - }, }); \ No newline at end of file From b9dacd959b5c3b040d924040bbb28502df50d33a Mon Sep 17 00:00:00 2001 From: Helene Lotsberg Date: Mon, 26 Oct 2026 15:00:30 +0100 Subject: [PATCH 04/22] fix normalize sunlight in server.ts after test failed --- backend/src/server.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/server.ts b/backend/src/server.ts index 331a810e..4d79315b 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -326,6 +326,9 @@ const resolvers = { $options: "i", }; } + if (args.sunlight) { + filter.sunlight = new RegExp(`^${normalize(args.sunlight)}$`, "i"); + } if (args.watering) { filter.watering = new RegExp(`^${normalize(args.watering)}$`, "i"); } From 20d7c75eec8e02141953a0050354b24f76c930e0 Mon Sep 17 00:00:00 2001 From: Helene Lotsberg Date: Mon, 26 Oct 2026 15:06:24 +0100 Subject: [PATCH 05/22] write two more e2e tests --- e2e/api/api-user-lifecycle.spec.ts | 177 +++++++++++++++++++++++++++++ e2e/ui/ui-user-journeys.spec.ts | 55 +++++++++ 2 files changed, 232 insertions(+) create mode 100644 e2e/api/api-user-lifecycle.spec.ts create mode 100644 e2e/ui/ui-user-journeys.spec.ts diff --git a/e2e/api/api-user-lifecycle.spec.ts b/e2e/api/api-user-lifecycle.spec.ts new file mode 100644 index 00000000..dbe8a82f --- /dev/null +++ b/e2e/api/api-user-lifecycle.spec.ts @@ -0,0 +1,177 @@ +import { test, expect, type APIRequestContext } from '@playwright/test'; + +const CREATE_USER = ` + mutation { + createUser { + id + name + description + profilePicture + preferences + matchedPlants { id name } + } + } +`; + +const GET_USER = ` + query GetUser($userId: ID!) { + getUser(userId: $userId) { + id + name + description + profilePicture + preferences + matchedPlants { id name } + } + } +`; + +const UPDATE_PROFILE = ` + mutation UpdateProfile( + $userId: ID! + $name: String + $description: String + $profilePicture: String + ) { + updateUserProfile( + userId: $userId + name: $name + description: $description + profilePicture: $profilePicture + ) { + id + name + description + profilePicture + } + } +`; + +const UPDATE_PREFERENCES = ` + mutation UpdatePreferences($userId: ID!, $preferences: [String!]!) { + updateUserPreferences(userId: $userId, preferences: $preferences) { + id + preferences + } + } +`; + +const ADD_MATCH = ` + mutation AddMatch($userId: ID!, $plantId: ID!) { + addUserMatch(userId: $userId, plantId: $plantId) { + id + matchedPlants { id name } + } + } +`; + +const REMOVE_MATCH = ` + mutation RemoveMatch($userId: ID!, $plantId: ID!) { + removeUserMatch(userId: $userId, plantId: $plantId) { + id + matchedPlants { id name } + } + } +`; + +const FIRST_PLANT = ` + query { + explorePlants(limit: 1) { + plants { id name } + } + } +`; + +async function graphql( + request: APIRequestContext, + query: string, + variables?: Record, +) { + const response = await request.post('graphql', { + data: { query, variables }, + }); + expect(response.ok()).toBeTruthy(); + return response.json(); +} + +test('brukerdata kan opprettes, oppdateres, leses tilbake og fjernes', async ({ + request, +}) => { + const created = await graphql(request, CREATE_USER); + expect(created.errors).toBeUndefined(); + const userId = created.data.createUser.id as string; + expect(created.data.createUser.matchedPlants).toEqual([]); + + const plantResult = await graphql(request, FIRST_PLANT); + const plant = plantResult.data.explorePlants.plants[0] as { + id: string; + name: string; + }; + + const profile = await graphql(request, UPDATE_PROFILE, { + userId, + name: 'Nina', + description: 'Glad i grønne planter', + profilePicture: 'monstera', + }); + expect(profile.data.updateUserProfile).toMatchObject({ + id: userId, + name: 'Nina', + description: 'Glad i grønne planter', + profilePicture: 'monstera', + }); + + const preferences = await graphql(request, UPDATE_PREFERENCES, { + userId, + preferences: ['fullSun', 'easyCare', 'fullSun'], + }); + expect(preferences.data.updateUserPreferences.preferences).toEqual([ + 'fullSun', + 'easyCare', + ]); + + const added = await graphql(request, ADD_MATCH, { + userId, + plantId: plant.id, + }); + expect(added.data.addUserMatch.matchedPlants).toEqual([ + { id: plant.id, name: plant.name }, + ]); + + const persisted = await graphql(request, GET_USER, { userId }); + expect(persisted.data.getUser).toMatchObject({ + id: userId, + name: 'Nina', + description: 'Glad i grønne planter', + profilePicture: 'monstera', + preferences: ['fullSun', 'easyCare'], + matchedPlants: [{ id: plant.id, name: plant.name }], + }); + + const removed = await graphql(request, REMOVE_MATCH, { + userId, + plantId: plant.id, + }); + expect(removed.data.removeUserMatch.matchedPlants).toEqual([]); +}); + +test('avviser ukjent preferanse og ugyldig plante-id', async ({ request }) => { + const created = await graphql(request, CREATE_USER); + const userId = created.data.createUser.id as string; + + const invalidPreference = await graphql(request, UPDATE_PREFERENCES, { + userId, + preferences: ['not-a-preference'], + }); + expect(invalidPreference.data).toBeNull(); + expect(invalidPreference.errors[0].message).toContain( + 'Unknown preferences', + ); + + const invalidMatch = await graphql(request, ADD_MATCH, { + userId, + plantId: '000000000000000000000000', + }); + expect(invalidMatch.data).toBeNull(); + expect(invalidMatch.errors[0].message).toContain('Unknown plant'); +}); diff --git a/e2e/ui/ui-user-journeys.spec.ts b/e2e/ui/ui-user-journeys.spec.ts new file mode 100644 index 00000000..6da47b75 --- /dev/null +++ b/e2e/ui/ui-user-journeys.spec.ts @@ -0,0 +1,55 @@ +import { test, expect, type Page } from '@playwright/test'; + +async function openSidebar(page: Page) { + await page.getByRole('button', { name: 'Open sidebar' }).click(); + await expect(page.locator('#sidebar')).toHaveAttribute('data-open', 'true'); +} + +test('bruker kan like en plante, finne den igjen og fjerne matchen', async ({ + page, +}) => { + await page.goto(''); + + const likeButton = page.locator('button.like-button'); + await expect(likeButton).toBeEnabled(); + await expect(page.locator('.plant-card-front')).toBeVisible(); + + await likeButton.click(); + await openSidebar(page); + await page.locator('a[href$="/my-matches"]').click(); + + const matchCards = page.locator('.plant-card-match'); + await expect(matchCards).toHaveCount(1); + await expect(matchCards.first().locator('.plant-card-name')).toBeVisible(); + + await matchCards.first().locator('.remove-match-button').click(); + await expect(matchCards).toHaveCount(0); + await expect(page.locator('.matches-grid')).toContainText(/no matches|ingen matcher/i); +}); + +test('bruker kan oppdatere profil, avatar og navigere mellom sider', async ({ + page, +}) => { + await page.goto('profile'); + + const name = page.locator('#profile-name'); + await expect(name).toBeVisible(); + + await page.getByRole('button', { name: /edit profile|endre profil/i }).click(); + await name.fill('Nina'); + await page.locator('#description').fill('Glad i grønne planter'); + await page.locator('button.avatar-option').first().click(); + + await expect(page.locator('main.profile')).toContainText('Nina'); + await page.waitForTimeout(700); + await page.reload(); + + await expect(page.locator('main.profile h1')).toContainText('Nina'); + await expect(page.locator('main.profile')).toContainText( + 'Glad i grønne planter', + ); + + await openSidebar(page); + await page.locator('a[href$="/explorePlants"]').click(); + await expect(page.locator('.explore-page')).toBeVisible(); +}); From 5f699e4f7ddb9d314eade36edd3b2698a75005da Mon Sep 17 00:00:00 2001 From: Helene Lotsberg Date: Mon, 26 Oct 2026 16:50:31 +0100 Subject: [PATCH 06/22] rename files and re-organize e2e folder --- e2e/{api => }/api-user-lifecycle.spec.ts | 0 ...-page.spec.ts => apiExplorePlants.spec.ts} | 0 e2e/apiMatchAndRemovePlant.spec.ts | 126 +++++++++++++ e2e/apiUserProfile.spec.ts | 169 ++++++++++++++++++ e2e/explore-plants.spec.ts | 8 - e2e/helpers/graphql.ts | 52 ++++++ e2e/{ui => }/ui-user-journeys.spec.ts | 0 ...e-page.spec.ts => uiExplorePlants.spec.ts} | 0 e2e/uiUserProfile.spec.ts | 0 playwright.config.ts | 28 +-- 10 files changed, 363 insertions(+), 20 deletions(-) rename e2e/{api => }/api-user-lifecycle.spec.ts (100%) rename e2e/{api/api-explore-page.spec.ts => apiExplorePlants.spec.ts} (100%) create mode 100644 e2e/apiMatchAndRemovePlant.spec.ts create mode 100644 e2e/apiUserProfile.spec.ts delete mode 100644 e2e/explore-plants.spec.ts create mode 100644 e2e/helpers/graphql.ts rename e2e/{ui => }/ui-user-journeys.spec.ts (100%) rename e2e/{ui/ui-explore-page.spec.ts => uiExplorePlants.spec.ts} (100%) create mode 100644 e2e/uiUserProfile.spec.ts diff --git a/e2e/api/api-user-lifecycle.spec.ts b/e2e/api-user-lifecycle.spec.ts similarity index 100% rename from e2e/api/api-user-lifecycle.spec.ts rename to e2e/api-user-lifecycle.spec.ts diff --git a/e2e/api/api-explore-page.spec.ts b/e2e/apiExplorePlants.spec.ts similarity index 100% rename from e2e/api/api-explore-page.spec.ts rename to e2e/apiExplorePlants.spec.ts diff --git a/e2e/apiMatchAndRemovePlant.spec.ts b/e2e/apiMatchAndRemovePlant.spec.ts new file mode 100644 index 00000000..25e8edb5 --- /dev/null +++ b/e2e/apiMatchAndRemovePlant.spec.ts @@ -0,0 +1,126 @@ +import { test, expect, type APIRequestContext } from '@playwright/test'; +import { graphql, createUser, GET_USER } from './helpers/graphql'; + +// Tests matching a plant and removing the match in the API, and that the +// matches are stored on the user in the database. + +const ADD_MATCH = ` + mutation AddMatch($userId: ID!, $plantId: ID!) { + addUserMatch(userId: $userId, plantId: $plantId) { + id + matchedPlants { id name } + } + } +`; + +const REMOVE_MATCH = ` + mutation RemoveMatch($userId: ID!, $plantId: ID!) { + removeUserMatch(userId: $userId, plantId: $plantId) { + id + matchedPlants { id name } + } + } +`; + +const FIRST_PLANTS = ` + query FirstPlants($limit: Int) { + explorePlants(limit: $limit) { + plants { id name } + } + } +`; + +// The first plants sorted a–z from the fixtures (Aloe Vera, Boston Fern, ...) +async function firstPlants(request: APIRequestContext, limit: number) { + const result = await graphql(request, FIRST_PLANTS, { limit }); + return result.data.explorePlants.plants as { id: string; name: string }[]; +} + +test.describe('typical use', () => { + test('a matched plant is stored and can be removed', async ({ request }) => { + const userId = await createUser(request); + const [plant] = await firstPlants(request, 1); + expect(plant.name).toBe('Aloe Vera'); + + const added = await graphql(request, ADD_MATCH, { userId, plantId: plant.id }); + expect(added.data.addUserMatch.matchedPlants).toEqual([ + { id: plant.id, name: plant.name }, + ]); + + // Fetches the user again to check that the match is stored in the database + const persisted = await graphql(request, GET_USER, { userId }); + expect(persisted.data.getUser.matchedPlants).toEqual([ + { id: plant.id, name: plant.name }, + ]); + + const removed = await graphql(request, REMOVE_MATCH, { userId, plantId: plant.id }); + expect(removed.data.removeUserMatch.matchedPlants).toEqual([]); + + const afterRemove = await graphql(request, GET_USER, { userId }); + expect(afterRemove.data.getUser.matchedPlants).toEqual([]); + }); + + test('matches are returned in the order they were added', async ({ request }) => { + const userId = await createUser(request); + const [first, second] = await firstPlants(request, 2); + + // Adds them in reverse alphabetical order + await graphql(request, ADD_MATCH, { userId, plantId: second.id }); + await graphql(request, ADD_MATCH, { userId, plantId: first.id }); + + const user = await graphql(request, GET_USER, { userId }); + expect(user.data.getUser.matchedPlants.map((p: { name: string }) => p.name)).toEqual([ + second.name, + first.name, + ]); + }); +}); + +test.describe('atypical use', () => { + test('the same plant is only matched once', async ({ request }) => { + const userId = await createUser(request); + const [plant] = await firstPlants(request, 1); + + await graphql(request, ADD_MATCH, { userId, plantId: plant.id }); + const second = await graphql(request, ADD_MATCH, { userId, plantId: plant.id }); + + expect(second.errors).toBeUndefined(); + expect(second.data.addUserMatch.matchedPlants).toHaveLength(1); + }); + + test('rejects a plant that does not exist', async ({ request }) => { + const userId = await createUser(request); + + const result = await graphql(request, ADD_MATCH, { + userId, + plantId: '000000000000000000000000', + }); + expect(result.data).toBeNull(); + expect(result.errors[0].extensions.code).toBe('BAD_USER_INPUT'); + expect(result.errors[0].message).toContain('Unknown plant'); + }); + + test('rejects a malformed plant id', async ({ request }) => { + const userId = await createUser(request); + + const result = await graphql(request, REMOVE_MATCH, { userId, plantId: 'abc' }); + expect(result.data).toBeNull(); + expect(result.errors[0].extensions.code).toBe('BAD_USER_INPUT'); + }); + + test('removing a plant that is not matched changes nothing', async ({ request }) => { + const userId = await createUser(request); + const [matched, notMatched] = await firstPlants(request, 2); + + await graphql(request, ADD_MATCH, { userId, plantId: matched.id }); + const result = await graphql(request, REMOVE_MATCH, { + userId, + plantId: notMatched.id, + }); + + expect(result.errors).toBeUndefined(); + expect(result.data.removeUserMatch.matchedPlants).toEqual([ + { id: matched.id, name: matched.name }, + ]); + }); +}); \ No newline at end of file diff --git a/e2e/apiUserProfile.spec.ts b/e2e/apiUserProfile.spec.ts new file mode 100644 index 00000000..525caacb --- /dev/null +++ b/e2e/apiUserProfile.spec.ts @@ -0,0 +1,169 @@ +import { test, expect } from '@playwright/test'; +import { graphql, createUser, CREATE_USER, GET_USER } from './helpers/graphql'; + +// Tests the user profile in the API: a new user's defaults, name, description, +// avatar and preferences, and that invalid values are rejected. + +const UPDATE_PROFILE = ` + mutation UpdateProfile( + $userId: ID! + $name: String + $description: String + $profilePicture: String + ) { + updateUserProfile( + userId: $userId + name: $name + description: $description + profilePicture: $profilePicture + ) { + id + name + description + profilePicture + } + } +`; + +const UPDATE_PREFERENCES = ` + mutation UpdatePreferences($userId: ID!, $preferences: [String!]!) { + updateUserPreferences(userId: $userId, preferences: $preferences) { + id + preferences + } + } +`; + +test.describe('typical use', () => { + test('a new user starts empty', async ({ request }) => { + const created = await graphql(request, CREATE_USER); + expect(created.errors).toBeUndefined(); + expect(created.data.createUser).toMatchObject({ + name: null, + description: null, + profilePicture: 'default', + preferences: [], + matchedPlants: [], + }); + }); + + test('profile and preferences can be updated and read back', async ({ request }) => { + const userId = await createUser(request); + + const profile = await graphql(request, UPDATE_PROFILE, { + userId, + name: 'John', + description: 'Loves green plants', + profilePicture: 'monstera', + }); + expect(profile.data.updateUserProfile).toMatchObject({ + id: userId, + name: 'John', + description: 'Loves green plants', + profilePicture: 'monstera', + }); + + // Duplicates should be removed + const preferences = await graphql(request, UPDATE_PREFERENCES, { + userId, + preferences: ['fullSun', 'easyCare', 'fullSun'], + }); + expect(preferences.data.updateUserPreferences.preferences).toEqual([ + 'fullSun', + 'easyCare', + ]); + + // Fetches the user again to check that everything is stored in the database + const persisted = await graphql(request, GET_USER, { userId }); + expect(persisted.data.getUser).toMatchObject({ + id: userId, + name: 'John', + description: 'Loves green plants', + profilePicture: 'monstera', + preferences: ['fullSun', 'easyCare'], + }); + }); + + test('only the fields that are sent are changed', async ({ request }) => { + const userId = await createUser(request); + + await graphql(request, UPDATE_PROFILE, { userId, name: 'John' }); + const result = await graphql(request, UPDATE_PROFILE, { + userId, + description: 'Loves green plants', + }); + + expect(result.data.updateUserProfile).toMatchObject({ + name: 'John', + description: 'Loves green plants', + }); + }); +}); + +test.describe('atypical use', () => { + test('an empty name is stored as null', async ({ request }) => { + const userId = await createUser(request); + + const result = await graphql(request, UPDATE_PROFILE, { userId, name: ' ' }); + expect(result.data.updateUserProfile.name).toBeNull(); + }); + + test('rejects a name that is too long', async ({ request }) => { + const userId = await createUser(request); + + const result = await graphql(request, UPDATE_PROFILE, { + userId, + name: 'a'.repeat(41), // max is 40 + }); + expect(result.data).toBeNull(); + expect(result.errors[0].extensions.code).toBe('BAD_USER_INPUT'); + }); + + test('rejects a description that is too long', async ({ request }) => { + const userId = await createUser(request); + + const result = await graphql(request, UPDATE_PROFILE, { + userId, + description: 'a'.repeat(101), // max is 100 + }); + expect(result.data).toBeNull(); + expect(result.errors[0].extensions.code).toBe('BAD_USER_INPUT'); + }); + + test('rejects an unknown profile picture', async ({ request }) => { + const userId = await createUser(request); + + const result = await graphql(request, UPDATE_PROFILE, { + userId, + profilePicture: 'not-a-picture', + }); + expect(result.data).toBeNull(); + expect(result.errors[0].extensions.code).toBe('BAD_USER_INPUT'); + }); + + test('rejects an unknown preference', async ({ request }) => { + const userId = await createUser(request); + + const result = await graphql(request, UPDATE_PREFERENCES, { + userId, + preferences: ['not-a-preference'], + }); + expect(result.data).toBeNull(); + expect(result.errors[0].extensions.code).toBe('BAD_USER_INPUT'); + expect(result.errors[0].message).toContain('Unknown preferences'); + }); + + test('an invalid or unknown user id returns null instead of crashing', async ({ + request, + }) => { + const malformed = await graphql(request, GET_USER, { userId: 'abc' }); + expect(malformed.errors).toBeUndefined(); + expect(malformed.data.getUser).toBeNull(); + + const unknown = await graphql(request, GET_USER, { + userId: '000000000000000000000000', + }); + expect(unknown.errors).toBeUndefined(); + expect(unknown.data.getUser).toBeNull(); + }); +}); \ No newline at end of file diff --git a/e2e/explore-plants.spec.ts b/e2e/explore-plants.spec.ts deleted file mode 100644 index 1ff9a6bb..00000000 --- a/e2e/explore-plants.spec.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { test, expect } from '@playwright/test'; - -test('explore-siden laster og viser planter', async ({ page }) => { - await page.goto(''); // = baseURL (/project2/) - - // Bytt ut med noe som faktisk finnes på siden deres: - await expect(page.getByRole('heading', { level: 1 })).toBeVisible(); -}); \ No newline at end of file diff --git a/e2e/helpers/graphql.ts b/e2e/helpers/graphql.ts new file mode 100644 index 00000000..a4922318 --- /dev/null +++ b/e2e/helpers/graphql.ts @@ -0,0 +1,52 @@ +import { expect, type APIRequestContext } from '@playwright/test'; + +// Shared helpers for the API tests (api-*.spec.ts). +// Queries used by more than one test file are kept here; queries only used +// in one file stay in that file. + +export const CREATE_USER = ` + mutation { + createUser { + id + name + description + profilePicture + preferences + matchedPlants { id name } + } + } +`; + +export const GET_USER = ` + query GetUser($userId: ID!) { + getUser(userId: $userId) { + id + name + description + profilePicture + preferences + matchedPlants { id name } + } + } +`; + +// Sends a GraphQL request to the test backend and returns the JSON response. +// GraphQL errors come back with status 200, so callers check `errors` themselves. +export async function graphql( + request: APIRequestContext, + query: string, + variables?: Record, +) { + const response = await request.post('graphql', { + data: { query, variables }, + }); + expect(response.ok()).toBeTruthy(); + return response.json(); +} + +// Creates a new user and returns its id, like the frontend does on a first visit +export async function createUser(request: APIRequestContext): Promise { + const created = await graphql(request, CREATE_USER); + expect(created.errors).toBeUndefined(); + return created.data.createUser.id; +} \ No newline at end of file diff --git a/e2e/ui/ui-user-journeys.spec.ts b/e2e/ui-user-journeys.spec.ts similarity index 100% rename from e2e/ui/ui-user-journeys.spec.ts rename to e2e/ui-user-journeys.spec.ts diff --git a/e2e/ui/ui-explore-page.spec.ts b/e2e/uiExplorePlants.spec.ts similarity index 100% rename from e2e/ui/ui-explore-page.spec.ts rename to e2e/uiExplorePlants.spec.ts diff --git a/e2e/uiUserProfile.spec.ts b/e2e/uiUserProfile.spec.ts new file mode 100644 index 00000000..e69de29b diff --git a/playwright.config.ts b/playwright.config.ts index fc761c80..f524ea38 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,47 +1,51 @@ import { defineConfig, devices } from '@playwright/test'; import { E2E_DB_NAME, E2E_DB_PORT, E2E_MONGODB_URI } from './e2e/test-db'; -// Testbackenden kjører på 3002, så den ikke kolliderer med dev-backenden på 3001 +// The test backend runs on 3002, so it does not collide with the dev backend on 3001 const E2E_BACKEND_PORT = 3002; export default defineConfig({ testDir: './e2e', - // Kjøres etter at webServerne er oppe: tømmer testdatabasen og fyller den med fixtures + // Runs after the web servers are up: empties the test database and fills it with fixtures globalSetup: './e2e/global-setup.ts', + // All tests share one database, so they run one at a time workers: 1, retries: process.env.CI ? 1 : 0, + // A test that only passes on retry is not hidden: in CI it counts as a failure failOnFlakyTests: !!process.env.CI, reporter: [ ['list'], ['html', { open: 'never' }], + // Shows failing tests as annotations in the pull request ...(process.env.CI ? [['github'] as const] : []), ], use: { baseURL: 'http://localhost:4173/project2/', trace: 'retain-on-failure', }, - projects: [ - // API-testene sender GraphQL rett til backend og trenger ingen nettleser + projects: [ + // The API tests send GraphQL straight to the backend and need no browser { name: 'api', - testMatch: 'api/**/*.spec.ts', + testMatch: '**/api*.spec.ts', use: { baseURL: `http://localhost:${E2E_BACKEND_PORT}/` }, }, - { name: 'desktop', testMatch: 'ui/**/*.spec.ts', use: { ...devices['Desktop Chrome'] } }, - { name: 'mobil', testMatch: 'ui/**/*.spec.ts', use: { ...devices['Pixel 7'] } }, + // The UI tests run in both a desktop and a mobile browser + { name: 'desktop', testMatch: '**/ui*.spec.ts', use: { ...devices['Desktop Chrome'] } }, + { name: 'mobile', testMatch: '**/ui*.spec.ts', use: { ...devices['Pixel 7'] } }, ], - // Startes i rekkefølge: databasen må være oppe før backend, som kobler til ved oppstart + // Started in order: the database must be up before the backend, which connects on startup webServer: [ { - // MongoDB i minnet, ingen installasjon nødvendig + // In-memory MongoDB, no installation needed command: 'node e2e/start-test-db.mjs', port: E2E_DB_PORT, env: { E2E_DB_PORT: String(E2E_DB_PORT) }, reuseExistingServer: !process.env.CI, - timeout: 180_000, // første kjøring laster ned MongoDB + timeout: 180_000, // the first run downloads MongoDB }, { - // Env-verdiene her vinner over backend/.env, så backend bruker testdatabasen + // These env values take priority over backend/.env, so the backend uses the test database command: 'npm run build --prefix backend && npm run start --prefix backend', url: `http://localhost:${E2E_BACKEND_PORT}/graphql?query=%7B__typename%7D`, env: { @@ -54,7 +58,7 @@ export default defineConfig({ timeout: 120_000, }, { - // Overstyrer VITE_GRAPHQL_URL fra .env.production, så frontend ikke snakker med VM-en + // Overrides VITE_GRAPHQL_URL from .env.production, so the frontend does not talk to the VM command: 'npm run build --prefix frontend && npm run preview --prefix frontend -- --port 4173 --strictPort', url: 'http://localhost:4173/project2/', From ae0458e422138c2c6a60adc066caf5eff8d1d0a5 Mon Sep 17 00:00:00 2001 From: Helene Lotsberg Date: Mon, 26 Oct 2026 16:59:43 +0100 Subject: [PATCH 07/22] fix english comments in e2e test files --- e2e/api-user-lifecycle.spec.ts | 177 ----------------------------- e2e/apiExplorePlants.spec.ts | 33 +++--- e2e/global-setup.ts | 8 +- e2e/helpers/navigation.ts | 11 ++ e2e/start-test-db.mjs | 6 +- e2e/test-db.ts | 4 +- e2e/ui-user-journeys.spec.ts | 55 --------- e2e/uiExplorePlants.spec.ts | 28 ++--- e2e/uiMatchAndRemovePlants.spec.ts | 37 ++++++ e2e/uiUserProfile.spec.ts | 43 +++++++ 10 files changed, 129 insertions(+), 273 deletions(-) delete mode 100644 e2e/api-user-lifecycle.spec.ts create mode 100644 e2e/helpers/navigation.ts delete mode 100644 e2e/ui-user-journeys.spec.ts create mode 100644 e2e/uiMatchAndRemovePlants.spec.ts diff --git a/e2e/api-user-lifecycle.spec.ts b/e2e/api-user-lifecycle.spec.ts deleted file mode 100644 index dbe8a82f..00000000 --- a/e2e/api-user-lifecycle.spec.ts +++ /dev/null @@ -1,177 +0,0 @@ -import { test, expect, type APIRequestContext } from '@playwright/test'; - -const CREATE_USER = ` - mutation { - createUser { - id - name - description - profilePicture - preferences - matchedPlants { id name } - } - } -`; - -const GET_USER = ` - query GetUser($userId: ID!) { - getUser(userId: $userId) { - id - name - description - profilePicture - preferences - matchedPlants { id name } - } - } -`; - -const UPDATE_PROFILE = ` - mutation UpdateProfile( - $userId: ID! - $name: String - $description: String - $profilePicture: String - ) { - updateUserProfile( - userId: $userId - name: $name - description: $description - profilePicture: $profilePicture - ) { - id - name - description - profilePicture - } - } -`; - -const UPDATE_PREFERENCES = ` - mutation UpdatePreferences($userId: ID!, $preferences: [String!]!) { - updateUserPreferences(userId: $userId, preferences: $preferences) { - id - preferences - } - } -`; - -const ADD_MATCH = ` - mutation AddMatch($userId: ID!, $plantId: ID!) { - addUserMatch(userId: $userId, plantId: $plantId) { - id - matchedPlants { id name } - } - } -`; - -const REMOVE_MATCH = ` - mutation RemoveMatch($userId: ID!, $plantId: ID!) { - removeUserMatch(userId: $userId, plantId: $plantId) { - id - matchedPlants { id name } - } - } -`; - -const FIRST_PLANT = ` - query { - explorePlants(limit: 1) { - plants { id name } - } - } -`; - -async function graphql( - request: APIRequestContext, - query: string, - variables?: Record, -) { - const response = await request.post('graphql', { - data: { query, variables }, - }); - expect(response.ok()).toBeTruthy(); - return response.json(); -} - -test('brukerdata kan opprettes, oppdateres, leses tilbake og fjernes', async ({ - request, -}) => { - const created = await graphql(request, CREATE_USER); - expect(created.errors).toBeUndefined(); - const userId = created.data.createUser.id as string; - expect(created.data.createUser.matchedPlants).toEqual([]); - - const plantResult = await graphql(request, FIRST_PLANT); - const plant = plantResult.data.explorePlants.plants[0] as { - id: string; - name: string; - }; - - const profile = await graphql(request, UPDATE_PROFILE, { - userId, - name: 'Nina', - description: 'Glad i grønne planter', - profilePicture: 'monstera', - }); - expect(profile.data.updateUserProfile).toMatchObject({ - id: userId, - name: 'Nina', - description: 'Glad i grønne planter', - profilePicture: 'monstera', - }); - - const preferences = await graphql(request, UPDATE_PREFERENCES, { - userId, - preferences: ['fullSun', 'easyCare', 'fullSun'], - }); - expect(preferences.data.updateUserPreferences.preferences).toEqual([ - 'fullSun', - 'easyCare', - ]); - - const added = await graphql(request, ADD_MATCH, { - userId, - plantId: plant.id, - }); - expect(added.data.addUserMatch.matchedPlants).toEqual([ - { id: plant.id, name: plant.name }, - ]); - - const persisted = await graphql(request, GET_USER, { userId }); - expect(persisted.data.getUser).toMatchObject({ - id: userId, - name: 'Nina', - description: 'Glad i grønne planter', - profilePicture: 'monstera', - preferences: ['fullSun', 'easyCare'], - matchedPlants: [{ id: plant.id, name: plant.name }], - }); - - const removed = await graphql(request, REMOVE_MATCH, { - userId, - plantId: plant.id, - }); - expect(removed.data.removeUserMatch.matchedPlants).toEqual([]); -}); - -test('avviser ukjent preferanse og ugyldig plante-id', async ({ request }) => { - const created = await graphql(request, CREATE_USER); - const userId = created.data.createUser.id as string; - - const invalidPreference = await graphql(request, UPDATE_PREFERENCES, { - userId, - preferences: ['not-a-preference'], - }); - expect(invalidPreference.data).toBeNull(); - expect(invalidPreference.errors[0].message).toContain( - 'Unknown preferences', - ); - - const invalidMatch = await graphql(request, ADD_MATCH, { - userId, - plantId: '000000000000000000000000', - }); - expect(invalidMatch.data).toBeNull(); - expect(invalidMatch.errors[0].message).toContain('Unknown plant'); -}); diff --git a/e2e/apiExplorePlants.spec.ts b/e2e/apiExplorePlants.spec.ts index 129b5ec1..943ff68f 100644 --- a/e2e/apiExplorePlants.spec.ts +++ b/e2e/apiExplorePlants.spec.ts @@ -1,7 +1,8 @@ import { test, expect, type APIRequestContext } from '@playwright/test'; +import { graphql } from './helpers/graphql'; -// Tester explorePlants-queryen direkte mot testbackenden. -// Forventede verdier er basert på de 20 plantene i e2e/fixtures/plants.json. +// Tests the explorePlants query directly against the test backend. +// Expected values are based on the 20 plants in e2e/fixtures/plants.json. const EXPLORE_PLANTS = ` query ExplorePlants( @@ -35,16 +36,12 @@ interface ExploreResult { plants: { name: string }[]; } -// Sender queryen og sjekker at svaret ikke inneholder GraphQL-feil +// Sends the query and checks that the response contains no GraphQL errors async function explorePlants( request: APIRequestContext, variables: Record = {}, ): Promise { - const res = await request.post('graphql', { - data: { query: EXPLORE_PLANTS, variables }, - }); - expect(res.ok()).toBeTruthy(); - const body = await res.json(); + const body = await graphql(request, EXPLORE_PLANTS, variables); expect(body.errors).toBeUndefined(); return body.data.explorePlants; } @@ -52,55 +49,55 @@ async function explorePlants( const names = (result: ExploreResult) => result.plants.map((p) => p.name); test.describe('explorePlants', () => { - test('uten argumenter gir første side sortert a–z', async ({ request }) => { + test('without arguments returns the first page sorted a–z', async ({ request }) => { const result = await explorePlants(request); expect(result.totalCount).toBe(20); expect(result.plants).toHaveLength(12); expect(result.plants[0].name).toBe('Aloe Vera'); }); - test('offset gir neste side', async ({ request }) => { + test('offset returns the next page', async ({ request }) => { const result = await explorePlants(request, { offset: 12 }); expect(result.totalCount).toBe(20); expect(result.plants).toHaveLength(8); expect(result.plants[0].name).toBe('Monstera'); }); - test('søk er case-insensitivt', async ({ request }) => { + test('search is case insensitive', async ({ request }) => { const result = await explorePlants(request, { search: 'PLANT' }); expect(result.totalCount).toBe(2); expect(names(result)).toEqual(['Jade Plant', 'Snake Plant']); }); - test('søk med regex-tegn tolkes som vanlig tekst', async ({ request }) => { + test('regex characters in search are treated as plain text', async ({ request }) => { const result = await explorePlants(request, { search: '.*' }); expect(result.totalCount).toBe(0); }); - test('care level medium inkluderer Moderate', async ({ request }) => { + test('care level medium includes Moderate', async ({ request }) => { const result = await explorePlants(request, { careLevel: 'medium' }); expect(result.totalCount).toBe(7); expect(names(result)).toEqual(expect.arrayContaining(['Monstera', 'Lavender'])); }); - test('watering-filter', async ({ request }) => { + test('watering filter', async ({ request }) => { const result = await explorePlants(request, { watering: 'minimum' }); expect(result.totalCount).toBe(7); }); - test('sortering z–a', async ({ request }) => { + test('sorting z–a', async ({ request }) => { const result = await explorePlants(request, { sort: 'name_desc' }); expect(result.plants[0].name).toBe('Zebra Haworthia'); }); - test('planter uten care level havner sist', async ({ request }) => { + test('plants without a care level are sorted last', async ({ request }) => { const result = await explorePlants(request, { sort: 'careLevel_asc', limit: 20 }); expect(result.plants[0].name).toBe('Aloe Vera'); expect(result.plants.at(-1)?.name).toBe('Snake Plant'); }); - // Feiler til sunlight-filteret er implementert i backend (resolveren ignorerer det i dag) - test('sunlight-filter', async ({ request }) => { + // Fails until the sunlight filter is implemented in the backend (the resolver ignores it today) + test('sunlight filter', async ({ request }) => { const result = await explorePlants(request, { sunlight: 'full_sun' }); expect(result.totalCount).toBe(9); }); diff --git a/e2e/global-setup.ts b/e2e/global-setup.ts index c6adb703..d93eb9ab 100644 --- a/e2e/global-setup.ts +++ b/e2e/global-setup.ts @@ -2,17 +2,17 @@ import { readFile } from 'node:fs/promises'; import { MongoClient } from 'mongodb'; import { E2E_DB_NAME, E2E_MONGODB_URI } from './test-db'; -// Kjøres én gang før alle testene: tømmer testdatabasen og fyller den med faste planter, -// slik at hver testkjøring starter fra nøyaktig samme data. +// Runs once before all tests: empties the test database and fills it with fixed plants, +// so every test run starts from exactly the same data. export default async function globalSetup() { - // Stien er relativ til roten, der Playwright kjøres fra + // The path is relative to the project root, where Playwright is run from const plants = JSON.parse(await readFile('e2e/fixtures/plants.json', 'utf8')); const client = new MongoClient(E2E_MONGODB_URI); try { await client.connect(); const db = client.db(E2E_DB_NAME); - await db.dropDatabase(); // fjerner også brukere og matcher fra forrige kjøring + await db.dropDatabase(); // also removes users and matches from the previous run await db.collection('plants').insertMany(plants); } finally { await client.close(); diff --git a/e2e/helpers/navigation.ts b/e2e/helpers/navigation.ts new file mode 100644 index 00000000..60837488 --- /dev/null +++ b/e2e/helpers/navigation.ts @@ -0,0 +1,11 @@ +import { expect, type Page } from '@playwright/test'; + +// Shared navigation helpers for the UI tests (ui*.spec.ts) + +// Opens the sidebar menu and waits until it is open. +// The regex matches the button text in both English and Norwegian. +export async function openSidebar(page: Page) { + // Replace "åpne sidemeny" with the actual Norwegian text from the translation file + await page.getByRole('button', { name: /open sidebar|åpne sidemeny/i }).click(); + await expect(page.locator('#sidebar')).toHaveAttribute('data-open', 'true'); +} \ No newline at end of file diff --git a/e2e/start-test-db.mjs b/e2e/start-test-db.mjs index 7910b5a0..219ba493 100644 --- a/e2e/start-test-db.mjs +++ b/e2e/start-test-db.mjs @@ -1,10 +1,10 @@ -// Starter en MongoDB i minnet for e2e-testene. Playwright kjører dette scriptet -// som en webServer og stopper det når testene er ferdige. +// Starts an in-memory MongoDB for the e2e tests. Playwright runs this script +// as a webServer and stops it when the tests are done. import { MongoMemoryServer } from 'mongodb-memory-server'; const port = Number(process.env.E2E_DB_PORT); const mongod = await MongoMemoryServer.create({ instance: { port } }); -console.log(`Testdatabasen kjører på ${mongod.getUri()}`); +console.log(`Test database running at ${mongod.getUri()}`); const stop = async () => { await mongod.stop(); diff --git a/e2e/test-db.ts b/e2e/test-db.ts index 1870544d..0b6291b6 100644 --- a/e2e/test-db.ts +++ b/e2e/test-db.ts @@ -1,5 +1,5 @@ -// Felles innstillinger for testdatabasen, brukt av playwright.config.ts og global-setup.ts. -// Port 27018 så den ikke kolliderer med SSH-tunnelen til VM-en på 27017. +// Shared settings for the test database, used by playwright.config.ts and global-setup.ts. +// Port 27018 so it does not collide with the SSH tunnel to the VM on 27017. export const E2E_DB_PORT = 27018; export const E2E_MONGODB_URI = `mongodb://127.0.0.1:${E2E_DB_PORT}`; export const E2E_DB_NAME = 'iloveplants_e2e'; \ No newline at end of file diff --git a/e2e/ui-user-journeys.spec.ts b/e2e/ui-user-journeys.spec.ts deleted file mode 100644 index 6da47b75..00000000 --- a/e2e/ui-user-journeys.spec.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { test, expect, type Page } from '@playwright/test'; - -async function openSidebar(page: Page) { - await page.getByRole('button', { name: 'Open sidebar' }).click(); - await expect(page.locator('#sidebar')).toHaveAttribute('data-open', 'true'); -} - -test('bruker kan like en plante, finne den igjen og fjerne matchen', async ({ - page, -}) => { - await page.goto(''); - - const likeButton = page.locator('button.like-button'); - await expect(likeButton).toBeEnabled(); - await expect(page.locator('.plant-card-front')).toBeVisible(); - - await likeButton.click(); - await openSidebar(page); - await page.locator('a[href$="/my-matches"]').click(); - - const matchCards = page.locator('.plant-card-match'); - await expect(matchCards).toHaveCount(1); - await expect(matchCards.first().locator('.plant-card-name')).toBeVisible(); - - await matchCards.first().locator('.remove-match-button').click(); - await expect(matchCards).toHaveCount(0); - await expect(page.locator('.matches-grid')).toContainText(/no matches|ingen matcher/i); -}); - -test('bruker kan oppdatere profil, avatar og navigere mellom sider', async ({ - page, -}) => { - await page.goto('profile'); - - const name = page.locator('#profile-name'); - await expect(name).toBeVisible(); - - await page.getByRole('button', { name: /edit profile|endre profil/i }).click(); - await name.fill('Nina'); - await page.locator('#description').fill('Glad i grønne planter'); - await page.locator('button.avatar-option').first().click(); - - await expect(page.locator('main.profile')).toContainText('Nina'); - await page.waitForTimeout(700); - await page.reload(); - - await expect(page.locator('main.profile h1')).toContainText('Nina'); - await expect(page.locator('main.profile')).toContainText( - 'Glad i grønne planter', - ); - - await openSidebar(page); - await page.locator('a[href$="/explorePlants"]').click(); - await expect(page.locator('.explore-page')).toBeVisible(); -}); diff --git a/e2e/uiExplorePlants.spec.ts b/e2e/uiExplorePlants.spec.ts index 16618918..224759d3 100644 --- a/e2e/uiExplorePlants.spec.ts +++ b/e2e/uiExplorePlants.spec.ts @@ -1,13 +1,13 @@ import { test, expect } from '@playwright/test'; -// En sammenhengende brukerreise på ExplorePlants, basert på de 20 plantene i -// e2e/fixtures/plants.json. Locatorene er språkuavhengige (roller, option-verdier og -// CSS-klasser), så testen fungerer både på norsk og engelsk. +// A continuous user journey on ExplorePlants, based on the 20 plants in +// e2e/fixtures/plants.json. The locators are language independent (roles, option values +// and CSS classes), so the test works in both Norwegian and English. -test('bruker blar, filtrerer, søker, sorterer og nullstiller', async ({ page }) => { +test('user pages, filters, searches, sorts and resets', async ({ page }) => { const cards = page.locator('.plant-grid > li'); const searchField = page.getByRole('searchbox'); - // Care level er den eneste select-en med "high" som valg + // Care level is the only select with "high" as an option const careLevelSelect = page.locator('select').filter({ has: page.locator('option[value="high"]'), }); @@ -15,44 +15,44 @@ test('bruker blar, filtrerer, søker, sorterer og nullstiller', async ({ page }) const previousButton = pagination.getByRole('button').first(); const nextButton = pagination.getByRole('button').last(); - await test.step('første side viser 12 planter sortert a–z', async () => { + await test.step('the first page shows 12 plants sorted a–z', async () => { await page.goto('explorePlants'); await expect(cards).toHaveCount(12); await expect(cards.first()).toContainText('Aloe Vera'); await expect(previousButton).toBeDisabled(); }); - await test.step('neste side viser de 8 siste', async () => { + await test.step('the next page shows the last 8', async () => { await nextButton.click(); await expect(cards).toHaveCount(8); await expect(cards.first()).toContainText('Monstera'); await expect(nextButton).toBeDisabled(); }); - await test.step('filter fra side 2 sender brukeren tilbake til side 1', async () => { + await test.step('a filter on page 2 takes the user back to page 1', async () => { await careLevelSelect.selectOption('medium'); - await expect(cards).toHaveCount(7); // inkluderer "Moderate" + await expect(cards).toHaveCount(7); // includes "Moderate" await expect(cards.first()).toContainText('Boston Fern'); await expect(previousButton).toBeDisabled(); }); - await test.step('søk viser bare treffene', async () => { + await test.step('search shows only the matching plants', async () => { await careLevelSelect.selectOption(''); await expect(cards).toHaveCount(12); await searchField.fill('plant'); - // expect venter automatisk, så debounce på 800 ms er ikke et problem + // expect waits automatically, so the 800 ms debounce is not a problem await expect(cards).toHaveCount(2); await expect(cards.nth(0)).toContainText('Jade Plant'); await expect(cards.nth(1)).toContainText('Snake Plant'); }); - await test.step('sortering z–a snur rekkefølgen', async () => { + await test.step('sorting z–a reverses the order', async () => { await page.locator('.sort-button').click(); - await page.locator('.sort-option').nth(1).click(); // name_desc, se SORT_OPTIONS + await page.locator('.sort-option').nth(1).click(); // name_desc, see SORT_OPTIONS await expect(cards.first()).toContainText('Snake Plant'); }); - await test.step('reset viser alle plantene igjen', async () => { + await test.step('reset shows all plants again', async () => { await page.locator('.reset-button').click(); await expect(searchField).toHaveValue(''); await expect(cards).toHaveCount(12); diff --git a/e2e/uiMatchAndRemovePlants.spec.ts b/e2e/uiMatchAndRemovePlants.spec.ts new file mode 100644 index 00000000..0f92e681 --- /dev/null +++ b/e2e/uiMatchAndRemovePlants.spec.ts @@ -0,0 +1,37 @@ +import { test, expect } from '@playwright/test'; +import { openSidebar } from './helpers/navigation'; + +// User journey: like a plant on PlantMatch, find it in MyMatches and remove it. +// Each test gets a new browser and therefore a new user with no matches. + +test('user can like a plant, find it in MyMatches and remove the match', async ({ + page, +}) => { + await page.goto(''); + + const likeButton = page.locator('button.like-button'); + await expect(likeButton).toBeEnabled(); + await expect(page.locator('.plant-card-front')).toBeVisible(); + + // Remember which plant was liked, since PlantMatch shows random plants + const likedName = ( + await page.locator('.plant-card-front .plant-card-name').textContent() + )?.trim(); + expect(likedName).toBeTruthy(); + await likeButton.click(); + + await openSidebar(page); + await page.locator('a[href$="/my-matches"]').click(); + + const matchCards = page.locator('.plant-card-match'); + await expect(matchCards).toHaveCount(1); + await expect(matchCards.first().locator('.plant-card-name')).toHaveText( + likedName ?? '', + ); + + await matchCards.first().locator('.remove-match-button').click(); + await expect(matchCards).toHaveCount(0); + await expect(page.locator('.matches-grid')).toContainText( + /no matches|ingen matcher/i, + ); +}); \ No newline at end of file diff --git a/e2e/uiUserProfile.spec.ts b/e2e/uiUserProfile.spec.ts index e69de29b..0bb33e18 100644 --- a/e2e/uiUserProfile.spec.ts +++ b/e2e/uiUserProfile.spec.ts @@ -0,0 +1,43 @@ +import { test, expect } from '@playwright/test'; +import { openSidebar } from './helpers/navigation'; + +// User journey: update name, description and avatar on the profile page, +// check that the changes are stored, and navigate on to another page. +// Each test gets a new browser and therefore a new user. + +test('user can update profile and avatar, and navigate between pages', async ({ + page, +}) => { + await page.goto('profile'); + + const name = page.locator('#profile-name'); + await expect(name).toBeVisible(); + + await page.getByRole('button', { name: /edit profile|endre profil/i }).click(); + await name.fill('John'); + await page.locator('#description').fill('Loves green plants'); + + // Picks the second avatar, since the first one ("default") is already selected for new users + const chosenAvatar = page.locator('button.avatar-option').nth(1); + await chosenAvatar.click(); + + await expect(page.locator('main.profile')).toContainText('John'); + + // Saving happens in the background: reload until the changes come from the database + await expect(async () => { + await page.reload(); + await expect(page.locator('main.profile h1')).toContainText('John', { + timeout: 1000, + }); + await expect(page.locator('main.profile')).toContainText('Loves green plants', { + timeout: 1000, + }); + }).toPass({ timeout: 10_000 }); + + // Assumes the selected avatar is marked with aria-pressed, like the sort buttons on ExplorePlants + await expect(chosenAvatar).toHaveAttribute('aria-pressed', 'true'); + + await openSidebar(page); + await page.locator('a[href$="/explorePlants"]').click(); + await expect(page.locator('.explore-page')).toBeVisible(); +}); \ No newline at end of file From 904d218b2dab6bfd4091c08913cebbce3fa06a18 Mon Sep 17 00:00:00 2001 From: Helene Lotsberg Date: Mon, 26 Oct 2026 17:44:00 +0100 Subject: [PATCH 08/22] fix e2e tests not running and expand user journey for ExplorePlants page --- e2e/apiMatchAndRemovePlant.spec.ts | 4 +- e2e/apiUserProfile.spec.ts | 8 +-- e2e/helpers/navigation.ts | 10 ++-- e2e/uiExplorePlants.spec.ts | 17 +++++- e2e/uiMatchAndRemovePlant.spec.ts | 60 +++++++++++++++++++++ e2e/uiMatchAndRemovePlants.spec.ts | 37 ------------- e2e/uiUserProfile.spec.ts | 84 ++++++++++++++++++------------ 7 files changed, 140 insertions(+), 80 deletions(-) create mode 100644 e2e/uiMatchAndRemovePlant.spec.ts delete mode 100644 e2e/uiMatchAndRemovePlants.spec.ts diff --git a/e2e/apiMatchAndRemovePlant.spec.ts b/e2e/apiMatchAndRemovePlant.spec.ts index 25e8edb5..2b9b2341 100644 --- a/e2e/apiMatchAndRemovePlant.spec.ts +++ b/e2e/apiMatchAndRemovePlant.spec.ts @@ -95,7 +95,7 @@ test.describe('atypical use', () => { userId, plantId: '000000000000000000000000', }); - expect(result.data).toBeNull(); + expect(result.data.addUserMatch).toBeNull(); expect(result.errors[0].extensions.code).toBe('BAD_USER_INPUT'); expect(result.errors[0].message).toContain('Unknown plant'); }); @@ -104,7 +104,7 @@ test.describe('atypical use', () => { const userId = await createUser(request); const result = await graphql(request, REMOVE_MATCH, { userId, plantId: 'abc' }); - expect(result.data).toBeNull(); + expect(result.data.removeUserMatch).toBeNull(); expect(result.errors[0].extensions.code).toBe('BAD_USER_INPUT'); }); diff --git a/e2e/apiUserProfile.spec.ts b/e2e/apiUserProfile.spec.ts index 525caacb..328a4c02 100644 --- a/e2e/apiUserProfile.spec.ts +++ b/e2e/apiUserProfile.spec.ts @@ -115,7 +115,7 @@ test.describe('atypical use', () => { userId, name: 'a'.repeat(41), // max is 40 }); - expect(result.data).toBeNull(); + expect(result.data.updateUserProfile).toBeNull(); expect(result.errors[0].extensions.code).toBe('BAD_USER_INPUT'); }); @@ -126,7 +126,7 @@ test.describe('atypical use', () => { userId, description: 'a'.repeat(101), // max is 100 }); - expect(result.data).toBeNull(); + expect(result.data.updateUserProfile).toBeNull(); expect(result.errors[0].extensions.code).toBe('BAD_USER_INPUT'); }); @@ -137,7 +137,7 @@ test.describe('atypical use', () => { userId, profilePicture: 'not-a-picture', }); - expect(result.data).toBeNull(); + expect(result.data.updateUserProfile).toBeNull(); expect(result.errors[0].extensions.code).toBe('BAD_USER_INPUT'); }); @@ -148,7 +148,7 @@ test.describe('atypical use', () => { userId, preferences: ['not-a-preference'], }); - expect(result.data).toBeNull(); + expect(result.data.updateUserPreferences).toBeNull(); expect(result.errors[0].extensions.code).toBe('BAD_USER_INPUT'); expect(result.errors[0].message).toContain('Unknown preferences'); }); diff --git a/e2e/helpers/navigation.ts b/e2e/helpers/navigation.ts index 60837488..52e67c11 100644 --- a/e2e/helpers/navigation.ts +++ b/e2e/helpers/navigation.ts @@ -2,10 +2,12 @@ import { expect, type Page } from '@playwright/test'; // Shared navigation helpers for the UI tests (ui*.spec.ts) -// Opens the sidebar menu and waits until it is open. -// The regex matches the button text in both English and Norwegian. +// Opens the sidebar menu on small screens. On desktop the sidebar is always +// visible and has no open button, so there is nothing to do. export async function openSidebar(page: Page) { - // Replace "åpne sidemeny" with the actual Norwegian text from the translation file - await page.getByRole('button', { name: /open sidebar|åpne sidemeny/i }).click(); + const openButton = page.getByRole('button', { name: /open sidebar|åpne sidemeny/i }); + if (!(await openButton.isVisible())) return; + + await openButton.click(); await expect(page.locator('#sidebar')).toHaveAttribute('data-open', 'true'); } \ No newline at end of file diff --git a/e2e/uiExplorePlants.spec.ts b/e2e/uiExplorePlants.spec.ts index 224759d3..f7585808 100644 --- a/e2e/uiExplorePlants.spec.ts +++ b/e2e/uiExplorePlants.spec.ts @@ -4,7 +4,7 @@ import { test, expect } from '@playwright/test'; // e2e/fixtures/plants.json. The locators are language independent (roles, option values // and CSS classes), so the test works in both Norwegian and English. -test('user pages, filters, searches, sorts and resets', async ({ page }) => { +test('user pages, filters, searches, opens a plant, sorts and resets', async ({ page }) => { const cards = page.locator('.plant-grid > li'); const searchField = page.getByRole('searchbox'); // Care level is the only select with "high" as an option @@ -46,6 +46,21 @@ test('user pages, filters, searches, sorts and resets', async ({ page }) => { await expect(cards.nth(1)).toContainText('Snake Plant'); }); + await test.step('opening a plant shows its details', async () => { + const jadeCard = cards.nth(0); + const details = jadeCard.locator('.plant-card-back'); + + await jadeCard.locator('.plant-card-front .plant-card-info-button').click(); + await expect(details).toHaveAttribute('aria-hidden', 'false'); + await expect(details).toContainText('Crassula ovata'); + await expect(details).toContainText('Minimum'); + await expect(details).toContainText('A succulent with round, glossy leaves.'); + + // Flip the card back so the next steps see the front again + await details.locator('.plant-card-info-button').click(); + await expect(details).toHaveAttribute('aria-hidden', 'true'); + }); + await test.step('sorting z–a reverses the order', async () => { await page.locator('.sort-button').click(); await page.locator('.sort-option').nth(1).click(); // name_desc, see SORT_OPTIONS diff --git a/e2e/uiMatchAndRemovePlant.spec.ts b/e2e/uiMatchAndRemovePlant.spec.ts new file mode 100644 index 00000000..5896b62a --- /dev/null +++ b/e2e/uiMatchAndRemovePlant.spec.ts @@ -0,0 +1,60 @@ +import { test, expect } from '@playwright/test'; +import { openSidebar } from './helpers/navigation'; + +// User journeys for matching plants: from PlantMatch and from ExplorePlants, +// and that matches show up in MyMatches and can be removed there. +// Each test gets a new browser and therefore a new user with no matches. + +test('user can like a plant in PlantMatch, find it in MyMatches and remove the match', async ({ + page, +}) => { + await page.goto(''); + + const likeButton = page.locator('button.like-button'); + await expect(likeButton).toBeEnabled(); + await expect(page.locator('.plant-card-front')).toBeVisible(); + + // Remember which plant was liked, since PlantMatch shows random plants + const likedName = ( + await page.locator('.plant-card-front .plant-card-name').textContent() + )?.trim(); + expect(likedName).toBeTruthy(); + await likeButton.click(); + + await openSidebar(page); + await page.locator('a[href$="/my-matches"]').click(); + + const matchCards = page.locator('.plant-card-match'); + await expect(matchCards).toHaveCount(1); + await expect(matchCards.first()).toContainText(likedName ?? ''); + + await matchCards.first().locator('.remove-match-button').click(); + await expect(matchCards).toHaveCount(0); + await expect(page.locator('.matches-grid')).toContainText( + /no matches|ingen matcher/i, + ); +}); + +test('user can add a plant from ExplorePlants and find it in MyMatches', async ({ + page, +}) => { + await page.goto('explorePlants'); + + // The first plant sorted a–z is always Aloe Vera in the fixtures + const firstCard = page.locator('.plant-grid > li').first(); + await expect(firstCard).toContainText('Aloe Vera'); + + const addButton = firstCard.locator('.add-match-button'); + await expect(addButton).toBeEnabled(); + await addButton.click(); + + // The button is disabled once the plant is in MyMatches + await expect(addButton).toBeDisabled(); + + await openSidebar(page); + await page.locator('a[href$="/my-matches"]').click(); + + const matchCards = page.locator('.plant-card-match'); + await expect(matchCards).toHaveCount(1); + await expect(matchCards.first()).toContainText('Aloe Vera'); +}); \ No newline at end of file diff --git a/e2e/uiMatchAndRemovePlants.spec.ts b/e2e/uiMatchAndRemovePlants.spec.ts deleted file mode 100644 index 0f92e681..00000000 --- a/e2e/uiMatchAndRemovePlants.spec.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { test, expect } from '@playwright/test'; -import { openSidebar } from './helpers/navigation'; - -// User journey: like a plant on PlantMatch, find it in MyMatches and remove it. -// Each test gets a new browser and therefore a new user with no matches. - -test('user can like a plant, find it in MyMatches and remove the match', async ({ - page, -}) => { - await page.goto(''); - - const likeButton = page.locator('button.like-button'); - await expect(likeButton).toBeEnabled(); - await expect(page.locator('.plant-card-front')).toBeVisible(); - - // Remember which plant was liked, since PlantMatch shows random plants - const likedName = ( - await page.locator('.plant-card-front .plant-card-name').textContent() - )?.trim(); - expect(likedName).toBeTruthy(); - await likeButton.click(); - - await openSidebar(page); - await page.locator('a[href$="/my-matches"]').click(); - - const matchCards = page.locator('.plant-card-match'); - await expect(matchCards).toHaveCount(1); - await expect(matchCards.first().locator('.plant-card-name')).toHaveText( - likedName ?? '', - ); - - await matchCards.first().locator('.remove-match-button').click(); - await expect(matchCards).toHaveCount(0); - await expect(page.locator('.matches-grid')).toContainText( - /no matches|ingen matcher/i, - ); -}); \ No newline at end of file diff --git a/e2e/uiUserProfile.spec.ts b/e2e/uiUserProfile.spec.ts index 0bb33e18..ee41c396 100644 --- a/e2e/uiUserProfile.spec.ts +++ b/e2e/uiUserProfile.spec.ts @@ -1,43 +1,63 @@ -import { test, expect } from '@playwright/test'; +import { test, expect, type Response } from '@playwright/test'; import { openSidebar } from './helpers/navigation'; // User journey: update name, description and avatar on the profile page, // check that the changes are stored, and navigate on to another page. // Each test gets a new browser and therefore a new user. +// Matches a GraphQL response whose request contains the given text, +// used to wait until a profile change has been saved +const graphqlRequestContaining = (text: string) => (response: Response) => + response.url().includes('/graphql') && + (response.request().postData() ?? '').includes(text); + test('user can update profile and avatar, and navigate between pages', async ({ page, }) => { - await page.goto('profile'); - - const name = page.locator('#profile-name'); - await expect(name).toBeVisible(); - - await page.getByRole('button', { name: /edit profile|endre profil/i }).click(); - await name.fill('John'); - await page.locator('#description').fill('Loves green plants'); - - // Picks the second avatar, since the first one ("default") is already selected for new users - const chosenAvatar = page.locator('button.avatar-option').nth(1); - await chosenAvatar.click(); - - await expect(page.locator('main.profile')).toContainText('John'); - - // Saving happens in the background: reload until the changes come from the database - await expect(async () => { + const editProfileTab = page.getByRole('button', { name: /edit profile|endre profil/i }); + const nameField = page.locator('#profile-name'); + const descriptionField = page.locator('#description'); + // New users have the profile picture "default", which is not in the list, + // so no avatar is selected from the start + const chosenAvatar = page.locator('button.avatar-option').first(); + + await test.step('user edits name, description and avatar', async () => { + await page.goto('profile'); + + // The edit form is only shown in the "Edit profile" tab + await editProfileTab.click(); + await expect(nameField).toBeVisible(); + + // Start listening before the changes are made, so no response is missed + const descriptionSaved = page.waitForResponse( + graphqlRequestContaining('Loves green plants'), + ); + const avatarSaved = page.waitForResponse(graphqlRequestContaining('"monstera"')); + + await nameField.fill('John'); + await descriptionField.fill('Loves green plants'); + await chosenAvatar.click(); + + await expect(page.locator('main.profile h1')).toContainText('John'); + await expect(chosenAvatar).toHaveAttribute('aria-pressed', 'true'); + + // Saving is debounced: wait until the changes have reached the backend + await Promise.all([descriptionSaved, avatarSaved]); + }); + + await test.step('the changes are stored after a reload', async () => { await page.reload(); - await expect(page.locator('main.profile h1')).toContainText('John', { - timeout: 1000, - }); - await expect(page.locator('main.profile')).toContainText('Loves green plants', { - timeout: 1000, - }); - }).toPass({ timeout: 10_000 }); - - // Assumes the selected avatar is marked with aria-pressed, like the sort buttons on ExplorePlants - await expect(chosenAvatar).toHaveAttribute('aria-pressed', 'true'); - - await openSidebar(page); - await page.locator('a[href$="/explorePlants"]').click(); - await expect(page.locator('.explore-page')).toBeVisible(); + await expect(page.locator('main.profile h1')).toContainText('John'); + await expect(page.locator('main.profile')).toContainText('Loves green plants'); + + // The page opens on the "Preferences" tab after a reload, so open the edit tab again + await editProfileTab.click(); + await expect(chosenAvatar).toHaveAttribute('aria-pressed', 'true'); + }); + + await test.step('user navigates to ExplorePlants', async () => { + await openSidebar(page); + await page.locator('a[href$="/explorePlants"]').click(); + await expect(page.locator('.explore-page')).toBeVisible(); + }); }); \ No newline at end of file From 2af33c3028bfc3a5e6abc21ba1f5ae6a7c4940f6 Mon Sep 17 00:00:00 2001 From: Helene Lotsberg Date: Mon, 26 Oct 2026 17:58:06 +0100 Subject: [PATCH 09/22] add useSessionState for languageSwitcher and for ThemeToggle --- .../sidebarButtons/LanguageSwitcher.tsx | 13 ++++++++++-- .../components/sidebarButtons/ThemeToggle.tsx | 21 ++++++++----------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/sidebarButtons/LanguageSwitcher.tsx b/frontend/src/components/sidebarButtons/LanguageSwitcher.tsx index 8e3a03ca..ba6885b5 100644 --- a/frontend/src/components/sidebarButtons/LanguageSwitcher.tsx +++ b/frontend/src/components/sidebarButtons/LanguageSwitcher.tsx @@ -1,11 +1,20 @@ import { useTranslation } from "react-i18next"; +import { useEffect } from "react"; +import { useSessionState } from "../../hooks/useSessionState"; function LanguageSwitcher() { const { i18n } = useTranslation(); - const isNorwegian = i18n.language === "no"; + const [language, setLanguage] = useSessionState("language", "no"); + const isNorwegian = language === "no"; + + useEffect(() => { + if (i18n.language !== language) { + void i18n.changeLanguage(language); + } + }, [i18n, language]); function toggleLanguage() { - i18n.changeLanguage(isNorwegian ? "en" : "no"); + setLanguage(isNorwegian ? "en" : "no"); } return ( diff --git a/frontend/src/components/sidebarButtons/ThemeToggle.tsx b/frontend/src/components/sidebarButtons/ThemeToggle.tsx index b029d627..138b4909 100644 --- a/frontend/src/components/sidebarButtons/ThemeToggle.tsx +++ b/frontend/src/components/sidebarButtons/ThemeToggle.tsx @@ -1,25 +1,22 @@ -import { useState } from "react"; +import { useEffect } from "react"; import { useTranslation } from "react-i18next"; import "./SideBarButton.css"; +import { useSessionState } from "../../hooks/useSessionState"; export default function ThemeToggle() { const { t } = useTranslation(); - const [darkMode, setDarkMode] = useState(false); + const [theme, setTheme] = useSessionState("theme", "light"); + const darkMode = theme === "dark"; - function changeTheme() { - if (darkMode) { - document.documentElement.setAttribute("data-theme", "light"); - setDarkMode(false); - } else { - document.documentElement.setAttribute("data-theme", "dark"); - setDarkMode(true); - } - } + useEffect(() => { + document.documentElement.setAttribute("data-theme", theme); + }, [theme]); return ( diff --git a/frontend/src/tests/LanguageSwitcher.test.tsx b/frontend/src/tests/LanguageSwitcher.test.tsx index 5c0f95b9..7ff3f30a 100644 --- a/frontend/src/tests/LanguageSwitcher.test.tsx +++ b/frontend/src/tests/LanguageSwitcher.test.tsx @@ -38,11 +38,11 @@ describe("LanguageSwitcher", () => { expect(screen.getByRole("button")).toHaveTextContent("EN"); }); - it('has the aria-label "Switch to English"', () => { + it('has an accessible name containing "Switch to English"', () => { render(); expect(screen.getByRole("button")).toHaveAccessibleName( - "Switch to English", + "EN - Switch to English", ); }); @@ -68,9 +68,11 @@ describe("LanguageSwitcher", () => { expect(screen.getByRole("button")).toHaveTextContent("NO"); }); - it('has the aria-label "Bytt til norsk"', () => { + it('has an accessible name containing "Bytt til norsk"', () => { render(); - expect(screen.getByRole("button")).toHaveAccessibleName("Bytt til norsk"); + expect(screen.getByRole("button")).toHaveAccessibleName( + "NO - Bytt til norsk", + ); }); it('calls changeLanguage with "no" when clicked', async () => { diff --git a/frontend/src/tests/__snapshots__/LanguageSwitcher.test.tsx.snap b/frontend/src/tests/__snapshots__/LanguageSwitcher.test.tsx.snap index 55ee7a2f..e04f7df6 100644 --- a/frontend/src/tests/__snapshots__/LanguageSwitcher.test.tsx.snap +++ b/frontend/src/tests/__snapshots__/LanguageSwitcher.test.tsx.snap @@ -3,7 +3,7 @@ exports[`LanguageSwitcher > matches the snapshot (English) 1`] = `