Skip to content
Merged
450 changes: 392 additions & 58 deletions e2e/uiAccessibility.spec.ts

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions e2e/uiMatchAndRemovePlant.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,71 @@ test("user can sort the matches in MyMatches and move between pages", async ({
await page.reload();
await expect(matchCards.first()).toContainText("Aloe Vera");
});

test("PlantMatch continues from the same card after visiting another page and after a reload", async ({
page,
}) => {
await page.goto("");
// Scoped to PlantMatch, so the cards on Explore Plants are not matched
const cardName = page.locator(
".plant-match .plant-card-front .plant-card-name",
);
await expect(cardName).toBeVisible();

// Skip the first plant, so the deck is on the second card
const firstName = (await cardName.textContent())?.trim();
await page.locator("button.dislike-button").click();
await expect(cardName).not.toHaveText(firstName ?? "");
const currentName = (await cardName.textContent())?.trim();

// Visit another page and come back
await openSidebar(page);
await page.locator('a[href$="/explorePlants"]').click();
await expect(page.locator(".plant-grid > li").first()).toBeVisible();
await openSidebar(page);
await page
.locator("#sidebar")
.getByRole("link", { name: /plant match|plante-matching/i })
.click();
await expect(cardName).toHaveText(currentName ?? "");

// sessionStorage is kept when the page is reloaded in the same tab
await page.reload();
await expect(cardName).toHaveText(currentName ?? "");
});

test("a plant matched on ExplorePlants never shows up in PlantMatch", async ({
page,
}) => {
await page.goto("#/explorePlants");
const firstItem = page.locator(".plant-grid > li").first();
const matchedName = (
await firstItem.locator(".plant-card-front .plant-card-name").textContent()
)?.trim();
const addButton = firstItem.locator(".add-match-button");
await addButton.click();
await expect(addButton).toHaveClass(/add-match-button--matched/);

await openSidebar(page);
await page
.locator("#sidebar")
.getByRole("link", { name: /plant match|plante-matching/i })
.click();

// Skip through the whole deck and check every card on the way
const cardName = page.locator(
".plant-match .plant-card-front .plant-card-name",
);
const doneCard = page.locator(".empty-plant-card");
const shown: string[] = [];
while (!(await doneCard.isVisible())) {
await expect(cardName.or(doneCard)).toBeVisible();
if (await doneCard.isVisible()) break;
const name = (await cardName.textContent())?.trim() ?? "";
shown.push(name);
await page.locator("button.dislike-button").click();
await expect(cardName.or(doneCard)).not.toHaveText(name);
}
expect(shown.length).toBeGreaterThan(0);
expect(shown).not.toContain(matchedName);
});
1 change: 0 additions & 1 deletion frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
border-radius: 8px;
background-color: var(--dark-green);
color: var(--text-on-green);
font-family: var(--font-ui);
text-decoration: none;
transform: translateY(-200%);
}
Expand Down
77 changes: 77 additions & 0 deletions frontend/src/components/matchButton/MatchButton.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* The round flower button in the top right corner of a plant card, used on
Explore Plants and My Matches. The parent of the card must be position: relative. */
.add-match {
position: absolute;
top: -15px;
right: -15px;
z-index: 2;
}

.add-match-tooltip {
position: absolute;
top: calc(100% + 8px);
right: 0;
z-index: 20;
padding: 8px 12px;
background: var(--light-background);
color: var(--pink-text);
border-radius: 10px;
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
font-size: 14px;
white-space: nowrap;
opacity: 0;
visibility: hidden;
pointer-events: none;
transition:
opacity 0.15s ease,
visibility 0.15s ease;
}

.add-match:hover .add-match-tooltip,
.add-match:focus-within .add-match-tooltip {
opacity: 1;
visibility: visible;
}

/* A filled dark pink button with a white flower (add) or X (remove) */
.add-match-button {
width: 50px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
border: 2px solid var(--dark-pink);
border-radius: 50%;
background-color: var(--dark-pink);
color: var(--text-light);
font-size: 18px;
line-height: 1;
cursor: pointer;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* In dark mode the dark pink border is too close to the dark pink results box
behind the button (2.6:1), so the border and focus ring are white */
[data-theme="dark"] .add-match-button {
border-color: var(--text-light);
}

[data-theme="dark"] .add-match-button:focus-visible {
box-shadow: 0 0 0 3px var(--text-light);
}

.add-match-button:hover {
transform: scale(1.1);
}

.add-match-button:focus-visible {
outline: none;
box-shadow: 0 0 0 3px var(--dark-pink);
}

@media (max-width: 767px) {
.add-match-button {
width: 35px;
height: 35px;
}
}
43 changes: 43 additions & 0 deletions frontend/src/components/matchButton/MatchButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import "./MatchButton.css";

type Props = {
isMatched: boolean;
// Says what the button does, shown as a tooltip and read by screen readers
label: string;
onClick: () => void;
className?: string;
};

// The round button on a plant card that adds the plant to My Matches (✿), or
// removes it if it is already there (✖). It looks the same on every page.
// Placed next to the card, not inside it, so there are no nested buttons.
export default function MatchButton({
isMatched,
label,
onClick,
className,
}: Props) {
const classes = [
"add-match-button",
isMatched && "add-match-button--matched",
className,
]
.filter(Boolean)
.join(" ");

return (
<span className="add-match">
<button
type="button"
className={classes}
onClick={onClick}
aria-label={label}
>
{isMatched ? "✖" : "✿"}
</button>
<span className="add-match-tooltip" aria-hidden="true">
{label}
</span>
</span>
);
}
1 change: 0 additions & 1 deletion frontend/src/components/pagination/Pagination.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
border-radius: 8px;
background-color: var(--light-green);
color: var(--text-dark);
font-family: var(--font-ui);
font-size: 1rem;
cursor: pointer;
}
Expand Down
64 changes: 55 additions & 9 deletions frontend/src/components/plantCard/PlantCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,16 @@
border-radius: 32px;

overflow: hidden;
}

/* The back of the card is too close to the page color in dark mode, so it gets
a light green border to show where it ends */
[data-theme="dark"] .plant-card-back {
border: 2px solid var(--dark-green);
}

font-family: var(--font-card);
.plant-card-front {
background: var(--card-front);
}

.plant-card-face > .plant-card {
Expand All @@ -116,8 +124,13 @@
height: var(--card-fold);

--flap-fill: var(--card-flap);
/* Same as the fill unless a face sets its own border color */
--flap-border: var(--flap-fill);
--flap-border-width: 2px;

background: var(--flap-fill);
/* The triangle is drawn in the border color, and a smaller triangle in the
fill color on top. A normal border would not follow the diagonal edge. */
background: var(--flap-border);
clip-path: polygon(0 0, 100% 0, 0 100%);

pointer-events: none;
Expand All @@ -127,6 +140,25 @@
height 0.2s ease;
}

.plant-card-flap::after {
/* The diagonal edge is moved in by the border width times sqrt(2) */
--flap-inset: calc(var(--flap-border-width) * 2.414);

content: "";
position: absolute;
inset: 0;
background: var(--flap-fill);
clip-path: polygon(
var(--flap-border-width) var(--flap-border-width),
calc(100% - var(--flap-inset)) var(--flap-border-width),
var(--flap-border-width) calc(100% - var(--flap-inset))
);
}

.plant-card-face-front .plant-card-flap {
--flap-border: var(--soft-green);
}

@media (prefers-reduced-motion: reduce) {
.plant-card-flipper,
.plant-card-face,
Expand Down Expand Up @@ -163,7 +195,9 @@
flex: none;
height: var(--card-name-height);

padding: 5px 40px;
/* Room on both sides for the round button in the top right corner of the
card, so a long name is not hidden under it */
padding: 5px 48px;

display: flex;
align-items: center;
Expand Down Expand Up @@ -229,14 +263,25 @@
margin: auto 0 0;
padding: 18px var(--card-hint-space) 32px 20px;

color: var(--dark-green);
color: var(--card-hint);

font-size: 1rem;
/* The same size as on the compact cards on Explore Plants
(1.125rem at 80 % zoom) */
font-size: 0.9rem;
font-weight: 600;
line-height: 1.3;
text-align: center;
}

/* Always room for two lines, so the card does not move when the text gets
shorter or longer, for example when the language is changed */
.plant-card-hint-text {
display: flex;
align-items: center;
justify-content: center;
min-height: calc(2 * 1.3em);
}

.plant-card-hint:focus {
outline: none;
}
Expand All @@ -247,7 +292,7 @@
}

.plant-card-face-back .plant-card-flap {
--flap-fill: var(--light-green);
--flap-fill: var(--cream);
}

.plant-card-back .plant-card-hint,
Expand All @@ -259,7 +304,8 @@
.plant-card-back-header {
flex: none;

padding: 20px 28px 16px;
/* Room on both sides for the round button in the top right corner */
padding: 20px 48px 16px;

background: var(--dark-green);
color: var(--text-on-green);
Expand Down Expand Up @@ -377,7 +423,7 @@
.plant-card-front .plant-card-name {
height: auto;
min-height: var(--card-name-height);
padding: 10px 16px;
padding: 10px 24px;
font-size: clamp(1.05rem, 6.5cqw, 1.25rem);
overflow-wrap: anywhere;
}
Expand All @@ -393,7 +439,7 @@
}

.plant-card-back-header {
padding: 16px 16px 12px;
padding: 16px 24px 12px;
}

.plant-card-back .plant-card-name {
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/components/plantCard/PlantCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export default function PlantCard({ plant, size = "large", onInfo }: Props) {
className="plant-card-hint"
aria-expanded={false}
>
{t("plantCard.tapForDetails")}
<span className="plant-card-hint-text">
{t("plantCard.tapForDetails")}
</span>
</button>
</article>
<span className="plant-card-flap" aria-hidden="true" />
Expand Down Expand Up @@ -153,7 +155,9 @@ export default function PlantCard({ plant, size = "large", onInfo }: Props) {
className="plant-card-hint"
aria-expanded={true}
>
{t("plantCard.tapToFlipBack")}
<span className="plant-card-hint-text">
{t("plantCard.tapToFlipBack")}
</span>
</button>
</article>
<span className="plant-card-flap" aria-hidden="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

.plant-preferences button {
padding: 12px 20px;
border: 1px solid var(--border-pink);
border: 2px solid var(--dark-pink);
border-radius: 10px 20px 20px 20px;
background: var(--light-pink);
color: var(--text-dark);
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/sidebar/Sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
width: var(--sidebar-width);
max-width: 100%;
height: 100vh;
/* 100vh is taller than the visible area on phones when the browser bar is
shown, which hid the language and theme buttons. dvh follows the bar. */
height: 100dvh;
position: fixed;
overflow-y: auto;
z-index: 100;
Expand Down Expand Up @@ -58,6 +61,7 @@

.sidebar__footer {
margin-top: auto;
padding-bottom: env(safe-area-inset-bottom);
display: flex;
flex-direction: row;
align-items: center;
Expand Down
Loading
Loading