Skip to content

Commit

Permalink
test: full coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jlp-craigmorten committed Feb 18, 2024
1 parent c4fb4e2 commit 356ac88
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 14 deletions.
12 changes: 6 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ["<rootDir>/test/jest.setup.ts"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const getLabelFromHtmlEquivalentAttribute = ({
});

if (label) {
return { label, value: attributeValue ?? "" };
return { label, value: attributeValue };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const getAccessibleAttributeLabels = ({
if (labelFromImplicitAriaAttributeValue) {
labels[attributeName] = {
label: labelFromImplicitAriaAttributeValue,
value: implicitAttributeValue ?? "",
value: implicitAttributeValue,
};

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const ariaPropertyToVirtualLabelMap: Record<

interface MapperArgs {
attributeValue: string;
container?: Node;
container: Node;
negative?: boolean;
node?: HTMLElement;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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 });
};
}

Expand Down
4 changes: 4 additions & 0 deletions test/int/activeNode.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
77 changes: 77 additions & 0 deletions test/int/multipleInstances.int.test.ts
Original file line number Diff line number Diff line change
@@ -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",
]);
});
});

0 comments on commit 356ac88

Please sign in to comment.