Skip to content

Commit

Permalink
test(progress-bar): add a11y; visual tests (#1522)
Browse files Browse the repository at this point in the history
* test(progress-bar): add a11y; visual tests

* Generate baseline visual regression images

* Formatting, fix a11y issues
  • Loading branch information
dancormier authored Oct 17, 2023
1 parent 240418e commit 12a2ab9
Show file tree
Hide file tree
Showing 147 changed files with 837 additions and 6 deletions.
12 changes: 6 additions & 6 deletions docs/product/components/progress-bars.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
<div class="stacks-preview">
{% highlight html %}
<div class="s-progress s-progress__circular" style="--s-progress-value: .75">
<svg class="s-progress-bar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75">
<svg class="s-progress-bar" role="progressbar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75">
<circle cx="16" cy="16" r="14"></circle>
<circle cx="16" cy="16" r="14"></circle>
</svg>
Expand All @@ -205,35 +205,35 @@
<div class="stacks-preview--example">
<div class="d-flex fw-wrap g16">
<div class="flex--item s-progress s-progress__circular s-progress__sm fc-blue-500" style="--s-progress-value: 0">
<svg class="s-progress-bar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
<svg class="s-progress-bar" role="progressbar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
<circle cx="16" cy="16" r="14"></circle>
<circle cx="16" cy="16" r="14"></circle>
</svg>
</div>

<div class="flex--item s-progress s-progress__circular fc-orange-400" style="--s-progress-value: .5">
<svg class="s-progress-bar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="50">
<svg class="s-progress-bar" role="progressbar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="50">
<circle cx="16" cy="16" r="14"></circle>
<circle cx="16" cy="16" r="14"></circle>
</svg>
</div>

<div class="flex--item s-progress s-progress__circular s-progress__md fc-green-400" style="--s-progress-value: .75">
<svg class="s-progress-bar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75">
<svg class="s-progress-bar" role="progressbar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75">
<circle cx="16" cy="16" r="14"></circle>
<circle cx="16" cy="16" r="14"></circle>
</svg>
</div>

<div class="flex--item s-progress s-progress__circular s-progress__lg fc-red-500" style="--s-progress-value: .94">
<svg class="s-progress-bar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="94">
<svg class="s-progress-bar" role="progressbar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="94">
<circle cx="16" cy="16" r="14"></circle>
<circle cx="16" cy="16" r="14"></circle>
</svg>
</div>

<div class="flex--item s-progress s-progress__circular s-progress__lg fc-blue-500" style="--s-progress-value: 1">
<svg class="s-progress-bar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="100">
<svg class="s-progress-bar" role="progressbar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="100">
<circle cx="16" cy="16" r="14"></circle>
<circle cx="16" cy="16" r="14"></circle>
</svg>
Expand Down
200 changes: 200 additions & 0 deletions lib/components/progress-bar/progress-bar.a11y.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
import { html } from "@open-wc/testing";
import {
IconAchievementsSm,
IconCheckmarkSm,
} from "@stackoverflow/stacks-icons/icons";
import { defaultOptions, runComponentTests } from "../../test/test-utils";
import "../../index";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const template = ({ component, testid }: any) => html`
<div class="d-flex ai-center jc-center p8 ws2" data-testid="${testid}">
${component}
</div>
`;

const steppedItems = [
{
complete: true,
label: "Select plan",
},
{
complete: true,
label: "Team name",
},
{
active: true,
label: "Payment",
},
{
label: "Create account",
},
];

const getChildren = (type: string) => {
switch (type) {
case "badge":
return `<div class="s-progress--label" id="example-label">
<div class="s-badge--label">Electorate</div>
</div>
<div class="s-progress--bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75" aria-labelledby="example-label" style="width: 75%;"></div>`;
case "circular":
return `<svg class="s-progress-bar" role="progressbar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75">
<circle cx="16" cy="16" r="14"></circle>
<circle cx="16" cy="16" r="14"></circle>
</svg>`;
case "privilege":
return `
<div class="s-progress--label" id="progress-label">
${IconAchievementsSm}
Access Review Queues
</div>
<div class="s-progress--bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75" aria-labelledby="progress-label" style="width: 75%;"></div>
`;
case "segmented":
return `
<div class="s-progress--bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75" aria-label="…" style="width: 75%;"></div>
<ol class="s-progress--segments">
<li></li><li></li><li></li>
</ol>
`;
case "stepped":
return steppedItems
.map((step, i) => {
return `
<div
class="
s-progress--step
${step.active ? "is-active" : ""}
${step.complete ? "is-complete" : ""}
"
>
<a href="#" class="s-progress--stop">
${step.complete ? IconCheckmarkSm : ""}
<span class="v-visible-sr">${step.label} ${
step.complete ? "complete" : "incomplete"
}</span>
</a>
${
i > 0
? '<div class="s-progress--bar s-progress--bar__left"></div>'
: ""
}
${
i < steppedItems.length - 1
? '<div class="s-progress--bar s-progress--bar__right"></div>'
: ""
}
<a class="s-progress--label">${step.label}</a>
</div>
`;
})
.join("");
default:
return `<div class="s-progress--bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75" aria-label="progress" style="width: 75%"></div>`;
}
};
describe("progress-bar", () => {
// Base
runComponentTests({
type: "a11y",
baseClass: "s-progress",
variants: ["brand", "info"],
children: {
default: getChildren(""),
},
template,
});

// Badge
runComponentTests({
type: "a11y",
baseClass: "s-progress",
variants: ["badge"],
modifiers: {
primary: ["gold", "silver", "bronze"],
},
children: {
default: getChildren("badge"),
},
template,
options: {
...defaultOptions,
includeNullVariant: false,
includeNullModifier: false,
},
});

// Circular
runComponentTests({
type: "a11y",
baseClass: "s-progress",
variants: ["circular"],
modifiers: {
global: ["fc-green-400", "fc-theme-primary"],
},
children: {
default: getChildren("circular"),
},
template,
attributes: {
style: "--s-progress-value: .75",
},
options: {
...defaultOptions,
includeNullVariant: false,
includeNullModifier: false,
},
});

// Privilege
runComponentTests({
type: "a11y",
baseClass: "s-progress",
variants: ["privilege"],
children: {
default: getChildren("privilege"),
},
template,
options: {
...defaultOptions,
includeNullVariant: false,
},
});

// Segmented
runComponentTests({
type: "a11y",
baseClass: "s-progress",
variants: ["segmented"],
children: {
default: getChildren("segmented"),
},
template,
options: {
...defaultOptions,
includeNullVariant: false,
},
});

// Stepped
runComponentTests({
type: "a11y",
baseClass: "s-progress",
variants: ["stepped"],
children: {
default: getChildren("stepped"),
},
template: ({ component, testid }) => html`
<div class="d-block p8 ws5" data-testid="${testid}">
${component}
</div>
`,
options: {
...defaultOptions,
includeNullVariant: false,
},
// TODO add skipped test ids
});
});
Loading

0 comments on commit 12a2ab9

Please sign in to comment.