Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
radium-v committed Aug 31, 2022
1 parent f8efc6e commit 4c146ff
Show file tree
Hide file tree
Showing 42 changed files with 2,514 additions and 3,993 deletions.
14 changes: 13 additions & 1 deletion packages/web-components/fast-foundation/.storybook/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module.exports = {
builder: "webpack5",
},
webpackFinal: async config => {
config.performance = {
...(config.performance ?? {}),
hints: false,
};
config.module.rules = [
{
test: /\.ts$/,
Expand All @@ -23,10 +27,18 @@ module.exports = {
transpileOnly: true,
},
},
{
test: /\.m?js$/,
enforce: "pre",
loader: require.resolve("source-map-loader"),
resolve: {
fullySpecified: false,
},
},
];

config.resolve.plugins = [
...(config.resolve.plugins || []),
...(config.resolve.plugins ?? []),
new ResolveTypescriptPlugin({
includeNodeModules: true,
}),
Expand Down

This file was deleted.

9 changes: 9 additions & 0 deletions packages/web-components/fast-foundation/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useArgs } from "@storybook/client-api";

import "@microsoft/fast-element/polyfills";
import "../src/anchor/stories/anchor.register.js";
import "../src/anchored-region/stories/anchored-region.register.js";
Expand Down Expand Up @@ -56,3 +58,10 @@ import "../src/menu/stories/menu.register.js";

import "../src/tree-item/stories/tree-item.register.js";
import "../src/tree-view/stories/tree-view.register.js";

export const decorators = [
(Story, context) => {
const [_, updateArgs] = useArgs();
return Story({ ...context, updateArgs });
},
];
4 changes: 3 additions & 1 deletion packages/web-components/fast-foundation/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,9 @@ export class FASTRadioGroup extends FASTElement {
name: string;
// (undocumented)
protected nameChanged(): void;
orientation: Orientation | "horizontal" | "vertical";
orientation: Orientation;
// (undocumented)
positioningRegion: HTMLDivElement;
readOnly: boolean;
// (undocumented)
protected readOnlyChanged(): void;
Expand Down
12 changes: 6 additions & 6 deletions packages/web-components/fast-foundation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@
"@microsoft/tsdoc-config": "^0.13.4",
"@playwright/test": "^1.25.1",
"@rollup/plugin-node-resolve": "^13.3.0",
"@storybook/addon-docs": "6.5.9",
"@storybook/addon-essentials": "6.5.9",
"@storybook/addon-links": "6.5.9",
"@storybook/builder-webpack5": "6.5.9",
"@storybook/addon-docs": "6.5.10",
"@storybook/addon-essentials": "6.5.10",
"@storybook/addon-links": "6.5.10",
"@storybook/builder-webpack5": "6.5.10",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/html": "6.5.9",
"@storybook/manager-webpack5": "6.5.9",
"@storybook/html": "6.5.10",
"@storybook/manager-webpack5": "6.5.10",
"concurrently": "^7.3.0",
"esm": "^3.2.25",
"express": "^4.18.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
Args,
ComponentAnnotations,
StoryAnnotations,
StoryContext,
} from "@storybook/csf";
import qs from "qs";

Expand Down Expand Up @@ -48,10 +49,10 @@ export function fixtureURL(
*/
export function renderComponent<TArgs = Args>(
template: ViewTemplate
): (args: TArgs) => Element | DocumentFragment | null {
return function (args) {
): (args: TArgs, context: StoryContext) => Element | DocumentFragment | null {
return function (args, { updateArgs }) {
const storyFragment = new DocumentFragment();
template.render(args, storyFragment);
template.render({...args, updateArgs }, storyFragment);
if (storyFragment.childElementCount === 1) {
return storyFragment.firstElementChild;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,118 +1,88 @@
import type { Locator, Page } from "@playwright/test";
import { expect, test } from "@playwright/test";
import { fixtureURL } from "../__test__/helpers.js";
import type { FASTAccordionItem } from "./accordion-item.js";

test.describe("Accordion item", () => {
test("should set an `aria-level` to the heading when provided", async ({ page }) => {
await page.goto(
fixtureURL("accordion-item--accordion-item", {
headinglevel: 4,
})
);
test.describe("States, Attributes, and Properties", () => {
let page: Page;
let element: Locator;
let heading: Locator;

const element = page.locator("fast-accordion-item");
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();

await expect(element).toHaveJSProperty("headinglevel", 4);
element = page.locator("fast-accordion-item");

const heading = element.locator(`[role="heading"]`);
heading = page.locator(`[role="heading"]`);

await expect(heading).toHaveAttribute("aria-level", "4");
});

test("should set a default heading level of 2 when NOT provided a `headinglevel`", async ({
page,
}) => {
await page.goto(fixtureURL("accordion-item--accordion-item"));

const element = page.locator("fast-accordion-item");

await expect(element).toHaveJSProperty("headinglevel", 2);

const heading = page.locator(`[role="heading"]`);

await expect(heading).toHaveAttribute("aria-level", "2");
});
await page.goto(fixtureURL("accordion-item--accordion-item"));
});

test("should set `aria-expanded` value to false on the internal button when expanded is undefined", async ({
page,
}) => {
await page.goto(fixtureURL("accordion-item--accordion-item"));
test.afterAll(async () => {
await page.close();
});

const element = page.locator("fast-accordion-item button");
test("should set a default heading level of 2 when `headinglevel` is not provided", async () => {
await expect(element).not.hasAttribute("headinglevel");

await expect(element).toHaveAttribute("aria-expanded", "false");
});
await expect(element).toHaveJSProperty("headinglevel", 2);
});

test.describe("when not expanded", () => {
test("should NOT have a class of `expanded`", async ({ page }) => {
await page.goto(
fixtureURL("accordion-item--accordion-item", {
expanded: false,
})
);
test("should set the `aria-level` attribute on the internal heading element equal to the heading level", async () => {
await expect(heading).toHaveAttribute("aria-level", "2");

const element = page.locator("fast-accordion-item");
await element.evaluate<void, FASTAccordionItem>(node => {
node.headinglevel = 3;
});

await expect(element).not.toHaveClass("expanded");
await expect(heading).toHaveAttribute("aria-level", "3");
});

test("should set `aria-expanded` value to false on the internal button", async ({
page,
}) => {
await page.goto(
fixtureURL("accordion-item--accordion-item", {
expanded: false,
})
);

const element = page.locator("fast-accordion-item button");
test("should NOT have a class of `expanded` when the `expanded` property is false", async () => {
await element.evaluate<void, FASTAccordionItem>(node => {
node.expanded = false;
});

await expect(element).toHaveAttribute("aria-expanded", "false");
await expect(element).not.toHaveClass(/expanded/);
});
});

test.describe("when expanded", () => {
test("should have a class of `expanded`", async ({ page }) => {
await page.goto(
fixtureURL("accordion-item--accordion-item", {
expanded: true,
})
);

const element = page.locator("fast-accordion-item");
test("should have a class of `expanded` when the `expanded` property is true", async () => {
await element.evaluate<void, FASTAccordionItem>(node => {
node.expanded = true;
});

await expect(element).toHaveClass("expanded");
await expect(element).toHaveClass(/expanded/);
});

test("should set `aria-expanded` value to true on the internal button", async ({
page,
}) => {
await page.goto(
fixtureURL("accordion-item--accordion-item", {
expanded: true,
})
);
test("should set `aria-expanded` property on the internal control equal to the `expanded` property", async () => {
const button = element.locator("button");

const element = page.locator("fast-accordion-item button");
await element.evaluate<void, FASTAccordionItem>(node => {
node.expanded = true;
});

await expect(element).toHaveAttribute("aria-expanded", "true");
});
});
await expect(button).toHaveAttribute("aria-expanded", "true");

test("should set internal properties to match the id when provided", async ({
page,
}) => {
const id = "testId";
await element.evaluate<void, FASTAccordionItem>(node => {
node.expanded = false;
});

await page.goto(fixtureURL("accordion-item--accordion-item", { id }));
await expect(button).toHaveAttribute("aria-expanded", "false");
});

const element = page.locator("fast-accordion-item");
test("should set internal properties to match the id when provided", async () => {
await element.evaluate<void, FASTAccordionItem>(node => {
node.id = "testId";
});

const region = element.locator(`[role="region"]`);
const region = element.locator(`[role="region"]`);

await expect(region).toHaveAttribute("aria-labelledby", id);
await expect(region).toHaveAttribute("aria-labelledby", "testId");

const button = element.locator("button");
const button = element.locator("button");

await expect(button).toHaveId(id);
await expect(button).toHaveId("testId");
});
});
});
Original file line number Diff line number Diff line change
@@ -1,47 +1,59 @@
import { spinalCase } from "@microsoft/fast-web-utilities";
import { expect, test } from "@playwright/test";
import type { Locator, Page } from "@playwright/test";
import { fixtureURL } from "../__test__/helpers.js";

test.describe("Anchor", () => {
test.describe("should set the attribute on the internal anchor", () => {
const attributes = {
href: "href",
ping: "ping",
hreflang: "en-GB",
referrerpolicy: "no-referrer",
rel: "external",
target: "_blank",
type: "foo",
ariaAtomic: "true",
ariaBusy: "false",
ariaControls: "testId",
ariaCurrent: "page",
ariaDescribedby: "testId",
ariaDetails: "testId",
ariaDisabled: "true",
ariaErrormessage: "test",
ariaExpanded: "true",
ariaFlowto: "testId",
ariaHaspopup: "true",
ariaHidden: "true",
ariaInvalid: "spelling",
ariaKeyshortcuts: "F4",
ariaLabel: "foo",
ariaLabelledby: "testId",
ariaLive: "polite",
ariaOwns: "testId",
ariaRelevant: "removals",
ariaRoledescription: "slide",
};

Object.entries(attributes).forEach(([key, value]) => {
test(key, async ({ page }) => {
await page.goto(fixtureURL("anchor--anchor", { [key]: value }));

const anchor = page.locator("fast-anchor a");

await expect(anchor).toHaveAttribute(spinalCase(key), `${value}`);
});
});
let page: Page;
let element: Locator;

test.beforeAll(async ({ browser }) => {
page = await browser.newPage();

element = page.locator("fast-anchor");

await page.goto(fixtureURL("anchor", attributes));
});

test.afterAll(async () => {
await page.close();
});

const attributes = {
href: "href",
ping: "ping",
hreflang: "en-GB",
referrerpolicy: "no-referrer",
rel: "external",
target: "_blank",
type: "foo",
ariaAtomic: "true",
ariaBusy: "false",
ariaControls: "testId",
ariaCurrent: "page",
ariaDescribedby: "testId",
ariaDetails: "testId",
ariaDisabled: "true",
ariaErrormessage: "test",
ariaExpanded: "true",
ariaFlowto: "testId",
ariaHaspopup: "true",
ariaHidden: "true",
ariaInvalid: "spelling",
ariaKeyshortcuts: "F4",
ariaLabel: "foo",
ariaLabelledby: "testId",
ariaLive: "polite",
ariaOwns: "testId",
ariaRelevant: "removals",
ariaRoledescription: "slide",
};

for (const [attribute, value] of Object.entries(attributes)) {
const attributeSpinalCase = spinalCase(attribute);

test(`should set the \`${attributeSpinalCase}\` attribute to \`${value}\` on the internal control`, async () => {
await expect(element).toHaveAttribute(attributeSpinalCase, `${value}`);
});
}
});
Loading

0 comments on commit 4c146ff

Please sign in to comment.