|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const { LANDMARK_ROLES, ALL_LANDMARK_ROLES } = require('../../../lib/utils/landmark-roles'); |
| 4 | + |
| 5 | +// The WAI-ARIA 1.2 §5.3.4 landmark roles known at authoring time. Asserting |
| 6 | +// set-inclusion (not an exact-equality / size match) keeps the test robust |
| 7 | +// to future aria-query updates that add non-abstract landmark roles — the |
| 8 | +// derivation (non-abstract + superClass contains 'landmark' + not doc-*) |
| 9 | +// is what we actually care about. |
| 10 | +const KNOWN_LANDMARK_ROLES = [ |
| 11 | + 'banner', |
| 12 | + 'complementary', |
| 13 | + 'contentinfo', |
| 14 | + 'form', |
| 15 | + 'main', |
| 16 | + 'navigation', |
| 17 | + 'region', |
| 18 | + 'search', |
| 19 | +]; |
| 20 | + |
| 21 | +describe('ALL_LANDMARK_ROLES', () => { |
| 22 | + it('includes every WAI-ARIA 1.2 §5.3.4 landmark role', () => { |
| 23 | + for (const role of KNOWN_LANDMARK_ROLES) { |
| 24 | + expect(ALL_LANDMARK_ROLES.has(role)).toBe(true); |
| 25 | + } |
| 26 | + // Floor, not ceiling — lets the set grow if aria-query adds new |
| 27 | + // non-abstract landmark roles upstream. |
| 28 | + expect(ALL_LANDMARK_ROLES.size).toBeGreaterThanOrEqual(KNOWN_LANDMARK_ROLES.length); |
| 29 | + }); |
| 30 | + |
| 31 | + it('excludes DPub-ARIA doc-* roles', () => { |
| 32 | + for (const role of ALL_LANDMARK_ROLES) { |
| 33 | + expect(role.startsWith('doc-')).toBe(false); |
| 34 | + } |
| 35 | + }); |
| 36 | +}); |
| 37 | + |
| 38 | +describe('LANDMARK_ROLES (the statically-verifiable subset)', () => { |
| 39 | + it('includes every known landmark role except region', () => { |
| 40 | + for (const role of KNOWN_LANDMARK_ROLES) { |
| 41 | + if (role === 'region') { |
| 42 | + continue; |
| 43 | + } |
| 44 | + expect(LANDMARK_ROLES.has(role)).toBe(true); |
| 45 | + } |
| 46 | + // Floor, not ceiling — mirrors the ALL_LANDMARK_ROLES rationale, minus |
| 47 | + // the deliberate region exclusion. |
| 48 | + expect(LANDMARK_ROLES.size).toBeGreaterThanOrEqual(KNOWN_LANDMARK_ROLES.length - 1); |
| 49 | + }); |
| 50 | + |
| 51 | + it('excludes region (cannot verify accessible-name presence statically)', () => { |
| 52 | + expect(LANDMARK_ROLES.has('region')).toBe(false); |
| 53 | + expect(ALL_LANDMARK_ROLES.has('region')).toBe(true); |
| 54 | + }); |
| 55 | + |
| 56 | + it('excludes non-landmark roles (button, link, article)', () => { |
| 57 | + expect(LANDMARK_ROLES.has('button')).toBe(false); |
| 58 | + expect(LANDMARK_ROLES.has('link')).toBe(false); |
| 59 | + expect(LANDMARK_ROLES.has('article')).toBe(false); |
| 60 | + }); |
| 61 | +}); |
0 commit comments