Skip to content

Commit 52953ce

Browse files
scomeachrisdholt
authored andcommitted
feat: rename component display names, update directory export tests (#1572)
BREAKING CHANGE: Component display names are now prefixed to improve discoverability
1 parent 395546a commit 52953ce

File tree

100 files changed

+437
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+437
-259
lines changed

build/helpers/file-includes-all-subdirectories-as-named-exports.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import fs from "fs";
33
import { pascalCase } from "../../packages/fast-web-utilities";
44

55
/**
6-
* Verifies all components in source directory are exported
6+
* Verifies all components in source directory are exported, directories listed in "excludes" parameter are ignored
77
*/
8-
export function includesAllSubdirectoriesAsNamedExports(indexFile: string): boolean {
8+
export function includesAllSubdirectoriesAsNamedExports(indexFile: string, excludes?: string[]): boolean {
99
// Get the folders in the indexFile directory to compare to export listing
1010
const directoryPath: string = path.dirname(indexFile);
1111
const components: string[] = fs.readdirSync(directoryPath)
@@ -15,7 +15,7 @@ export function includesAllSubdirectoriesAsNamedExports(indexFile: string): bool
1515

1616
// Get listing of all exports and compare against folder listings
1717
const foundExports: any = Object.keys(require(path.resolve(__dirname, indexFile)));
18-
const missingExports: string[] = components.filter((component: string) => !foundExports.includes(component));
18+
const missingExports: string[] = components.filter((component: string) => !foundExports.includes(component) && excludes.indexOf(component) !== -1);
1919

2020
if (missingExports.length === 0) {
2121
return true;

packages/fast-components-react-base/src/auto-suggest/auto-suggest.spec.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { configure, mount, render, shallow } from "enzyme";
44
import AutoSuggest, { AutoSuggestUnhandledProps } from "./auto-suggest";
55
import ListboxItem from "../listbox-item";
66
import { KeyCodes } from "@microsoft/fast-web-utilities";
7+
import { DisplayNamePrefix } from "../utilities";
78

89
/*
910
* Configure Enzyme
@@ -16,7 +17,9 @@ const itemC: JSX.Element = <ListboxItem id="c" value="c" />;
1617

1718
describe("auto suggest", (): void => {
1819
test("should have a displayName that matches the component name", () => {
19-
expect((AutoSuggest as any).name).toBe(AutoSuggest.displayName);
20+
expect(`${DisplayNamePrefix}${(AutoSuggest as any).name}`).toBe(
21+
AutoSuggest.displayName
22+
);
2023
});
2124

2225
test("should not throw if managedClasses are not provided", () => {
@@ -117,7 +120,7 @@ describe("auto suggest", (): void => {
117120

118121
rendered
119122
.find({ id: "a" })
120-
.find("ListboxItem")
123+
.find(ListboxItem.displayName)
121124
.simulate("keydown", { keyCode: KeyCodes.arrowDown });
122125
input = rendered.find("input");
123126
expect(input.prop("aria-owns")).toEqual("listboxId");
@@ -151,7 +154,7 @@ describe("auto suggest", (): void => {
151154

152155
rendered
153156
.find({ id: "a" })
154-
.find("ListboxItem")
157+
.find(ListboxItem.displayName)
155158
.simulate("keydown", { keyCode: KeyCodes.arrowDown });
156159
input = rendered.find("input");
157160
expect(input.prop("aria-owns")).toEqual("listboxId");
@@ -182,7 +185,7 @@ describe("auto suggest", (): void => {
182185

183186
rendered
184187
.find({ id: "a" })
185-
.find("ListboxItem")
188+
.find(ListboxItem.displayName)
186189
.simulate("keydown", { keyCode: KeyCodes.arrowDown });
187190
input = rendered.find("input");
188191
expect(input.prop("aria-activedescendant")).toEqual("b");
@@ -228,19 +231,19 @@ describe("auto suggest", (): void => {
228231
expect(rendered.state("value")).toEqual("a");
229232
rendered
230233
.find({ id: "a" })
231-
.find("ListboxItem")
234+
.find(ListboxItem.displayName)
232235
.simulate("keydown", { keyCode: KeyCodes.arrowDown });
233236
expect(document.activeElement.id).toBe("b");
234237
expect(rendered.state("value")).toEqual("b");
235238
rendered
236239
.find({ id: "b" })
237-
.find("ListboxItem")
240+
.find(ListboxItem.displayName)
238241
.simulate("keydown", { keyCode: KeyCodes.arrowDown });
239242
expect(document.activeElement.id).toBe("c");
240243
expect(rendered.state("value")).toEqual("c");
241244
rendered
242245
.find({ id: "c" })
243-
.find("ListboxItem")
246+
.find(ListboxItem.displayName)
244247
.simulate("keydown", { keyCode: KeyCodes.arrowDown });
245248
expect(document.activeElement.id).toBe("");
246249
expect(rendered.state("value")).toEqual("c");
@@ -249,19 +252,19 @@ describe("auto suggest", (): void => {
249252
expect(rendered.state("value")).toEqual("c");
250253
rendered
251254
.find({ id: "c" })
252-
.find("ListboxItem")
255+
.find(ListboxItem.displayName)
253256
.simulate("keydown", { keyCode: KeyCodes.arrowUp });
254257
expect(document.activeElement.id).toBe("b");
255258
expect(rendered.state("value")).toEqual("b");
256259
rendered
257260
.find({ id: "b" })
258-
.find("ListboxItem")
261+
.find(ListboxItem.displayName)
259262
.simulate("keydown", { keyCode: KeyCodes.arrowUp });
260263
expect(document.activeElement.id).toBe("a");
261264
expect(rendered.state("value")).toEqual("a");
262265
rendered
263266
.find({ id: "a" })
264-
.find("ListboxItem")
267+
.find(ListboxItem.displayName)
265268
.simulate("keydown", { keyCode: KeyCodes.arrowUp });
266269
expect(document.activeElement.id).toBe("");
267270
expect(rendered.state("value")).toEqual("a");
@@ -312,7 +315,7 @@ describe("auto suggest", (): void => {
312315
input.simulate("keydown", { keyCode: KeyCodes.arrowDown });
313316
rendered
314317
.find({ id: "a" })
315-
.find("ListboxItem")
318+
.find(ListboxItem.displayName)
316319
.simulate("keydown", { keyCode: KeyCodes.enter });
317320
expect(onInvoked).toHaveBeenCalledTimes(1);
318321

packages/fast-components-react-base/src/auto-suggest/auto-suggest.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ListboxItemProps } from "../listbox-item";
1212
import Listbox from "../listbox";
1313
import TextField, { TextFieldType } from "../text-field";
1414
import { AutoSuggestContext, AutoSuggestContextType } from "./auto-suggest-context";
15+
import { DisplayNamePrefix } from "../utilities";
1516

1617
export interface AutoSuggestState {
1718
value: string;
@@ -24,7 +25,7 @@ class AutoSuggest extends Foundation<
2425
AutoSuggestUnhandledProps,
2526
AutoSuggestState
2627
> {
27-
public static displayName: string = "AutoSuggest";
28+
public static displayName: string = `${DisplayNamePrefix}AutoSuggest`;
2829

2930
public static defaultProps: Partial<AutoSuggestProps> = {
3031
initialValue: "",

packages/fast-components-react-base/src/badge/badge.spec.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import React from "react";
22
import Adapter from "enzyme-adapter-react-16";
33
import { configure, mount, shallow } from "enzyme";
44
import Badge, { BadgeHandledProps, BadgeProps, BadgeUnhandledProps } from "./index";
5+
import { DisplayNamePrefix } from "../utilities";
56

67
/*
78
* Configure Enzyme
89
*/
910
configure({ adapter: new Adapter() });
1011

1112
describe("badge", (): void => {
12-
test("should have a displayName that matches the component name", () => {
13-
expect((Badge as any).name).toBe(Badge.displayName);
13+
test("should have a displayName that includes the component name", () => {
14+
expect(`${DisplayNamePrefix}${(Badge as any).name}`).toBe(Badge.displayName);
1415
});
1516

1617
test("should not throw if managedClasses are not provided", () => {

packages/fast-components-react-base/src/badge/badge.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import Foundation, { HandledProps } from "@microsoft/fast-components-foundation-
33
import { BadgeClassNameContract } from "@microsoft/fast-components-class-name-contracts-base";
44
import { BadgeHandledProps, BadgeUnhandledProps } from "./badge.props";
55
import { get } from "lodash-es";
6-
6+
import { DisplayNamePrefix } from "../utilities";
77
class Badge extends Foundation<BadgeHandledProps, BadgeUnhandledProps, {}> {
8-
public static displayName: string = "Badge";
8+
public static displayName: string = `${DisplayNamePrefix}Badge`;
99

1010
protected handledProps: HandledProps<BadgeHandledProps> = {
1111
managedClasses: void 0,

packages/fast-components-react-base/src/breadcrumb/breadcrumb.spec.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Breadcrumb, {
55
BreadcrumbClassNameContract,
66
BreadcrumbUnhandledProps,
77
} from "./breadcrumb";
8+
import { DisplayNamePrefix } from "../utilities";
89

910
/*
1011
* Configure Enzyme
@@ -21,7 +22,9 @@ const managedClasses: BreadcrumbClassNameContract = {
2122

2223
describe("breadcrumb", (): void => {
2324
test("should have a displayName that matches the component name", () => {
24-
expect((Breadcrumb as any).name).toBe(Breadcrumb.displayName);
25+
expect(`${DisplayNamePrefix}${(Breadcrumb as any).name}`).toBe(
26+
Breadcrumb.displayName
27+
);
2528
});
2629

2730
test("should have correct root element type 'nav'", () => {

packages/fast-components-react-base/src/breadcrumb/breadcrumb.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import {
88
BreadcrumbUnhandledProps,
99
} from "./breadcrumb.props";
1010
import { get } from "lodash-es";
11+
import { DisplayNamePrefix } from "../utilities";
1112

1213
class Breadcrumb extends Foundation<
1314
BreadcrumbHandledProps,
1415
BreadcrumbUnhandledProps,
1516
{}
1617
> {
17-
public static displayName: string = "Breadcrumb";
18+
public static displayName: string = `${DisplayNamePrefix}Breadcrumb`;
1819

1920
protected handledProps: HandledProps<BreadcrumbHandledProps> = {
2021
children: void 0,

packages/fast-components-react-base/src/button/button.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Button, {
1111
ButtonProps,
1212
ButtonUnhandledProps,
1313
} from "./button";
14+
import { DisplayNamePrefix } from "../utilities";
1415

1516
/*
1617
* Configure Enzyme
@@ -24,7 +25,7 @@ describe("button", (): void => {
2425
const href: string = "https://www.microsoft.com";
2526

2627
test("should have a displayName that matches the component name", () => {
27-
expect((Button as any).name).toBe(Button.displayName);
28+
expect(`${DisplayNamePrefix}${(Button as any).name}`).toBe(Button.displayName);
2829
});
2930

3031
test("should not throw if managedClasses are not provided", () => {

packages/fast-components-react-base/src/button/button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ButtonClassNameContract,
88
ManagedClasses,
99
} from "@microsoft/fast-components-class-name-contracts-base";
10+
import { DisplayNamePrefix } from "../utilities";
1011

1112
/**
1213
* Button HTML tags
@@ -17,7 +18,7 @@ export enum ButtonHTMLTags {
1718
}
1819

1920
class Button extends Foundation<ButtonHandledProps, ButtonUnhandledProps, {}> {
20-
public static displayName: string = "Button";
21+
public static displayName: string = `${DisplayNamePrefix}Button`;
2122

2223
protected handledProps: HandledProps<ButtonHandledProps> = {
2324
disabled: void 0,

packages/fast-components-react-base/src/card/card.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Card, {
1010
CardTag,
1111
CardUnhandledProps,
1212
} from "./card";
13+
import { DisplayNamePrefix } from "../utilities";
1314

1415
/*
1516
* Configure Enzyme
@@ -22,7 +23,7 @@ describe("card", (): void => {
2223
};
2324

2425
test("should have a displayName that matches the component name", () => {
25-
expect((Card as any).name).toBe(Card.displayName);
26+
expect(`${DisplayNamePrefix}${(Card as any).name}`).toBe(Card.displayName);
2627
});
2728

2829
test("should return an object that includes all valid props which are not enumerated as handledProps", () => {

0 commit comments

Comments
 (0)