diff --git a/README.md b/README.md
index 5fa92af0..f7b825a4 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,7 @@ http://it2810-03.idi.ntnu.no/project2/
- **Plant Match:** Plants matching the most preferences come first, otherwise the order is random. The deck is kept while the user visits other pages, so they can continue where they left off.
- **My Matches:** Collects liked plants from both Plant Match and Explore Plants. The user only stores plant ids, and the list is fetched one page at a time, so responses do not grow with the number of matches.
-- **Explore Plants:** Search, filtering, sorting and pagination run in the backend, so the frontend only receives one page at a time, whatever the size of the collection. The state is kept in the URL, so a view survives a refresh and can be shared as a link.
+- **Explore Plants:** Search, filtering, sorting and pagination run in the backend, so the frontend only receives one page at a time, whatever the size of the collection. The state is kept in the URL, so a view survives a refresh and can be shared as a link. Each filter value shows how many plants it would give, and values that would give none can't be chosen, so filtering never ends in an empty list.
## Tech stack
diff --git a/backend/src/queryBuilders.ts b/backend/src/queryBuilders.ts
index 39d7b74e..99305ca5 100644
--- a/backend/src/queryBuilders.ts
+++ b/backend/src/queryBuilders.ts
@@ -1,5 +1,10 @@
import type { Document, Filter, ObjectId } from "mongodb";
-import type { ExplorePlantsArgs, PlantDoc } from "./types.js";
+import type {
+ ExplorePlantsArgs,
+ FilterCounts,
+ FilterParam,
+ PlantDoc,
+} from "./types.js";
// Helpers for searching, filtering and sorting plants
@@ -120,6 +125,54 @@ export const buildExploreFilter = (
return filter;
};
+// The values each filter can have. Must match FILTERS in
+// frontend/src/pages/explorePlants/ExplorePlantsPage.tsx
+export const FILTER_OPTIONS: Record = {
+ watering: ["minimum", "average", "frequent"],
+ sunlight: ["full_sun", "part_shade", "filtered_shade"],
+ careLevel: ["low", "medium", "high"],
+};
+
+// The name of one count in the $facet result, e.g. "watering:minimum"
+const facetKey = (param: string, value: string) => `${param}:${value}`;
+
+// Stages that count, for every filter value, how many plants the user would get
+// by choosing it. The value replaces the current choice in that filter, while the
+// search and the other filters stay. Uses buildExploreFilter, so the counts
+// always agree with the results. All counts are done in one query.
+export const buildFilterCountStages = (args: ExplorePlantsArgs): Document[] => {
+ const facets: Record = {};
+ for (const [param, options] of Object.entries(FILTER_OPTIONS)) {
+ // "" is "All": nothing chosen in this filter, so only the search and the other filters count
+ for (const value of ["", ...options]) {
+ facets[facetKey(param, value)] = [
+ { $match: buildExploreFilter({ ...args, [param]: value }) },
+ { $count: "count" },
+ ];
+ }
+ }
+ return [
+ // Only the plants matching the search need to be looked at
+ { $match: buildExploreFilter({ search: args.search }) },
+ { $facet: facets },
+ ];
+};
+
+// Turns the $facet result into the FilterCounts the API returns.
+// $count gives an empty list when nothing matches, so that becomes 0.
+export const toFilterCounts = (
+ facets: Record = {},
+): FilterCounts => {
+ const counts = {} as FilterCounts;
+ for (const [param, options] of Object.entries(FILTER_OPTIONS)) {
+ counts[param as FilterParam] = ["", ...options].map((value) => ({
+ value,
+ count: facets[facetKey(param, value)]?.[0]?.count ?? 0,
+ }));
+ }
+ return counts;
+};
+
// Lowercased field value, missing values become ""
const lower = (field: string): Document => ({
$toLower: { $ifNull: [field, ""] },
diff --git a/backend/src/resolvers.ts b/backend/src/resolvers.ts
index ecdd4101..67ed8d96 100644
--- a/backend/src/resolvers.ts
+++ b/backend/src/resolvers.ts
@@ -4,13 +4,16 @@ import type { Document, WithId } from "mongodb";
import { db } from "./db.js";
import {
buildExploreFilter,
+ buildFilterCountStages,
buildMatchSortStages,
buildSortStages,
matchScore,
PREFERENCE_MATCHERS,
+ toFilterCounts,
} from "./queryBuilders.js";
import type {
ExplorePlantsArgs,
+ ExplorePage,
GetPlantsArgs,
MyMatchesArgs,
Plant,
@@ -181,10 +184,10 @@ export const resolvers = {
explorePlants: async (
_parent: unknown,
args: ExplorePlantsArgs,
- ): Promise<{ plants: Plant[]; totalCount: number }> => {
+ ): Promise => {
const filter = buildExploreFilter(args);
- const [docs, totalCount] = await Promise.all([
+ const [docs, totalCount, [facets]] = await Promise.all([
plants
.aggregate>([
{ $match: filter },
@@ -194,9 +197,20 @@ export const resolvers = {
])
.toArray(),
plants.countDocuments(filter),
+ // Match counts for the filter values, so the frontend can show them
+ // and disable the values that would give no plants
+ plants
+ .aggregate>(
+ buildFilterCountStages(args),
+ )
+ .toArray(),
]);
- return { plants: docs.map(toPlant), totalCount };
+ return {
+ plants: docs.map(toPlant),
+ totalCount,
+ filterCounts: toFilterCounts(facets),
+ };
},
getUser: async (
diff --git a/backend/src/schema.ts b/backend/src/schema.ts
index f6d1f935..87193276 100644
--- a/backend/src/schema.ts
+++ b/backend/src/schema.ts
@@ -10,7 +10,7 @@ export const typeDefs = `
sort: String
limit: Int = 12
offset: Int = 0
- ): PlantPage!
+ ): ExplorePage!
getUser(userId: ID!): User
myMatches(
userId: ID!
@@ -38,6 +38,23 @@ export const typeDefs = `
totalCount: Int!
}
+ type OptionCount {
+ value: String!
+ count: Int!
+ }
+
+ type FilterCounts {
+ watering: [OptionCount!]!
+ sunlight: [OptionCount!]!
+ careLevel: [OptionCount!]!
+ }
+
+ type ExplorePage {
+ plants: [Plant!]!
+ totalCount: Int!
+ filterCounts: FilterCounts!
+ }
+
type Plant{
id: ID!
name: String!
diff --git a/backend/src/types.ts b/backend/src/types.ts
index b0e4f0a8..ffe1d580 100644
--- a/backend/src/types.ts
+++ b/backend/src/types.ts
@@ -45,6 +45,25 @@ export interface ExplorePlantsArgs {
offset?: number | null;
}
+// The filters on Explore Plants
+export type FilterParam = "watering" | "sunlight" | "careLevel";
+
+// How many plants a filter value would give, with the current search and other filters
+export interface OptionCount {
+ value: string;
+ count: number;
+}
+
+export type FilterCounts = Record;
+
+// What explorePlants returns. A separate type from PlantPage, since
+// My Matches also uses PlantPage but has no filters to count.
+export interface ExplorePage {
+ plants: Plant[];
+ totalCount: number;
+ filterCounts: FilterCounts;
+}
+
// The shape of a user document in MongoDB. _id is added by MongoDB.
export interface UserDoc {
// null means the user has not chosen one, the frontend shows a translated default
diff --git a/backend/tests/server.test.ts b/backend/tests/server.test.ts
index 5d4b8661..7ef20356 100644
--- a/backend/tests/server.test.ts
+++ b/backend/tests/server.test.ts
@@ -459,6 +459,71 @@ describe("plants", () => {
])("sorts with %s", async (sort, expected) => {
expect((await explore({ sort })).names).toEqual(expected);
});
+
+ const FILTER_COUNTS = `
+ query ($search: String, $watering: String) {
+ explorePlants(search: $search, watering: $watering) {
+ filterCounts {
+ watering { value count }
+ sunlight { value count }
+ careLevel { value count }
+ }
+ }
+ }
+ `;
+
+ type Counts = Record;
+
+ // The counts as { watering: { minimum: 2, ... }, ... }, easier to read in the tests
+ async function filterCounts(variables: Record = {}) {
+ const result = await execute<{ explorePlants: { filterCounts: Counts } }>(
+ FILTER_COUNTS,
+ variables,
+ );
+ expect(result.errors).toBeUndefined();
+ return Object.fromEntries(
+ Object.entries(result.data!.explorePlants.filterCounts).map(
+ ([param, options]) => [
+ param,
+ Object.fromEntries(options.map((o) => [o.value, o.count])),
+ ],
+ ),
+ );
+ }
+
+ it("counts the matches for every filter value", async () => {
+ expect(await filterCounts()).toEqual({
+ watering: { "": 6, minimum: 2, average: 2, frequent: 1 },
+ sunlight: { "": 6, full_sun: 2, part_shade: 2, filtered_shade: 1 },
+ careLevel: { "": 6, low: 1, medium: 3, high: 1 },
+ });
+ });
+
+ it("counts with the search and the other filters, but not the filter's own choice", async () => {
+ const counts = await filterCounts({ watering: "average" });
+ // Choosing another watering value replaces "average", so these are unchanged
+ expect(counts.watering).toEqual({
+ "": 6,
+ minimum: 2,
+ average: 2,
+ frequent: 1,
+ });
+ // Only Daisy and Fern (giant) have average watering
+ expect(counts.sunlight).toEqual({
+ "": 2,
+ full_sun: 0,
+ part_shade: 1,
+ filtered_shade: 1,
+ });
+ expect(counts.careLevel).toEqual({ "": 2, low: 0, medium: 2, high: 0 });
+
+ expect((await filterCounts({ search: "fern" })).watering).toEqual({
+ "": 2,
+ minimum: 0,
+ average: 1,
+ frequent: 0,
+ });
+ });
});
describe("users", () => {
diff --git a/docs/architecture.md b/docs/architecture.md
index e556b12c..7647b3f5 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -101,7 +101,7 @@ The backend exposes a single GraphQL endpoint. With GraphQL, the frontend asks f
- `server.ts` starts Apollo Server on `PORT` (default 3001) with the schema and resolvers below.
- `schema.ts` defines the GraphQL schema (`typeDefs`).
- `resolvers.ts` has the resolvers for plants and users, and validates user input.
-- `queryBuilders.ts` builds the MongoDB filters and sort stages for searching, filtering and sorting plants on Explore Plants and My Matches.
+- `queryBuilders.ts` builds the MongoDB filters and sort stages for searching, filtering and sorting plants on Explore Plants and My Matches, and the counts of how many plants each filter value would give on Explore Plants.
- `indexes.ts` creates the database indexes the app needs when the server starts (see [Scalability](#design-choices-made-for-scalability)).
- `types.ts` has the TypeScript types for the MongoDB documents, the GraphQL types and the resolver arguments.
- `seedDataFetch.js` fills the `plants` collection with plant data (see [Data source](#data-source-the-perenual-api) below).
@@ -110,12 +110,12 @@ The backend exposes a single GraphQL endpoint. With GraphQL, the frontend asks f
**Queries**
-| Query | Description |
-| ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `getPlants(limit = 50, excludeIds, preferences): [Plant]` | Returns up to `limit` plants (at most 50) for the match page, leaving out the plants in `excludeIds` so each batch only has new plants (malformed ids are ignored). Without `preferences` the order is random (MongoDB `$sample`). With `preferences`, each plant gets a score: the number of the preferences it matches on watering, sunlight and care level ("Low" counts as easy care, "Medium" and "Moderate" as medium care). The highest scores come first and plants with the same score are shuffled. Unknown preferences are ignored. |
-| `explorePlants(search, sunlight, watering, careLevel, sort, limit = 12, offset = 0): PlantPage!` | Search on common or scientific name (case-insensitive), filter on sunlight, watering and care level, sort and paginate (`limit` is kept between 1 and 50, and a negative `offset` counts as 0). Returns the plants on the page and `totalCount` for the whole result. Sort can be `name_desc`, `watering_asc` or `careLevel_asc`; the default is name A–Z. |
-| `getUser(userId): User` | Returns the user, or `null` if the id is unknown or malformed. |
-| `myMatches(userId, sort, limit = 12, offset = 0): PlantPage!` | Returns one page of the user's matched plants and `totalCount` (`limit` and `offset` are kept within the same bounds as in `explorePlants`). Sort can be `oldest`, `name_asc` or `name_desc`; the default is newest first. The order of `matchedPlantIds` is the order the plants were matched, so no date is needed. An unknown or malformed user id gives an empty page. |
+| Query | Description |
+| -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `getPlants(limit = 50, excludeIds, preferences): [Plant]` | Returns up to `limit` plants (at most 50) for the match page, leaving out the plants in `excludeIds` so each batch only has new plants (malformed ids are ignored). Without `preferences` the order is random (MongoDB `$sample`). With `preferences`, each plant gets a score: the number of the preferences it matches on watering, sunlight and care level ("Low" counts as easy care, "Medium" and "Moderate" as medium care). The highest scores come first and plants with the same score are shuffled. Unknown preferences are ignored. |
+| `explorePlants(search, sunlight, watering, careLevel, sort, limit = 12, offset = 0): ExplorePage!` | Search on common or scientific name (case-insensitive), filter on sunlight, watering and care level, sort and paginate (`limit` is kept between 1 and 50, and a negative `offset` counts as 0). Returns the plants on the page and `totalCount` for the whole result. Sort can be `name_desc`, `watering_asc` or `careLevel_asc`; the default is name A–Z. Also returns `filterCounts`: for every filter value, and for "All" (an empty value), the number of plants it would give instead of the current choice in the same filter, together with the search and the other filters. The counts use the same filter as the results, so they always agree, and are done in one `$facet` aggregation. |
+| `getUser(userId): User` | Returns the user, or `null` if the id is unknown or malformed. |
+| `myMatches(userId, sort, limit = 12, offset = 0): PlantPage!` | Returns one page of the user's matched plants and `totalCount` (`limit` and `offset` are kept within the same bounds as in `explorePlants`). Sort can be `oldest`, `name_asc` or `name_desc`; the default is newest first. The order of `matchedPlantIds` is the order the plants were matched, so no date is needed. An unknown or malformed user id gives an empty page. |
**Mutations**
@@ -131,6 +131,7 @@ The backend exposes a single GraphQL endpoint. With GraphQL, the frontend asks f
- `Plant`: `id`, `name`, `imageURL`, `scientificName`, `description`, `watering`, `sunlight`, `careLevel`
- `PlantPage`: `plants`, `totalCount`
+- `ExplorePage`: `plants`, `totalCount`, `filterCounts`. `FilterCounts` has `watering`, `sunlight` and `careLevel`, each a list of `OptionCount` (`value`, `count`). Explore has its own type, since My Matches also uses `PlantPage` but has no filters to count.
- `User`: `id`, `name`, `description`, `profilePicture`, `preferences`, `matchedPlantIds`, `createdAt`
`User.matchedPlantIds` only returns the ids, so the pages that just need to know whether a plant is matched do not fetch the whole plants with images. The plants themselves are fetched one page at a time with `myMatches`, which only shows and counts plants that still exist (for example after a reseed).
diff --git a/docs/quality.md b/docs/quality.md
index 938e1af5..45b6e20a 100644
--- a/docs/quality.md
+++ b/docs/quality.md
@@ -53,7 +53,7 @@ The app includes the following accessibility features:
- **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 and the mobile menu button expose their expanded state and which element they control. Sort, avatar and preference choices and the profile tabs expose their selected state with `aria-pressed`. The preference chips on the plant cards are a list, and a chip that matches the user's preferences also says so in text that only screen readers read, so the information is not given by color alone. Pagination marks the current page with `aria-current="page"` and announces page changes through an `aria-live="polite"` region. On Explore Plants and My Matches, the number of results or matches is also announced when it changes, including "no matches" when the last match is removed. Every page has one `h1` (the page title in the header) and a `main` landmark. The match button on the plant cards shows ✿ to add a plant to My Matches and ✖ to remove it, and its accessible name and tooltip say what a click does. If adding or removing a match fails, an error message is shown at the top of the screen in a `role="alert"` region, so screen readers read it at once without moving focus.
+- **Control states:** The sort menu and the mobile menu button expose their expanded state and which element they control. Sort, avatar and preference choices and the profile tabs expose their selected state with `aria-pressed`. The preference chips on the plant cards are a list, and a chip that matches the user's preferences also says so in text that only screen readers read, so the information is not given by color alone. Pagination marks the current page with `aria-current="page"` and announces page changes through an `aria-live="polite"` region. On Explore Plants and My Matches, the number of results or matches is also announced when it changes, including "No results found" when a search gives no plants and "no matches" when the last match is removed. Filter values that would give no plants are disabled options, so screen readers say they are unavailable, and the number of plants is part of the option text. Every page has one `h1` (the page title in the header) and a `main` landmark. The match button on the plant cards shows ✿ to add a plant to My Matches and ✖ to remove it, and its accessible name and tooltip say what a click does. If adding or removing a match fails, an error message is shown at the top of the screen in a `role="alert"` region, so screen readers read it at once without moving focus.
- **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.
@@ -83,12 +83,16 @@ We considered sustainability through both our design choices and our approach to
- **Debouncing:** On the Explore Plants page, the search waits 300 ms after the user stops typing before sending a request, so results still feel instant without a request per keystroke, reducing unnecessary search operations. Profile text is saved after 500 ms, since the text is shown right away and the save happens in the background, and a longer delay only means fewer writes to the database. The profile is also saved immediately when a field loses focus or the user leaves the page, so no text is lost.
+- **Filter counts in one query:** The number of plants for every filter value on Explore Plants is counted in the same request as the results, in one database query, instead of one request per value. Values that would give no plants can't be chosen, so the user does not send requests that only return an empty list.
+
## Design choices
- **Color palette and contrast:** We used a limited color palette to maintain a consistent visual identity across the application. We also checked the contrast between our chosen colors to help ensure that text and other interface elements remain distinguishable and in line with accessibility requirements. See [Accessibility](#accessibility).
- **Reusable components:** Shared UI is kept in reusable components, so the pages look and work the same way and changes only need to be made in one place. This makes the application easier to maintain. The Header, Sidebar and plant cards are used across pages, `Pagination`, `SortMenu` and `MatchButton` are shared by Explore Plants and My Matches, and `ErrorMessage` shows error messages on every page. The filters on Explore Plants are defined in one list of `FilterSelect` components, so a new filter only needs one new line.
+- **Keeping the previous results while loading:** On Explore Plants, the previous results and the number of results stay on screen, slightly dimmed, while new ones load (with Apollo's `previousData`). The page does not flicker or jump when the search, a filter or the page changes, and the loading text is only shown the first time.
+
- **Consistent icons:** All icons are inline SVG components in [Icons.tsx](../frontend/src/components/icons/Icons.tsx) and [ThemeIcons.tsx](../frontend/src/components/sidebarButtons/ThemeIcons.tsx), drawn on the same 24 × 24 grid. They use `currentColor`, so they follow the text color in both light and dark mode, and they are sized with `font-size`, so they scale with the text around them. They are marked with `aria-hidden` and `focusable="false"`, since the search field and the buttons they are in already have accessible names, so screen readers do not read the icons twice. Because we drew the icons ourselves, there are no third-party licences to credit.
- **Responsive design:** We designed the application for both desktop and mobile screens. The layout adapts to different screen sizes to ensure that the content and navigation remain usable across devices.
diff --git a/docs/tests.md b/docs/tests.md
index d60e7c72..75dd1c66 100644
--- a/docs/tests.md
+++ b/docs/tests.md
@@ -116,7 +116,7 @@ The tests are in `frontend/src/tests`. Snapshot tests are used for the explore p
- `ExplorePlantsPage.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, the selected sort is visible and included in the sort button's accessible name, and the sort menu closes with Escape and with a click outside.
- - Number of results: the total number for the whole result is shown, not only the plants on the page, it updates when a filter changes, it is in an `aria-live` region, and it is hidden while loading and when nothing matches.
+ - Number of results: the total number for the whole result is shown, not only the plants on the page, it updates when a filter changes, it is in an `aria-live` region together with "No results found", and it is hidden while loading. Each filter value shows its number of matches, values with no matches are disabled except the chosen one, and the previous results stay on screen while new ones load.
- Pagination: moving between pages, disabled buttons at the ends, and going back to page 1 when a filter or the search text changes.
- Matches: the button adds a plant that is not matched (✿), and removes a plant that is already matched (✖).
- URL state: search, filters, sorting and page are restored from the URL, changes are written to the URL, and reset clears the Explore parameters.
@@ -181,7 +181,7 @@ The tests are in `backend/tests`. They use a real MongoDB in memory, started in
- 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`
- Starting the server: the default port 3001, the port in `PORT`, and stopping with the error when the port is in use.
- - Plants: `getPlants` returns the plants that match the most of the user's preferences first, also when they are fetched in batches ("Low" counts as easy care), random plants when there are no preferences or only unknown ones, and leaves out the plants in `excludeIds` (returning none when all are excluded). Also stored image data before the image URL, and in `explorePlants` the default sorting, case-insensitive search across common and scientific names 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, that `limit` and `offset` are kept within valid bounds (at most 50 plants per request), and all sort orders.
+ - Plants: `getPlants` returns the plants that match the most of the user's preferences first, also when they are fetched in batches ("Low" counts as easy care), random plants when there are no preferences or only unknown ones, and leaves out the plants in `excludeIds` (returning none when all are excluded). Also stored image data before the image URL, and in `explorePlants` the default sorting, case-insensitive search across common and scientific names 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, that `limit` and `offset` are kept within valid bounds (at most 50 plants per request), and all sort orders, and the match counts for every filter value (with the search and the other filters, but not the filter's own choice).
- 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, and adding and removing matches in order.
- My matches: `myMatches` sorts by newest (the default), oldest, A–Z and Z–A, returns one page at a time with the total count, leaves out and does not count matched plants that were deleted, and returns an empty page for a user without matches and for an unknown or malformed user id.
- 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.
diff --git a/e2e/uiExplorePlants.spec.ts b/e2e/uiExplorePlants.spec.ts
index 1016a177..78ddb4c2 100644
--- a/e2e/uiExplorePlants.spec.ts
+++ b/e2e/uiExplorePlants.spec.ts
@@ -1,8 +1,8 @@
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.
+// e2e/fixtures/plants.json. The locators are language independent (roles, option values,
+// names in both languages and some CSS classes), so the test works in Norwegian and English.
test("user pages, filters, searches, opens a plant, sorts and resets", async ({
page,
@@ -72,7 +72,7 @@ test("user pages, filters, searches, opens a plant, sorts and resets", async ({
});
await test.step("reset shows all plants again", async () => {
- await page.locator(".reset-button").click();
+ await page.getByRole("button", { name: /^(reset|nullstill)$/i }).click();
await expect(searchField).toHaveValue("");
await expect(cards).toHaveCount(12);
await expect(cards.first()).toContainText("Aloe Vera");
diff --git a/frontend/src/components/filterSelect/FilterSelect.tsx b/frontend/src/components/filterSelect/FilterSelect.tsx
index 2f7dee90..d09c81a7 100644
--- a/frontend/src/components/filterSelect/FilterSelect.tsx
+++ b/frontend/src/components/filterSelect/FilterSelect.tsx
@@ -1,11 +1,14 @@
import "./FilterSelect.css";
-type FilterOption = { value: string; label: string };
+// count is how many plants the value would give. Without a count, only the label is shown.
+type FilterOption = { value: string; label: string; count?: number };
type FilterSelectProps = {
label: string;
value: string;
allLabel: string;
+ // How many plants "All" gives. Without a count, only the label is shown.
+ allCount?: number;
options: FilterOption[];
onChange: (value: string) => void;
};
@@ -16,6 +19,7 @@ export default function FilterSelect({
label,
value,
allLabel,
+ allCount,
options,
onChange,
}: FilterSelectProps) {
@@ -23,10 +27,20 @@ export default function FilterSelect({
@@ -93,22 +93,22 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with n
@@ -120,22 +120,22 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with n
@@ -200,24 +200,23 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with n
+
-
-
@@ -271,7 +270,7 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with r
@@ -292,22 +291,22 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with r
@@ -319,22 +318,22 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with r
@@ -346,22 +345,22 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with r
@@ -426,14 +425,14 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with r
+
-
@@ -877,7 +876,7 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with t
@@ -898,22 +897,22 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with t
@@ -925,22 +924,22 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with t
@@ -952,22 +951,22 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with t
@@ -975,7 +974,7 @@ exports[`ExplorePlantsPage > snapshots > matches the snapshot of the page with t
class="sort-menu"
>