Skip to content

Commit

Permalink
Add tests for focus styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Iuliia Kulagina committed Sep 12, 2023
1 parent c3f73ba commit c5327bd
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion test/visualTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ describe("SankeyDiagram", () => {
});

describe("Focus elements tests:", () => {
it("links should have :focus-visible style", (done: DoneFn) => {
it("focused links should have :focus-visible style", (done: DoneFn) => {
visualBuilder.updateRenderTimeout(dataView, () => {
const links: NodeListOf<HTMLElement> = visualBuilder.linkElements;

Expand All @@ -945,6 +945,41 @@ describe("SankeyDiagram", () => {
});
});

it("focused links should have styled stroke and outline", (done: DoneFn) => {
visualBuilder.updateRenderTimeout(dataView, () => {
// defaults
const focusedStrokeWidth: string = "2px";
const focusedStrokeOpacity: string = "1";
const focusedOutline: string = "rgb(0, 0, 0) none 0px";
const strokeWidth: string = "1px";
const strokeOpacity: string = "0.2";
const outline: string = "rgb(0, 0, 0) none 0px";

const links: NodeListOf<HTMLElement> = visualBuilder.linkElements;

links[0].focus();

links.forEach((element: Element, index: number) => {
const linkComputedStyle: CSSStyleDeclaration = getComputedStyle(element);
const linkStrokeWidth: string = linkComputedStyle.getPropertyValue("stroke-width");
const linkStrokeOpacity: string = linkComputedStyle.getPropertyValue("stroke-opacity");
const linkOutline: string = linkComputedStyle.getPropertyValue("outline");

if (index === 0){
expect(linkStrokeWidth).toBe(focusedStrokeWidth);
expect(linkStrokeOpacity).toBe(focusedStrokeOpacity);
expect(linkOutline).toBe(focusedOutline);
}
else {
expect(linkStrokeWidth).toBe(strokeWidth);
expect(linkStrokeOpacity).toBe(strokeOpacity);
expect(linkOutline).toBe(outline);
}
});
done();
});
});

it("nodes should have :focus-visible style", (done: DoneFn) => {
visualBuilder.updateRenderTimeout(dataView, () => {
const nodeRects: NodeListOf<HTMLElement> = visualBuilder.nodeRectElements;
Expand All @@ -962,6 +997,36 @@ describe("SankeyDiagram", () => {
done();
});
});

it("focused nodes should have styled stroke and outline", (done: DoneFn) => {
visualBuilder.updateRenderTimeout(dataView, () => {
// defaults
const focusedStrokeWidth: string = "4px";
const focusedOutline: string = "rgb(0, 0, 0) none 0px";
const strokeWidth: string = "1px";
const outline: string = "rgb(0, 0, 0) none 0px";

const nodes: NodeListOf<HTMLElement> = visualBuilder.nodeRectElements;

nodes[0].focus();

nodes.forEach((element: Element, index: number) => {
const nodeComputedStyle: CSSStyleDeclaration = getComputedStyle(element);
const nodeStrokeWidth: string = nodeComputedStyle.getPropertyValue("stroke-width");
const nodeOutline: string = nodeComputedStyle.getPropertyValue("outline");

if (index === 0){
expect(nodeStrokeWidth).toBe(focusedStrokeWidth);
expect(nodeOutline).toBe(focusedOutline);
}
else {
expect(nodeStrokeWidth).toBe(strokeWidth);
expect(nodeOutline).toBe(outline);
}
});
done();
});
});
});

describe("high contrast mode test", () => {
Expand Down

0 comments on commit c5327bd

Please sign in to comment.