Skip to content

Commit

Permalink
add visual and a11y tests for required symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
giamir committed May 3, 2024
1 parent cea55e3 commit ba4a5ee
Show file tree
Hide file tree
Showing 183 changed files with 432 additions and 105 deletions.
46 changes: 2 additions & 44 deletions lib/components/label/label.a11y.test.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,6 @@
import { html } from "@open-wc/testing";
import { runA11yTests } from "../../test/a11y-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>
`
: ""
}
`;
};
import getTestArgs from "./label.test.setup";

describe("label", () => {
runA11yTests({
baseClass: `s-label`,
modifiers: {
primary: ["sm", "md", "lg", "xl"],
},
// TODO: add abbr s-required-symbol variant
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 }),
});
runA11yTests(getTestArgs());
});
67 changes: 67 additions & 0 deletions lib/components/label/label.test.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { html } from "@open-wc/testing";
import type { TestVariationArgs } from "../../test/test-utils";
import "../../index";

type StatusType = "base" | "beta" | "new" | "required";

const labelTemplate = ({
component,
testid,
disabled,
}: {
component: unknown;
testid: string;
disabled: boolean;
}) => {
return html`
<fieldset
data-testid="${testid}"
class="p8 ws3"
?disabled="${disabled}"
>
${component}
</fieldset>
`;
};

const getStatus = (status: StatusType | undefined) => {
if (!status) return "";
const statusTypeClass =
status !== "base" ? `s-label--status__${status}` : "";
return `<span class="s-label--status ${statusTypeClass}">${status}</span>`;
};

const getRequiredSymbol = (required: boolean | undefined) => {
return required
? `<abbr class="s-required-symbol" title="required">*</abbr>`
: "";
};

const getChildren = (text: string, status?: StatusType, required?: boolean) => {
return `${text}${getRequiredSymbol(required)} ${getStatus(status)}`;
};

const getTestArgs = (disabled = false): TestVariationArgs => {
const text = disabled ? "Disabled label" : "Example label";
const prefix = disabled ? "disabled-" : "";

return {
baseClass: `s-label`,
modifiers: {
primary: ["sm", "md", "lg", "xl"],
},
children: {
[`${prefix}default`]: getChildren(text),
[`${prefix}required`]: getChildren(text, undefined, true),
[`${prefix}status`]: getChildren(text, "base"),
[`${prefix}status-beta`]: getChildren(text, "beta"),
[`${prefix}status-new`]: getChildren(text, "new"),
[`${prefix}status-required`]: getChildren(text, "required"),
},
tag: "label",
template: ({ component, testid }) =>
labelTemplate({ component, testid, disabled }),
};
};

export default getTestArgs;
64 changes: 3 additions & 61 deletions lib/components/label/label.visual.test.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,8 @@
import { html } from "@open-wc/testing";
import { runVisualTests } from "../../test/visual-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>
`
: ""
}
`;
};
import getTestArgs from "./label.test.setup";

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

runVisualTests({
baseClass: `s-label`,
modifiers: {
primary: ["sm", "md", "lg", "xl"],
},
// TODO: add abbr s-required-symbol variant
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 }),
});
[true, false].forEach((disabled) => {
runVisualTests(getTestArgs(disabled));
});
});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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-required.png
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-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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-xl-required.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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-light-lg-required.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-light-md-required.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-light-required.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-light-sm-required.png
3 changes: 3 additions & 0 deletions screenshots/Chromium/baseline/s-label-light-xl-required.png
3 changes: 3 additions & 0 deletions screenshots/Firefox/baseline/s-label-dark-lg-required.png
3 changes: 3 additions & 0 deletions screenshots/Firefox/baseline/s-label-dark-md-required.png
3 changes: 3 additions & 0 deletions screenshots/Firefox/baseline/s-label-dark-required.png
3 changes: 3 additions & 0 deletions screenshots/Firefox/baseline/s-label-dark-sm-required.png
3 changes: 3 additions & 0 deletions screenshots/Firefox/baseline/s-label-dark-xl-required.png

0 comments on commit ba4a5ee

Please sign in to comment.