Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 10 additions & 15 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 @@ -88,7 +87,7 @@ See [backend/README.md](backend/README.md) for more details about the backend se
Both the frontend and the backend are tested with [Vitest](https://vitest.dev/).

- **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.
- **Backend:** The database connection and the GraphQL server are tested 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.

See [tests.md](docs/tests.md) for what each test file covers.

Expand Down Expand Up @@ -116,16 +115,12 @@ The coverage table is printed in the terminal. A detailed report is saved in `fr

TODO!

### 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.

## Quality and design

See [quality.md](docs/quality.md) for Lighthouse results, testing, accessibility, design choices, sustainable web development
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 @@ -337,6 +337,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
48 changes: 41 additions & 7 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,6 +317,20 @@ describe("plants", () => {
expect((await explore({ careLevel: "high" })).names).toEqual(["Cactus"]);
});

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({
names: ["Cactus", "Daisy"],
Expand Down
Loading
Loading