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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ 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.

Expand All @@ -114,11 +113,12 @@ npm run test:frontend -- --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!

### 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 and build 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, and runs lint, tests for both the backend and the frontend.

## Quality and design

Expand Down
10 changes: 9 additions & 1 deletion backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ interface UserMatchArgs extends UserIdArgs {
const NAME_MAX_LENGTH = 40;
const DESCRIPTION_MAX_LENGTH = 100;

// Must match the avatar ids in frontend/src/pages/profile/Profile.tsx
// Must match the avatar ids in frontend/src/pages/profile/Profile.tsx and the
// result ids in frontend/src/pages/plantOwnerTest/plantownertest.ts
const PROFILE_PICTURES = [
"default",
"monstera",
Expand All @@ -101,6 +102,13 @@ const PROFILE_PICTURES = [
"succulent",
"fern",
"orchid",
// Results from the plant owner test
"cityMinimalist",
"averageCityGardener",
"cityGardenerDreaming",
"countryMinimalist",
"averageCountryGardener",
"gardenExpert",
];

// Must match the preference ids in frontend/src/pages/profile/Profile.tsx
Expand Down
22 changes: 22 additions & 0 deletions backend/tests/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,28 @@ describe("users", () => {
expect(result.data?.updateUserProfile?.profilePicture).toBe("default");
});

it.each([
"cityMinimalist",
"averageCityGardener",
"cityGardenerDreaming",
"countryMinimalist",
"averageCountryGardener",
"gardenExpert",
])(
"accepts the plant owner test result %s as profile picture",
async (picture) => {
const { id } = await createUser();

const result = await updateProfile({
userId: id,
profilePicture: picture,
});

expect(result.errors).toBeUndefined();
expect(result.data?.updateUserProfile?.profilePicture).toBe(picture);
},
);

it("updateUserPreferences saves preferences without duplicates", async () => {
const { id } = await createUser();

Expand Down
15 changes: 3 additions & 12 deletions docs/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
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).




**end-to-end tests** TODO: skriv her
**end-to-end tests** TODO: skriv her

The tests cover the following areas:

Expand All @@ -17,7 +14,8 @@ The tests cover the following areas:
- Accessibility, such as the sidebar navigation landmark and accessible names.

## Test coverage
TODO! Sett inn bilde

TODO! Sett inn bilde

## Overview of test files

Expand Down Expand Up @@ -78,18 +76,11 @@ Backend:
- `cd backend`
- `npm run test -- --run --coverage`


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.

### To run tests with test coverage if not all tests are running

- `npx vitest run --coverage --coverage.reportOnFailure=true`



End-to-end testing:
TODO! fyll inn




5 changes: 5 additions & 0 deletions frontend/src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ const ExplorePlants = lazy(
);
const MyMatchesPage = lazy(() => import("./pages/myMatches/MyMatchesPage.tsx"));
const Profile = lazy(() => import("./pages/profile/Profile.tsx"));
const PlantOwnerTest = lazy(
() => import("./pages/plantOwnerTest/PlantOwnerTest.tsx"),
);

// eslint-disable-next-line react-refresh/only-export-components
export const ROUTES = {
plantMatch: "/",
explore: "/explorePlants",
myMatches: "/my-matches",
profile: "/profile",
plantOwnerTest: "/plantOwnerTest",
} as const;

function AppRoutes() {
Expand All @@ -24,6 +28,7 @@ function AppRoutes() {
<Route path={ROUTES.explore} element={<ExplorePlants />} />
<Route path={ROUTES.myMatches} element={<MyMatchesPage />} />
<Route path={ROUTES.profile} element={<Profile />} />
<Route path={ROUTES.plantOwnerTest} element={<PlantOwnerTest />} />
</Routes>
</Suspense>
);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/plantQuiz/city_dreamer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/plantQuiz/garden_expert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions frontend/src/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ export default function Sidebar({ isOpen, onCloseSidebar }: SidebarProps) {
{t("sidebar.profile")}
</NavLink>
</li>

<li>
<NavLink
to={ROUTES.plantOwnerTest}
className="sidebar__link"
onClick={onCloseSidebar}
>
{t("sidebar.plantOwnerTest")}
</NavLink>
</li>
</ul>
</nav>

Expand Down
35 changes: 20 additions & 15 deletions frontend/src/hooks/useProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,28 @@ export function useProfile() {
});
}, [userId, savedDraft, updateProfile]);

const setProfilePicture = (profilePicture: string) => {
if (!userId) return;
updateProfile({
variables: { userId, profilePicture },
// Shows the new picture right away instead of waiting for the server
optimisticResponse: {
updateUserProfile: {
__typename: "User",
id: userId,
name: user?.name ?? null,
description: user?.description ?? null,
profilePicture,
// Resolves to true when the picture was saved in the database
const setProfilePicture = async (profilePicture: string) => {
if (!userId) return false;
try {
await updateProfile({
variables: { userId, profilePicture },
// Shows the new picture right away instead of waiting for the server
optimisticResponse: {
updateUserProfile: {
__typename: "User",
id: userId,
name: user?.name ?? null,
description: user?.description ?? null,
profilePicture,
},
},
},
}).catch(() => {
});
return true;
} catch {
// Apollo rolls the picture back if the server fails
});
return false;
}
};

return {
Expand Down
72 changes: 68 additions & 4 deletions frontend/src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"myMatches": "My Matches",
"explorePlants": "Explore Plants",
"profile": "Profile",
"title": "I <3 Plants"
"title": "I <3 Plants",
"plantOwnerTest": "Plant Owner Test"
},
"plantMatchPage": {
"skipPlant": "Skip plant",
Expand All @@ -30,15 +31,12 @@
},
"preferences": {
"title": "Plant preferences ✿",

"minimumWater": "low watering",
"averageWater": "average watering",
"frequentWater": "frequent watering",

"fullSun": "full sun",
"partShade": "part shade",
"filteredShade": "filtered shade",

"easyCare": "easy care",
"mediumCare": "medium care",
"hardCare": "high care"
Expand Down Expand Up @@ -111,5 +109,71 @@
"careLevel": "Care level",
"unknown": "Unknown",
"noImage": "No image available"
},
"plantQuiz": {
"title": "What kind of plant owner are you?",
"subtitle": "Answer four questions and find out what kind of plant owner you are!",
"next": "Next",
"back": "Back",
"finish": "See my result",
"restart": "Retake test",
"resultTitle": "You are a:",
"questions": {
"time": {
"title": "How much time do you like to spend on caring for your plants?",
"tenMinutes": "10 minutes a week",
"thirtyMinutes": "30 minutes a week",
"oneHour": "1 hour a week",
"oneDay": "1 day a week"
},
"light": {
"title": "How much light do your plants get?",
"partShade": "Partial shade",
"partSun": "Partial sun",
"fullSun": "Full sun"
},
"location": {
"title": "Do you live in the city or in the countryside?",
"city": "City",
"country": "Countryside"
},
"watering": {
"title": "How often do you like to water your plants?",
"minimum": "As little as possible",
"frequent": "Often",
"average": "Now and then"
}
},
"results": {
"cityMinimalist": {
"name": "City minimalist",
"description": "You like a green home in the city without much work. Choose hardy plants that are happy with a little water now and then."
},
"averageCityGardener": {
"name": "Average city gardener",
"description": "You enjoy looking after your plants in the city, as long as it fits into everyday life. Plants with average watering needs suit you well."
},
"cityGardenerDreaming": {
"name": "City gardener dreaming",
"description": "You love caring for plants and dream of a big garden, even if you live in the city. Fill your home with plants that like a lot of water and attention."
},
"countryMinimalist": {
"name": "Country minimalist",
"description": "You live in the countryside and like plants that look after themselves. Choose hardy plants that need little water."
},
"averageCountryGardener": {
"name": "Average country gardener",
"description": "You have room for plants in the countryside and enjoy caring for them now and then. Plants with average watering needs suit you well."
},
"gardenExpert": {
"name": "Garden expert",
"description": "You live in the countryside and know your garden inside out. You love watering and caring for plants that need a lot of attention."
}
},
"profilePicture": {
"use": "Use as profile picture",
"saved": "This is now your profile picture!",
"failed": "Could not save the profile picture. Try again later."
}
}
}
72 changes: 68 additions & 4 deletions frontend/src/i18n/locales/no/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"myMatches": "Mine Matches",
"explorePlants": "Utforsk Planter",
"profile": "Profil",
"title": "I <3 Plants"
"title": "I <3 Plants",
"plantOwnerTest": "Planteeier Test"
},
"plantMatchPage": {
"skipPlant": "Hopp over planten",
Expand All @@ -30,15 +31,12 @@
},
"preferences": {
"title": "Plantepreferanser ✿",

"minimumWater": "trenger lite vann",
"averageWater": "middels vannbehov",
"frequentWater": "trenger mye vann",

"fullSun": "full sol",
"partShade": "delvis skygge",
"filteredShade": "filtrert skygge",

"easyCare": "lettstelt",
"mediumCare": "middels stell",
"hardCare": "krever mye stell"
Expand Down Expand Up @@ -111,5 +109,71 @@
"careLevel": "Stell",
"unknown": "Ukjent",
"noImage": "Bilde ikke tilgjengelig"
},
"plantQuiz": {
"title": "Hvilken type planteeier er du?",
"subtitle": "Svar på fire spørsmål og finn ut hvilken type planteeier du er!",
"next": "Neste",
"back": "Tilbake",
"finish": "Se resultatet mitt",
"restart": "Ta testen på nytt",
"resultTitle": "Du er en:",
"questions": {
"time": {
"title": "Hvor mye tid liker du å bruke på å stelle plantene dine?",
"tenMinutes": "10 minutter i uken",
"thirtyMinutes": "30 minutter i uken",
"oneHour": "1 time i uken",
"oneDay": "1 dag i uken"
},
"light": {
"title": "Hvor mye lys får plantene dine?",
"partShade": "Delvis skygge",
"partSun": "Delvis sol",
"fullSun": "Full sol"
},
"location": {
"title": "Bor du i byen eller på landet?",
"city": "Byen",
"country": "Landet"
},
"watering": {
"title": "Hvor ofte liker du å vanne plantene dine?",
"minimum": "Så lite som mulig",
"frequent": "Ofte",
"average": "Innimellom"
}
},
"results": {
"cityMinimalist": {
"name": "Byminimalist",
"description": "Du liker et grønt hjem i byen uten for mye arbeid. Velg hardføre planter som klarer seg med litt vann innimellom."
},
"averageCityGardener": {
"name": "Gjennomsnittlig bygartner",
"description": "Du liker å stelle plantene dine i byen, så lenge det passer inn i hverdagen. Planter med middels vannbehov passer deg godt."
},
"cityGardenerDreaming": {
"name": "Drømmende bygartner",
"description": "Du elsker å stelle planter og drømmer om en stor hage, selv om du bor i byen. Fyll hjemmet med planter som liker mye vann og oppmerksomhet."
},
"countryMinimalist": {
"name": "Landminimalist",
"description": "Du bor på landet og liker planter som klarer seg selv. Velg hardføre planter som trenger lite vann."
},
"averageCountryGardener": {
"name": "Gjennomsnittlig landgartner",
"description": "Du har plass til planter på landet og liker å stelle dem innimellom. Planter med middels vannbehov passer deg godt."
},
"gardenExpert": {
"name": "Hageekspert",
"description": "Du bor på landet og kjenner hagen din ut og inn. Du elsker å vanne og stelle planter som trenger mye oppmerksomhet."
}
},
"profilePicture": {
"use": "Bruk som profilbilde",
"saved": "Dette er nå profilbildet ditt!",
"failed": "Kunne ikke lagre profilbildet. Prøv igjen senere."
}
}
}
Loading
Loading