@ilo-org/react 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/.storybook/main.ts +41 -0
  2. package/.storybook/manager-head.html +92 -0
  3. package/.storybook/manager.ts +6 -0
  4. package/.storybook/preview-head.html +5 -0
  5. package/.storybook/preview.tsx +81 -0
  6. package/.storybook/styles.scss +25 -0
  7. package/.storybook/theme.ts +46 -0
  8. package/.turbo/turbo-build:lib.log +15 -0
  9. package/CHANGELOG.md +26 -0
  10. package/lib/cjs/components/Cards/CardGroup/CardGroup.js +0 -1
  11. package/lib/cjs/components/Cards/CardGroup/index.js +197 -160
  12. package/lib/cjs/components/Cards/FactlistCard/FactListCard.js +0 -1
  13. package/lib/cjs/components/Cards/FactlistCard/index.js +0 -1
  14. package/lib/cjs/components/Cards/TextCard/TextCard.js +1 -1
  15. package/lib/cjs/components/List/List.js +9 -11
  16. package/lib/cjs/components/List/ListItem.js +4 -7
  17. package/lib/cjs/components/List/index.js +1 -2
  18. package/lib/cjs/components/index.js +0 -1
  19. package/lib/cjs/index.js +0 -1
  20. package/lib/esm/components/Cards/CardGroup/CardGroup.js +0 -1
  21. package/lib/esm/components/Cards/CardGroup/index.js +197 -160
  22. package/lib/esm/components/Cards/FactlistCard/FactListCard.js +0 -1
  23. package/lib/esm/components/Cards/FactlistCard/index.js +0 -1
  24. package/lib/esm/components/Cards/TextCard/TextCard.js +1 -1
  25. package/lib/esm/components/List/List.js +10 -12
  26. package/lib/esm/components/List/ListItem.js +4 -7
  27. package/lib/esm/components/List/index.js +1 -2
  28. package/lib/esm/components/index.js +0 -1
  29. package/lib/esm/index.js +0 -1
  30. package/lib/types/react/src/components/List/List.props.d.ts +2 -9
  31. package/lib/types/react/src/components/List/ListItem.props.d.ts +0 -6
  32. package/lib/types/react/src/types/index.d.ts +0 -2
  33. package/package.json +32 -12
  34. package/public/fao-logo.svg +195 -0
  35. package/public/favicon.ico +0 -0
  36. package/public/hero.jpg +0 -0
  37. package/public/ilo-dg.jpg +0 -0
  38. package/public/ilo-headquarters.jpg +0 -0
  39. package/public/large.jpg +0 -0
  40. package/public/media-file-poster.jpg +0 -0
  41. package/public/medium.jpg +0 -0
  42. package/public/react.svg +8 -0
  43. package/public/small.jpg +0 -0
  44. package/public/unhcr-logo.svg +1 -0
  45. package/public/unicef-logo.png +0 -0
  46. package/public/video-example.mp4 +0 -0
  47. package/public/wfp-logo.svg +1 -0
  48. package/public/who-logo.svg +1 -0
  49. package/public/youtube-video-poster.avif +0 -0
  50. package/rollup.config.mjs +2 -0
  51. package/src/__tests__/Accordion.test.tsx +16 -0
  52. package/src/__tests__/Button.test.tsx +60 -0
  53. package/src/__tests__/Callout.test.tsx +43 -0
  54. package/src/__tests__/ContextMenu.test.tsx +19 -0
  55. package/src/__tests__/Dropdown.test.tsx +38 -0
  56. package/src/__tests__/Heading.test.tsx +51 -0
  57. package/src/__tests__/Image.test.tsx +21 -0
  58. package/src/__tests__/LinkList.test.tsx +17 -0
  59. package/src/__tests__/List.test.tsx +25 -0
  60. package/src/__tests__/Loading.test.tsx +33 -0
  61. package/src/__tests__/Notification.test.tsx +39 -0
  62. package/src/__tests__/Pagination.test.tsx +58 -0
  63. package/src/__tests__/Profile.test.tsx +48 -0
  64. package/src/__tests__/ReadMore.test.tsx +43 -0
  65. package/src/__tests__/RichText.test.tsx +16 -0
  66. package/src/__tests__/SearchField.test.tsx +35 -0
  67. package/src/__tests__/TableOfContents.test.tsx +12 -0
  68. package/src/__tests__/Tag.test.tsx +10 -0
  69. package/src/components/Cards/CardGroup/CardGroup.args.ts +205 -166
  70. package/src/components/Cards/TextCard/TextCard.tsx +1 -1
  71. package/src/components/List/List.props.ts +2 -10
  72. package/src/components/List/List.tsx +17 -22
  73. package/src/components/List/ListItem.props.ts +0 -7
  74. package/src/components/List/ListItem.tsx +6 -11
  75. package/src/setup.ts +6 -0
  76. package/src/stories/Accordion/Accordion.stories.tsx +145 -0
  77. package/src/stories/Breadcrumb/Breadcrumb.mdx +17 -0
  78. package/src/stories/Breadcrumb/Breadcrumb.stories.tsx +20 -0
  79. package/src/stories/Button/Button.mdx +94 -0
  80. package/src/stories/Button/Button.stories.tsx +68 -0
  81. package/src/stories/Callout/Callout.mdx +35 -0
  82. package/src/stories/Callout/Callout.stories.tsx +43 -0
  83. package/src/stories/Card/DataCard.stories.tsx +45 -0
  84. package/src/stories/Card/DetailCard.stories.tsx +41 -0
  85. package/src/stories/Card/FactlistCard.stories.tsx +48 -0
  86. package/src/stories/Card/FeatureCard.stories.tsx +56 -0
  87. package/src/stories/Card/MultilinkCard.stories.tsx +48 -0
  88. package/src/stories/Card/PromoCard.stories.tsx +48 -0
  89. package/src/stories/Card/StatCard.stories.tsx +45 -0
  90. package/src/stories/Card/TextCard.stories.tsx +45 -0
  91. package/src/stories/CardGroup/CardGroup.mdx +17 -0
  92. package/src/stories/CardGroup/CardGroup.stories.tsx +50 -0
  93. package/src/stories/Checkbox/Checkbox.stories.tsx +118 -0
  94. package/src/stories/ContextMenu/ContextMenu.stories.tsx +83 -0
  95. package/src/stories/DatePicker/DatePicker.stories.tsx +110 -0
  96. package/src/stories/Dropdown/Dropdown.stories.tsx +145 -0
  97. package/src/stories/Empty/Empty.stories.tsx +53 -0
  98. package/src/stories/Fieldset/Fieldset.stories.tsx +167 -0
  99. package/src/stories/FileUpload/FileUpload.stories.tsx +103 -0
  100. package/src/stories/Footer/Footer.mdx +17 -0
  101. package/src/stories/Footer/Footer.stories.tsx +15 -0
  102. package/src/stories/Form/Form.mdx +58 -0
  103. package/src/stories/Form/Form.stories.tsx +162 -0
  104. package/src/stories/GetStarted.mdx +57 -0
  105. package/src/stories/Heading/Heading.stories.tsx +193 -0
  106. package/src/stories/Hero/Hero.stories.tsx +68 -0
  107. package/src/stories/Image/Image.stories.tsx +50 -0
  108. package/src/stories/Link/Link.stories.tsx +81 -0
  109. package/src/stories/LinkList/LinkList.args.ts +190 -0
  110. package/src/stories/LinkList/LinkList.stories.tsx +60 -0
  111. package/src/stories/List/List.stories.tsx +167 -0
  112. package/src/stories/Loading/Loading.stories.tsx +97 -0
  113. package/src/stories/LocalNav/LocalNav.mdx +17 -0
  114. package/src/stories/LocalNav/LocalNav.stories.tsx +15 -0
  115. package/src/stories/Logo/Logo.stories.tsx +172 -0
  116. package/src/stories/LogoGrid/LogoGrid.stories.tsx +59 -0
  117. package/src/stories/Navigation/Navigation.mdx +17 -0
  118. package/src/stories/Navigation/Navigation.stories.tsx +15 -0
  119. package/src/stories/Notification/Notification.stories.tsx +187 -0
  120. package/src/stories/NumberPicker/NumberPicker.stories.tsx +69 -0
  121. package/src/stories/Pagination/Pagination.stories.tsx +86 -0
  122. package/src/stories/Profile/Profile.stories.tsx +64 -0
  123. package/src/stories/Radio/Radio.stories.tsx +232 -0
  124. package/src/stories/ReadMore/ReadMore.stories.tsx +59 -0
  125. package/src/stories/RichText/RichText.stories.tsx +63 -0
  126. package/src/stories/SearchField/SearchField.stories.tsx +91 -0
  127. package/src/stories/SocialMedia/SocialMedia.stories.tsx +60 -0
  128. package/src/stories/TableOfContents/TableOfContents.stories.tsx +55 -0
  129. package/src/stories/Tabs/Tabs.mdx +17 -0
  130. package/src/stories/Tabs/Tabs.stories.tsx +25 -0
  131. package/src/stories/Tag/Tag.stories.tsx +130 -0
  132. package/src/stories/TextInput/TextInput.stories.tsx +100 -0
  133. package/src/stories/Textarea/Textarea.stories.tsx +147 -0
  134. package/src/stories/Toggle/Toggle.stories.tsx +99 -0
  135. package/src/stories/Tooltip/Tooltip.stories.tsx +82 -0
  136. package/src/stories/Video/Video.stories.tsx +71 -0
  137. package/src/stories/Welcome.stories.mdx +37 -0
  138. package/src/stories/assets/code-brackets.svg +1 -0
  139. package/src/stories/assets/colors.svg +1 -0
  140. package/src/stories/assets/comments.svg +1 -0
  141. package/src/stories/assets/direction.svg +1 -0
  142. package/src/stories/assets/flow.svg +1 -0
  143. package/src/stories/assets/plugin.svg +1 -0
  144. package/src/stories/assets/repo.svg +1 -0
  145. package/src/stories/assets/stackalt.svg +1 -0
  146. package/src/stories/welcome.scss +133 -0
  147. package/src/types/index.ts +0 -2
  148. package/lib/cjs/ListCtx-14aa546f.js +0 -9
  149. package/lib/esm/ListCtx-da435fdf.js +0 -6
  150. package/lib/types/react/src/components/List/ListCtx.d.ts +0 -4
  151. package/src/components/List/ListCtx.ts +0 -7
@@ -0,0 +1,16 @@
1
+ import { render, screen, fireEvent } from "@testing-library/react";
2
+ import { composeStories } from "@storybook/react";
3
+ import * as stories from "../stories/Accordion/Accordion.stories";
4
+
5
+ const { Default: AccordionLarge } = composeStories(stories);
6
+
7
+ describe("<Accordion>", () => {
8
+ it("Expect button to exist and aria expanded value to change on accordion button click.", () => {
9
+ render(<AccordionLarge />);
10
+ const buttonElement = screen.getAllByRole("button");
11
+ expect(buttonElement).not.toBeNull();
12
+ expect(buttonElement[0].getAttribute("aria-expanded")).toBe("true");
13
+ fireEvent.click(buttonElement[0]);
14
+ expect(buttonElement[0].getAttribute("aria-expanded")).toBe("false");
15
+ });
16
+ });
@@ -0,0 +1,60 @@
1
+ import { fireEvent, render, screen } from "@testing-library/react";
2
+ import { Button } from "../components/Button";
3
+ import buttonArgs from "../components/Button/Button.args";
4
+
5
+ describe("<Button>", () => {
6
+ it("Should render `button` with correct class name from type prop", () => {
7
+ render(<Button {...buttonArgs.primary} />);
8
+ const buttonElement = screen.getAllByRole("button");
9
+ expect(buttonElement).not.toBeNull();
10
+ expect(buttonElement[0].getAttribute("class")).toEqual(
11
+ expect.stringContaining(buttonArgs.primary.type as string)
12
+ );
13
+ });
14
+
15
+ it("Should render `button` with correct size class name from prop size", () => {
16
+ render(<Button {...buttonArgs.primary} />);
17
+ const buttonElement = screen.getAllByRole("button");
18
+ expect(buttonElement).not.toBeNull();
19
+ expect(buttonElement[0].getAttribute("class")).toContain(
20
+ buttonArgs.primary.size
21
+ );
22
+ });
23
+
24
+ it("Should render `button` with correct label from prop label", () => {
25
+ render(<Button {...buttonArgs.primary} />);
26
+ const buttonElement = screen.getAllByRole("button");
27
+ expect(buttonElement).not.toBeNull();
28
+ expect(buttonElement[0].textContent).toEqual(buttonArgs.primary.label);
29
+ });
30
+
31
+ it("Should render `button` as anchor, with the correct url", () => {
32
+ render(<Button {...buttonArgs.link} />);
33
+ const buttonElement = screen.getAllByRole("link");
34
+ expect(buttonElement).not.toBeNull();
35
+ expect(buttonElement[0]).toHaveAttribute("href", buttonArgs.link.url);
36
+ });
37
+
38
+ it("Should render `button` with disabled attribute", () => {
39
+ render(<Button {...buttonArgs.disabled} />);
40
+ const buttonElement = screen.getAllByRole("button");
41
+ expect(buttonElement).not.toBeNull();
42
+ expect(buttonElement[0]).toHaveAttribute("disabled", "");
43
+ });
44
+
45
+ it("Should render `button` as anchor with target attribute and rel attribute", () => {
46
+ render(<Button {...buttonArgs.link} />);
47
+ const buttonElement = screen.getAllByRole("link");
48
+ expect(buttonElement).not.toBeNull();
49
+ expect(buttonElement[0]).toHaveAttribute("target", buttonArgs.link.target);
50
+ expect(buttonElement[0]).toHaveAttribute("rel", "noopener noreferrer");
51
+ });
52
+
53
+ it('calls "callback" prop on button click', () => {
54
+ const onClick = jest.fn();
55
+ render(<Button {...buttonArgs.primary} callback={onClick} />);
56
+ const buttonElement = screen.getAllByRole("button");
57
+ fireEvent.click(buttonElement[0]);
58
+ expect(onClick).toHaveBeenCalled();
59
+ });
60
+ });
@@ -0,0 +1,43 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import userEvent from "@testing-library/user-event";
3
+ import { Callout } from "../components/Callout";
4
+ import calloutArgs from "../components/Callout/Callout.args";
5
+
6
+ // const { InfoCallout, ErrorCallout, SuccessCallout, WarningCallout } =
7
+ // composeStories(stories);
8
+
9
+ describe("<Callout>", () => {
10
+ it("Should render Callout headline with content.", () => {
11
+ const { container } = render(<Callout {...calloutArgs.baseArgs} />);
12
+ expect(container.children[0]).not.toBeNull();
13
+ const headlineElement = document.querySelector('[class*="--headline"]');
14
+ console.log(headlineElement);
15
+ expect(headlineElement?.textContent).toEqual(
16
+ calloutArgs.baseArgs.headline as string
17
+ );
18
+ });
19
+
20
+ it("Should render Callout copy with content.", () => {
21
+ const { container } = render(<Callout {...calloutArgs.baseArgs} />);
22
+ expect(container.children[0]).not.toBeNull();
23
+ const copyElement = document.querySelector('[class*="--copy"]');
24
+ expect(copyElement?.textContent).toEqual(calloutArgs.baseArgs.copy);
25
+ });
26
+
27
+ it("Should render `button` with correct label from prop toggleClosedLabel", () => {
28
+ render(<Callout {...calloutArgs.error} />);
29
+ const buttonElement = screen.getAllByRole("button");
30
+ expect(buttonElement).not.toBeNull();
31
+ expect(buttonElement[0].textContent).toEqual(
32
+ calloutArgs.error.toggleClosedLabel
33
+ );
34
+ });
35
+
36
+ it("Should open the callout on button click", () => {
37
+ const { container } = render(<Callout {...calloutArgs.error} />);
38
+ expect(container.children[0]).not.toBeNull();
39
+ userEvent.click(screen.getByRole("button"));
40
+ const calloutOpenElement = document.querySelector('[class*="--open"]');
41
+ expect(calloutOpenElement).not.toBeNull();
42
+ });
43
+ });
@@ -0,0 +1,19 @@
1
+ import { render } from "@testing-library/react";
2
+ import { ContextMenu } from "../components/ContextMenu";
3
+ import contextMenuArgs from "../components/ContextMenu/ContextMenu.args";
4
+
5
+ describe("<ContextMenu>", () => {
6
+ it("Should render `ul` with some items.", () => {
7
+ const { container } = render(<ContextMenu {...contextMenuArgs.basic} />);
8
+ expect(container).not.toBeNull();
9
+ });
10
+
11
+ it("Should render `ul` with `li`s with the `endsection` prop containing the class `endsection`", () => {
12
+ const { container } = render(
13
+ <ContextMenu {...contextMenuArgs.withsection} />
14
+ );
15
+ expect(container).not.toBeNull();
16
+ const endsectionElement = document.querySelector(".endsection");
17
+ expect(endsectionElement).not.toBeNull();
18
+ });
19
+ });
@@ -0,0 +1,38 @@
1
+ import { fireEvent, render, screen } from "@testing-library/react";
2
+ import { Dropdown } from "../components/Dropdown";
3
+ import dropdownArgs from "../components/Dropdown/Dropdown.args";
4
+
5
+ describe("<Dropdown>", () => {
6
+ it("Should render `Dropdown` with correct label from prop label", () => {
7
+ const { container } = render(<Dropdown {...dropdownArgs.basic} />);
8
+ expect(container.children[0]).not.toBeNull();
9
+ expect(container.querySelector("label")?.textContent).toEqual(
10
+ dropdownArgs.basic.label
11
+ );
12
+ });
13
+
14
+ it("should display the correct number of options", () => {
15
+ render(<Dropdown {...dropdownArgs.basic} />);
16
+ expect(screen.getAllByRole("option").length).toBe(
17
+ dropdownArgs?.basic?.options?.length
18
+ );
19
+ });
20
+
21
+ it("selects the correct option", () => {
22
+ render(<Dropdown {...dropdownArgs.basic} />);
23
+ fireEvent.change(screen.getByLabelText("Select a country" as string), {
24
+ target: { value: "CH" },
25
+ });
26
+ const chosenoption = document.querySelector('option[value="CH"]');
27
+ expect((chosenoption as HTMLOptionElement).selected).toBeTruthy();
28
+ });
29
+
30
+ it('calls "onChange" prop on button click', () => {
31
+ const handleChange = jest.fn();
32
+ render(<Dropdown {...dropdownArgs.basic} onChange={handleChange} />);
33
+ fireEvent.change(screen.getByLabelText("Select a country" as string), {
34
+ target: { value: "CH" },
35
+ });
36
+ expect(handleChange).toHaveBeenCalled();
37
+ });
38
+ });
@@ -0,0 +1,51 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import { composeStories } from "@storybook/react";
3
+ import headingArgs from "../components/Heading/Heading.args";
4
+ import * as stories from "../stories/Heading/Heading.stories";
5
+
6
+ const { Heading1, Heading2, Heading3, Heading4, Heading5, Heading6 } =
7
+ composeStories(stories);
8
+
9
+ describe("<Heading>", () => {
10
+ it("Should render `h1` with story text.", () => {
11
+ render(<Heading1 />);
12
+ const headingElement = screen.getByRole("heading", { level: 1 });
13
+ expect(headingElement).not.toBeNull();
14
+ expect(headingElement.textContent).toEqual(headingArgs.heading1.children);
15
+ });
16
+
17
+ it("Should render `h2` with story text.", () => {
18
+ render(<Heading2 />);
19
+ const headingElement = screen.getByRole("heading", { level: 2 });
20
+ expect(headingElement).not.toBeNull();
21
+ expect(headingElement.textContent).toEqual(headingArgs.heading2.children);
22
+ });
23
+
24
+ it("Should render `h3` with story text.", () => {
25
+ render(<Heading3 />);
26
+ const headingElement = screen.getByRole("heading", { level: 3 });
27
+ expect(headingElement).not.toBeNull();
28
+ expect(headingElement.textContent).toEqual(headingArgs.heading3.children);
29
+ });
30
+
31
+ it("Should render `h4` with story text.", () => {
32
+ render(<Heading4 />);
33
+ const headingElement = screen.getByRole("heading", { level: 4 });
34
+ expect(headingElement).not.toBeNull();
35
+ expect(headingElement.textContent).toEqual(headingArgs.heading4.children);
36
+ });
37
+
38
+ it("Should render `h5` with story text.", () => {
39
+ render(<Heading5 />);
40
+ const headingElement = screen.getByRole("heading", { level: 5 });
41
+ expect(headingElement).not.toBeNull();
42
+ expect(headingElement.textContent).toEqual(headingArgs.heading5.children);
43
+ });
44
+
45
+ it("Should render `h6` with story text.", () => {
46
+ render(<Heading6 />);
47
+ const headingElement = screen.getByRole("heading", { level: 6 });
48
+ expect(headingElement).not.toBeNull();
49
+ expect(headingElement.textContent).toEqual(headingArgs.heading6.children);
50
+ });
51
+ });
@@ -0,0 +1,21 @@
1
+ import { render } from "@testing-library/react";
2
+ import { Image } from "../components/Image";
3
+ import imageArgs from "../components/Image/Image.args";
4
+
5
+ describe("<Image>", () => {
6
+ it("Should render `img` with correct image src", () => {
7
+ const { container } = render(<Image {...imageArgs} />);
8
+ expect(container).not.toBeNull();
9
+ expect(container.querySelector("img")?.getAttribute("src")).toEqual(
10
+ imageArgs.url?.[0].src
11
+ );
12
+ });
13
+
14
+ it("Should render `img` with correct image alt", () => {
15
+ const { container } = render(<Image {...imageArgs} />);
16
+ expect(container).not.toBeNull();
17
+ expect(container.querySelector("img")?.getAttribute("alt")).toEqual(
18
+ imageArgs.alt
19
+ );
20
+ });
21
+ });
@@ -0,0 +1,17 @@
1
+ import { render } from "@testing-library/react";
2
+ import { LinkList } from "../components/LinkList";
3
+ import linkListArgs from "../components/LinkList/LinkList.args";
4
+
5
+ describe("<LinkList>", () => {
6
+ it("Should render `ul` with some items.", () => {
7
+ const { container } = render(<LinkList {...linkListArgs.basic} />);
8
+ expect(container).not.toBeNull();
9
+ });
10
+
11
+ it("Should render `ul` with `li`s with the `indented` prop containing the class `indented`", () => {
12
+ const { container } = render(<LinkList {...linkListArgs.withindented} />);
13
+ expect(container).not.toBeNull();
14
+ const indentedElement = document.querySelectorAll(".indented");
15
+ expect(indentedElement).not.toEqual([]);
16
+ });
17
+ });
@@ -0,0 +1,25 @@
1
+ import { render } from "@testing-library/react";
2
+ import { List } from "../components/List";
3
+ import listArgs from "../components/List/List.args";
4
+
5
+ describe("<List>", () => {
6
+ it("Should render `ol` with some items.", () => {
7
+ const { container } = render(<List {...listArgs.ordered} />);
8
+ expect(container).not.toBeNull();
9
+ });
10
+
11
+ it("Should render `ul` with some items.", () => {
12
+ const { container } = render(<List {...listArgs.unordered} />);
13
+ expect(container).not.toBeNull();
14
+ });
15
+
16
+ it("Should render `ul` horizontally with some items.", () => {
17
+ const { container } = render(<List {...listArgs.horizontal} />);
18
+ expect(container).not.toBeNull();
19
+ });
20
+
21
+ it("Should render `ul` unstyled with some items.", () => {
22
+ const { container } = render(<List {...listArgs.unstyled} />);
23
+ expect(container).not.toBeNull();
24
+ });
25
+ });
@@ -0,0 +1,33 @@
1
+ import { render } from "@testing-library/react";
2
+ import { Loading } from "../components/Loading";
3
+ import loadingArgs from "../components/Loading/Loading.args";
4
+
5
+ describe("<Loading>", () => {
6
+ it("Should render `Loading` with correct label from prop label", () => {
7
+ const { container } = render(<Loading {...loadingArgs.loadinglarge} />);
8
+ expect(container.children[0]).not.toBeNull();
9
+ const paragraphElement = document.querySelector(
10
+ 'p[class*="--copy"]'
11
+ ) as Element;
12
+ expect(paragraphElement).not.toBeNull();
13
+ expect(paragraphElement.textContent).toEqual(
14
+ loadingArgs.loadinglarge.message
15
+ );
16
+ });
17
+
18
+ it("Should render `Loading` with correct class derived from prop status", () => {
19
+ const { container } = render(<Loading {...loadingArgs.loadinglarge} />);
20
+ expect(container.children[0]).not.toBeNull();
21
+ expect(container.children[0].getAttribute("class")).toContain(
22
+ loadingArgs.loadinglarge.status
23
+ );
24
+ });
25
+
26
+ it("Should render `Loading` with correct class derived from prop size", () => {
27
+ const { container } = render(<Loading {...loadingArgs.loadinglarge} />);
28
+ expect(container.children[0]).not.toBeNull();
29
+ expect(container.children[0].getAttribute("class")).toContain(
30
+ loadingArgs.loadinglarge.size
31
+ );
32
+ });
33
+ });
@@ -0,0 +1,39 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import userEvent from "@testing-library/user-event";
3
+ import { Notification } from "../components/Notification";
4
+ import notificationArgs from "../components/Notification/Notification.args";
5
+
6
+ describe("<Notification>", () => {
7
+ it("Should render Notification headline with content.", () => {
8
+ const { container } = render(<Notification {...notificationArgs.hascta} />);
9
+ expect(container.children[0]).not.toBeNull();
10
+ const headlineElement = document.querySelector('[class*="--headline"]');
11
+ console.log(headlineElement);
12
+ expect(headlineElement?.textContent).toEqual(
13
+ notificationArgs?.hascta?.headline
14
+ );
15
+ });
16
+
17
+ it("Should render Notification copy with content.", () => {
18
+ const { container } = render(<Notification {...notificationArgs.hascta} />);
19
+ expect(container.children[0]).not.toBeNull();
20
+ const copyElement = document.querySelector('[class*="--copy"]');
21
+ expect(copyElement?.textContent).toEqual(notificationArgs?.hascta?.copy);
22
+ });
23
+
24
+ it("Should render `button` with correct label from prop closelabel", () => {
25
+ render(<Notification {...notificationArgs.hascta} />);
26
+ const buttonElement = screen.getAllByRole("button");
27
+ expect(buttonElement).not.toBeNull();
28
+ expect(buttonElement[0].textContent).toEqual(
29
+ notificationArgs?.hascta?.closelabel
30
+ );
31
+ });
32
+
33
+ it("Should delete the component on click of the button", () => {
34
+ const { container } = render(<Notification {...notificationArgs.hascta} />);
35
+ expect(container.children[0]).not.toBeNull();
36
+ userEvent.click(screen.getByRole("button"));
37
+ expect(container.children[0]).toBeUndefined();
38
+ });
39
+ });
@@ -0,0 +1,58 @@
1
+ import { render } from "@testing-library/react";
2
+ import { Pagination } from "../components/Pagination";
3
+ import paginationArgs from "../components/Pagination/Pagination.args";
4
+
5
+ describe("<Pagination>", () => {
6
+ it("Pagination link should render with a disable class", () => {
7
+ const { container } = render(
8
+ <Pagination {...paginationArgs.firstDisabled} />
9
+ );
10
+ expect(container.children[0]).not.toBeNull();
11
+ const previousPagination = document.querySelector('a[class*="--disable"]');
12
+ expect(previousPagination).not.toBeNull();
13
+ });
14
+
15
+ it("First link should match the args", () => {
16
+ render(<Pagination {...paginationArgs.firstDisabled} />);
17
+ const pagination = document.querySelector('a[class*="--first-page"]');
18
+ expect(pagination).not.toBeNull();
19
+ expect(pagination?.getAttribute("href")).toEqual(
20
+ expect.stringContaining(
21
+ paginationArgs.firstDisabled.firstPageUrl as string
22
+ )
23
+ );
24
+ });
25
+
26
+ it("Previous link should match the args", () => {
27
+ render(<Pagination {...paginationArgs.firstDisabled} />);
28
+ const pagination = document.querySelector('a[class*="--prev-page"]');
29
+ expect(pagination).not.toBeNull();
30
+ expect(pagination?.getAttribute("href")).toEqual(
31
+ expect.stringContaining(
32
+ paginationArgs.firstDisabled.prevPageUrl as string
33
+ )
34
+ );
35
+ });
36
+
37
+ it("Next link should match the args", () => {
38
+ render(<Pagination {...paginationArgs.firstDisabled} />);
39
+ const pagination = document.querySelector('a[class*="--next-page"]');
40
+ expect(pagination).not.toBeNull();
41
+ expect(pagination?.getAttribute("href")).toEqual(
42
+ expect.stringContaining(
43
+ paginationArgs.firstDisabled.nextPageUrl as string
44
+ )
45
+ );
46
+ });
47
+
48
+ it("Last link should match the args", () => {
49
+ render(<Pagination {...paginationArgs.firstDisabled} />);
50
+ const pagination = document.querySelector('a[class*="--last-page"]');
51
+ expect(pagination).not.toBeNull();
52
+ expect(pagination?.getAttribute("href")).toEqual(
53
+ expect.stringContaining(
54
+ paginationArgs.firstDisabled.lastPageUrl as string
55
+ )
56
+ );
57
+ });
58
+ });
@@ -0,0 +1,48 @@
1
+ import { render } from "@testing-library/react";
2
+ import { Profile } from "../components/Profile";
3
+ import profileArgs from "../components/Profile/Profile.args";
4
+
5
+ describe("<Profile>", () => {
6
+ it("Should render Profile with content from name prop.", () => {
7
+ const { container } = render(<Profile {...profileArgs.basic} />);
8
+ expect(container.children[0]).not.toBeNull();
9
+ const nameElement = document.querySelector('[class*="--name"]');
10
+ expect(nameElement?.textContent).toEqual(profileArgs?.basic?.name);
11
+ });
12
+
13
+ it("Should render Profile with content from avatar prop.", () => {
14
+ const { container } = render(<Profile {...profileArgs.basic} />);
15
+ expect(container.children[0]).not.toBeNull();
16
+ const imgElement = document.querySelector('[class*="--avatar"]');
17
+ expect(imgElement).toHaveAttribute("src", profileArgs?.basic?.avatar);
18
+ });
19
+
20
+ it("Should render Profile with content from role prop.", () => {
21
+ const { container } = render(<Profile {...profileArgs.hasrole} />);
22
+ expect(container.children[0]).not.toBeNull();
23
+ const roleElement = document.querySelector('[class*="--role"]');
24
+ expect(roleElement?.textContent).toEqual(profileArgs?.hasrole?.role);
25
+ });
26
+
27
+ it("Should render Profile with content from description prop.", () => {
28
+ const { container } = render(<Profile {...profileArgs.hasdescription} />);
29
+ expect(container.children[0]).not.toBeNull();
30
+ const descriptionElement = document.querySelector(
31
+ '[class*="--description"]'
32
+ );
33
+ expect(descriptionElement?.textContent).toEqual(
34
+ profileArgs?.hasdescription?.description
35
+ );
36
+ });
37
+
38
+ it("Should render Profile with content from link prop.", () => {
39
+ const { container } = render(<Profile {...profileArgs.haslink} />);
40
+ expect(container.children[0]).not.toBeNull();
41
+ const linkElement = document.querySelector('[class*="--link"] a');
42
+ expect(linkElement?.textContent).toEqual(profileArgs?.haslink?.link?.label);
43
+ expect(linkElement).toHaveAttribute(
44
+ "href",
45
+ profileArgs?.haslink?.link?.url
46
+ );
47
+ });
48
+ });
@@ -0,0 +1,43 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import userEvent from "@testing-library/user-event";
3
+ import { ReadMore } from "../components/ReadMore";
4
+ import readMoreArgs from "../components/ReadMore/ReadMore.args";
5
+
6
+ describe("<ReadMore>", () => {
7
+ it("Should render RichText `div` with content.", () => {
8
+ const { container } = render(<ReadMore {...readMoreArgs.base} />);
9
+ expect(container.children[0]).not.toBeNull();
10
+ const richTextElement = document.querySelector('div[class*="--richtext"]');
11
+ const excerpt = new DOMParser().parseFromString(
12
+ readMoreArgs.base.excerpt,
13
+ "text/html"
14
+ ).documentElement.textContent;
15
+ expect(richTextElement?.textContent).toEqual(excerpt);
16
+ });
17
+
18
+ it("Should render `button` with correct label from prop buttonlabel", () => {
19
+ render(<ReadMore {...readMoreArgs.base} />);
20
+ const buttonElement = screen.getAllByRole("button");
21
+ expect(buttonElement).not.toBeNull();
22
+ expect(buttonElement[0].textContent).toEqual(
23
+ readMoreArgs?.base?.buttonlabel?.closed
24
+ );
25
+ });
26
+
27
+ it("Should change contents of RichText `div` with new content.", () => {
28
+ render(<ReadMore {...readMoreArgs.base} />);
29
+ const richTextElement = document.querySelector(
30
+ 'div[class*="--richtext"]'
31
+ ) as Element;
32
+ const fulltext = new DOMParser().parseFromString(
33
+ readMoreArgs.open.fulltext,
34
+ "text/html"
35
+ ).documentElement.textContent;
36
+ userEvent.click(
37
+ screen.getByText(readMoreArgs?.base?.buttonlabel?.closed as string, {
38
+ selector: "button",
39
+ })
40
+ );
41
+ expect(richTextElement.textContent).toEqual(fulltext);
42
+ });
43
+ });
@@ -0,0 +1,16 @@
1
+ import { render } from "@testing-library/react";
2
+ import { RichText } from "../components/RichText";
3
+ import richTextArgs from "../components/RichText/richText.args";
4
+
5
+ describe("<RichText>", () => {
6
+ it("Should render `div` with content.", () => {
7
+ const { container } = render(<RichText {...richTextArgs.richtext} />);
8
+ // Parse the content as a domstring and get the text content
9
+ const textContent = new DOMParser().parseFromString(
10
+ richTextArgs.richtext.content,
11
+ "text/html"
12
+ ).documentElement.textContent;
13
+ expect(container.children[0]).not.toBeNull();
14
+ expect(container.children[0].textContent).toEqual(textContent);
15
+ });
16
+ });
@@ -0,0 +1,35 @@
1
+ import { fireEvent, render, screen } from "@testing-library/react";
2
+ import { SearchField } from "../components/SearchField";
3
+ import searchFieldArgs from "../components/SearchField/SearchField.args";
4
+
5
+ describe("<SearchField>", () => {
6
+ it("Should render `search field` with correct label from prop input.placeholder", () => {
7
+ const { container } = render(
8
+ <SearchField {...searchFieldArgs.searchfield} />
9
+ );
10
+ expect(container.children[0]).not.toBeNull();
11
+ const inputElement = screen.getByPlaceholderText(
12
+ searchFieldArgs.searchfield.input?.placeholder as string
13
+ );
14
+ expect(inputElement).not.toBeNull();
15
+ });
16
+
17
+ it("Should render `search field input` with disabled attribute", () => {
18
+ const { container } = render(
19
+ <SearchField {...searchFieldArgs.searchfielddisabled} />
20
+ );
21
+ expect(container.children[0]).not.toBeNull();
22
+ const inputElement = screen.getByPlaceholderText(
23
+ searchFieldArgs.searchfielddisabled.input?.placeholder as string
24
+ );
25
+ expect(inputElement).toHaveAttribute("disabled", "");
26
+ });
27
+
28
+ it('calls "callback" prop on button click', () => {
29
+ const onClick = jest.fn();
30
+ render(<SearchField {...searchFieldArgs.searchfield} callback={onClick} />);
31
+ const buttonElement = screen.getAllByRole("button");
32
+ fireEvent.click(buttonElement[0]);
33
+ expect(onClick).toHaveBeenCalled();
34
+ });
35
+ });
@@ -0,0 +1,12 @@
1
+ import { render } from "@testing-library/react";
2
+ import { TableOfContents } from "../components/TableOfContents";
3
+ import tableOfContentsArgs from "../components/TableOfContents/TableOfContents.args";
4
+
5
+ describe("<TableOfContents>", () => {
6
+ it("Should render `ul` with some items.", () => {
7
+ const { container } = render(
8
+ <TableOfContents {...tableOfContentsArgs.toc} />
9
+ );
10
+ expect(container).not.toBeNull();
11
+ });
12
+ });
@@ -0,0 +1,10 @@
1
+ import { render } from "@testing-library/react";
2
+ import { TagSet } from "../components/Tag";
3
+ import tagSetArgs from "../components/Tag/TagSet.args";
4
+
5
+ describe("<TagSet>", () => {
6
+ it("Should render `button` with correct class name from type prop", () => {
7
+ const { container } = render(<TagSet {...tagSetArgs.tag} />);
8
+ expect(container).not.toBeNull();
9
+ });
10
+ });