Skip to content

Commit

Permalink
test(label): add a11y; visual tests (#1529)
Browse files Browse the repository at this point in the history
  • Loading branch information
dancormier authored Oct 18, 2023
1 parent e4705a5 commit 5069982
Show file tree
Hide file tree
Showing 604 changed files with 1,923 additions and 12 deletions.
20 changes: 8 additions & 12 deletions docs/product/components/labels.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,21 @@
<div class="stacks-preview">
{% highlight html %}
<form class="d-flex gy4 fd-column">
<div class="flex--item">
<label class="d-block s-label" for="example-item">
Question title
<p class="s-description mt2">Clear question titles are more likely to get answered.</p>
</label>
</div>
<label class="d-block s-label" for="example-item">
Question title
</label>
<p class="s-description mtn2 mb0">Clear question titles are more likely to get answered.</p>
<div class="d-flex ps-relative">
<input class="s-input" id="example-item" type="text" placeholder="e.g. Why doesn’t Stack Overflow use a custom web font?" />
</div>
</form>
{% endhighlight %}
<div class="stacks-preview--example">
<form class="d-flex gy4 fd-column">
<div class="flex--item">
<label class="d-block s-label" for="question-title-copy">
Question title
<p class="s-description mt2">Clear question titles are more likely to get answered.</p>
</label>
</div>
<label class="d-block s-label" for="question-title-copy">
Question title
</label>
<p class="s-description mtn2 mb0">Clear question titles are more likely to get answered.</p>
<div class="d-flex ps-relative">
<input class="s-input" id="question-title-copy" type="text" placeholder="e.g. Why doesn’t Stack Overflow use a custom web font?" />
</div>
Expand Down
48 changes: 48 additions & 0 deletions lib/components/label/label.a11y.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { html } from "@open-wc/testing";
import { runComponentTests } from "../../test/test-utils";
import "../../index";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const labelTemplate = ({ component, testid }: any) => {
return html`
<fieldset data-testid="${testid}" class="p8 ws3">${component}</fieldset>
`;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const getChildren = (status?: any) => {
const typeClass =
status && status !== "base" ? `s-label--status__${status}` : "";
return `
Example label
${
status
? `
<span class="s-label--status ${typeClass}">${
status ?? "no type"
}</span>
`
: ""
}
`;
};

describe("label", () => {
runComponentTests({
type: "a11y",
baseClass: `s-label`,
modifiers: {
primary: ["sm", "md", "lg", "xl"],
},
children: {
"default": getChildren(),
"status": getChildren("base"),
"status-beta": getChildren("beta"),
"status-new": getChildren("new"),
"status-required": getChildren("required"),
},
tag: "label",
template: ({ component, testid }) =>
labelTemplate({ component, testid }),
});
});
1 change: 1 addition & 0 deletions lib/components/label/label.less
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
vertical-align: text-bottom;
}

// TODO we shouldn't support descriptions and messages within labels
.s-description,
.s-input-message {
font-weight: normal;
Expand Down
66 changes: 66 additions & 0 deletions lib/components/label/label.visual.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { html } from "@open-wc/testing";
import { runComponentTests } from "../../test/test-utils";
import "../../index";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const labelTemplate = ({ component, testid, isDisabled }: any) => {
return html`
<fieldset
data-testid="${testid}"
class="p8 ws3"
?disabled="${isDisabled}"
>
${component}
</fieldset>
`;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const getChildren = (text: string, status?: any) => {
const typeClass =
status && status !== "base" ? `s-label--status__${status}` : "";
return `
${text}
${
status
? `
<span class="s-label--status ${typeClass}">${
status ?? "no type"
}</span>
`
: ""
}
`;
};

describe("label", () => {
[true, false].forEach((isDisabled) => {
const text = isDisabled ? "Disabled label" : "Example label";

runComponentTests({
type: "visual",
baseClass: `s-label`,
modifiers: {
primary: ["sm", "md", "lg", "xl"],
},
children: isDisabled
? {
"disabled": getChildren(text),
"disabled-status": getChildren(text, "base"),
"disabled-status-beta": getChildren(text, "beta"),
"disabled-status-new": getChildren(text, "new"),
"disabled-status-required": getChildren(text, "required"),
}
: {
"default": getChildren(text),
"status": getChildren(text, "base"),
"status-beta": getChildren(text, "beta"),
"status-new": getChildren(text, "new"),
"status-required": getChildren(text, "required"),
},
tag: "label",
template: ({ component, testid }) =>
labelTemplate({ component, testid, isDisabled }),
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-lg-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-lg-status-beta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-lg-status-new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-lg-status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-lg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-md-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-md-status-beta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-md-status-new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-md-status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-md.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-sm-disabled.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-sm-status-beta.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-sm-status-new.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-sm-status.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-sm.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-status-beta.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-status-new.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-status.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-xl-disabled.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-xl-status-beta.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-xl-status-new.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-xl-status.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark-xl.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-dark.png
Loading

0 comments on commit 5069982

Please sign in to comment.