Skip to content
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

Fix the timestamp in the screen reader narrative for current conditions #1029

Merged
merged 1 commit into from
Apr 15, 2024
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
40 changes: 40 additions & 0 deletions tests/a11y/cypress/e2e/dates-are-localized.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const dayjs = require("dayjs");

describe("main script", () => {
before(() => {
cy.request("http://localhost:8081/play/testing");
});

const obsTime = dayjs("2024-02-20T15:53:00+00:00").toDate();

describe("formats the narrative timestamp according to the browser's locale settings", () => {
// US English, Mexican Spanish, Puerto Rican Spanish, and US Spanish. Just
// some representative test cases. If these pass, others should too.
["en-US", "es-MX", "es-PR", "es-US"].forEach((locale) => {
it(`for the ${locale} locale`, () => {
const formatter = new Intl.DateTimeFormat(locale, {
weekday: "long",
hour: "numeric",
minute: "2-digit",
timeZoneName: "short",
});

cy.visit("/point/33.521/-86.812/#current", {
onBeforeLoad: (win) => {
Object.defineProperty(win.navigator, "languages", {
value: [locale],
});
},
});

cy.get(".usa-sr-only").then((sr) => {
expect(sr.length).to.be.greaterThan(0);

const expected = formatter.format(obsTime);
console.log(expected);
expect(sr).to.contain(expected);
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
{# First row is temperature #}
<div class="display-flex">
<div class="current-conditions-temp display-flex flex-row flex-align-start margin-right-2 text-primary-darker">
{{ content.temperature }}<span aria-hidden="true" class="font-body-xs display-inline-block left-full margin-top-05 margin-left-neg-2px">&deg;F</span>
<span class="usa-sr-only">℉</span>
{{ content.temperature }}<span class="font-body-xs display-inline-block left-full margin-top-05 margin-left-neg-2px">&deg;F</span>
</div>
<div class="margin-top-05 position-relative">
<div class="font-mono-2xs font-family-mono text-base text-uppercase">{{ "Feels like" | t }}</div>
<div class="text-primary-darker">
<p class="margin-top-2px font-body-md">{{ content.feels_like }}
<span aria-hidden="true" class="font-body-3xs position-absolute margin-top">&deg;F</span>
<span class="usa-sr-only">℉</span>
<p class="margin-top-2px font-body-md">
{{ content.feels_like }}<span class="font-body-3xs position-absolute margin-top">&deg;F</span>
Comment on lines -17 to +23
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need screen reader-specific handling here because these entire blocks are hidden from screen readers.

</p>
</div>
</div>
Expand Down Expand Up @@ -91,12 +89,12 @@
</div>

{# Weather narrative is for screen readers only #}
<div data-wx-current-conditions-narrative class="tablet:grid-col-12 usa-sr-only height-1px">
<div role="text" data-wx-current-conditions-narrative class="tablet:grid-col-12 usa-sr-only height-1px">
{{ 'Weather as of' | t }}
{# Datetimes are localized in client-side Javascript. #}
<weather-timestamp data-utc="{{ content.timestamp.utc }}">
<time datetime="{{ content.timestamp.utc }}" data-wx-local-time>
{{ content.timestamp.formatted }}
</weather-timestamp>
</time>.
{{ "The weather in @place, is @conditions.
Temperature is @temperature ℉." |
t({
Expand Down