@mitodl/smoot-design 0.0.0-355a925
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.
- package/LICENSE +28 -0
- package/README.md +35 -0
- package/dist/bundles/remoteTutorDrawer.es.js +38364 -0
- package/dist/bundles/remoteTutorDrawer.umd.js +207 -0
- package/dist/cjs/ai.d.ts +3 -0
- package/dist/cjs/ai.js +9 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/FlashcardsScreen.d.ts +9 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/FlashcardsScreen.js +87 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.d.ts +56 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.js +276 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.d.ts +16 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.js +284 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.d.ts +1 -0
- package/dist/cjs/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.js +241 -0
- package/dist/cjs/bundles/remoteTutorDrawer.d.ts +7 -0
- package/dist/cjs/bundles/remoteTutorDrawer.js +40 -0
- package/dist/cjs/components/AiChat/AiChat.d.ts +5 -0
- package/dist/cjs/components/AiChat/AiChat.js +226 -0
- package/dist/cjs/components/AiChat/AiChat.stories.d.ts +21 -0
- package/dist/cjs/components/AiChat/AiChat.stories.js +243 -0
- package/dist/cjs/components/AiChat/AiChat.test.d.ts +1 -0
- package/dist/cjs/components/AiChat/AiChat.test.js +211 -0
- package/dist/cjs/components/AiChat/AiChatContext.d.ts +22 -0
- package/dist/cjs/components/AiChat/AiChatContext.js +105 -0
- package/dist/cjs/components/AiChat/AiChatContext.stories.d.ts +14 -0
- package/dist/cjs/components/AiChat/AiChatContext.stories.js +75 -0
- package/dist/cjs/components/AiChat/ChatTitle.d.ts +8 -0
- package/dist/cjs/components/AiChat/ChatTitle.js +43 -0
- package/dist/cjs/components/AiChat/EntryScreen.d.ts +11 -0
- package/dist/cjs/components/AiChat/EntryScreen.js +123 -0
- package/dist/cjs/components/AiChat/TimLogo.d.ts +5 -0
- package/dist/cjs/components/AiChat/TimLogo.js +15 -0
- package/dist/cjs/components/AiChat/test-utils/api.d.ts +2 -0
- package/dist/cjs/components/AiChat/test-utils/api.js +125 -0
- package/dist/cjs/components/AiChat/types.d.ts +86 -0
- package/dist/cjs/components/AiChat/types.js +3 -0
- package/dist/cjs/components/Alert/Alert.d.ts +15 -0
- package/dist/cjs/components/Alert/Alert.js +62 -0
- package/dist/cjs/components/Alert/Alert.stories.d.ts +8 -0
- package/dist/cjs/components/Alert/Alert.stories.js +53 -0
- package/dist/cjs/components/Button/ActionButton.d.ts +30 -0
- package/dist/cjs/components/Button/ActionButton.js +73 -0
- package/dist/cjs/components/Button/ActionButton.stories.d.ts +15 -0
- package/dist/cjs/components/Button/ActionButton.stories.js +113 -0
- package/dist/cjs/components/Button/Button.d.ts +54 -0
- package/dist/cjs/components/Button/Button.js +240 -0
- package/dist/cjs/components/Button/Button.stories.d.ts +17 -0
- package/dist/cjs/components/Button/Button.stories.js +135 -0
- package/dist/cjs/components/Button/Button.test.d.ts +1 -0
- package/dist/cjs/components/Button/Button.test.js +46 -0
- package/dist/cjs/components/ImageAdapter/ImageAdapter.d.ts +23 -0
- package/dist/cjs/components/ImageAdapter/ImageAdapter.js +30 -0
- package/dist/cjs/components/Input/Input.d.ts +116 -0
- package/dist/cjs/components/Input/Input.js +237 -0
- package/dist/cjs/components/Input/Input.stories.d.ts +19 -0
- package/dist/cjs/components/Input/Input.stories.js +135 -0
- package/dist/cjs/components/Input/Input.test.d.ts +1 -0
- package/dist/cjs/components/Input/Input.test.js +32 -0
- package/dist/cjs/components/LinkAdapter/LinkAdapter.d.ts +23 -0
- package/dist/cjs/components/LinkAdapter/LinkAdapter.js +34 -0
- package/dist/cjs/components/ScrollSnap/ScrollSnap.d.ts +19 -0
- package/dist/cjs/components/ScrollSnap/ScrollSnap.js +59 -0
- package/dist/cjs/components/ScrollSnap/ScrollSnap.stories.d.ts +6 -0
- package/dist/cjs/components/ScrollSnap/ScrollSnap.stories.js +43 -0
- package/dist/cjs/components/ScrollSnap/useScrollSnap.d.ts +6 -0
- package/dist/cjs/components/ScrollSnap/useScrollSnap.js +36 -0
- package/dist/cjs/components/SrAnnouncer/SrAnnouncer.d.ts +25 -0
- package/dist/cjs/components/SrAnnouncer/SrAnnouncer.js +43 -0
- package/dist/cjs/components/SrAnnouncer/SrAnnouncer.stories.d.ts +6 -0
- package/dist/cjs/components/SrAnnouncer/SrAnnouncer.stories.js +44 -0
- package/dist/cjs/components/SrAnnouncer/SrAnnouncer.test.d.ts +1 -0
- package/dist/cjs/components/SrAnnouncer/SrAnnouncer.test.js +62 -0
- package/dist/cjs/components/TabButtons/TabButtonList.d.ts +25 -0
- package/dist/cjs/components/TabButtons/TabButtonList.js +97 -0
- package/dist/cjs/components/TabButtons/TabButtonList.stories.d.ts +24 -0
- package/dist/cjs/components/TabButtons/TabButtonList.stories.js +139 -0
- package/dist/cjs/components/TextField/TextField.d.ts +29 -0
- package/dist/cjs/components/TextField/TextField.js +33 -0
- package/dist/cjs/components/TextField/TextField.stories.d.ts +10 -0
- package/dist/cjs/components/TextField/TextField.stories.js +136 -0
- package/dist/cjs/components/TextField/TextField.test.d.ts +1 -0
- package/dist/cjs/components/TextField/TextField.test.js +77 -0
- package/dist/cjs/components/ThemeProvider/ThemeProvider.d.ts +21 -0
- package/dist/cjs/components/ThemeProvider/ThemeProvider.js +86 -0
- package/dist/cjs/components/ThemeProvider/ThemeProvider.stories.d.ts +63 -0
- package/dist/cjs/components/ThemeProvider/ThemeProvider.stories.js +102 -0
- package/dist/cjs/components/ThemeProvider/Typography.stories.d.ts +39 -0
- package/dist/cjs/components/ThemeProvider/Typography.stories.js +65 -0
- package/dist/cjs/components/ThemeProvider/breakpoints.d.ts +4 -0
- package/dist/cjs/components/ThemeProvider/breakpoints.js +19 -0
- package/dist/cjs/components/ThemeProvider/buttons.d.ts +7 -0
- package/dist/cjs/components/ThemeProvider/buttons.js +20 -0
- package/dist/cjs/components/ThemeProvider/chips.d.ts +3 -0
- package/dist/cjs/components/ThemeProvider/chips.js +154 -0
- package/dist/cjs/components/ThemeProvider/colors.d.ts +32 -0
- package/dist/cjs/components/ThemeProvider/colors.js +35 -0
- package/dist/cjs/components/ThemeProvider/typography.d.ts +18 -0
- package/dist/cjs/components/ThemeProvider/typography.js +173 -0
- package/dist/cjs/components/VisuallyHidden/VisuallyHidden.d.ts +24 -0
- package/dist/cjs/components/VisuallyHidden/VisuallyHidden.js +33 -0
- package/dist/cjs/components/VisuallyHidden/VisuallyHidden.stories.d.ts +6 -0
- package/dist/cjs/components/VisuallyHidden/VisuallyHidden.stories.js +13 -0
- package/dist/cjs/components/internal/FormHelpers/FormHelpers.d.ts +39 -0
- package/dist/cjs/components/internal/FormHelpers/FormHelpers.js +78 -0
- package/dist/cjs/components/internal/FormHelpers/FormHelpers.test.d.ts +1 -0
- package/dist/cjs/components/internal/FormHelpers/FormHelpers.test.js +93 -0
- package/dist/cjs/index.d.ts +16 -0
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/jest-setup.d.ts +1 -0
- package/dist/cjs/jest-setup.js +18 -0
- package/dist/cjs/jsdom-extended.d.ts +6 -0
- package/dist/cjs/jsdom-extended.js +14 -0
- package/dist/cjs/story-utils/index.d.ts +6 -0
- package/dist/cjs/story-utils/index.js +17 -0
- package/dist/cjs/utils/composeRefs.d.ts +7 -0
- package/dist/cjs/utils/composeRefs.js +20 -0
- package/dist/cjs/utils/composeRefs.test.d.ts +1 -0
- package/dist/cjs/utils/composeRefs.test.js +19 -0
- package/dist/cjs/utils/useDevCheckStable.d.ts +8 -0
- package/dist/cjs/utils/useDevCheckStable.js +29 -0
- package/dist/cjs/utils/useInterval.d.ts +7 -0
- package/dist/cjs/utils/useInterval.js +25 -0
- package/dist/esm/ai.d.ts +3 -0
- package/dist/esm/ai.js +2 -0
- package/dist/esm/bundles/RemoteTutorDrawer/FlashcardsScreen.d.ts +9 -0
- package/dist/esm/bundles/RemoteTutorDrawer/FlashcardsScreen.js +83 -0
- package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.d.ts +56 -0
- package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.js +273 -0
- package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.d.ts +16 -0
- package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.stories.js +281 -0
- package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.d.ts +1 -0
- package/dist/esm/bundles/RemoteTutorDrawer/RemoteTutorDrawer.test.js +239 -0
- package/dist/esm/bundles/remoteTutorDrawer.d.ts +7 -0
- package/dist/esm/bundles/remoteTutorDrawer.js +37 -0
- package/dist/esm/components/AiChat/AiChat.d.ts +5 -0
- package/dist/esm/components/AiChat/AiChat.js +222 -0
- package/dist/esm/components/AiChat/AiChat.stories.d.ts +21 -0
- package/dist/esm/components/AiChat/AiChat.stories.js +240 -0
- package/dist/esm/components/AiChat/AiChat.test.d.ts +1 -0
- package/dist/esm/components/AiChat/AiChat.test.js +209 -0
- package/dist/esm/components/AiChat/AiChatContext.d.ts +22 -0
- package/dist/esm/components/AiChat/AiChatContext.js +101 -0
- package/dist/esm/components/AiChat/AiChatContext.stories.d.ts +14 -0
- package/dist/esm/components/AiChat/AiChatContext.stories.js +72 -0
- package/dist/esm/components/AiChat/ChatTitle.d.ts +8 -0
- package/dist/esm/components/AiChat/ChatTitle.js +40 -0
- package/dist/esm/components/AiChat/EntryScreen.d.ts +11 -0
- package/dist/esm/components/AiChat/EntryScreen.js +120 -0
- package/dist/esm/components/AiChat/TimLogo.d.ts +5 -0
- package/dist/esm/components/AiChat/TimLogo.js +13 -0
- package/dist/esm/components/AiChat/test-utils/api.d.ts +2 -0
- package/dist/esm/components/AiChat/test-utils/api.js +122 -0
- package/dist/esm/components/AiChat/types.d.ts +86 -0
- package/dist/esm/components/AiChat/types.js +2 -0
- package/dist/esm/components/Alert/Alert.d.ts +15 -0
- package/dist/esm/components/Alert/Alert.js +59 -0
- package/dist/esm/components/Alert/Alert.stories.d.ts +8 -0
- package/dist/esm/components/Alert/Alert.stories.js +50 -0
- package/dist/esm/components/Button/ActionButton.d.ts +30 -0
- package/dist/esm/components/Button/ActionButton.js +68 -0
- package/dist/esm/components/Button/ActionButton.stories.d.ts +15 -0
- package/dist/esm/components/Button/ActionButton.stories.js +110 -0
- package/dist/esm/components/Button/Button.d.ts +54 -0
- package/dist/esm/components/Button/Button.js +232 -0
- package/dist/esm/components/Button/Button.stories.d.ts +17 -0
- package/dist/esm/components/Button/Button.stories.js +132 -0
- package/dist/esm/components/Button/Button.test.d.ts +1 -0
- package/dist/esm/components/Button/Button.test.js +44 -0
- package/dist/esm/components/ImageAdapter/ImageAdapter.d.ts +23 -0
- package/dist/esm/components/ImageAdapter/ImageAdapter.js +27 -0
- package/dist/esm/components/Input/Input.d.ts +116 -0
- package/dist/esm/components/Input/Input.js +232 -0
- package/dist/esm/components/Input/Input.stories.d.ts +19 -0
- package/dist/esm/components/Input/Input.stories.js +132 -0
- package/dist/esm/components/Input/Input.test.d.ts +1 -0
- package/dist/esm/components/Input/Input.test.js +30 -0
- package/dist/esm/components/LinkAdapter/LinkAdapter.d.ts +23 -0
- package/dist/esm/components/LinkAdapter/LinkAdapter.js +31 -0
- package/dist/esm/components/ScrollSnap/ScrollSnap.d.ts +19 -0
- package/dist/esm/components/ScrollSnap/ScrollSnap.js +56 -0
- package/dist/esm/components/ScrollSnap/ScrollSnap.stories.d.ts +6 -0
- package/dist/esm/components/ScrollSnap/ScrollSnap.stories.js +40 -0
- package/dist/esm/components/ScrollSnap/useScrollSnap.d.ts +6 -0
- package/dist/esm/components/ScrollSnap/useScrollSnap.js +33 -0
- package/dist/esm/components/SrAnnouncer/SrAnnouncer.d.ts +25 -0
- package/dist/esm/components/SrAnnouncer/SrAnnouncer.js +40 -0
- package/dist/esm/components/SrAnnouncer/SrAnnouncer.stories.d.ts +6 -0
- package/dist/esm/components/SrAnnouncer/SrAnnouncer.stories.js +41 -0
- package/dist/esm/components/SrAnnouncer/SrAnnouncer.test.d.ts +1 -0
- package/dist/esm/components/SrAnnouncer/SrAnnouncer.test.js +60 -0
- package/dist/esm/components/TabButtons/TabButtonList.d.ts +25 -0
- package/dist/esm/components/TabButtons/TabButtonList.js +92 -0
- package/dist/esm/components/TabButtons/TabButtonList.stories.d.ts +24 -0
- package/dist/esm/components/TabButtons/TabButtonList.stories.js +136 -0
- package/dist/esm/components/TextField/TextField.d.ts +29 -0
- package/dist/esm/components/TextField/TextField.js +30 -0
- package/dist/esm/components/TextField/TextField.stories.d.ts +10 -0
- package/dist/esm/components/TextField/TextField.stories.js +133 -0
- package/dist/esm/components/TextField/TextField.test.d.ts +1 -0
- package/dist/esm/components/TextField/TextField.test.js +75 -0
- package/dist/esm/components/ThemeProvider/ThemeProvider.d.ts +21 -0
- package/dist/esm/components/ThemeProvider/ThemeProvider.js +82 -0
- package/dist/esm/components/ThemeProvider/ThemeProvider.stories.d.ts +63 -0
- package/dist/esm/components/ThemeProvider/ThemeProvider.stories.js +99 -0
- package/dist/esm/components/ThemeProvider/Typography.stories.d.ts +39 -0
- package/dist/esm/components/ThemeProvider/Typography.stories.js +62 -0
- package/dist/esm/components/ThemeProvider/breakpoints.d.ts +4 -0
- package/dist/esm/components/ThemeProvider/breakpoints.js +15 -0
- package/dist/esm/components/ThemeProvider/buttons.d.ts +7 -0
- package/dist/esm/components/ThemeProvider/buttons.js +17 -0
- package/dist/esm/components/ThemeProvider/chips.d.ts +3 -0
- package/dist/esm/components/ThemeProvider/chips.js +151 -0
- package/dist/esm/components/ThemeProvider/colors.d.ts +32 -0
- package/dist/esm/components/ThemeProvider/colors.js +32 -0
- package/dist/esm/components/ThemeProvider/typography.d.ts +18 -0
- package/dist/esm/components/ThemeProvider/typography.js +167 -0
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.d.ts +24 -0
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.js +30 -0
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.stories.d.ts +6 -0
- package/dist/esm/components/VisuallyHidden/VisuallyHidden.stories.js +10 -0
- package/dist/esm/components/internal/FormHelpers/FormHelpers.d.ts +39 -0
- package/dist/esm/components/internal/FormHelpers/FormHelpers.js +73 -0
- package/dist/esm/components/internal/FormHelpers/FormHelpers.test.d.ts +1 -0
- package/dist/esm/components/internal/FormHelpers/FormHelpers.test.js +91 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/jest-setup.d.ts +1 -0
- package/dist/esm/jest-setup.js +16 -0
- package/dist/esm/jsdom-extended.d.ts +6 -0
- package/dist/esm/jsdom-extended.js +12 -0
- package/dist/esm/story-utils/index.d.ts +6 -0
- package/dist/esm/story-utils/index.js +13 -0
- package/dist/esm/utils/composeRefs.d.ts +7 -0
- package/dist/esm/utils/composeRefs.js +17 -0
- package/dist/esm/utils/composeRefs.test.d.ts +1 -0
- package/dist/esm/utils/composeRefs.test.js +17 -0
- package/dist/esm/utils/useDevCheckStable.d.ts +8 -0
- package/dist/esm/utils/useDevCheckStable.js +26 -0
- package/dist/esm/utils/useInterval.d.ts +7 -0
- package/dist/esm/utils/useInterval.js +22 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/type-augmentation/TypescriptDocs.mdx +17 -0
- package/dist/type-augmentation/imports.d.ts +3 -0
- package/dist/type-augmentation/index.d.ts +3 -0
- package/dist/type-augmentation/theme.d.ts +105 -0
- package/dist/type-augmentation/typography.d.ts +54 -0
- package/package.json +155 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import * as React from "react";
|
|
13
|
+
import { render, screen } from "@testing-library/react";
|
|
14
|
+
import { FormFieldWrapper } from "./FormHelpers";
|
|
15
|
+
import { ThemeProvider } from "../../../components/ThemeProvider/ThemeProvider";
|
|
16
|
+
import { faker } from "@faker-js/faker/locale/en";
|
|
17
|
+
const assertDescription = ({ text, total, exists, }) => {
|
|
18
|
+
var _a;
|
|
19
|
+
const input = screen.getByRole("textbox");
|
|
20
|
+
const describedBy = input.getAttribute("aria-describedby");
|
|
21
|
+
const descriptionIds = (_a = describedBy === null || describedBy === void 0 ? void 0 : describedBy.split(" ")) !== null && _a !== void 0 ? _a : [];
|
|
22
|
+
if (total === 0) {
|
|
23
|
+
expect(describedBy).toBe(null);
|
|
24
|
+
}
|
|
25
|
+
expect(descriptionIds.length).toBe(total);
|
|
26
|
+
const description = screen.queryByText(text);
|
|
27
|
+
expect(!!description).toBe(exists);
|
|
28
|
+
if (exists) {
|
|
29
|
+
expect(description).toBeInTheDocument();
|
|
30
|
+
expect(descriptionIds).toContain(description === null || description === void 0 ? void 0 : description.id);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
describe("FormFieldWrapper", () => {
|
|
34
|
+
const setup = (props) => {
|
|
35
|
+
const defaults = {
|
|
36
|
+
name: "test-name",
|
|
37
|
+
value: "test-value",
|
|
38
|
+
label: "test-label",
|
|
39
|
+
};
|
|
40
|
+
const { rerender: _rerender } = render(React.createElement(FormFieldWrapper, Object.assign({}, defaults, props), (_a) => {
|
|
41
|
+
var { error, labelId, fullWidth } = _a, childProps = __rest(_a, ["error", "labelId", "fullWidth"]);
|
|
42
|
+
return (React.createElement("input", Object.assign({}, childProps)));
|
|
43
|
+
}), {
|
|
44
|
+
wrapper: ThemeProvider,
|
|
45
|
+
});
|
|
46
|
+
const rerender = (newProps) => {
|
|
47
|
+
_rerender(React.createElement(FormFieldWrapper, Object.assign({}, defaults, newProps), (_a) => {
|
|
48
|
+
var { error, labelId, fullWidth } = _a, childProps = __rest(_a, ["error", "labelId", "fullWidth"]);
|
|
49
|
+
return (React.createElement("input", Object.assign({}, childProps)));
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
return { rerender };
|
|
53
|
+
};
|
|
54
|
+
it("Labels the input", () => {
|
|
55
|
+
const label = faker.lorem.words();
|
|
56
|
+
setup({ label });
|
|
57
|
+
const input = screen.getByRole("textbox", { name: label });
|
|
58
|
+
expect(input).toBeInstanceOf(HTMLInputElement);
|
|
59
|
+
});
|
|
60
|
+
it("Has a description only if description provided", () => {
|
|
61
|
+
const label = faker.lorem.words();
|
|
62
|
+
const helpText = faker.lorem.words();
|
|
63
|
+
const { rerender } = setup({ label, helpText });
|
|
64
|
+
assertDescription({ text: helpText, total: 1, exists: true });
|
|
65
|
+
rerender({ label });
|
|
66
|
+
assertDescription({ text: helpText, total: 0, exists: false });
|
|
67
|
+
});
|
|
68
|
+
it("Has an error message only if errorText provided AND error=true", () => {
|
|
69
|
+
const label = faker.lorem.words();
|
|
70
|
+
const errorText = faker.lorem.words();
|
|
71
|
+
const { rerender } = setup({ label, errorText, error: true });
|
|
72
|
+
assertDescription({ text: errorText, total: 1, exists: true });
|
|
73
|
+
rerender({ label, errorText });
|
|
74
|
+
assertDescription({ text: errorText, total: 0, exists: false });
|
|
75
|
+
rerender({ label, error: true });
|
|
76
|
+
assertDescription({ text: errorText, total: 0, exists: false });
|
|
77
|
+
rerender({ label, errorText, error: true });
|
|
78
|
+
assertDescription({ text: errorText, total: 1, exists: true });
|
|
79
|
+
});
|
|
80
|
+
it("Shows both description and errormessage if both provided and error", () => {
|
|
81
|
+
const label = faker.lorem.words();
|
|
82
|
+
const errorText = faker.lorem.words();
|
|
83
|
+
const helpText = faker.lorem.words();
|
|
84
|
+
const { rerender } = setup({ label, errorText, helpText });
|
|
85
|
+
assertDescription({ text: helpText, total: 1, exists: true });
|
|
86
|
+
assertDescription({ text: errorText, total: 1, exists: false });
|
|
87
|
+
rerender({ label, errorText, helpText, error: true });
|
|
88
|
+
assertDescription({ text: helpText, total: 2, exists: true });
|
|
89
|
+
assertDescription({ text: errorText, total: 2, exists: true });
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { default as styled } from "@emotion/styled";
|
|
2
|
+
export { css, Global } from "@emotion/react";
|
|
3
|
+
export { ThemeProvider, createTheme, } from "./components/ThemeProvider/ThemeProvider";
|
|
4
|
+
export { Button, ButtonLink } from "./components/Button/Button";
|
|
5
|
+
export type { ButtonProps, ButtonLinkProps } from "./components/Button/Button";
|
|
6
|
+
export { ActionButton, ActionButtonLink, } from "./components/Button/ActionButton";
|
|
7
|
+
export type { ActionButtonProps, ActionButtonLinkProps, } from "./components/Button/ActionButton";
|
|
8
|
+
export type { LinkAdapterPropsOverrides } from "./components/LinkAdapter/LinkAdapter";
|
|
9
|
+
export { Input } from "./components/Input/Input";
|
|
10
|
+
export type { InputProps } from "./components/Input/Input";
|
|
11
|
+
export { TextField } from "./components/TextField/TextField";
|
|
12
|
+
export type { TextFieldProps } from "./components/TextField/TextField";
|
|
13
|
+
export { SrAnnouncer } from "./components/SrAnnouncer/SrAnnouncer";
|
|
14
|
+
export type { SrAnnouncerProps } from "./components/SrAnnouncer/SrAnnouncer";
|
|
15
|
+
export { TabButton, TabButtonLink, TabButtonList, } from "./components/TabButtons/TabButtonList";
|
|
16
|
+
export { VisuallyHidden } from "./components/VisuallyHidden/VisuallyHidden";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
export { default as styled } from "@emotion/styled";
|
|
3
|
+
export { css, Global } from "@emotion/react";
|
|
4
|
+
export { ThemeProvider, createTheme, } from "./components/ThemeProvider/ThemeProvider";
|
|
5
|
+
export { Button, ButtonLink } from "./components/Button/Button";
|
|
6
|
+
export { ActionButton, ActionButtonLink, } from "./components/Button/ActionButton";
|
|
7
|
+
export { Input } from "./components/Input/Input";
|
|
8
|
+
export { TextField } from "./components/TextField/TextField";
|
|
9
|
+
export { SrAnnouncer } from "./components/SrAnnouncer/SrAnnouncer";
|
|
10
|
+
export { TabButton, TabButtonLink, TabButtonList, } from "./components/TabButtons/TabButtonList";
|
|
11
|
+
export { VisuallyHidden } from "./components/VisuallyHidden/VisuallyHidden";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
3
|
+
const failOnConsole = require("jest-fail-on-console");
|
|
4
|
+
failOnConsole();
|
|
5
|
+
beforeAll(() => {
|
|
6
|
+
const scrollBy = jest.fn();
|
|
7
|
+
HTMLElement.prototype.scrollBy = scrollBy;
|
|
8
|
+
});
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
/**
|
|
11
|
+
* Clear all mock call counts between tests.
|
|
12
|
+
* This does NOT clear mock implementations.
|
|
13
|
+
* Mock implementations are always cleared between test files.
|
|
14
|
+
*/
|
|
15
|
+
jest.clearAllMocks();
|
|
16
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TestEnvironment } from "jest-environment-jsdom";
|
|
2
|
+
import { EnvironmentContext, JestEnvironmentConfig } from "@jest/environment";
|
|
3
|
+
declare class JSDOMEnvironmentExtended extends TestEnvironment {
|
|
4
|
+
constructor(config: JestEnvironmentConfig, context: EnvironmentContext);
|
|
5
|
+
}
|
|
6
|
+
export default JSDOMEnvironmentExtended;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Jest environment extended with Web APIs para tranbajar con MSW
|
|
2
|
+
import { TestEnvironment } from "jest-environment-jsdom";
|
|
3
|
+
class JSDOMEnvironmentExtended extends TestEnvironment {
|
|
4
|
+
constructor(config, context) {
|
|
5
|
+
super(config, context);
|
|
6
|
+
this.global.TransformStream = TransformStream;
|
|
7
|
+
this.global.ReadableStream = ReadableStream;
|
|
8
|
+
this.global.Response = Response;
|
|
9
|
+
this.global.TextDecoderStream = TextDecoderStream;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export default JSDOMEnvironmentExtended;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type helper just to make sure an array contains union values.
|
|
3
|
+
*/
|
|
4
|
+
declare const enumValues: <T extends string | undefined>(obj: Record<NonNullable<T>, unknown>) => NonNullable<T>[];
|
|
5
|
+
declare const gitLink: (filepath: string) => string;
|
|
6
|
+
export { enumValues, gitLink };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type helper just to make sure an array contains union values.
|
|
3
|
+
*/
|
|
4
|
+
const enumValues = (obj) => {
|
|
5
|
+
return Object.keys(obj);
|
|
6
|
+
};
|
|
7
|
+
const gitLink = (filepath) => {
|
|
8
|
+
if (!filepath.startsWith("src/")) {
|
|
9
|
+
throw new Error(`Invalid filepath: ${filepath}\nShould start with "src/"`);
|
|
10
|
+
}
|
|
11
|
+
return `https://github.com/mitodl/smoot-design/blob/${process.env.STORYBOOK_GIT_SHA}/${filepath}`;
|
|
12
|
+
};
|
|
13
|
+
export { enumValues, gitLink };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MutableRefObject, ForwardedRef, RefCallback } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Compose 2+ refs. Useful when a reusable component needs a ref itself, but
|
|
4
|
+
* consumers may also need the ref.
|
|
5
|
+
*/
|
|
6
|
+
declare const composeRefs: <T>(...refs: (ForwardedRef<T> | MutableRefObject<T | undefined> | RefCallback<T>)[]) => RefCallback<T>;
|
|
7
|
+
export { composeRefs };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compose 2+ refs. Useful when a reusable component needs a ref itself, but
|
|
3
|
+
* consumers may also need the ref.
|
|
4
|
+
*/
|
|
5
|
+
const composeRefs = (...refs) => {
|
|
6
|
+
return (value) => {
|
|
7
|
+
refs.forEach((ref) => {
|
|
8
|
+
if (typeof ref === "function") {
|
|
9
|
+
ref(value);
|
|
10
|
+
}
|
|
11
|
+
else if (ref) {
|
|
12
|
+
ref.current = value;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export { composeRefs };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { composeRefs } from "./composeRefs";
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
describe("composeRefs", () => {
|
|
5
|
+
test("Composing object + fn ref", () => {
|
|
6
|
+
const objRef1 = React.createRef();
|
|
7
|
+
const objRef2 = React.createRef();
|
|
8
|
+
const fnRef1 = jest.fn();
|
|
9
|
+
const fnRef2 = jest.fn();
|
|
10
|
+
render(React.createElement("div", { "data-testid": "my-div", ref: composeRefs(objRef1, objRef2, fnRef1, fnRef2) }));
|
|
11
|
+
const el = screen.getByTestId("my-div");
|
|
12
|
+
expect(objRef1.current).toBe(el);
|
|
13
|
+
expect(objRef2.current).toBe(el);
|
|
14
|
+
expect(fnRef1).toHaveBeenCalledWith(el);
|
|
15
|
+
expect(fnRef2).toHaveBeenCalledWith(el);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emits `console.error` if two subsequent values of `jsonSerializable` serialize
|
|
3
|
+
* to the same thing but are different references.
|
|
4
|
+
*
|
|
5
|
+
* This hook does NOT run in production.
|
|
6
|
+
*/
|
|
7
|
+
declare const useDevCheckStable: (jsonSerializable: unknown, msg?: string) => void;
|
|
8
|
+
export { useDevCheckStable };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Emits `console.error` if two subsequent values of `jsonSerializable` serialize
|
|
4
|
+
* to the same thing but are different references.
|
|
5
|
+
*
|
|
6
|
+
* This hook does NOT run in production.
|
|
7
|
+
*/
|
|
8
|
+
const useDevCheckStable = (jsonSerializable, msg = "The value has changed. This may cause unnecessary re-renders") => {
|
|
9
|
+
if (process.env.NODE_ENV !== "production") {
|
|
10
|
+
/**
|
|
11
|
+
* Calling hooks conditionally based on env vars is not really a problem.
|
|
12
|
+
* In a given environment, the hook will always run or always not run.
|
|
13
|
+
*/
|
|
14
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
15
|
+
const valRef = useRef(jsonSerializable);
|
|
16
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const sameJson = JSON.stringify(valRef.current) === JSON.stringify(jsonSerializable);
|
|
19
|
+
const differentRefs = valRef.current !== jsonSerializable;
|
|
20
|
+
if (!sameJson || differentRefs) {
|
|
21
|
+
console.error(`useDevCheckStable: ${msg}`, valRef.current, jsonSerializable);
|
|
22
|
+
}
|
|
23
|
+
}, [jsonSerializable, msg]);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export { useDevCheckStable };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useRef, useEffect } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Calls a function at a specified interval.
|
|
4
|
+
*
|
|
5
|
+
* Based on https://overreacted.io/making-setinterval-declarative-with-react-hooks/
|
|
6
|
+
*/
|
|
7
|
+
const useInterval = (callback, delay) => {
|
|
8
|
+
const savedCallback = useRef(null);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
savedCallback.current = callback;
|
|
11
|
+
}, [callback]);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (delay !== null) {
|
|
14
|
+
const id = setInterval(() => { var _a; return (_a = savedCallback.current) === null || _a === void 0 ? void 0 : _a.call(savedCallback); }, delay);
|
|
15
|
+
return () => clearInterval(id);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return () => { };
|
|
19
|
+
}
|
|
20
|
+
}, [delay]);
|
|
21
|
+
};
|
|
22
|
+
export { useInterval };
|