diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c988b021..74559583 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -51,3 +51,33 @@ jobs:
- run: npm run lint
- run: npm test -- --run
- run: npm run build
+
+ e2e:
+ # Playwright starts the in-memory test database, the backend and the frontend
+ # itself, so no VM, VPN or SSH tunnel is needed
+ runs-on: ubuntu-latest
+ timeout-minutes: 20
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 24
+ cache: npm
+ cache-dependency-path: |
+ package-lock.json
+ backend/package-lock.json
+ frontend/package-lock.json
+ - run: npm ci
+ - run: npm ci
+ working-directory: backend
+ - run: npm ci
+ working-directory: frontend
+ - run: npx playwright install --with-deps chromium
+ - run: npm run test:e2e
+ # The HTML report with traces of failed tests can be downloaded from the run
+ - uses: actions/upload-artifact@v4
+ if: failure()
+ with:
+ name: playwright-report
+ path: playwright-report/
+ retention-days: 7
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/README.md b/README.md
index 3fdd408c..31ee238a 100644
--- a/README.md
+++ b/README.md
@@ -22,13 +22,13 @@ http://it2810-03.idi.ntnu.no/project2/
## Tech stack
-| Part | Technology |
-| -------- | ------------------------------------------------------------- |
-| Frontend | React, TypeScript, Vite, Apollo Client, React Router, i18next |
-| Backend | Node.js, TypeScript, Apollo Server (GraphQL) |
-| Database | MongoDB, running on the course VM |
-| Testing | Vitest, React Testing Library, jsdom, mongodb-memory-server |
-| Tooling | ESLint, Prettier, GitHub Actions |
+| Part | Technology |
+| -------- | --------------------------------------------------------------------------------- |
+| Frontend | React, TypeScript, Vite, Apollo Client, React Router, i18next |
+| Backend | Node.js, TypeScript, Apollo Server (GraphQL) |
+| Database | MongoDB, running on the course VM |
+| Testing | Vitest, React Testing Library, jsdom, mongodb-memory-server, Playwright, axe-core |
+| Tooling | ESLint, Prettier, GitHub Actions |
## Architecture
@@ -85,40 +85,56 @@ See [backend/README.md](backend/README.md) for more details about the backend se
## Testing
-Both the frontend and the backend are tested with [Vitest](https://vitest.dev/).
+The application is tested on three levels:
-- **Frontend:** Pages, components and hooks are tested with React Testing Library in a simulated browser (jsdom). Calls to the backend are mocked, so the backend does not need to be running.
-- **Backend:** The database connection and the GraphQL server are tested against a real MongoDB that runs in memory ([mongodb-memory-server](https://www.npmjs.com/package/mongodb-memory-server)). The tests never use the database on the VM, so they do not need the VPN or the SSH tunnel. MongoDB is downloaded once the first time the backend tests run.
+- **Frontend:** Pages, components and hooks are tested with **Vitest** and **React Testing Library** in a simulated browser (**jsdom**). Calls to the backend are mocked, so the backend does not need to be running.
+- **Backend:** The database connection and the GraphQL server are tested with **Vitest** against a real MongoDB that runs in memory (**mongodb-memory-server**). The tests never use the database on the VM, so they do not need the VPN or the SSH tunnel. MongoDB is downloaded once the first time the backend tests run.
+- **End-to-end:** Longer user journeys and the GraphQL API are tested with **Playwright**, against the real backend and a built frontend with a separate in-memory test database. The tests run on both desktop and mobile, and check all pages against WCAG 2.1 AA with **axe**.
-See [tests.md](docs/tests.md) for what each test file covers.
+See [tests.md](docs/tests.md) for what the test files cover, the e2e setup, the scenarios and what the tests found.
### Run the tests
Run these from the repo root:
```bash
-
-npm run test:backend
npm run test:frontend
+npm run test:backend
+npm run test:e2e
```
+The first time you run the e2e tests, install the browser with `npx playwright install chromium`.
+Use `npm run test:e2e:ui` to step through the tests in Playwright's UI mode, or
+`npm run test:e2e:headed` to watch them in a browser.
+
### Run the tests with coverage
```bash
-# Coverage for only the backend or only the frontend
-npm run test:backend -- --coverage
+# Coverage for only the frontend or only the backend
npm run test:frontend -- --coverage
+npm run test:backend -- --coverage
```
The coverage table is printed in the terminal. A detailed report is saved in `frontend/coverage/index.html` and `backend/coverage/index.html`, which you can open in a browser to see which lines are not tested.
### Test coverage
-TODO!
+| Part | Statements | Branches | Functions | Lines |
+| -------- | ---------- | -------- | --------- | ------- |
+| Frontend | 96.7 % | 94.73 % | 92.92 % | 98.33 % |
+| Backend | 100 % | 100 % | 100 % | 100 % |
+
+- Frontend test coverage:
+
+
+
+- Backend test coverage:
+
+
### Continuous integration
-GitHub Actions ([.github/workflows/ci.yml](.github/workflows/ci.yml)) runs on every pull request and on every push to `main`. It checks the formatting with Prettier, and runs lint, tests for both the backend and the frontend.
+GitHub Actions ([.github/workflows/ci.yml](.github/workflows/ci.yml)) runs on every pull request and on every push to `main`. It checks the formatting with Prettier, runs lint and tests for both the backend and the frontend, and runs the Playwright e2e and API tests. If an e2e test fails, the HTML report with traces can be downloaded from the workflow run.
## Quality and design
diff --git a/backend/package-lock.json b/backend/package-lock.json
index e4bcd521..b5a989db 100644
--- a/backend/package-lock.json
+++ b/backend/package-lock.json
@@ -1531,17 +1531,17 @@
}
},
"node_modules/@typescript-eslint/eslint-plugin": {
- "version": "8.72.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.72.0.tgz",
- "integrity": "sha512-aysKgysPX9XOv/dk95UkvUDe++Q3n3dJPG9CEWT3RUccxfkPJ+Qn6nhKPDhZXU6Ofo9kgwGWwKyQCnZIXTgngg==",
+ "version": "8.72.1",
+ "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.72.1.tgz",
+ "integrity": "sha512-5CokTWXpmbylfFabsbvHC0CAw3XLaGnoa+nFJX5FR592h/LoZsENUE6p/rg5xvkKrFEXz6pYmgI29AgXc2N3BQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@eslint-community/regexpp": "^4.12.2",
- "@typescript-eslint/scope-manager": "8.72.0",
- "@typescript-eslint/type-utils": "8.72.0",
- "@typescript-eslint/utils": "8.72.0",
- "@typescript-eslint/visitor-keys": "8.72.0",
+ "@typescript-eslint/scope-manager": "8.72.1",
+ "@typescript-eslint/type-utils": "8.72.1",
+ "@typescript-eslint/utils": "8.72.1",
+ "@typescript-eslint/visitor-keys": "8.72.1",
"ignore": "^7.0.5",
"natural-compare": "^1.4.0",
"ts-api-utils": "^2.5.0"
@@ -1554,7 +1554,7 @@
"url": "https://opencollective.com/typescript-eslint"
},
"peerDependencies": {
- "@typescript-eslint/parser": "^8.72.0",
+ "@typescript-eslint/parser": "^8.72.1",
"eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
"typescript": ">=4.8.4 <6.1.0"
}
@@ -1570,16 +1570,16 @@
}
},
"node_modules/@typescript-eslint/parser": {
- "version": "8.72.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.72.0.tgz",
- "integrity": "sha512-0O+x3ynciD6zuXb1CKSu165haQV6ey53DKhHHUnujP7U+XlltJG+/keT0Xhd1HXCze+IHf7Tvt39ovyepX/LNw==",
+ "version": "8.72.1",
+ "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.72.1.tgz",
+ "integrity": "sha512-ZGwZP4OCfyA0AQTpEAMWz+rtX01DRhQWW5hB0ucKDEIX5U7jdmPSaMx94rQfaPAQzIYz2BimOgKOJtjfpRFQ9g==",
"dev": true,
"license": "MIT",
"dependencies": {
- "@typescript-eslint/scope-manager": "8.72.0",
- "@typescript-eslint/types": "8.72.0",
- "@typescript-eslint/typescript-estree": "8.72.0",
- "@typescript-eslint/visitor-keys": "8.72.0",
+ "@typescript-eslint/scope-manager": "8.72.1",
+ "@typescript-eslint/types": "8.72.1",
+ "@typescript-eslint/typescript-estree": "8.72.1",
+ "@typescript-eslint/visitor-keys": "8.72.1",
"debug": "^4.4.3"
},
"engines": {
@@ -1595,14 +1595,14 @@
}
},
"node_modules/@typescript-eslint/project-service": {
- "version": "8.72.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.72.0.tgz",
- "integrity": "sha512-bzHngBbmIgzj6TsTjVUCntGx6FFLgE7mPjpO0PzHycOaZHXqS43XnrkFIHRS16LLr/xO6FHSXG3GJFo/F4bSBQ==",
+ "version": "8.72.1",
+ "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.72.1.tgz",
+ "integrity": "sha512-fAuVMkwdO/huI8nyo/WKnNKf6Gag93S56Rh3Ts5mGcavwSdaN8tRg1gCeIGX8PF+nzp1BjGfO4gHhGzW1J6jTg==",
"dev": true,
"license": "MIT",
"dependencies": {
- "@typescript-eslint/tsconfig-utils": "^8.72.0",
- "@typescript-eslint/types": "^8.72.0",
+ "@typescript-eslint/tsconfig-utils": "^8.72.1",
+ "@typescript-eslint/types": "^8.72.1",
"debug": "^4.4.3"
},
"engines": {
@@ -1617,14 +1617,14 @@
}
},
"node_modules/@typescript-eslint/scope-manager": {
- "version": "8.72.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.72.0.tgz",
- "integrity": "sha512-JewPyJOYcXBSAS7PIgufscHOwZqhTGyBRiQJhhuDln66tMchxvvt7nJ90JKKIoOelmdHA3kAQbm9cEUHc4JSEA==",
+ "version": "8.72.1",
+ "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.72.1.tgz",
+ "integrity": "sha512-lC/t6eMCZZQAAKZEYGL6RDVSuFehpdmMT6h+nJIjIa6oylN/PwDgDVtEIbB7O9xFfZYtZAYLoLlDNWKJhtF+uQ==",
"dev": true,
"license": "MIT",
"dependencies": {
- "@typescript-eslint/types": "8.72.0",
- "@typescript-eslint/visitor-keys": "8.72.0"
+ "@typescript-eslint/types": "8.72.1",
+ "@typescript-eslint/visitor-keys": "8.72.1"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
@@ -1635,9 +1635,9 @@
}
},
"node_modules/@typescript-eslint/tsconfig-utils": {
- "version": "8.72.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.72.0.tgz",
- "integrity": "sha512-0vbxCf7xLVPSjcOdm6eQbgViH8EDJ8xnl1laLT9yoqSz2YmcSfSg5Vdl0JUvZf6rcuJ0ZivJIuMD4edTg8obaA==",
+ "version": "8.72.1",
+ "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.72.1.tgz",
+ "integrity": "sha512-e4D5R5vpeAEPBxT2BAzsFQL3sbwyeeeo5+aczgNSRK1V734jE7pTqaGFU+fXapWEQwnZbpFaTn32+Z8DwS6OTg==",
"dev": true,
"license": "MIT",
"engines": {
@@ -1652,15 +1652,15 @@
}
},
"node_modules/@typescript-eslint/type-utils": {
- "version": "8.72.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.72.0.tgz",
- "integrity": "sha512-gEXxmmbSTSOVTC37IYYvremOM31v+UN2W772bJxmVYPhAOPSUxtacyb7wkm1EhkYKU6KzFJsdU44DCV4to0LWw==",
+ "version": "8.72.1",
+ "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.72.1.tgz",
+ "integrity": "sha512-iY2wlmyrXJmx4yxUGP3aYCFF3cA/6ShddOKmLU2dx7LnEykbAM8WThlxZEfd1NddqceF6eJmZUayxx9oKIYNlg==",
"dev": true,
"license": "MIT",
"dependencies": {
- "@typescript-eslint/types": "8.72.0",
- "@typescript-eslint/typescript-estree": "8.72.0",
- "@typescript-eslint/utils": "8.72.0",
+ "@typescript-eslint/types": "8.72.1",
+ "@typescript-eslint/typescript-estree": "8.72.1",
+ "@typescript-eslint/utils": "8.72.1",
"debug": "^4.4.3",
"ts-api-utils": "^2.5.0"
},
@@ -1677,9 +1677,9 @@
}
},
"node_modules/@typescript-eslint/types": {
- "version": "8.72.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.72.0.tgz",
- "integrity": "sha512-Adfoy59kxNEjT5E5fnyrp7GpHYuWs8ONbdohu4ez6IU46qDq8LltG90tLmkucZB2uhYL8mqBjtXqGd8yhfjXqQ==",
+ "version": "8.72.1",
+ "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.72.1.tgz",
+ "integrity": "sha512-LmE5IhQet1BWOWEXqBrVtBPsMAOQ6Nzk35d+WLh3mk4EUF33sqlfxjio1MdYeSvKSG5skactKKuixBIKXhL4Rw==",
"dev": true,
"license": "MIT",
"engines": {
@@ -1691,16 +1691,16 @@
}
},
"node_modules/@typescript-eslint/typescript-estree": {
- "version": "8.72.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.72.0.tgz",
- "integrity": "sha512-gwLfFgWcw15tN2KXDCJvxEOQjPn+P3j/n3eSqkZ5sX4VpW9Cosodr+tWwBZRvJT3TcKx6HnPRGZMCNAiP1Xhug==",
+ "version": "8.72.1",
+ "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.72.1.tgz",
+ "integrity": "sha512-DAlUoUV93hIvrtIQLwCbmZQYVZwOMhiHJrOVUUIWicFZaIYjTRqlY3I/NZevfkLmSqkNHRu2qYDcq9lrn16oOQ==",
"dev": true,
"license": "MIT",
"dependencies": {
- "@typescript-eslint/project-service": "8.72.0",
- "@typescript-eslint/tsconfig-utils": "8.72.0",
- "@typescript-eslint/types": "8.72.0",
- "@typescript-eslint/visitor-keys": "8.72.0",
+ "@typescript-eslint/project-service": "8.72.1",
+ "@typescript-eslint/tsconfig-utils": "8.72.1",
+ "@typescript-eslint/types": "8.72.1",
+ "@typescript-eslint/visitor-keys": "8.72.1",
"debug": "^4.4.3",
"minimatch": "^10.2.2",
"semver": "^7.7.3",
@@ -1719,16 +1719,16 @@
}
},
"node_modules/@typescript-eslint/utils": {
- "version": "8.72.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.72.0.tgz",
- "integrity": "sha512-0up3oArJZBYnzOaEXKo8DmI43QvMZyPoFEt9LWzRJcyl/RcJjfKKPebknN1VbTgXBf3M/KggUh5uUMdURLnseg==",
+ "version": "8.72.1",
+ "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.72.1.tgz",
+ "integrity": "sha512-5v5liypurJBFHCBNqh/RjsymAD+VWcE0djuGY/BUqp5fC3Qn+luWDEksjuTtWjPn6i5zQlUtkZCRG/CYG0yCkA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@eslint-community/eslint-utils": "^4.9.1",
- "@typescript-eslint/scope-manager": "8.72.0",
- "@typescript-eslint/types": "8.72.0",
- "@typescript-eslint/typescript-estree": "8.72.0"
+ "@typescript-eslint/scope-manager": "8.72.1",
+ "@typescript-eslint/types": "8.72.1",
+ "@typescript-eslint/typescript-estree": "8.72.1"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
@@ -1743,13 +1743,13 @@
}
},
"node_modules/@typescript-eslint/visitor-keys": {
- "version": "8.72.0",
- "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.72.0.tgz",
- "integrity": "sha512-E2mroviasaWecDzTGiGMtuEguuLVOeRggnrIn93CJuxYJzQBHbyymlT08aVQydbBal5538o+JkBKXh2sRuCyIA==",
+ "version": "8.72.1",
+ "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.72.1.tgz",
+ "integrity": "sha512-SB8xqipSzZHUePCCLNeYxqnxq83X61/qzNhjQGbTfjxGZIeOEP7tBgWYX05Tcd6CgE02WdTJnh5b8kMZJ/+bnQ==",
"dev": true,
"license": "MIT",
"dependencies": {
- "@typescript-eslint/types": "8.72.0",
+ "@typescript-eslint/types": "8.72.1",
"eslint-visitor-keys": "^5.0.0"
},
"engines": {
@@ -3548,9 +3548,9 @@
}
},
"node_modules/magic-string": {
- "version": "1.4.4",
- "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.4.tgz",
- "integrity": "sha512-jQz9sVhrZuphH4NrAIHSgkDJCluQO7Ioi4KGRLa7aTUjAODQ13hENX0YIytqYE/rIkO485gQG2LeBxJaW53kkQ==",
+ "version": "1.4.5",
+ "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.5.tgz",
+ "integrity": "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==",
"dev": true,
"license": "MIT",
"dependencies": {
@@ -4131,9 +4131,9 @@
}
},
"node_modules/postcss": {
- "version": "8.5.31",
- "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.31.tgz",
- "integrity": "sha512-YUbWYCgErwnMAVkjUnYa+KlMBzGpHwiIt/DE7f0G33AuX2LH9UcTk6KgWxd3zRU+pN3u/C+Xl3EnMLM4Hea7Sg==",
+ "version": "8.5.32",
+ "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.32.tgz",
+ "integrity": "sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g==",
"dev": true,
"funding": [
{
@@ -4200,9 +4200,9 @@
"license": "MIT"
},
"node_modules/qs": {
- "version": "6.16.1",
- "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.1.tgz",
- "integrity": "sha512-5Px6J7rfHBAGUhNQ3es4YzcOdBBw0SDcVtThJml4RdnKw4tKs2epA0kPZ+K8X+WiHktT93RHVcQ/3ym5aTCgtg==",
+ "version": "6.17.0",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.17.0.tgz",
+ "integrity": "sha512-5LK5BZ2XDHMvcUJaf0CQ5HL3aVgKbpklvByC7qLSxYkfE8COEEbJg5xCHWCTqzqi0Gs4Jn5Mv5v3R38W6edscA==",
"license": "BSD-3-Clause",
"dependencies": {
"es-define-property": "^1.0.1",
@@ -4724,16 +4724,16 @@
}
},
"node_modules/typescript-eslint": {
- "version": "8.72.0",
- "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.72.0.tgz",
- "integrity": "sha512-r26Fkc8As+mZvqp7SLsMmNFyYUup/6CjK7/eHBHmhOw6GH6n6YFxHVFrG0jN1c5CMpDzelLPxvgeCOzx7BjN+A==",
+ "version": "8.72.1",
+ "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.72.1.tgz",
+ "integrity": "sha512-3Li9FfPmQp45nxEtFD1ZCrYFI3cYK5kpyNtmm1H7lMagm8u9sy6PTjy3ytwQZs7KNukOyKFHAZ6z6GjYFeaeXw==",
"dev": true,
"license": "MIT",
"dependencies": {
- "@typescript-eslint/eslint-plugin": "8.72.0",
- "@typescript-eslint/parser": "8.72.0",
- "@typescript-eslint/typescript-estree": "8.72.0",
- "@typescript-eslint/utils": "8.72.0"
+ "@typescript-eslint/eslint-plugin": "8.72.1",
+ "@typescript-eslint/parser": "8.72.1",
+ "@typescript-eslint/typescript-estree": "8.72.1",
+ "@typescript-eslint/utils": "8.72.1"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
diff --git a/backend/src/server.ts b/backend/src/server.ts
index 177cf9f4..032c780f 100644
--- a/backend/src/server.ts
+++ b/backend/src/server.ts
@@ -334,6 +334,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");
}
diff --git a/backend/tests/server.test.ts b/backend/tests/server.test.ts
index 54a2f61d..d4434880 100644
--- a/backend/tests/server.test.ts
+++ b/backend/tests/server.test.ts
@@ -297,6 +297,36 @@ describe("plants", () => {
expect((await explore({ careLevel: "high" })).names).toEqual(["Cactus"]);
});
+ it("filters on sunlight in any of a plant's sunlight values, without caring about case", async () => {
+ // Replaces the plants from beforeEach with plants that have sunlight values
+ await db.collection("plants").deleteMany({});
+ await insertPlants(
+ { commonName: "Aloe", sunlight: ["full sun"] },
+ { commonName: "Basil", sunlight: ["full sun", "part shade"] },
+ { commonName: "Cactus", sunlight: ["Full sun"] },
+ { commonName: "Daisy", sunlight: ["part shade"] },
+ { commonName: "Fern" },
+ );
+
+ const bySunlight = async (sunlight: string) => {
+ const result = await execute<{ explorePlants: Page }>(
+ `query ($sunlight: String) {
+ explorePlants(sunlight: $sunlight) { totalCount plants { name } }
+ }`,
+ { sunlight },
+ );
+ expect(result.errors).toBeUndefined();
+ return result.data!.explorePlants.plants.map((p) => p.name);
+ };
+
+ // "full_sun" from the frontend matches "full sun" and "Full sun" in the database,
+ // also when the plant has several sunlight values
+ expect(await bySunlight("full_sun")).toEqual(["Aloe", "Basil", "Cactus"]);
+ expect(await bySunlight("part_shade")).toEqual(["Basil", "Daisy"]);
+ // The whole value must match, so part of a word gives no plants
+ expect(await bySunlight("sun")).toEqual([]);
+ });
+
it("returns one page at a time with the total count", async () => {
expect(await explore({ limit: 2, offset: 2 })).toEqual({
names: ["Cactus", "Daisy"],
@@ -360,6 +390,23 @@ describe("users", () => {
expect(result.data?.updateUserProfile?.profilePicture).toBe("default");
});
+ it("stores null when the name or description is sent as null", async () => {
+ const { id } = await createUser();
+ await updateProfile({ userId: id, name: "Nina", description: "Hi" });
+
+ const result = await updateProfile({
+ userId: id,
+ name: null,
+ description: null,
+ });
+
+ expect(result.errors).toBeUndefined();
+ expect(result.data?.updateUserProfile).toMatchObject({
+ name: null,
+ description: null,
+ });
+ });
+
it.each([
"cityMinimalist",
"averageCityGardener",
diff --git a/docs/media/coverageBackend.png b/docs/media/coverageBackend.png
new file mode 100644
index 00000000..b93dc85e
Binary files /dev/null and b/docs/media/coverageBackend.png differ
diff --git a/docs/media/coverageFrontend.png b/docs/media/coverageFrontend.png
new file mode 100644
index 00000000..0adc9625
Binary files /dev/null and b/docs/media/coverageFrontend.png differ
diff --git a/docs/quality.md b/docs/quality.md
index ffe4182b..9fbf7b4d 100644
--- a/docs/quality.md
+++ b/docs/quality.md
@@ -21,44 +21,33 @@ This document describes how we have worked to ensure the quality of the applicat
- In addition to writing automated tests, we manually tested the application throughout development to identify issues and verify its functionality.
-## Testing
-
-See [tests.md](tests.md) for what we test, how the tests are organised and how to run them.
-
-To run all tests from the repo root:
-
-```bash
-npm test
-```
-
-Lint, tests and build also run automatically on every pull request through GitHub Actions ([.github/workflows/ci.yml](../.github/workflows/ci.yml)).
-
-TODO! The testing coverage is:
-
-`npm run lint`, `npm test` and `npm run build` are the same checks GitHub Actions runs on every pull request, so running them locally first saves you a failed CI run.
-
-- Snapshot tests are used to detect unintended changes to the rendered UI.
+- As part of our code review process, team members checked out pull requests locally and tested the new functionality before approving changes. This helped us verify that changes worked as expected in practice, rather than relying solely on code review.
-- In addition to automated testing, we manually tested the application throughout development as new features were implemented. This allowed us to evaluate usability and verify that the application behaved as intended.
+## Testing
-- Testing was performed on both mobile and desktop devices, leading to adjustments such as improvements to the mobile layout.
+Automated tests help ensure that the application works as intended and that new changes do not break existing functionality. The application is tested on three levels: component tests check each part of the frontend in isolation, backend tests check every GraphQL query and mutation against a real database, and end-to-end tests check that the whole application works together the way a user experiences it, on both desktop and mobile.
-- As part of our code review process, team members checked out pull requests locally and tested the new functionality before approving changes. This helped us verify that changes worked as expected in practice, rather than relying solely on code review.
+All tests run in GitHub Actions on every pull request, so a pull request that breaks a test cannot be merged unnoticed. The end-to-end tests also check all pages against WCAG 2.1 AA, which helped us find and fix accessibility problems that the other tests did not catch.
-For more details about individual test files, see test coverage, and instructions for running the tests, see [Tests](tests.md).
+See [tests.md](tests.md) for the test strategy, the coverage, the results and how to run the tests.
## Accessibility
The app includes the following accessibility features:
- **Page structure:** Semantic `header`, `nav`, `main` and `article` elements organise the content. Sidebar navigation has an accessible name, and the current page is marked with `aria-current="page"`.
+
- **Keyboard controls:** Navigation uses links, and actions use native buttons. Sidebar links, pagination, sorting controls and avatar options have explicit focus styles. Plant Match instructions are also shown when their control receives focus.
+
- **Forms and images:** Search, filters and profile inputs have associated labels. Plant images use the plant name as alternative text, and profile and avatar images also include alternative text.
+
- **Control states:** The sort menu exposes its expanded state, and sort and avatar choices expose their selected state with ARIA attributes. Pagination announces page changes through an `aria-live="polite"` region.
+
- **Plant cards:** The inactive side of a flipped card is hidden from assistive technology with `aria-hidden`, and its information button is removed from the keyboard tab order.
+
- **Reduced motion:** The card flip and My Matches hover transitions are disabled when the user requests reduced motion.
-The deployed production version received an Accessibility score of **100 in Lighthouse** in our latest reported run. Automated component tests also check selected accessible names, navigation state and sorting states.
+- **Automated and manual testing:** The end-to-end tests check all pages against WCAG 2.1 AA with axe, in both light and dark mode, and the app has been tested manually with the keyboard only and at 200 % zoom. See [tests.md](tests.md#end-to-end-and-api-tests) for the results, including two problems the tests found.
- **axe DevTools:** Axe Accessibility Testing found no automatic accessibility issues on the page when tested against WCAG 2.1 AA.
@@ -68,6 +57,8 @@ The deployed production version received an Accessibility score of **100 in Ligh
- **Responsive layout:** We tested the application on both mobile and desktop devices. Manual testing helped us identify usability issues and make adjustments to the mobile layout.
+- The deployed production version received an Accessibility score of **100 in Lighthouse** in our latest reported run. Automated component tests also check selected accessible names, navigation state and sorting states.
+
## Sustainable web development
We considered sustainability through both our design choices
@@ -75,7 +66,7 @@ and our approach to data handling.
- **Limited colour palette:** We use a limited number of colours throughout the application to maintain a consistent design and follow the principle of avoiding unnecessary use of colours.
-- **Dark mode:** The application supports both light and dark themes. Dark mode can reduce energy consumption because darker pixels generally require less power.
+- **Dark mode:** The application supports both light and dark themes. Dark mode can reduce energy consumption on OLED screens, which are common on phones, because dark pixels use less power there. It also gives users a choice that can be more comfortable in low light.
- **Caching:** Apollo Client uses an in-memory cache to reuse previously fetched data. This can reduce repeated network requests when the same data is needed again.
diff --git a/docs/tests.md b/docs/tests.md
index 2511dcbe..5653c670 100644
--- a/docs/tests.md
+++ b/docs/tests.md
@@ -1,86 +1,270 @@
# Tests
-The application is tested using **Vitest** and **React Testing Library**. We test pages, components and hooks, including rendering, user interactions and functionality.
-**Snapshot tests** are also used to ensure that the rendered UI remains consistent when changes are made. Both the frontend and backend code was tested as specified below. The test coverage was found to be --- (TODO fyll inn).
+- [Tests](#tests)
+ - [Test strategy](#test-strategy)
+ - [Run the tests](#run-the-tests)
+ - [If the tests do not start](#if-the-tests-do-not-start)
+ - [To run the Vitest tests with coverage](#to-run-the-vitest-tests-with-coverage)
+ - [Test coverage](#test-coverage)
+ - [Overview of test files](#overview-of-test-files)
+ - [Component tests (frontend)](#component-tests-frontend)
+ - [Backend tests](#backend-tests)
+ - [End-to-end and API tests](#end-to-end-and-api-tests)
+ - [Setup](#setup)
+ - [Scenarios](#scenarios)
+ - [Accessibility](#accessibility)
+ - [Finding: label in name (WCAG 2.5.3)](#finding-label-in-name-wcag-253)
+ - [Finding: colour contrast measured during a transition](#finding-colour-contrast-measured-during-a-transition)
+ - [Limitations of the automatic accessibility tests](#limitations-of-the-automatic-accessibility-tests)
+ - [Manual testing](#manual-testing)
-**end-to-end tests** TODO: skriv her
+## Test strategy
-The tests cover the following areas:
+The application is tested on three levels, each with its own purpose:
-- Rendering of pages and components.
-- User interactions, such as navigating between pages, opening plant cards and liking or disliking plants.
-- Switching between Norwegian and English, and that both languages have the same translation keys.
-- Reusable hooks, including debouncing and storing state in `sessionStorage`.
-- Accessibility, such as the sidebar navigation landmark and accessible names.
+| Level | Tools | What it tests | Data |
+| -------------------------- | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
+| Component tests (frontend) | Vitest, React Testing Library, jsdom | Pages, components, hooks and context in isolation: rendering, props and state, user interaction, accessibility and snapshots | Mocked GraphQL responses, so the backend is not needed |
+| Backend tests | Vitest, mongodb-memory-server | The database connection and every GraphQL query and mutation, including validation and error handling | A real MongoDB in memory, filled by each test |
+| End-to-end and API tests | Playwright, axe | Longer user journeys through the whole application, the GraphQL API over HTTP, and WCAG 2.1 AA on every page | A real backend and a built frontend against a separate in-memory test database with fixed test plants |
+
+The component and backend tests are fast and detailed, and test one part at a time, including cases that are hard to reach through the user interface. The end-to-end tests are fewer, but check that the parts work together the way a user experiences them.
+
+All levels test both **typical use** (searching, filtering, matching plants, editing the profile) and **atypical use**: empty results, too long input, unknown values, invalid ids, a backend that is down, blocked browser storage and invalid GraphQL requests.
+
+None of the tests use the database on the VM, so they need neither the VPN nor the SSH tunnel.
+
+## Run the tests
+
+The first time the e2e tests run, install the browser with `npx playwright install chromium`. The first time the backend or e2e tests run, MongoDB is downloaded once. The e2e tests also build the backend and frontend, so they take a little longer the first time.
+
+Run from the root folder:
+
+```bash
+npm run test:frontend # component tests
+npm run test:backend # backend tests
+npm run test:e2e # end-to-end and API tests
+npm run test:e2e:ui # e2e tests in Playwright's UI mode, step by step
+npm run test:e2e:headed # desktop e2e tests in a visible browser
+npx playwright test --project=mobile --headed # the same on mobile (Pixel 7)
+npx playwright show-report # HTML report with traces of failed e2e tests
+```
+
+### If the tests do not start
+
+If the tests stop with `Cannot find native binding` or `Cannot find module '@rolldown/binding-...'`,
+npm has skipped a platform-specific package (a known npm bug). Reinstall the dependencies for
+that folder, for example for the backend:
+
+```bash
+rm -rf backend/node_modules
+npm install --prefix backend
+```
+
+If that does not help, the lock file is missing the package for your platform. Delete it as well
+and reinstall, and commit the new `package-lock.json`:
+
+```bash
+rm -rf backend/node_modules backend/package-lock.json
+npm install --prefix backend
+```
+
+### To run the Vitest tests with coverage
+
+```bash
+npm run test:frontend -- --coverage
+npm run test:backend -- --coverage
+```
+
+If some tests fail, a report can still be made with `npx vitest run --coverage --coverage.reportOnFailure=true`.
+
+To watch an e2e test, open UI mode, run a test, and expand it to choose the desktop or mobile run. The trace shows every step the test took, with a screenshot of the page before and after each action, the network requests and the browser console.
+
+All tests also run in GitHub Actions on every pull request, see [Continuous integration](../README.md#continuous-integration) in the README.
## Test coverage
-TODO! Sett inn bilde
+| Part | Statements | Branches | Functions | Lines |
+| -------- | ---------- | -------- | --------- | ------- |
+| Frontend | 96.7 % | 94.73 % | 92.92 % | 98.33 % |
+| Backend | 100 % | 100 % | 100 % | 100 % |
+
+- Frontend test coverage:
+
+
+
+- Backend test coverage:
+
+
+
+The frontend coverage counts every source file in `frontend/src`, not only the files a test happens to import, so files without tests are shown with 0 % instead of being left out. Only the test files themselves, type declarations (`.d.ts`) and `main.tsx`, which only starts the app, are left out.
+
+The coverage only counts the Vitest tests. Code that is only run by the end-to-end tests is shown as not covered, even when it is tested there.
## Overview of test files
-### Tests in frontend
+### Component tests (frontend)
-The following tests are located in the folder `frontend/src/tests`.
+The tests are in `frontend/src/tests`. Snapshot tests are used for the explore page, the language switcher and the profile page.
-- `Sidebar.test.tsx`
- - Tests the sidebar, including the title, navigation links to all pages, and that the language switcher and theme toggle are displayed. Also verifies that the sidebar closes when a link or the close button is clicked, that the open state is reflected in the `data-open` attribute, and that the navigation landmark is accessible and only the current page is marked as active.
+- `App.test.tsx`
+ - Shows the right page for each route, and opens and closes the sidebar from the header.
+- `ExplorePage.test.tsx`
+ - Loading, error and empty results: a loading message, an error message when the query fails, and a message without page navigation when nothing matches.
+ - Search, filters and sorting: the search text is only sent after the debounce delay, the chosen filters and sort order are sent in the query, and the sort menu closes with Escape and with a click outside.
+ - Pagination: moving between pages, disabled buttons at the ends, and going back to page 1 when a filter or the search text changes.
+ - Reset and session: reset clears the search and all filters, and the filters are remembered when the page is opened again in the same session.
+ - Accessibility: a search landmark, a heading and labelled controls.
+ - Snapshots of the page with results, with no results and with the sort menu open.
- `Header.test.tsx`
- - **TODO!**
+ - Shows the right title for each page, and opens the sidebar with the menu button.
+- `LanguageSettings.test.tsx`
+ - Switching language changes the content at once and is kept after a reload, an unsupported saved language falls back to Norwegian, and switching works when browser storage is blocked.
+- `LanguageSwitcher.test.tsx`
+ - The button text and accessible name in both languages, that clicking switches to the other language, and snapshots for both languages.
- `MyMatchesPage.test.tsx`
- - Tests the my matches page, including that the page and its scroll buttons are rendered, and that clicking the left and right buttons scrolls the scroll bar in the correct direction.
-- `ExplorePage.test.tsx`
- - Tests the explore page, including that all plants are displayed when no filters are selected, and that plant cards can be opened and closed to show or hide plant information.
+ - A message when there are no matches, the loading state instead of that message, and that saved matches are shown and can be removed.
+- `PlantCard.test.tsx`
+ - The back of the card shows the whole plant after clicking information, missing facts and images are shown as unknown, and watering, sunlight and care level are turned into the right preference chips.
- `PlantMatchPage.test.tsx`
- - Tests the plant match page, including the title, instructions and preferences button, and that the next plant is shown when the user clicks like or dislike.
+ - The instructions and the first plant, going to the next plant with like and dislike and the empty card at the end, that a liked plant is saved as a match and a skipped one is not, the loading and error states, and that preferences saved on the profile are highlighted on the card.
+- `PlantOwnerTest.test.tsx`
+ - The result for all six combinations of answers, and that the time and light answers do not change it.
+ - Going on is only possible with an answer, an earlier answer is shown when going back, the result is shown with its picture, the result can be saved as profile picture, an error is shown when saving fails, the page says so when the result already is the profile picture, and the test can be taken again with no answers.
+- `PlantPreferences.test.tsx`
+ - Saved preferences are marked, preferences can be added and removed, the page does not crash when saving fails, and nothing is saved before the user exists.
- `Profile.test.tsx`
- - Tests the profile page, including the name and image, that the preferences tab is shown by default, and that the user can switch to the saved plants tab and see the saved plants. Also includes a snapshot test.
+ - The name, the image alt text and a screen reader prefix for the description, the preferences tab by default, the labelled fields and avatar chooser in the edit tab, saving name, description and avatar, the saved avatar, that a picture from the plant owner test is shown but not offered in the chooser, and a snapshot.
+- `Sidebar.test.tsx`
+ - The title, links to all pages, the language switcher and theme toggle, that the sidebar closes when a link or the close button is clicked, that the open state is shown in the `data-open` attribute, an accessible navigation landmark, and that only the current page is marked as active.
- `ThemeToggle.test.tsx`
- - **TODO!**
-- `LanguageSwitcher.test.tsx`
- - Tests the language switcher button in both Norwegian and English, and verifies that it shows the correct label and accessible name, and that clicking it switches to the other language.
+ - Switching between dark and light mode, restoring the saved mode on load, falling back to light mode for an invalid saved theme, and switching when browser storage is blocked.
- `Translation.test.tsx`
- - Verifies that the Norwegian and English translation files contain exactly the same keys, so no text is missing in either language.
-- `useDebounce.test.tsx`
- - Tests the `useDebounce` hook, including that the initial value is returned immediately, that updates only happen after the delay, that the delay restarts on rapid changes, and that the default delay is 800 ms.
-- `useSessionState.test.tsx`
- - Tests the `useSessionState` hook, including default and initial values, reading and saving values in `sessionStorage`, persistence when the hook is mounted again, and fallback behavior when storage reading or saving fails.
-
-### Tests in backend
+ - The Norwegian and English translation files have exactly the same keys, so no text is missing in either language.
+- `UserContext.test.tsx`
+ - No user without a provider, loading the user saved in the browser, creating and saving a new user on the first visit, creating a new user when the saved one no longer exists, keeping the saved user when the backend is down, working on when creating a user fails, and removing old user data left in the browser.
+- `useDebounce.test.ts`
+ - The initial value is returned at once, updates only come after the delay, the delay restarts on quick changes, and the default delay is 800 ms.
+- `useSessionState.test.ts`
+ - Default and initial values, reading and saving in `sessionStorage`, keeping the value when the hook is mounted again, and working on when reading or saving fails.
-The following tests are located in the folder `backend/tests`.
+### Backend tests
-The test in backend uses a mongodb-memory-server that is setup in the `tests/globalSetup.ts`. It keeps its data in memory and is shut down when the tests finish. This is a real in-memory MongoDB, not the database on the VM. The database starts empty, and each test adds the plants and users it needs, so the results are predictable and the real data is never changed. The tests therefore do not need the VPN or the SSH tunnel. The first time the tests run, MongoDB is downloaded once.
+The tests are in `backend/tests`. They use a real MongoDB in memory, started in `globalSetup.ts` and stopped when the tests finish. The database starts empty and each test adds the plants and users it needs, so the results are predictable and the real data is never changed.
- `globalSetup.ts`
- - Not a test file. Starts the in-memory MongoDB before the tests run and stops it afterwards.
+ - Not a test file. Starts the in-memory MongoDB before the tests and stops it afterwards.
- `db.test.ts`
- - Tests the database connection in `db.ts`, including that it connects to the database in `MONGODB_URI` and `DB_NAME`, and uses `iloveplants` when `DB_NAME` is not set. Also verifies the error messages when the connection fails: when `MONGODB_URI` is missing or empty, when it is not a MongoDB address, and when MongoDB cannot be reached (for example when the SSH tunnel is down).
+ - Connecting to the database in `MONGODB_URI` and `DB_NAME`, using `iloveplants` when `DB_NAME` is not set, and the error messages when `MONGODB_URI` is missing or empty, is not a MongoDB address, or MongoDB cannot be reached (for example when the SSH tunnel is down).
- `server.test.ts`
- - Tests the GraphQL server in `server.ts`. The database connection is replaced by the in-memory MongoDB, and the server does not open a port, so the tests send their requests directly to the server.
- - Plants: random plants from `getPlants`, and search, filters, sorting and pagination in `explorePlants`, including that "Medium" and "Moderate" count as the same care level and that special characters in the search are treated as plain text.
- - Users: creating and fetching users, updating the profile and preferences, and adding and removing matched plants.
- - Error messages: that invalid input gives the right message and code (`BAD_USER_INPUT`) and saves nothing, for example a name over 40 characters, an unknown profile picture, unknown preferences or an unknown plant. Also verifies the errors for invalid GraphQL requests, and that the server passes on the error and keeps running when the database fails.
+ - Starting the server: the default port 3001, the port in `PORT`, and stopping with the error when the port is in use.
+ - Plants: random plants from `getPlants`, stored image data before the image URL, and in `explorePlants` the default sorting, case-insensitive search with special characters read as text, the watering, care level and sunlight filters ("Medium" and "Moderate" count as the same care level), pagination with the total count, and all sort orders.
+ - Users: creating and fetching users, updating the profile (trimming text, storing empty text and `null` as `null`, and only changing the sent fields), the plant owner test results as profile pictures, preferences without duplicates, adding and removing matches in order, and skipping matched plants that were deleted.
+ - Error messages: invalid input gives the right message and the code `BAD_USER_INPUT` and saves nothing (too long name or description, unknown profile picture, unknown preferences, unknown or malformed plant ids), invalid GraphQL requests give the right error, and the server passes on a database error and keeps running.
+
+### End-to-end and API tests
+
+End-to-end (e2e) tests check that the application works as a whole, from the browser through the GraphQL backend to the database, by running longer sequences of interactions the way a user would. We use **Playwright** for both the e2e tests and the API tests, so both run against the same backend and the same test data. The tests are in `e2e/`.
+
+#### Setup
+
+The tests run in an environment as close to production as possible: a real browser, a real backend and a real MongoDB database, with a built frontend instead of the dev server.
+
+`playwright.config.ts` starts three servers in order before the tests run:
+
+| Server | Port | Purpose |
+| ---------------------------------------------- | ----- | --------------------------------------------------------------------------------------------------- |
+| In-memory MongoDB (`e2e/start-test-db.mjs`) | 27018 | A separate test database, so the tests never touch the development data on the VM |
+| Backend (`npm run build` + `npm run start`) | 3002 | The real GraphQL backend, pointed at the test database through `MONGODB_URI` and `DB_NAME` |
+| Frontend (`npm run build` + `npm run preview`) | 4173 | The built app, with `VITE_GRAPHQL_URL` overridden so it talks to the test backend instead of the VM |
+
+The ports differ from the dev setup (27017 for the SSH tunnel, 3001 for the dev backend), so the tests can run while the dev servers are running.
+
+Before the tests start, `e2e/global-setup.ts` empties the test database and fills it with the 20 plants in `e2e/fixtures/plants.json`. Every test run therefore starts from exactly the same data, which lets the tests check exact results (for example that searching for "plant" gives exactly two plants). The fixture plants were chosen to cover the cases we want to test: both "Medium" and "Moderate" as care level, a plant without a care level, and more than 12 plants so there are two pages.
+
+The tests run in three Playwright projects:
+
+- **api**: the API tests (`api*.spec.ts`), which send GraphQL requests straight to the backend without a browser
+- **desktop** and **mobile**: the UI tests (`ui*.spec.ts`), which run in Desktop Chrome and on a Pixel 7, so every user journey is tested on both screen sizes
+
+Other choices in the config:
+
+- `workers: 1`: all tests share one database, so they run one at a time.
+- `retries: 1` and `failOnFlakyTests` in CI: a test that only passes on the second attempt still counts as a failure, so unstable tests are not hidden.
+- `trace: 'retain-on-failure'`: a failed test saves a trace with screenshots of every step, which can be opened in the HTML report.
+
+#### Scenarios
+
+Each file covers one scenario, and API and UI tests for the same feature come in pairs. The **API tests** check the backend logic over HTTP, including atypical input that is hard to reach through the UI. The **UI tests** check that the frontend is correctly connected to the backend and that the user journeys work from start to finish.
+
+| Feature | API test | UI test |
+| ----------------------------------------- | ------------------------ | ----------------------- |
+| Search, filter, sort, pagination, details | `apiExplorePlants` | `uiExplorePlants` |
+| Profile and avatar | `apiUserProfile` | `uiUserProfile` |
+| Matching and removing plants | `apiMatchAndRemovePlant` | `uiMatchAndRemovePlant` |
+| Accessibility on all pages | – | `uiAccessibility` |
+
+**ExplorePlants (`uiExplorePlants`):** one continuous user journey that tests pagination, filtering, search, the detail view, sorting and reset, and that changing a filter on page 2 takes the user back to page 1.
+
+**Matching plants (`uiMatchAndRemovePlant`):**
+
+- Liking a plant on PlantMatch adds it to MyMatches, where it can be removed.
+- Adding a plant from ExplorePlants adds it to MyMatches and disables its ✿ button.
+
+PlantMatch shows random plants, so the test remembers the name of the liked plant and checks that it is the same plant that ends up in MyMatches.
+
+**Profile (`uiUserProfile`):** changing name, description and avatar is shown at once and is still there after a reload, so the changes are stored in the database.
+
+Saving the profile is debounced by 800 ms. The test waits until the save request has reached the backend before reloading, instead of waiting a fixed time, so it does not depend on the length of the debounce.
+
+**API tests:**
+
+- **explorePlants**: default sorting and page size, `offset`, case-insensitive search, regex characters treated as plain text, the watering, care level and sunlight filters, the sort orders, and that plants without a care level are sorted last.
+- **User profile**: a new user's default values, updating and reading back the profile and preferences, that only the sent fields change, that duplicate preferences are removed, and that too long names and descriptions, unknown profile pictures, unknown preferences and invalid user ids are rejected or return `null` without crashing.
+- **Matches**: adding, reading back and removing a match, that matches keep the order they were added in, that the same plant is only matched once, and that unknown or malformed plant ids are rejected.
+
+#### Accessibility
+
+`uiAccessibility.spec.ts` runs **axe** through `@axe-core/playwright` against WCAG 2.1 level A and AA, the level required for the public sector in Norway. It checks:
+
+- all five pages (PlantMatch, ExplorePlants, MyMatches, Profile and PlantOwnerTest), in both light and dark mode, since colour contrast has to meet the requirements in both themes
+- content that only appears after an interaction: a flipped plant card, the edit tab on the profile page, MyMatches with a matched plant, and the result of the plant owner test
+
+The tests run on both desktop and mobile, since the layout, and the elements that are visible, differ between them. A failing test lists each element that breaks a rule, with axe's explanation (for contrast: the colours and the ratio).
+
+##### Finding: label in name (WCAG 2.5.3)
+
+The first run of the accessibility tests failed on every page on desktop with the same violation:
+
+```
+label-content-name-mismatch: Elements must have their visible text as part of their accessible name
+```
+
+WCAG 2.5.3 (Label in Name) requires that the accessible name of an element includes its visible text. This matters for users of speech input, who say what they see ("click EN"). If the accessible name is something else, the command does not work.
+
+The violation only appeared on desktop, where the sidebar is always visible, and not on mobile, where it is hidden until opened. This pointed to the sidebar, and the cause turned out to be the language button:
+
+| | Visible text | Accessible name |
+| ------ | ------------ | ------------------------ |
+| Before | `EN` | `Switch to English` |
+| After | `EN` | `EN - Switch to English` |
-## Run tests
+The accessible name now starts with the visible text. After the fix, the test passes on all pages.
-`npm run test` in the root folder runs both the backend and the frontend tests, and `npm run test:coverage` runs them with test coverage. The same tests run in GitHub Actions on every pull request. To run the tests with coverage for only one part:
+This is a good example of what automated e2e testing adds: the button worked visually and with a mouse, and the component tests only checked that it had the accessible name we had given it, so the problem was not visible until the whole page was checked against the WCAG rules.
-Frontend:
+##### Finding: colour contrast measured during a transition
-- `cd frontend`
-- `npm run test -- --coverage`
+The dark mode tests first failed with `color-contrast` violations, but the reported colours did not exist anywhere in our CSS, and the result changed from run to run. The colours turned out to be about 85 % of the way between the light and the dark theme: the app has CSS transitions on colours, and the test ran axe right after switching theme, before the transition had finished. The test now turns off transitions before switching theme, so axe measures the final colours. After this change, all pages pass the contrast check in both light and dark mode.
-Backend:
+##### Limitations of the automatic accessibility tests
-- `cd backend`
-- `npm run test -- --run --coverage`
+Automatic testing only finds some accessibility problems, and the tests only check the formal WCAG A and AA rules, not axe's extra "best practice" rules (such as one `` landmark and one `` per page). They also cannot check that the tab order is logical or that the app is easy to use with a screen reader, which needs manual testing.
-The coverage report is shown in the terminal. A more detailed report is saved in `frontend/coverage/index.html` or `backend/coverage/index.html`, which can be opened in a browser to see which lines are not tested.
+## Manual testing
-### To run tests with test coverage if not all tests are running
+The group has tested the application manually in Chrome on Mac and on a mobile phone throughout development, using all pages and features on both. This testing led to adjustments such as improvements to the mobile layout.
-- `npx vitest run --coverage --coverage.reportOnFailure=true`
+**Keyboard only:** all pages have been tested with Tab, Shift+Tab, Enter and Escape only. All links and buttons can be reached and used, the focus is visible at all times, and the sort menu closes with Escape.
-End-to-end testing:
-TODO! fyll inn
+**Zoom to 200 %:** on a laptop screen, the app switches to the mobile layout at 200 % zoom. The sidebar is hidden and can be opened with the menu button in the header, so the layout adapts to the larger text instead of needing horizontal scrolling (WCAG 1.4.4 and 1.4.10).
diff --git a/e2e/apiExplorePlants.spec.ts b/e2e/apiExplorePlants.spec.ts
new file mode 100644
index 00000000..19efe555
--- /dev/null
+++ b/e2e/apiExplorePlants.spec.ts
@@ -0,0 +1,113 @@
+import { test, expect, type APIRequestContext } from "@playwright/test";
+import { graphql } from "./helpers/graphql";
+
+// 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(
+ $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 }[];
+}
+
+// Sends the query and checks that the response contains no GraphQL errors
+async function explorePlants(
+ request: APIRequestContext,
+ variables: Record = {},
+): Promise {
+ const body = await graphql(request, EXPLORE_PLANTS, variables);
+ expect(body.errors).toBeUndefined();
+ return body.data.explorePlants;
+}
+
+const names = (result: ExploreResult) => result.plants.map((p) => p.name);
+
+test.describe("explorePlants", () => {
+ 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 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("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("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 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 }) => {
+ const result = await explorePlants(request, { watering: "minimum" });
+ expect(result.totalCount).toBe(7);
+ });
+
+ test("sorting z–a", async ({ request }) => {
+ const result = await explorePlants(request, { sort: "name_desc" });
+ expect(result.plants[0].name).toBe("Zebra Haworthia");
+ });
+
+ 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");
+ });
+
+ // 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/apiMatchAndRemovePlant.spec.ts b/e2e/apiMatchAndRemovePlant.spec.ts
new file mode 100644
index 00000000..f9c4e21b
--- /dev/null
+++ b/e2e/apiMatchAndRemovePlant.spec.ts
@@ -0,0 +1,141 @@
+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.addUserMatch).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.removeUserMatch).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 },
+ ]);
+ });
+});
diff --git a/e2e/apiUserProfile.spec.ts b/e2e/apiUserProfile.spec.ts
new file mode 100644
index 00000000..3c12cd5d
--- /dev/null
+++ b/e2e/apiUserProfile.spec.ts
@@ -0,0 +1,174 @@
+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.updateUserProfile).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.updateUserProfile).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.updateUserProfile).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.updateUserPreferences).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();
+ });
+});
diff --git a/e2e/fixtures/plants.json b/e2e/fixtures/plants.json
new file mode 100644
index 00000000..67869c3b
--- /dev/null
+++ b/e2e/fixtures/plants.json
@@ -0,0 +1,202 @@
+[
+ {
+ "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
+ }
+]
diff --git a/e2e/global-setup.ts b/e2e/global-setup.ts
new file mode 100644
index 00000000..4b0588ba
--- /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";
+
+// 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() {
+ // 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(); // also removes users and matches from the previous run
+ await db.collection("plants").insertMany(plants);
+ } finally {
+ await client.close();
+ }
+}
diff --git a/e2e/helpers/graphql.ts b/e2e/helpers/graphql.ts
new file mode 100644
index 00000000..72d12817
--- /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;
+}
diff --git a/e2e/helpers/navigation.ts b/e2e/helpers/navigation.ts
new file mode 100644
index 00000000..f609e4bf
--- /dev/null
+++ b/e2e/helpers/navigation.ts
@@ -0,0 +1,15 @@
+import { expect, type Page } from "@playwright/test";
+
+// Shared navigation helpers for the UI tests (ui*.spec.ts)
+
+// 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) {
+ 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");
+}
diff --git a/e2e/start-test-db.mjs b/e2e/start-test-db.mjs
new file mode 100644
index 00000000..80d3a531
--- /dev/null
+++ b/e2e/start-test-db.mjs
@@ -0,0 +1,14 @@
+// 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(`Test database running at ${mongod.getUri()}`);
+
+const stop = async () => {
+ await mongod.stop();
+ process.exit(0);
+};
+process.on("SIGINT", stop);
+process.on("SIGTERM", stop);
diff --git a/e2e/test-db.ts b/e2e/test-db.ts
new file mode 100644
index 00000000..298eba73
--- /dev/null
+++ b/e2e/test-db.ts
@@ -0,0 +1,5 @@
+// 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";
diff --git a/e2e/uiAccessibility.spec.ts b/e2e/uiAccessibility.spec.ts
new file mode 100644
index 00000000..85e5a50c
--- /dev/null
+++ b/e2e/uiAccessibility.spec.ts
@@ -0,0 +1,125 @@
+import { test, expect, type Page } from "@playwright/test";
+import AxeBuilder from "@axe-core/playwright";
+
+// Automatic accessibility check with axe against WCAG 2.1 level A and AA,
+// the level required for the public sector in Norway.
+// axe only finds part of the problems, so this is combined with manual testing
+// (keyboard only, 200 % zoom and screen reader), see tests.md.
+
+const WCAG_TAGS = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"];
+
+/// Runs axe on the page and lists the violations in a readable form: the rule,
+// which elements broke it, and axe's explanation (for contrast: the colours and ratio)
+async function checkAccessibility(page: Page) {
+ const results = await new AxeBuilder({ page }).withTags(WCAG_TAGS).analyze();
+ const violations = results.violations.flatMap((v) =>
+ v.nodes.map(
+ (node) =>
+ `${v.id}: ${node.target.join(" ")} – ${node.any[0]?.message ?? v.help}`,
+ ),
+ );
+ expect(violations).toEqual([]);
+}
+
+// Sets the theme the same way ThemeToggle does, after the page has loaded.
+// CSS transitions are turned off first, otherwise axe measures the colours
+// halfway between the light and the dark theme.
+async function setTheme(page: Page, theme: "light" | "dark") {
+ await page.addStyleTag({
+ content: "*, *::before, *::after { transition: none !important; }",
+ });
+ await page.evaluate(
+ (value) => document.documentElement.setAttribute("data-theme", value),
+ theme,
+ );
+ await expect(page.locator("html")).toHaveAttribute("data-theme", theme);
+}
+
+// Each page and an element that shows the page has finished loading
+const PAGES = [
+ { name: "PlantMatch", path: "", loaded: ".plant-card-front" },
+ { name: "ExplorePlants", path: "explorePlants", loaded: ".plant-grid > li" },
+ { name: "MyMatches", path: "my-matches", loaded: ".matches-grid" },
+ { name: "Profile", path: "profile", loaded: "main.profile" },
+ {
+ name: "PlantOwnerTest",
+ path: "plantOwnerTest",
+ loaded: ".plant-owner-test",
+ },
+];
+
+// Colour contrast is the only check that differs between the themes,
+// but both themes must meet the contrast requirements
+const THEMES = ["light", "dark"] as const;
+
+for (const theme of THEMES) {
+ test.describe(`${theme} mode`, () => {
+ for (const { name, path, loaded } of PAGES) {
+ test(`${name} has no WCAG 2.1 AA violations`, async ({ page }) => {
+ await page.goto(path);
+ await expect(page.locator(loaded).first()).toBeVisible();
+ await setTheme(page, theme);
+ await checkAccessibility(page);
+ });
+ }
+ });
+}
+
+// Content that only appears after an interaction is not checked above
+
+test.describe("after interaction", () => {
+ test("ExplorePlants with a plant card flipped", async ({ page }) => {
+ await page.goto("explorePlants");
+ const firstCard = page.locator(".plant-grid > li").first();
+ await firstCard
+ .locator(".plant-card-front .plant-card-info-button")
+ .click();
+ await expect(firstCard.locator(".plant-card-back")).toHaveAttribute(
+ "aria-hidden",
+ "false",
+ );
+ await checkAccessibility(page);
+ });
+
+ test("Profile with the edit tab open", async ({ page }) => {
+ await page.goto("profile");
+ await page
+ .getByRole("button", { name: /edit profile|endre profil/i })
+ .click();
+ await expect(page.locator("#profile-name")).toBeVisible();
+ await checkAccessibility(page);
+ });
+
+ test("MyMatches with a matched plant", async ({ page }) => {
+ // A new user has no matches, so add one from ExplorePlants first
+ await page.goto("explorePlants");
+ const addButton = page
+ .locator(".plant-grid > li")
+ .first()
+ .locator(".add-match-button");
+ await addButton.click();
+ await expect(addButton).toBeDisabled();
+
+ await page.goto("my-matches");
+ await expect(page.locator(".plant-card-match")).toHaveCount(1);
+ await checkAccessibility(page);
+ });
+
+ test("PlantOwnerTest showing a result", async ({ page }) => {
+ await page.goto("plantOwnerTest");
+
+ const options = page.locator(".plant-owner-test-option");
+ const nextButton = page
+ .locator(".plant-owner-test-navigation button")
+ .last();
+
+ // Picks the first option on all four questions, which gives "cityMinimalist"
+ for (let question = 0; question < 4; question++) {
+ await options.first().click();
+ await nextButton.click();
+ }
+
+ await expect(page.locator(".plant-owner-test-result")).toBeVisible();
+ await checkAccessibility(page);
+ });
+});
diff --git a/e2e/uiExplorePlants.spec.ts b/e2e/uiExplorePlants.spec.ts
new file mode 100644
index 00000000..ee0a8334
--- /dev/null
+++ b/e2e/uiExplorePlants.spec.ts
@@ -0,0 +1,80 @@
+import { test, expect } from "@playwright/test";
+
+// 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("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
+ 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("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("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("a filter on page 2 takes the user back to page 1", async () => {
+ await careLevelSelect.selectOption("medium");
+ await expect(cards).toHaveCount(7); // includes "Moderate"
+ await expect(cards.first()).toContainText("Boston Fern");
+ await expect(previousButton).toBeDisabled();
+ });
+
+ await test.step("search shows only the matching plants", async () => {
+ await careLevelSelect.selectOption("");
+ await expect(cards).toHaveCount(12);
+ await searchField.fill("plant");
+ // 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("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
+ await expect(cards.first()).toContainText("Snake Plant");
+ });
+
+ await test.step("reset shows all plants again", async () => {
+ await page.locator(".reset-button").click();
+ await expect(searchField).toHaveValue("");
+ await expect(cards).toHaveCount(12);
+ await expect(cards.first()).toContainText("Aloe Vera");
+ });
+});
diff --git a/e2e/uiMatchAndRemovePlant.spec.ts b/e2e/uiMatchAndRemovePlant.spec.ts
new file mode 100644
index 00000000..41b44458
--- /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");
+});
diff --git a/e2e/uiUserProfile.spec.ts b/e2e/uiUserProfile.spec.ts
new file mode 100644
index 00000000..44126be4
--- /dev/null
+++ b/e2e/uiUserProfile.spec.ts
@@ -0,0 +1,69 @@
+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,
+}) => {
+ 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");
+ 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();
+ });
+});
diff --git a/frontend/src/components/sidebarButtons/LanguageSwitcher.tsx b/frontend/src/components/sidebarButtons/LanguageSwitcher.tsx
index 8e3a03ca..3961694f 100644
--- a/frontend/src/components/sidebarButtons/LanguageSwitcher.tsx
+++ b/frontend/src/components/sidebarButtons/LanguageSwitcher.tsx
@@ -1,11 +1,21 @@
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 initialLanguage = i18n.language === "en" ? "en" : "no";
+ const [language, setLanguage] = useSessionState("language", initialLanguage);
+ 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 (
@@ -13,7 +23,9 @@ function LanguageSwitcher() {
type="button"
className="sidebar-button language-button"
onClick={toggleLanguage}
- aria-label={isNorwegian ? "Switch to English" : "Bytt til norsk"}
+ aria-label={
+ isNorwegian ? "EN - Switch to English" : "NO - Bytt til norsk"
+ }
>
{isNorwegian ? "EN" : "NO"}
diff --git a/frontend/src/tests/LanguageSettings.test.tsx b/frontend/src/tests/LanguageSettings.test.tsx
index 24f4399a..8094e653 100644
--- a/frontend/src/tests/LanguageSettings.test.tsx
+++ b/frontend/src/tests/LanguageSettings.test.tsx
@@ -32,7 +32,9 @@ describe("language settings", () => {
expect(screen.getByRole("heading")).toHaveTextContent("Profil");
expect(document.documentElement.lang).toBe("no");
- await user.click(screen.getByRole("button", { name: "Switch to English" }));
+ await user.click(
+ screen.getByRole("button", { name: "EN - Switch to English" }),
+ );
expect(screen.getByRole("heading")).toHaveTextContent("Profile");
expect(document.documentElement.lang).toBe("en");
expect(localStorage.getItem("language")).toBe("en");
diff --git a/frontend/src/tests/LanguageSwitcher.test.tsx b/frontend/src/tests/LanguageSwitcher.test.tsx
index 3cee7e0c..7ff3f30a 100644
--- a/frontend/src/tests/LanguageSwitcher.test.tsx
+++ b/frontend/src/tests/LanguageSwitcher.test.tsx
@@ -3,6 +3,12 @@ import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi, beforeEach } from "vitest";
import LanguageSwitcher from "../components/sidebarButtons/LanguageSwitcher";
+// The language choice is stored in sessionStorage, so clear it between tests
+// to stop one test's click from deciding the next test's starting language
+beforeEach(() => {
+ sessionStorage.clear();
+});
+
const changeLanguage = vi.fn();
let mockLanguage = "no";
@@ -32,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",
);
});
@@ -62,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/Profile.test.tsx b/frontend/src/tests/Profile.test.tsx
index 22f41d88..28b57019 100644
--- a/frontend/src/tests/Profile.test.tsx
+++ b/frontend/src/tests/Profile.test.tsx
@@ -115,7 +115,6 @@ describe("Profile page", () => {
]) {
const button = screen.getByRole("button", {
name: `profile.${avatar}`,
- exact: true,
});
expect(button.querySelector("img")).toHaveAttribute("alt", "");
expect(button).not.toHaveAttribute("aria-label");
@@ -210,7 +209,9 @@ describe("Profile page", () => {
);
// Only the seven plant avatars can be chosen, and none of them is selected
- const choices = screen.getAllByRole("button", { name: /^Choose / });
+ const choices = screen.getAllByRole("button", {
+ name: /^profile\.(monstera|pothos|snake-plant|anthurium|succulent|fern|orchid)$/,
+ });
expect(choices).toHaveLength(7);
choices.forEach((choice) =>
expect(choice).toHaveAttribute("aria-pressed", "false"),
diff --git a/frontend/src/tests/ThemeToggle.test.tsx b/frontend/src/tests/ThemeToggle.test.tsx
index 8b72af02..dacc91d0 100644
--- a/frontend/src/tests/ThemeToggle.test.tsx
+++ b/frontend/src/tests/ThemeToggle.test.tsx
@@ -40,7 +40,9 @@ describe("ThemeToggle", () => {
expect(document.documentElement).toHaveAttribute("data-theme", theme);
expect(screen.getByRole("button")).toHaveAccessibleName(
- theme === "dark" ? "sidebar.switchToLightMode" : "sidebar.switchToDarkMode",
+ theme === "dark"
+ ? "sidebar.switchToLightMode"
+ : "sidebar.switchToDarkMode",
);
});
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`] = `