From 356ac88d2a6bf731ab841b0d3e4101cbf83eee97 Mon Sep 17 00:00:00 2001 From: jlp-craigmorten Date: Sun, 18 Feb 2024 13:23:57 +0000 Subject: [PATCH] test: full coverage --- jest.config.js | 12 +-- .../getLabelFromHtmlEquivalentAttribute.ts | 2 +- .../getAccessibleAttributeLabels/index.ts | 2 +- .../mapAttributeNameAndValueToLabel.ts | 8 +- test/int/activeNode.int.test.ts | 4 + test/int/multipleInstances.int.test.ts | 77 +++++++++++++++++++ 6 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 test/int/multipleInstances.int.test.ts diff --git a/jest.config.js b/jest.config.js index 6d21e47..44ebb47 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,14 +4,14 @@ module.exports = { resolver: "ts-jest-resolver", testEnvironment: "jsdom", roots: ["test"], - collectCoverageFrom: ["**/*.ts", "**/*.tsx"], - coveragePathIgnorePatterns: [], + collectCoverageFrom: ["src/**/*.ts", "src/**/*.tsx"], + coveragePathIgnorePatterns: ["/node_modules/", "/test/"], coverageThreshold: { global: { - branches: 98, - functions: 98, - lines: 98, - statements: 98, + branches: 100, + functions: 100, + lines: 100, + statements: 100, }, }, setupFilesAfterEnv: ["/test/jest.setup.ts"], diff --git a/src/getNodeAccessibilityData/getAccessibleAttributeLabels/getLabelFromHtmlEquivalentAttribute.ts b/src/getNodeAccessibilityData/getAccessibleAttributeLabels/getLabelFromHtmlEquivalentAttribute.ts index 237dac9..1d67821 100644 --- a/src/getNodeAccessibilityData/getAccessibleAttributeLabels/getLabelFromHtmlEquivalentAttribute.ts +++ b/src/getNodeAccessibilityData/getAccessibleAttributeLabels/getLabelFromHtmlEquivalentAttribute.ts @@ -158,7 +158,7 @@ export const getLabelFromHtmlEquivalentAttribute = ({ }); if (label) { - return { label, value: attributeValue ?? "" }; + return { label, value: attributeValue }; } } diff --git a/src/getNodeAccessibilityData/getAccessibleAttributeLabels/index.ts b/src/getNodeAccessibilityData/getAccessibleAttributeLabels/index.ts index d668cba..f5287c0 100644 --- a/src/getNodeAccessibilityData/getAccessibleAttributeLabels/index.ts +++ b/src/getNodeAccessibilityData/getAccessibleAttributeLabels/index.ts @@ -102,7 +102,7 @@ export const getAccessibleAttributeLabels = ({ if (labelFromImplicitAriaAttributeValue) { labels[attributeName] = { label: labelFromImplicitAriaAttributeValue, - value: implicitAttributeValue ?? "", + value: implicitAttributeValue, }; return; diff --git a/src/getNodeAccessibilityData/getAccessibleAttributeLabels/mapAttributeNameAndValueToLabel.ts b/src/getNodeAccessibilityData/getAccessibleAttributeLabels/mapAttributeNameAndValueToLabel.ts index c1bf0e5..792288c 100644 --- a/src/getNodeAccessibilityData/getAccessibleAttributeLabels/mapAttributeNameAndValueToLabel.ts +++ b/src/getNodeAccessibilityData/getAccessibleAttributeLabels/mapAttributeNameAndValueToLabel.ts @@ -121,7 +121,7 @@ const ariaPropertyToVirtualLabelMap: Record< interface MapperArgs { attributeValue: string; - container?: Node; + container: Node; negative?: boolean; node?: HTMLElement; } @@ -184,10 +184,6 @@ function idRefs( function idRef(propertyName: string) { return function mapper({ attributeValue: idRef, container }: MapperArgs) { - if (!container) { - return ""; - } - const node = getNodeByIdRef({ container, idRef }); if (!node) { @@ -198,7 +194,7 @@ function idRef(propertyName: string) { const accessibleValue = getAccessibleValue(node); const itemText = getItemText({ accessibleName, accessibleValue }); - return concat(propertyName)({ attributeValue: itemText }); + return concat(propertyName)({ attributeValue: itemText, container }); }; } diff --git a/test/int/activeNode.int.test.ts b/test/int/activeNode.int.test.ts index 659a488..b33b641 100644 --- a/test/int/activeNode.int.test.ts +++ b/test/int/activeNode.int.test.ts @@ -36,4 +36,8 @@ describe("Active Node", () => { document.getElementsByTagName("section")[0] ); }); + + it("should gracefully handle when there is no active node", async () => { + expect(virtual.activeNode).toBeNull(); + }); }); diff --git a/test/int/multipleInstances.int.test.ts b/test/int/multipleInstances.int.test.ts new file mode 100644 index 0000000..90d6ae8 --- /dev/null +++ b/test/int/multipleInstances.int.test.ts @@ -0,0 +1,77 @@ +import { setupBasicPage } from "../utils.js"; +import { Virtual } from "../../src/index.js"; + +const virtual1 = new Virtual(); +const virtual2 = new Virtual(); + +describe("Multiple Instances", () => { + beforeEach(async () => { + setupBasicPage(); + + await virtual1.start({ container: document.body }); + await virtual2.start({ container: document.body }); + }); + + afterEach(async () => { + await virtual1.stop(); + await virtual2.stop(); + + document.body.innerHTML = ""; + }); + + it("should allow you to use two virtual screen readers on the same DOM at the same time", async () => { + while ((await virtual1.lastSpokenPhrase()) !== "end of document") { + await virtual1.next(); + } + + await virtual2.previous(); + while ((await virtual2.lastSpokenPhrase()) !== "document") { + await virtual2.previous(); + } + + expect(await virtual1.spokenPhraseLog()).toEqual([ + "document", + "navigation", + "Nav Text", + "end of navigation", + "region", + "heading, Section Heading 1, level 1", + "Section Text", + "article", + "banner", + "heading, Article Header Heading 1, level 1", + "Article Header Text", + "end of banner", + "Article Text", + "end of article", + "end of region", + "contentinfo", + "Footer", + "end of contentinfo", + "end of document", + ]); + + expect(await virtual2.spokenPhraseLog()).toEqual([ + "document", + "end of document", + "end of contentinfo", + "Footer", + "contentinfo", + "end of region", + "end of article", + "Article Text", + "end of banner", + "Article Header Text", + "heading, Article Header Heading 1, level 1", + "banner", + "article", + "Section Text", + "heading, Section Heading 1, level 1", + "region", + "end of navigation", + "Nav Text", + "navigation", + "document", + ]); + }); +});