-
Notifications
You must be signed in to change notification settings - Fork 57
fix(portfolio): keep the balance out of the aria labels in privacy mode #8044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yhabib
wants to merge
4
commits into
main
Choose a base branch
from
fix/aria-labels-privacy-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2592946
fix(portfolio): keep the balance out of the aria labels in privacy mode
yhabib 543cc94
test(portfolio): add an e2e spec for the privacy mode aria labels
yhabib eb63717
fix(e2e): close the account menu by re-clicking its toggle
yhabib 9724708
fix(e2e): click the popover backdrop to close the account menu
yhabib File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
frontend/src/tests/e2e/portfolio-privacy-aria-labels.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| /** | ||
| * The "Hide Balance" option must keep the amounts out of the accessibility | ||
| * tree, and it must still leave every cell with a usable accessible name. | ||
| * | ||
| * The Portfolio cards mask the amounts on screen with PrivacyAwareAmount. | ||
| * PrivacyAwareAmount masks the element content only. An aria-label on the same | ||
| * element replaces that content as the accessible name, so the label must | ||
| * follow the same store as the visible value. | ||
| * | ||
| * This test drives the real application and reads the accessible names in both | ||
| * states. | ||
| */ | ||
| import { AppPo } from "$tests/page-objects/App.page-object"; | ||
| import { PlaywrightPageObjectElement } from "$tests/page-objects/playwright.page-object"; | ||
| import { signInWithNewUser, step } from "$tests/utils/e2e.test-utils"; | ||
| import { expect, test } from "@playwright/test"; | ||
|
|
||
| // A Playwright spec cannot import $lib/i18n/en.json, because ESM asks for an | ||
| // import attribute of type json. The expected strings are copied here. | ||
| const HELD_ICP_CARD_TITLE = "ICP Balance"; | ||
| const STAKED_ICP_CARD_TITLE = "ICP Staking Balance"; | ||
| const HIDDEN_BALANCE_LABEL = "hidden"; | ||
|
|
||
| const DIGIT = /\d/; | ||
|
|
||
| // playwright.config.ts sets expect.timeout to 0, so every poll needs its own | ||
| // timeout. Without one a failing poll hangs until the 300 s test timeout. | ||
| const POLL = { timeout: 30_000 }; | ||
|
|
||
| test("Privacy mode keeps the balances out of the Portfolio accessible names", async ({ | ||
| page, | ||
| browser, | ||
| }) => { | ||
| await page.goto("/"); | ||
| await expect(page).toHaveTitle("Portfolio | Network Nervous System"); | ||
|
|
||
| const pageElement = PlaywrightPageObjectElement.fromPage(page); | ||
| const appPo = new AppPo(pageElement); | ||
|
|
||
| step("Sign in"); | ||
| await signInWithNewUser({ page, context: browser.contexts()[0] }); | ||
|
yhabib marked this conversation as resolved.
|
||
|
|
||
| step("Get some ICP"); | ||
| await appPo.getIcpTokens(20); | ||
|
|
||
| step("Stake a neuron, so the staked tokens card has a row"); | ||
| await appPo.goToStaking(); | ||
| await appPo | ||
| .getStakingPo() | ||
| .stakeFirstNnsNeuron({ amount: 10, dissolveDelayDays: "max" }); | ||
| await appPo.getNeuronsPo().waitFor(); | ||
|
|
||
| step("Open the Portfolio page"); | ||
| await page.goto("/"); | ||
| const portfolioPagePo = appPo.getPortfolioPo().getPortfolioPagePo(); | ||
| const heldCardPo = portfolioPagePo.getHeldICPCardPo(); | ||
| const stakedCardPo = portfolioPagePo.getStakedICPCardPo(); | ||
| await heldCardPo.waitFor(); | ||
| await stakedCardPo.waitFor(); | ||
|
|
||
| // Every accessible name that carries a balance on the Portfolio page. | ||
| const getBalanceAriaLabels = async (): Promise<(string | null)[]> => [ | ||
| ...(await heldCardPo.getHeldTokensBalanceInUsdAriaLabels()), | ||
| await heldCardPo.getAmountAriaLabel(), | ||
| ...(await stakedCardPo.getStakedTokensStakeInUsdAriaLabels()), | ||
| ...(await stakedCardPo.getStakedTokensStakeInNativeCurrencyAriaLabels()), | ||
| await stakedCardPo.getAmountAriaLabel(), | ||
| ]; | ||
|
|
||
| // Every attribute inside the two cards that a screen reader can use as an | ||
| // accessible name. | ||
| const getAllAccessibleNamesInCards = (): Promise<string[]> => | ||
| page | ||
| .locator( | ||
| [ | ||
| '[data-tid="held-icp-card"] [aria-label]', | ||
| '[data-tid="held-icp-card"] [title]', | ||
| '[data-tid="held-icp-card"] [alt]', | ||
| '[data-tid="staked-icp-card"] [aria-label]', | ||
| '[data-tid="staked-icp-card"] [title]', | ||
| '[data-tid="staked-icp-card"] [alt]', | ||
| ].join(", ") | ||
| ) | ||
| .evaluateAll((elements) => | ||
| elements.flatMap((element) => | ||
| ["aria-label", "title", "alt"] | ||
| .map((attribute) => element.getAttribute(attribute)) | ||
| .filter((value): value is string => value !== null) | ||
| ) | ||
| ); | ||
|
|
||
| const toggleBalancePrivacy = async () => { | ||
| // The account menu button toggles Popover visibility (AccountMenu.svelte). | ||
| // The Popover backdrop closes on click or on Enter/Space, not Escape | ||
| // (gix-components handleKeyPress only handles those two keys), so a | ||
| // second click on the same button is the reliable way to close it. | ||
| const accountMenuPo = appPo.getAccountMenuPo(); | ||
| await accountMenuPo.openMenu(); | ||
| await accountMenuPo.getToggleBalancePrivacyOptionPo().click(); | ||
| await accountMenuPo.openMenu(); | ||
| await expect.poll(() => accountMenuPo.isOpen(), POLL).toBe(false); | ||
| }; | ||
|
|
||
| step("Privacy mode off: every accessible name carries its amount"); | ||
| await expect | ||
| .poll(getBalanceAriaLabels, POLL) | ||
| .toEqual([ | ||
| expect.stringMatching(/^Internet Computer USD: \d/), | ||
| expect.stringMatching(new RegExp(`^${HELD_ICP_CARD_TITLE}: \\d`)), | ||
| expect.stringMatching(/^Internet Computer USD: \d/), | ||
| expect.stringMatching(/^Internet Computer ICP: \d/), | ||
| expect.stringMatching(new RegExp(`^${STAKED_ICP_CARD_TITLE}: \\d`)), | ||
| ]); | ||
|
|
||
| step("Turn privacy mode on"); | ||
| await toggleBalancePrivacy(); | ||
|
|
||
| step("Privacy mode on: the amounts are masked on screen"); | ||
| await expect.poll(() => heldCardPo.getAmount(), POLL).toContain("•"); | ||
| await expect.poll(() => stakedCardPo.getAmount(), POLL).toContain("•"); | ||
|
|
||
| step("Privacy mode on: no accessible name carries an amount"); | ||
| // Each name still says which token and which unit the cell holds, so a | ||
| // screen reader user can still tell the cells apart. | ||
| await expect | ||
| .poll(getBalanceAriaLabels, POLL) | ||
| .toEqual([ | ||
| `Internet Computer USD: ${HIDDEN_BALANCE_LABEL}`, | ||
| `${HELD_ICP_CARD_TITLE}: ${HIDDEN_BALANCE_LABEL}`, | ||
| `Internet Computer USD: ${HIDDEN_BALANCE_LABEL}`, | ||
| `Internet Computer ICP: ${HIDDEN_BALANCE_LABEL}`, | ||
| `${STAKED_ICP_CARD_TITLE}: ${HIDDEN_BALANCE_LABEL}`, | ||
| ]); | ||
|
|
||
| step("Privacy mode on: no attribute in either card holds a digit"); | ||
| const namesWithADigit = (await getAllAccessibleNamesInCards()).filter( | ||
| (name) => DIGIT.test(name) | ||
| ); | ||
| expect(namesWithADigit).toEqual([]); | ||
|
|
||
| step("Turn privacy mode off again: the amounts come back"); | ||
| await toggleBalancePrivacy(); | ||
| await expect | ||
| .poll(getBalanceAriaLabels, POLL) | ||
| .toEqual([ | ||
| expect.stringMatching(/^Internet Computer USD: \d/), | ||
| expect.stringMatching(new RegExp(`^${HELD_ICP_CARD_TITLE}: \\d`)), | ||
| expect.stringMatching(/^Internet Computer USD: \d/), | ||
| expect.stringMatching(/^Internet Computer ICP: \d/), | ||
| expect.stringMatching(new RegExp(`^${STAKED_ICP_CARD_TITLE}: \\d`)), | ||
| ]); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.