@octopusdeploy/design-system-components
Version:
The design systems component library.
74 lines (73 loc) • 3.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const testing_library_1 = require("@octopusdeploy/testing-library");
const react_1 = require("@testing-library/react");
const vitest_1 = require("vitest");
const vitest_axe_1 = require("vitest-axe");
const LinearProgress_1 = require("../LinearProgress");
const variants = ["indeterminate", "determinate"];
(0, vitest_1.describe)("LinearProgress", () => {
(0, vitest_1.describe)("indeterminate variant", () => {
(0, vitest_1.it)("can show the progress bar", () => {
const { progress } = renderIndeterminateProgress({ show: true });
progress.assertIsShown();
});
(0, vitest_1.it)("can hide the progress bar", () => {
const { progress } = renderIndeterminateProgress({ show: false });
progress.assertIsNotShown();
});
(0, vitest_1.it)("is accessible", async () => {
const { container } = renderIndeterminateProgress({ show: true });
const results = await (0, vitest_axe_1.axe)(container);
(0, vitest_1.expect)(results).toHaveNoViolations();
});
});
(0, vitest_1.describe)("determinate variant", () => {
(0, vitest_1.it)("can show the progress bar", () => {
const { progress } = renderDeterminateProgress({ show: true, value: 0 });
progress.assertIsShown();
});
(0, vitest_1.it)("can hide the progress bar", () => {
const { progress } = renderDeterminateProgress({ show: false, value: 0 });
progress.assertIsNotShown();
});
(0, vitest_1.it)("is accessible", async () => {
const { progress, container } = renderDeterminateProgress({ show: true, value: 15 });
const results = await (0, vitest_axe_1.axe)(container);
(0, vitest_1.expect)(results).toHaveNoViolations();
progress.assertHasDeterminateProgressAccessibilityAttributes(15);
});
});
});
function renderIndeterminateProgress({ show }) {
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(LinearProgress_1.LinearProgress, { show: show, variant: "indeterminate" }));
return { progress: getProgressInteractions(), container };
}
function renderDeterminateProgress({ show, value }) {
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(LinearProgress_1.LinearProgress, { show: show, variant: "determinate", value: value }));
return { progress: getDeterminateProgressInteractions(), container };
}
function getProgressInteractions() {
const interactions = {
assertIsShown: () => {
(0, vitest_1.expect)(testing_library_1.domQueries.getProgressBar()).toBeInTheDocument();
},
assertIsNotShown: () => {
(0, vitest_1.expect)(testing_library_1.domQueries.queryProgressbars().length).toBe(0);
},
};
return interactions;
}
function getDeterminateProgressInteractions() {
const interactions = {
...getProgressInteractions(),
assertHasDeterminateProgressAccessibilityAttributes(value) {
const progress = testing_library_1.domQueries.getProgressBar();
(0, vitest_1.expect)(progress).toHaveAttribute("aria-valuenow", `${value}`);
(0, vitest_1.expect)(progress).toHaveAttribute("aria-valuemin");
(0, vitest_1.expect)(progress).toHaveAttribute("aria-valuemax");
},
};
return interactions;
}