Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 13 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ http://it2810-03.idi.ntnu.no/project2/
## Core features

- **Plant Match:** Shows plants one at a time, best matches for your preferences first. Click ✿ to like a plant or ✖ to skip it.
- **Preferences:** Choose what you want from a plant: how much water it needs (minimum, average, frequent), how much sun it needs (full sun, part shade, filtered shade) and how much care it needs (easy, medium, hard). The preferences are saved in the database. Plant cards highlight the traits that match your preferences, and Plant Match shows the plants that match the most of your preferences first. Without preferences, the plants come in random order.
- **Preferences:** Choose what you want from a plant: how much water it needs (minimum, average, frequent), how much sun it needs (full sun, part shade, filtered shade) and how much care it needs (easy, medium, hard). The preferences are saved in the database. Plant cards highlight the traits that match your preferences, and Plant Match shows the plants that match the most of your preferences first. Changing your preferences starts Plant Match over with a newly ordered deck. Without preferences, the plants come in random order.
- **My Matches:** A list of all the plants you have liked in Plant Match or added from Explore Plants, with the number of matches shown above. Sort them by newest, oldest or name (A–Z or Z–A), and move between pages when there are many. The sort order is remembered for the session, also when you go to another page and back. You can also remove plants from the list.
- **Explore Plants:** Search the plant collection by common or scientific name and filter by watering, sunlight and care level. Sort the plants alphabetically (A–Z or Z–A), by watering or by care level. Search, filtering and sorting run in the backend on the whole collection, and the number of results is shown above the plants. The results are split into pages, and you can jump straight to any page. The search, filters, sorting and current page are stored in the URL, so an Explore view can be refreshed or shared as a link. Add a plant to My Matches with the ✿ button, and click it again to remove it.
- **Explore Plants:** Search the plant collection by common or scientific name and filter by watering, sunlight and care level. Sort the plants alphabetically (A–Z or Z–A), by watering or by care level. Search, filtering and sorting run in the backend on the whole collection, and the number of results is shown above the plants. The results are split into pages, and you can jump straight to any page. The search, filters, sorting and current page are stored in the URL, so an Explore view can be refreshed or shared as a link. Add a plant to My Matches with the ✿ button, which then turns into ✖, and click it again to remove it.
- **Plant details:** Each plant card shows an image, the scientific name, a description and care information (watering, sunlight and care level). Flip the card to read more about the plant.
- **Profile:** Your name, description, avatar and preferences are saved in the database.
- **Plant Owner Test:** A short quiz that tells you what kind of plant owner you are. Each result has its own picture, which you can only get through the test, and you can save it as your profile picture.
Expand Down Expand Up @@ -52,15 +52,15 @@ npm run install:all

This installs the dependencies for the repo root, `backend` and `frontend`.

### 2. Create the backend `.env` file (in the VSC terminal window)
### 2. Create the backend `.env` file (in the VS Code terminal)

```bash
cp backend/.env.example backend/.env
```

The default values work as they are. `.env` is ignored by git and must never be committed.

### 3. Open an SSH tunnel to the database (in PC terminal window)
### 3. Open an SSH tunnel to the database (in a separate PC-terminal)

Open a **separate terminal**, replace `<ntnu-username>` with your username and run the command below.

Expand All @@ -70,7 +70,7 @@ After you enter your password, the command looks like it hangs. That means the t
ssh -N -L 27017:localhost:27017 <ntnu-username>@it2810-03.idi.ntnu.no
```

### 4. Start the app (in the VSC terminal window)
### 4. Start the app (in the VS Code terminal)

From the repo root:

Expand All @@ -92,29 +92,21 @@ Browser ──> Apache (port 80, /project2) serves the built frontend

### Backend

The backend runs with pm2, which keeps it running in the background and restarts it if it crashes or the VM reboots. The backend reads `MONGODB_URI=mongodb://localhost:27017`, `DB_NAME=iloveplants` and `PORT=3001` from `backend/.env` on the VM (see `.env.example`). If the backend stops, see [How to start the backend if it stops](../T03-Project-2/docs/architecture.md) .
The backend runs with pm2, which keeps it running in the background and restarts it if it crashes or the VM reboots. The backend reads `MONGODB_URI=mongodb://localhost:27017`, `DB_NAME=iloveplants` and `PORT=3001` from `backend/.env` on the VM (see `.env.example`).

### Frontend

The frontend runs on the VM by using Apache serves. It was copied to the folder Apache serves for `/project2`. The build reads `VITE_GRAPHQL_URL` from [frontend/.env.production](frontend/.env.production), so the deployed app sends its requests to the backend on port 3001 on the VM.
Apache serves the built frontend on the VM. The build was copied to the folder Apache serves for `/project2`. The build reads `VITE_GRAPHQL_URL` from [frontend/.env.production](frontend/.env.production), so the deployed app sends its requests to the backend on port 3001 on the VM.

### Database

MongoDB is installed directly on the VM and only listens on `127.0.0.1`, so it cannot be reached from outside the VM. The plant data was loaded once with `npm run seed` in the backend (see [architecture.md](docs/architecture.md#data-source-the-perenual-api)).

## Testing

The application is tested on three levels:
The application is tested on three levels: component tests for the frontend (Vitest and React Testing Library), backend tests against an in-memory MongoDB (Vitest and mongodb-memory-server), and end-to-end and API tests with Playwright, which also check all pages against WCAG 2.1 AA with axe. None of the tests use the database on the VM, so they need neither the VPN nor the SSH tunnel.

- **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 the test files cover, the e2e setup, the scenarios and what the tests found.

### Run the tests

Run these from the repo root:
Run the tests from the repo root:

```bash
npm run test:frontend
Expand All @@ -123,39 +115,20 @@ 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 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

| Part | Statements | Branches | Functions | Lines |
| -------- | ---------- | -------- | --------- | ------- |
| Frontend | 96.7 % | 94.82 % | 92.92 % | 98.33 % |
| Frontend | 96.95 % | 92.75 % | 95.31 % | 97.67 % |
| Backend | 100 % | 100 % | 100 % | 100 % |

- Frontend test coverage:

<img src="docs/media/coverageFrontend.png" alt="Test coverage for the frontend" width="500">

- Backend test coverage:

<img src="docs/media/coverageBackend.png" alt="Test coverage for the backend" width="500">
See [tests.md](docs/tests.md) for the test strategy, more ways to run the tests, how to run the tests with coverage and screenshots of the coverage reports, what the test files cover and what the tests found.

## Quality and design

See [quality.md](docs/quality.md) for Lighthouse results, testing, accessibility, design choices, sustainable web development and work practices.
See [quality.md](docs/quality.md) for work practices, accessibility, sustainable web development and design choices.

## Known issues

- Information on plant card does not translate to Norwegian.
- There is no login. The user id is stored in the browser, so the profile and matches belong to that browser and cannot be reached from other devices, and anyone who knows a user id can change that user, since the id is sent with every request. Login would solve both, and is a possible next step.
- The plant information on the plant cards is not translated to Norwegian.
Loading
Loading