UNPKG

@octopusdeploy/design-system-components

Version:
61 lines (60 loc) 2.65 kB
"use strict"; 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 StatusBadge_1 = require("../StatusBadge"); (0, vitest_1.describe)("StatusBadge", () => { (0, vitest_1.describe)("accessibility", () => { (0, vitest_1.test)("is accessible with label hidden", async () => { const badge = renderStatusBadge({ status: "healthy", showLabel: false }); await badge.shouldHaveNoAccessibilityViolations(); }); (0, vitest_1.test)("is accessible with label shown", async () => { const badge = renderStatusBadge({ status: "healthy", showLabel: true }); await badge.shouldHaveNoAccessibilityViolations(); }); }); (0, vitest_1.describe)("rendering", () => { vitest_1.test.each(StatusBadge_1.badgeStatuses)("renders %s status", (status) => { const badge = renderStatusBadge({ status }); const expectedStatusLabel = expectedStatusLabels[status]; badge.shouldShowIcon(expectedStatusLabel); }); (0, vitest_1.test)("shows label when showLabel is true", () => { const badge = renderStatusBadge({ status: "healthy", showLabel: true }); badge.shouldShowLabel("Healthy"); }); }); }); const expectedStatusLabels = { healthy: "Healthy", "healthy-with-warnings": "Healthy with warnings", unavailable: "Unavailable", unhealthy: "Unhealthy", unknown: "Unknown", disabled: "Disabled", }; function renderStatusBadge({ status, showLabel }) { const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(StatusBadge_1.StatusBadge, { status: status, showLabel: showLabel })); return getStatusBadgeInteractions(container); } function getStatusBadgeInteractions(container) { return { shouldShowIcon: (label) => { testing_library_1.domQueries.getImage(label).assertIsInTheDocument(); }, shouldShowLabel: (label) => { testing_library_1.domQueries.getText(label).assertIsInTheDocument(); }, shouldNotShowLabel: (label) => { testing_library_1.domQueries.queryText(label).assertIsNotInTheDocument(); }, shouldHaveNoAccessibilityViolations: async () => { const results = await (0, vitest_axe_1.axe)(container); (0, vitest_1.expect)(results).toHaveNoViolations(); }, }; }