Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# I <3 Plants

> **Live version:** _TODO: add link to the deployed app on the VM_
I <3 Plants offers a fun way of finding plants and reading about them! Instead of scrolling through a long catalogue, you set your preferences and get shown one plant at a time. You like the plants you want and skip the ones you don't, and your matches are saved so you can come back to them later. If you already know what you are looking for, you can also search and filter the full plant collection.

The full project description and specification are in [docs/Specifications for project 2.pdf](docs/Specifications%20for%20project%202.pdf).

## Link to VM

http://it2810-03.idi.ntnu.no/project2/
Expand All @@ -14,11 +10,14 @@ http://it2810-03.idi.ntnu.no/project2/

- **Plant Match:** Shows plants one at a time. Click ✿ to like a plant or ✖ to skip it.
- **Preferences:** Choose what kind of plants you want, for example indoor, outdoor, flowering, pet friendly or succulent. Your preferences are remembered between visits.
- **My Matches:** A list of all the plants you have matched with or have added as matches.
- **Explore Plants:** Search the plant collection and filter by watering needs, sunlight, location (indoor/outdoor) and edibility.
- **My Matches:** A list of all the plants you have matched with or have added as matches. Can also delet plants from my matches.
- **Explore Plants:** Search athe plant collection and filter by watering needs, sunlight, location (indoor/outdoor) and edibility. Sort the plants by; alphabetical order, watering and care. Can also add plants to my matches from here.
- **Plant details:** Each plant card shows an image, the scientific name, a description and care information (watering, sunlight and care level).
- **Profile:** Your preferences and saved plants in one place.
- **Language and theme:** The app is available in English and Norwegian, and has a light and a dark theme.
- **Profile:** Your preferences, description, name and plant avtar is saved.
- **Language:** The app is available in English and Norwegian.
- **Theme:** has a light and a dark theme.
- **Plant Owner Test:** TODO exlusive picture
- **Plant Card** read about the plant and its prefernaces. Add the plant to my matches and remove it from my matches

## Tech stack

Expand Down Expand Up @@ -91,6 +90,7 @@ The application is tested on three levels:
- **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
Expand Down Expand Up @@ -132,6 +132,7 @@ The coverage table is printed in the terminal. A detailed report is saved in `fr

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


### 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, 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.
Expand All @@ -142,6 +143,6 @@ See [quality.md](docs/quality.md) for Lighthouse results, testing, accessibility
and work practices.

## Known issues

TODO!
If you type and switch pages within half a second after updating your profile, the last few letters are not saved, because the debounce didn't have time to send.

Information on plant card does not translate to Norwegian.
5 changes: 5 additions & 0 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ const resolvers = {
if (args.watering) {
filter.watering = new RegExp(`^${normalize(args.watering)}$`, "i");
}
if (args.sunlight) {
// sunlight is a list, and a value can be combined, e.g. "part sun/part shade".
// A regex on a list matches if any of the values contain the filter.
filter.sunlight = new RegExp(normalize(args.sunlight), "i");
}
if (args.careLevel) {
const level = normalize(args.careLevel);
// "Medium" and "Moderate" both exist in the data and mean the same
Expand Down
74 changes: 39 additions & 35 deletions backend/tests/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,37 @@ describe("starting the server", () => {
describe("plants", () => {
// Made-up plants with the same spellings as the real data, e.g. both "Medium" and "Moderate"
const PLANTS = [
{ commonName: "Aloe", watering: "Minimum", careLevel: "Low" },
{ commonName: "Basil", watering: "Frequent", careLevel: "Moderate" },
{
commonName: "Aloe",
watering: "Minimum",
careLevel: "Low",
sunlight: ["full sun"],
},
{
commonName: "Basil",
watering: "Frequent",
careLevel: "Moderate",
sunlight: ["Full sun", "part shade"],
},
{ commonName: "Cactus", watering: "minimum", careLevel: "High" },
{ commonName: "Daisy", watering: "Average", careLevel: "Medium" },
{ commonName: "Fern", watering: null, careLevel: null },
{ commonName: "Fern (giant)", watering: "Average", careLevel: "Medium" },
{
commonName: "Daisy",
watering: "Average",
careLevel: "Medium",
sunlight: ["part sun/part shade"],
},
{ commonName: "Fern", watering: null, careLevel: null, sunlight: null },
{
commonName: "Fern (giant)",
watering: "Average",
careLevel: "Medium",
sunlight: ["filtered shade"],
},
];

const EXPLORE = `
query ($search: String, $watering: String, $careLevel: String, $sort: String, $limit: Int, $offset: Int) {
explorePlants(search: $search, watering: $watering, careLevel: $careLevel, sort: $sort, limit: $limit, offset: $offset) {
query ($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 }
}
Expand Down Expand Up @@ -297,35 +317,19 @@ 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("filters on sunlight, matching any value in the list", async () => {
expect((await explore({ sunlight: "full_sun" })).names).toEqual([
"Aloe",
"Basil",
]);
expect((await explore({ sunlight: "part_shade" })).names).toEqual([
"Basil",
"Daisy",
]);
expect((await explore({ sunlight: "part_sun" })).names).toEqual([
"Daisy",
]);

it("returns one page at a time with the total count", async () => {
expect(await explore({ limit: 2, offset: 2 })).toEqual({
Expand Down
Loading
Loading