From f10e9dbcf32bd4c67bf9dd2a3a0a45be9a652686 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 13 Nov 2022 07:01:12 -0800 Subject: [PATCH] fix(a11y): fix number of headings (#2183) Fixes #2162 --- src/intl/en-US.js | 9 +++- src/routes/_components/DynamicHeading.html | 5 ++ src/routes/_components/TimelineHomePage.html | 5 +- .../_components/compose/ComposeBox.html | 2 +- src/routes/_components/timeline/Timeline.html | 25 +++++---- src/routes/_pages/community/index.html | 2 +- src/routes/_pages/search.html | 1 + tests/spec/042-headings.js | 52 +++++++++++++++++++ tests/utils.js | 6 +++ 9 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 src/routes/_components/DynamicHeading.html create mode 100644 tests/spec/042-headings.js diff --git a/src/intl/en-US.js b/src/intl/en-US.js index d111dfc8f..106e7c975 100644 --- a/src/intl/en-US.js +++ b/src/intl/en-US.js @@ -680,5 +680,12 @@ export default { statusOptions: 'Status options', confirm: 'Confirm', closeDialog: 'Close dialog', - postPrivacy: 'Post privacy' + postPrivacy: 'Post privacy', + homeOnInstance: 'Home on {instance}', + statusesTimelineOnInstance: 'Statuses: {timeline} timeline on {instance}', + statusesHashtag: 'Statuses: #{hashtag} hashtag', + statusesThread: 'Statuses: thread', + statusesAccountTimeline: 'Statuses: account timeline', + statusesList: 'Statuses: list', + notificationsOnInstance: 'Notifications on {instance}' } diff --git a/src/routes/_components/DynamicHeading.html b/src/routes/_components/DynamicHeading.html new file mode 100644 index 000000000..5485b7728 --- /dev/null +++ b/src/routes/_components/DynamicHeading.html @@ -0,0 +1,5 @@ +{#if level === 2} +

+{:else} +

+{/if} diff --git a/src/routes/_components/TimelineHomePage.html b/src/routes/_components/TimelineHomePage.html index b8efb2215..ea13dc67d 100644 --- a/src/routes/_components/TimelineHomePage.html +++ b/src/routes/_components/TimelineHomePage.html @@ -3,6 +3,7 @@ without a div wrapper due to sticky-positioned compose button. TODO: this is a bit hacky due to code duplication --> +

{headingLabel}

{#if hidePage} @@ -30,6 +31,7 @@ import { store } from '../_store/store.js' import LoadingPage from './LoadingPage.html' import LazyComposeBox from './compose/LazyComposeBox.html' + import { formatIntl } from '../_utils/formatIntl.js' export default { oncreate () { @@ -40,7 +42,8 @@ }, computed: { hidePage: ({ $timelineInitialized, $timelinePreinitialized }) => !$timelineInitialized && !$timelinePreinitialized, - hideTimeline: ({ $timelineInitialized }) => !$timelineInitialized + hideTimeline: ({ $timelineInitialized }) => !$timelineInitialized, + headingLabel: ({ $currentInstance }) => formatIntl('intl.homeOnInstance', { instance: $currentInstance }) }, store: () => store, components: { diff --git a/src/routes/_components/compose/ComposeBox.html b/src/routes/_components/compose/ComposeBox.html index 305ca4e7d..c4ed8562a 100644 --- a/src/routes/_components/compose/ComposeBox.html +++ b/src/routes/_components/compose/ComposeBox.html @@ -1,5 +1,5 @@ {#if realm === 'home'} -

{intl.composeStatus}

+

{intl.composeStatus}

{/if}
diff --git a/src/routes/_components/timeline/Timeline.html b/src/routes/_components/timeline/Timeline.html index 6cf1bf84c..c0537aaa8 100644 --- a/src/routes/_components/timeline/Timeline.html +++ b/src/routes/_components/timeline/Timeline.html @@ -1,4 +1,4 @@ -

{label}

+{label}
{#if components} @@ -26,6 +26,7 @@

{label}

diff --git a/src/routes/_pages/community/index.html b/src/routes/_pages/community/index.html index 31d3dd2d8..14d1cc843 100644 --- a/src/routes/_pages/community/index.html +++ b/src/routes/_pages/community/index.html @@ -1,6 +1,6 @@ {#if $isUserLoggedIn} +

{intl.community}

- {intl.search}
diff --git a/tests/spec/042-headings.js b/tests/spec/042-headings.js new file mode 100644 index 000000000..6b6c7cf6a --- /dev/null +++ b/tests/spec/042-headings.js @@ -0,0 +1,52 @@ +import { + settingsNavButton, + notificationsNavButton, + localTimelineNavButton, + communityNavButton, + searchNavButton, + getNumElementsMatchingSelector, + getUrl, getNthStatus +} from '../utils' +import { loginAsFoobar } from '../roles' + +fixture`042-headings.js` + .page`http://localhost:4002` + +async function testHeadings (t, loggedIn) { + const navButtons = [ + { button: notificationsNavButton, url: 'notifications' }, + { button: localTimelineNavButton, url: 'local' }, + { button: communityNavButton, url: 'community' }, + { button: searchNavButton, url: 'search' }, + { button: settingsNavButton, url: 'settings' } + ] + + // home page + await t + .expect(getNumElementsMatchingSelector('h1')()).eql(1) + + if (loggedIn) { + // status page + await t + .click(getNthStatus(1)) + .expect(getUrl()).contains('status') + .expect(getNumElementsMatchingSelector('h1')()).eql(1) + } + + // non-home pages + for (const { button, url } of navButtons) { + await t + .click(button) + .expect(getUrl()).contains(url) + .expect(getNumElementsMatchingSelector('h1')()).eql(1) + } +} + +test('Only one

when not logged in', async t => { + await testHeadings(t, false) +}) + +test('Only one

when logged in', async t => { + await loginAsFoobar(t) + await testHeadings(t, true) +}) diff --git a/tests/utils.js b/tests/utils.js index 593ba305e..888da0a3e 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -570,6 +570,12 @@ export function getNthPinnedStatusFavoriteButton (n) { return $(`${getNthPinnedStatusSelector(n)} .status-toolbar button:nth-child(3)`) } +export const getNumElementsMatchingSelector = (selector) => (exec(() => { + return document.querySelectorAll(selector).length +}, { + dependencies: { selector } +})) + export async function validateTimeline (t, timeline) { const timeout = 30000 for (let i = 0; i < timeline.length; i++) {