@hubspot/ui-extensions 0.11.2 → 0.11.4
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/dist/__tests__/crm/hooks/useAssociations.spec.js +4 -4
- package/dist/__tests__/crm/hooks/useCrmProperties.spec.js +2 -2
- package/dist/__tests__/crm/utils/fetchAssociations.spec.js +5 -5
- package/dist/__tests__/crm/utils/fetchCrmProperties.spec.js +4 -4
- package/dist/clientTypes.d.ts +1 -0
- package/dist/clientTypes.js +1 -1
- package/dist/crm/hooks/useAssociations.d.ts +5 -3
- package/dist/crm/hooks/useAssociations.js +4 -2
- package/dist/crm/hooks/useCrmProperties.d.ts +4 -2
- package/dist/crm/hooks/useCrmProperties.js +4 -2
- package/dist/crm/index.d.ts +4 -4
- package/dist/crm/index.js +3 -3
- package/dist/crm/utils/fetchAssociations.d.ts +1 -1
- package/dist/experimental/index.d.ts +4 -4
- package/dist/experimental/index.js +3 -3
- package/dist/experimental/testing/__tests__/createRenderer.spec.js +23 -0
- package/dist/experimental/testing/__tests__/debug.spec.js +21 -7
- package/dist/experimental/testing/__tests__/find.spec.js +23 -8
- package/dist/experimental/testing/__tests__/findAll.spec.js +4 -3
- package/dist/experimental/testing/__tests__/findAllChildren.spec.js +14 -8
- package/dist/experimental/testing/__tests__/findByTestId.spec.js +126 -0
- package/dist/experimental/testing/__tests__/findChild.spec.js +11 -7
- package/dist/experimental/testing/__tests__/fragments.spec.js +17 -10
- package/dist/experimental/testing/__tests__/invalid-components.spec.js +16 -8
- package/dist/experimental/testing/__tests__/isMatch.spec.js +106 -53
- package/dist/experimental/testing/__tests__/logger.spec.js +10 -0
- package/dist/experimental/testing/__tests__/maybeFind.spec.js +20 -11
- package/dist/experimental/testing/__tests__/maybeFindByTestId.spec.js +65 -0
- package/dist/experimental/testing/__tests__/maybeFindChild.spec.js +22 -12
- package/dist/experimental/testing/__tests__/mocks.actions.spec.js +19 -0
- package/dist/experimental/testing/__tests__/mocks.context.spec.js +24 -0
- package/dist/experimental/testing/__tests__/mocks.runServerlessFunction.spec.js +35 -0
- package/dist/experimental/testing/__tests__/mocks.useAssociations.spec.js +47 -0
- package/dist/experimental/testing/__tests__/mocks.useCrmProperties.spec.js +58 -0
- package/dist/experimental/testing/__tests__/props.spec.js +13 -0
- package/dist/experimental/testing/__tests__/testId.spec.js +18 -0
- package/dist/experimental/testing/__tests__/trigger.spec.js +9 -6
- package/dist/experimental/testing/__tests__/type-utils.spec.js +12 -10
- package/dist/experimental/testing/__tests__/waitFor.spec.js +7 -5
- package/dist/experimental/testing/index.d.ts +4 -3
- package/dist/experimental/testing/index.js +4 -3
- package/dist/experimental/testing/internal/constants.d.ts +2 -2
- package/dist/experimental/testing/internal/constants.js +1 -1
- package/dist/experimental/testing/internal/convert.d.ts +2 -2
- package/dist/experimental/testing/internal/convert.js +42 -24
- package/dist/experimental/testing/internal/debug.d.ts +3 -3
- package/dist/experimental/testing/internal/debug.js +4 -5
- package/dist/experimental/testing/internal/document.d.ts +1 -1
- package/dist/experimental/testing/internal/document.js +4 -1
- package/dist/experimental/testing/internal/element.d.ts +4 -3
- package/dist/experimental/testing/internal/element.js +15 -10
- package/dist/experimental/testing/internal/errors.d.ts +45 -2
- package/dist/experimental/testing/internal/errors.js +44 -2
- package/dist/experimental/testing/internal/fragment.d.ts +3 -2
- package/dist/experimental/testing/internal/fragment.js +13 -9
- package/dist/experimental/testing/internal/match.d.ts +3 -12
- package/dist/experimental/testing/internal/match.js +0 -23
- package/dist/experimental/testing/internal/mocks/index.d.ts +17 -0
- package/dist/experimental/testing/internal/mocks/index.js +46 -0
- package/dist/experimental/testing/internal/mocks/mock-extension-point-api.d.ts +2 -0
- package/dist/experimental/testing/internal/mocks/mock-extension-point-api.js +166 -0
- package/dist/experimental/testing/internal/mocks/mock-hooks.d.ts +2 -0
- package/dist/experimental/testing/internal/mocks/mock-hooks.js +59 -0
- package/dist/experimental/testing/internal/print.d.ts +2 -2
- package/dist/experimental/testing/internal/print.js +17 -11
- package/dist/experimental/testing/internal/query.d.ts +19 -9
- package/dist/experimental/testing/internal/query.js +91 -28
- package/dist/experimental/testing/internal/root.d.ts +1 -1
- package/dist/experimental/testing/internal/root.js +12 -8
- package/dist/experimental/testing/internal/text.d.ts +3 -2
- package/dist/experimental/testing/internal/text.js +12 -3
- package/dist/experimental/testing/internal/type-utils-internal.d.ts +44 -0
- package/dist/experimental/testing/internal/type-utils-internal.js +54 -0
- package/dist/experimental/testing/internal/types-internal.d.ts +20 -2
- package/dist/experimental/testing/render.d.ts +32 -6
- package/dist/experimental/testing/render.js +96 -32
- package/dist/experimental/testing/type-utils.d.ts +2 -2
- package/dist/experimental/testing/type-utils.js +1 -1
- package/dist/experimental/testing/types.d.ts +127 -10
- package/dist/experimental/testing/utils.d.ts +11 -0
- package/dist/experimental/testing/utils.js +24 -0
- package/dist/hubspot.d.ts +2 -4
- package/dist/hubspot.js +3 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/internal/global-utils.d.ts +6 -0
- package/dist/internal/global-utils.js +37 -0
- package/dist/internal/hook-utils.d.ts +19 -0
- package/dist/internal/hook-utils.js +34 -0
- package/dist/logger.d.ts +1 -8
- package/dist/logger.js +3 -2
- package/dist/pages/home/index.d.ts +1 -1
- package/dist/pages/home/index.js +1 -1
- package/dist/{__synced__/remoteComponents.synced.d.ts → shared/remoteComponents.d.ts} +103 -103
- package/dist/{__synced__/remoteComponents.synced.js → shared/remoteComponents.js} +1 -1
- package/dist/{__synced__/types/components/accordion.synced.d.ts → shared/types/components/accordion.d.ts} +2 -2
- package/dist/{__synced__/types/components/alert.synced.d.ts → shared/types/components/alert.d.ts} +2 -1
- package/dist/{__synced__/types/components/app-home-header-actions.synced.d.ts → shared/types/components/app-home-header-actions.d.ts} +4 -4
- package/dist/{__synced__/types/components/button-row.synced.d.ts → shared/types/components/button-row.d.ts} +2 -2
- package/dist/{__synced__/types/components/button.synced.d.ts → shared/types/components/button.d.ts} +3 -3
- package/dist/{__synced__/types/components/card.synced.d.ts → shared/types/components/card.d.ts} +2 -1
- package/dist/{__synced__/types/components/chart.synced.d.ts → shared/types/components/chart.d.ts} +2 -1
- package/dist/{__synced__/types/components/description-list.synced.d.ts → shared/types/components/description-list.d.ts} +3 -2
- package/dist/{__synced__/types/components/divider.synced.d.ts → shared/types/components/divider.d.ts} +2 -2
- package/dist/{__synced__/types/components/dropdown.synced.d.ts → shared/types/components/dropdown.d.ts} +5 -5
- package/dist/{__synced__/types/components/empty-state.synced.d.ts → shared/types/components/empty-state.d.ts} +2 -1
- package/dist/{__synced__/types/components/error-state.synced.d.ts → shared/types/components/error-state.d.ts} +2 -1
- package/dist/{__synced__/types/components/form.synced.d.ts → shared/types/components/form.d.ts} +3 -3
- package/dist/{__synced__/types/components/heading.synced.d.ts → shared/types/components/heading.d.ts} +2 -1
- package/dist/{__synced__/types/components/icon.synced.d.ts → shared/types/components/icon.d.ts} +2 -2
- package/dist/{__synced__/types/components/iframe.synced.d.ts → shared/types/components/iframe.d.ts} +2 -2
- package/dist/{__synced__/types/components/illustration.synced.d.ts → shared/types/components/illustration.d.ts} +2 -1
- package/dist/{__synced__/types/components/image.synced.d.ts → shared/types/components/image.d.ts} +3 -3
- package/dist/shared/types/components/index.d.ts +38 -0
- package/dist/{__synced__/types/components/inputs.synced.d.ts → shared/types/components/inputs.d.ts} +2 -1
- package/dist/{__synced__/types/components/layouts.synced.d.ts → shared/types/components/layouts.d.ts} +6 -6
- package/dist/{__synced__/types/components/link.synced.d.ts → shared/types/components/link.d.ts} +3 -3
- package/dist/{__synced__/types/components/list.synced.d.ts → shared/types/components/list.d.ts} +2 -1
- package/dist/{__synced__/types/components/loading-spinner.synced.d.ts → shared/types/components/loading-spinner.d.ts} +2 -2
- package/dist/{__synced__/types/components/modal.synced.d.ts → shared/types/components/modal.d.ts} +4 -4
- package/dist/{__synced__/types/components/panel.synced.d.ts → shared/types/components/panel.d.ts} +5 -5
- package/dist/{__synced__/types/components/progress-bar.synced.d.ts → shared/types/components/progress-bar.d.ts} +2 -1
- package/dist/{__synced__/types/components/selects.synced.d.ts → shared/types/components/selects.d.ts} +2 -1
- package/dist/{__synced__/types/components/statistics.synced.d.ts → shared/types/components/statistics.d.ts} +4 -3
- package/dist/{__synced__/types/components/status-tag.synced.d.ts → shared/types/components/status-tag.d.ts} +2 -1
- package/dist/{__synced__/types/components/step-indicator.synced.d.ts → shared/types/components/step-indicator.d.ts} +2 -2
- package/dist/{__synced__/types/components/table.synced.d.ts → shared/types/components/table.d.ts} +5 -4
- package/dist/shared/types/components/table.js +1 -0
- package/dist/{__synced__/types/components/tabs.synced.d.ts → shared/types/components/tabs.d.ts} +3 -2
- package/dist/shared/types/components/tabs.js +1 -0
- package/dist/{__synced__/types/components/tag.synced.d.ts → shared/types/components/tag.d.ts} +3 -3
- package/dist/shared/types/components/tag.js +1 -0
- package/dist/{__synced__/types/components/text.synced.d.ts → shared/types/components/text.d.ts} +2 -1
- package/dist/shared/types/components/text.js +1 -0
- package/dist/{__synced__/types/components/tile.synced.d.ts → shared/types/components/tile.d.ts} +2 -1
- package/dist/shared/types/components/tile.js +1 -0
- package/dist/{__synced__/types/components/toggle.synced.d.ts → shared/types/components/toggle.d.ts} +2 -2
- package/dist/shared/types/components/toggle.js +1 -0
- package/dist/{__synced__/types/components/toggleInputs.synced.d.ts → shared/types/components/toggleInputs.d.ts} +4 -4
- package/dist/shared/types/components/toggleInputs.js +1 -0
- package/dist/{__synced__/types/components/tooltip.synced.d.ts → shared/types/components/tooltip.d.ts} +2 -1
- package/dist/shared/types/components/tooltip.js +1 -0
- package/dist/{__synced__/types/context.synced.d.ts → shared/types/context.d.ts} +1 -1
- package/dist/shared/types/context.js +1 -0
- package/dist/{__synced__/types/crm.synced.d.ts → shared/types/crm.d.ts} +13 -13
- package/dist/shared/types/crm.js +1 -0
- package/dist/{__synced__/experimental/types.synced.d.ts → shared/types/experimental.d.ts} +10 -14
- package/dist/shared/types/experimental.js +1 -0
- package/dist/shared/types/extend.d.ts +4 -0
- package/dist/shared/types/extend.js +1 -0
- package/dist/{__synced__/types/extension-points.synced.d.ts → shared/types/extension-points.d.ts} +18 -10
- package/dist/{__synced__/types/http-requests.synced.d.ts → shared/types/http-requests.d.ts} +1 -1
- package/dist/shared/types/index.d.ts +8 -0
- package/dist/shared/types/index.js +1 -0
- package/dist/shared/types/logger.d.ts +7 -0
- package/dist/shared/types/logger.js +1 -0
- package/dist/shared/types/reactions.js +1 -0
- package/dist/{__synced__/types/shared.synced.d.ts → shared/types/shared.d.ts} +3 -0
- package/dist/shared/types/worker-globals.d.ts +17 -0
- package/dist/shared/types/worker-globals.js +1 -0
- package/dist/{__synced__/utils/remote-component-registry.synced.d.ts → shared/utils/remote-component-registry.d.ts} +1 -1
- package/dist/{__synced__/utils/remote-component-registry.synced.js → shared/utils/remote-component-registry.js} +0 -1
- package/package.json +6 -4
- package/dist/__synced__/experimental/types.synced.js +0 -5
- package/dist/__synced__/types/components/index.synced.d.ts +0 -38
- package/dist/__synced__/types/index.synced.d.ts +0 -8
- package/dist/__synced__/types/index.synced.js +0 -1
- /package/dist/{__synced__/types/actions.synced.js → experimental/testing/__tests__/createRenderer.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/accordion.synced.js → experimental/testing/__tests__/findByTestId.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/alert.synced.js → experimental/testing/__tests__/logger.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/app-home-header-actions.synced.js → experimental/testing/__tests__/maybeFindByTestId.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/button-row.synced.js → experimental/testing/__tests__/mocks.actions.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/button.synced.js → experimental/testing/__tests__/mocks.context.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/card.synced.js → experimental/testing/__tests__/mocks.runServerlessFunction.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/description-list.synced.js → experimental/testing/__tests__/mocks.useAssociations.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/divider.synced.js → experimental/testing/__tests__/mocks.useCrmProperties.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/dropdown.synced.js → experimental/testing/__tests__/props.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/empty-state.synced.js → experimental/testing/__tests__/testId.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/actions.synced.d.ts → shared/types/actions.d.ts} +0 -0
- /package/dist/{__synced__/types/components/error-state.synced.js → shared/types/actions.js} +0 -0
- /package/dist/{__synced__/types/components/form.synced.js → shared/types/components/accordion.js} +0 -0
- /package/dist/{__synced__/types/components/heading.synced.js → shared/types/components/alert.js} +0 -0
- /package/dist/{__synced__/types/components/icon.synced.js → shared/types/components/app-home-header-actions.js} +0 -0
- /package/dist/{__synced__/types/components/iframe.synced.js → shared/types/components/button-row.js} +0 -0
- /package/dist/{__synced__/types/components/image.synced.js → shared/types/components/button.js} +0 -0
- /package/dist/{__synced__/types/components/index.synced.js → shared/types/components/card.js} +0 -0
- /package/dist/{__synced__/types/components/chart.synced.js → shared/types/components/chart.js} +0 -0
- /package/dist/{__synced__/types/components/inputs.synced.js → shared/types/components/description-list.js} +0 -0
- /package/dist/{__synced__/types/components/layouts.synced.js → shared/types/components/divider.js} +0 -0
- /package/dist/{__synced__/types/components/link.synced.js → shared/types/components/dropdown.js} +0 -0
- /package/dist/{__synced__/types/components/list.synced.js → shared/types/components/empty-state.js} +0 -0
- /package/dist/{__synced__/types/components/loading-spinner.synced.js → shared/types/components/error-state.js} +0 -0
- /package/dist/{__synced__/types/components/modal.synced.js → shared/types/components/form.js} +0 -0
- /package/dist/{__synced__/types/components/panel.synced.js → shared/types/components/heading.js} +0 -0
- /package/dist/{__synced__/types/components/progress-bar.synced.js → shared/types/components/icon.js} +0 -0
- /package/dist/{__synced__/types/components/selects.synced.js → shared/types/components/iframe.js} +0 -0
- /package/dist/{__synced__/types/components/illustration.synced.js → shared/types/components/illustration.js} +0 -0
- /package/dist/{__synced__/types/components/statistics.synced.js → shared/types/components/image.js} +0 -0
- /package/dist/{__synced__/types/components/status-tag.synced.js → shared/types/components/index.js} +0 -0
- /package/dist/{__synced__/types/components/step-indicator.synced.js → shared/types/components/inputs.js} +0 -0
- /package/dist/{__synced__/types/components/table.synced.js → shared/types/components/layouts.js} +0 -0
- /package/dist/{__synced__/types/components/tabs.synced.js → shared/types/components/link.js} +0 -0
- /package/dist/{__synced__/types/components/tag.synced.js → shared/types/components/list.js} +0 -0
- /package/dist/{__synced__/types/components/text.synced.js → shared/types/components/loading-spinner.js} +0 -0
- /package/dist/{__synced__/types/components/tile.synced.js → shared/types/components/modal.js} +0 -0
- /package/dist/{__synced__/types/components/toggle.synced.js → shared/types/components/panel.js} +0 -0
- /package/dist/{__synced__/types/components/toggleInputs.synced.js → shared/types/components/progress-bar.js} +0 -0
- /package/dist/{__synced__/types/components/tooltip.synced.js → shared/types/components/selects.js} +0 -0
- /package/dist/{__synced__/types/context.synced.js → shared/types/components/statistics.js} +0 -0
- /package/dist/{__synced__/types/crm.synced.js → shared/types/components/status-tag.js} +0 -0
- /package/dist/{__synced__/types/reactions.synced.js → shared/types/components/step-indicator.js} +0 -0
- /package/dist/{__synced__/types/extension-points.synced.js → shared/types/extension-points.js} +0 -0
- /package/dist/{__synced__/types/http-requests.synced.js → shared/types/http-requests.js} +0 -0
- /package/dist/{__synced__/types/reactions.synced.d.ts → shared/types/reactions.d.ts} +0 -0
- /package/dist/{__synced__/types/shared.synced.js → shared/types/shared.js} +0 -0
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { Alert, Button, ButtonRow } from
|
|
4
|
-
import {
|
|
5
|
-
import { ComponentNotFoundError, FindInvalidComponentError, } from
|
|
3
|
+
import { Alert, Button, ButtonRow } from "../../../index.js";
|
|
4
|
+
import { createRenderer } from "../index.js";
|
|
5
|
+
import { ComponentNotFoundError, FindInvalidComponentError, } from "../internal/errors.js";
|
|
6
6
|
describe('findChild()', () => {
|
|
7
7
|
it('should allow finding a child from the root node', () => {
|
|
8
8
|
const buttonLabel = '';
|
|
9
|
-
const {
|
|
9
|
+
const { render, findChild } = createRenderer('crm.record.tab');
|
|
10
|
+
render(_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: buttonLabel }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
10
11
|
expect(findChild(ButtonRow)).toBeDefined();
|
|
11
12
|
});
|
|
12
13
|
it('should allow finding a child from a nested component', () => {
|
|
13
14
|
const buttonLabel = '';
|
|
14
|
-
const {
|
|
15
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
16
|
+
render(_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: buttonLabel }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
15
17
|
const buttonRow = find(ButtonRow);
|
|
16
18
|
expect(buttonRow.findChild(Button).props).toEqual({ variant: 'primary' });
|
|
17
19
|
});
|
|
18
20
|
it('should throw an error when no match is found', () => {
|
|
19
|
-
const { find } =
|
|
21
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
22
|
+
render(_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: "Click me!" }) }));
|
|
20
23
|
const buttonRow = find(ButtonRow);
|
|
21
24
|
expect(() => buttonRow.findChild(Alert)).toThrow(ComponentNotFoundError);
|
|
22
25
|
});
|
|
23
26
|
it('should throw an error when target component is invalid', () => {
|
|
24
|
-
const { find } =
|
|
27
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
28
|
+
render(_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: "Click me!" }) }));
|
|
25
29
|
const MyFakeComponent = () => { };
|
|
26
30
|
const buttonRow = find(ButtonRow);
|
|
27
31
|
expect(() => buttonRow.findChild(MyFakeComponent)).toThrow(FindInvalidComponentError);
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { Alert, Button, ButtonRow, List, Text } from
|
|
4
|
-
import {
|
|
5
|
-
import { InvalidFragmentPropArrayError } from
|
|
3
|
+
import { Alert, Button, ButtonRow, List, Text } from "../../../index.js";
|
|
4
|
+
import { createRenderer } from "../index.js";
|
|
5
|
+
import { InvalidFragmentPropArrayError } from "../internal/errors.js";
|
|
6
6
|
describe('fragments', () => {
|
|
7
7
|
it('should allow assertions against components with fragment props', () => {
|
|
8
8
|
const buttonLabel = 'Click me!';
|
|
9
|
-
const {
|
|
9
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
10
|
+
render(_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", overlay: _jsx(List, { children: _jsx(Text, { children: "Item 1" }) }), children: buttonLabel }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
10
11
|
expect(find(Text).text).toEqual('Item 1');
|
|
11
12
|
expect(find(Button).text).toEqual(buttonLabel);
|
|
12
13
|
});
|
|
13
14
|
it('should handle undefined fragment props', () => {
|
|
14
15
|
const buttonLabel = 'Click me!';
|
|
15
|
-
const {
|
|
16
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
17
|
+
render(_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: buttonLabel }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
16
18
|
const button = find(Button);
|
|
17
19
|
const { props: buttonProps } = button;
|
|
18
20
|
expect(buttonProps.overlay).toBeUndefined();
|
|
@@ -20,29 +22,33 @@ describe('fragments', () => {
|
|
|
20
22
|
});
|
|
21
23
|
it('should handle null fragment props', () => {
|
|
22
24
|
const buttonLabel = 'Click me!';
|
|
23
|
-
const {
|
|
25
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
26
|
+
render(_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", overlay: null, children: buttonLabel }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
24
27
|
const button = find(Button);
|
|
25
28
|
const { props: buttonProps } = button;
|
|
26
|
-
expect(buttonProps.overlay?.
|
|
29
|
+
expect(buttonProps.overlay?.childNodes).toHaveLength(0);
|
|
27
30
|
expect(find(Alert).props).toEqual({ title: 'My Alert' });
|
|
28
31
|
});
|
|
29
32
|
it('should throw an error if an array fragment prop is passed', () => {
|
|
30
33
|
const buttonLabel = 'Click me!';
|
|
31
34
|
const arrayProp = [1, 2, 3];
|
|
35
|
+
const { render } = createRenderer('crm.record.tab');
|
|
32
36
|
expect(() => {
|
|
33
37
|
render(_jsx(Button, { variant: "primary", overlay: arrayProp, children: buttonLabel }));
|
|
34
38
|
}).toThrow(InvalidFragmentPropArrayError);
|
|
35
39
|
});
|
|
36
40
|
it('should handle string fragment props', () => {
|
|
37
41
|
const buttonLabel = 'Click me!';
|
|
38
|
-
const {
|
|
42
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
43
|
+
render(_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", overlay: "My Overlay", children: buttonLabel }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
39
44
|
const button = find(Button);
|
|
40
45
|
expect(button.props.overlay?.text).toEqual('My Overlay');
|
|
41
46
|
expect(find(Alert).props).toEqual({ title: 'My Alert' });
|
|
42
47
|
});
|
|
43
48
|
it('should handle fragment props that are a JSX fragment', () => {
|
|
44
49
|
const buttonLabel = 'Click me!';
|
|
45
|
-
const {
|
|
50
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
51
|
+
render(_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", overlay: _jsx(_Fragment, { children: "My Overlay" }), children: buttonLabel }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
46
52
|
const button = find(Button);
|
|
47
53
|
expect(button.props.overlay?.text).toEqual('My Overlay');
|
|
48
54
|
expect(find(Alert).props).toEqual({ title: 'My Alert' });
|
|
@@ -52,7 +58,8 @@ describe('fragments', () => {
|
|
|
52
58
|
function MyOverlay() {
|
|
53
59
|
return (_jsx(List, { children: _jsx(Text, { children: "Item 1" }) }));
|
|
54
60
|
}
|
|
55
|
-
const {
|
|
61
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
62
|
+
render(_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", overlay: _jsx(MyOverlay, {}), children: buttonLabel }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
56
63
|
expect(find(Text).text).toEqual('Item 1');
|
|
57
64
|
expect(find(Button).text).toEqual(buttonLabel);
|
|
58
65
|
});
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
3
|
import { describe, expect, it } from 'vitest';
|
|
4
|
-
import { Alert, Button, ButtonRow, Text } from
|
|
5
|
-
import {
|
|
6
|
-
import { InvalidComponentsError } from
|
|
7
|
-
import { createDeferred } from
|
|
4
|
+
import { Alert, Button, ButtonRow, Text } from "../../../index.js";
|
|
5
|
+
import { createRenderer } from "../index.js";
|
|
6
|
+
import { InvalidComponentsError } from "../internal/errors.js";
|
|
7
|
+
import { createDeferred } from "../internal/utils/promise-utils.js";
|
|
8
8
|
const setTimeoutPromise = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
9
9
|
describe('handling invalid components', () => {
|
|
10
10
|
it('should throw an error if initial render contains invalid components', () => {
|
|
11
|
+
const { render } = createRenderer('crm.record.tab');
|
|
11
12
|
function MyComponent() {
|
|
12
13
|
return (_jsx("div", { children: _jsx("span", { children: _jsx(Button, { variant: "primary", children: "Click me!" }) }) }));
|
|
13
14
|
}
|
|
@@ -22,12 +23,14 @@ describe('handling invalid components', () => {
|
|
|
22
23
|
expect(errorMessage).toMatchSnapshot();
|
|
23
24
|
});
|
|
24
25
|
it('should throw an error if initial render contains invalid components inside a fragment', () => {
|
|
26
|
+
const { render } = createRenderer('crm.record.tab');
|
|
25
27
|
function MyComponent() {
|
|
26
28
|
return (_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", overlay: _jsx("div", { children: "Overlay" }), children: "Click me!" }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
27
29
|
}
|
|
28
30
|
expect(() => render(_jsx(MyComponent, {}))).toThrow(InvalidComponentsError);
|
|
29
31
|
});
|
|
30
32
|
it('should throw an error if triggering an event results in an invalid component to be rendered', () => {
|
|
33
|
+
const { render } = createRenderer('crm.record.tab');
|
|
31
34
|
function Counter() {
|
|
32
35
|
const [count, setCount] = useState(0);
|
|
33
36
|
const handleClick = () => {
|
|
@@ -52,7 +55,8 @@ describe('handling invalid components', () => {
|
|
|
52
55
|
}, []);
|
|
53
56
|
return (_jsx(Button, { children: count === 0 ? 'Click me!' : _jsxs("div", { children: ["Clicked ", count, " times"] }) }));
|
|
54
57
|
}
|
|
55
|
-
const { find, waitFor } =
|
|
58
|
+
const { render, find, waitFor } = createRenderer('crm.record.tab');
|
|
59
|
+
render(_jsx(AsyncCounter, {}));
|
|
56
60
|
expect(find(Button).text).toEqual('Click me!');
|
|
57
61
|
await expect(waitFor(() => {
|
|
58
62
|
expect(find(Button).text).toEqual('Clicked 1 times');
|
|
@@ -74,15 +78,19 @@ describe('handling invalid components', () => {
|
|
|
74
78
|
if (isPending) {
|
|
75
79
|
return _jsx(Text, { children: "Loading..." });
|
|
76
80
|
}
|
|
81
|
+
// NOTE: `<div>` is an invalid component that should trigger an error after it is loaded.
|
|
77
82
|
return _jsx("div", { children: "Loaded!" });
|
|
78
83
|
}
|
|
79
84
|
const loadingDeferred = createDeferred();
|
|
80
|
-
const { find } =
|
|
85
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
86
|
+
render(_jsx(AsyncCounter, { promise: loadingDeferred.promise }));
|
|
81
87
|
expect(find(Text).text).toEqual('Loading...');
|
|
82
88
|
loadingDeferred.resolve();
|
|
83
|
-
await
|
|
89
|
+
await loadingDeferred.promise;
|
|
90
|
+
// Wait another 5ms to be extra sure that the component has rerendered
|
|
91
|
+
await setTimeoutPromise(5);
|
|
84
92
|
expect(() => {
|
|
85
|
-
find(
|
|
93
|
+
find(Text);
|
|
86
94
|
}).toThrow(InvalidComponentsError);
|
|
87
95
|
});
|
|
88
96
|
});
|
|
@@ -1,60 +1,113 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { Alert, Button } from
|
|
4
|
-
import {
|
|
3
|
+
import { Alert, Button } from "../../../index.js";
|
|
4
|
+
import { createRenderer, isMatch, isRenderedFragmentNode, } from "../index.js";
|
|
5
5
|
describe('isMatch()', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
describe('isMatch() utility function', () => {
|
|
7
|
+
it('should allow assertions against a mix of text and element nodes', () => {
|
|
8
|
+
const { render, getRootNode } = createRenderer('crm.record.tab');
|
|
9
|
+
render(_jsxs(_Fragment, { children: [_jsx(Button, { variant: "primary", children: "Click me!" }), _jsx(Alert, { title: "My Alert" }), "Hello"] }));
|
|
10
|
+
const rootNode = getRootNode();
|
|
11
|
+
const { childNodes } = rootNode;
|
|
12
|
+
const buttonNode = childNodes[0];
|
|
13
|
+
const alertNode = childNodes[1];
|
|
14
|
+
const textNode = childNodes[2];
|
|
15
|
+
if (isMatch(buttonNode, Button)) {
|
|
16
|
+
expect(buttonNode.props.variant).toEqual('primary');
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new Error('Expected button node');
|
|
20
|
+
}
|
|
21
|
+
expect(isMatch(alertNode, Button)).toBe(false);
|
|
22
|
+
expect(isMatch(textNode, Button)).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
it('should allow a custom matcher function to be provided', () => {
|
|
25
|
+
const { render, getRootNode } = createRenderer('crm.record.tab');
|
|
26
|
+
render(_jsxs(_Fragment, { children: [_jsx(Button, { variant: "primary", children: "Primary" }), _jsx(Button, { variant: "secondary", children: "Secondary" }), _jsx(Alert, { title: "My Alert" }), "Hello"] }));
|
|
27
|
+
const rootNode = getRootNode();
|
|
28
|
+
const { childNodes } = rootNode;
|
|
29
|
+
const primaryButtonNode = childNodes[0];
|
|
30
|
+
const secondaryButtonNode = childNodes[1];
|
|
31
|
+
const alertNode = childNodes[2];
|
|
32
|
+
const textNode = childNodes[3];
|
|
33
|
+
const matcher = (node) => node.props.variant === 'primary';
|
|
34
|
+
if (isMatch(primaryButtonNode, Button, matcher)) {
|
|
35
|
+
expect(primaryButtonNode.props.variant).toEqual('primary');
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error('Expected button node');
|
|
39
|
+
}
|
|
40
|
+
expect(isMatch(secondaryButtonNode, Button, matcher)).toBe(false);
|
|
41
|
+
expect(isMatch(alertNode, Button, matcher)).toBe(false);
|
|
42
|
+
expect(isMatch(textNode, Button, matcher)).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
it('should allow a partial props object to be provided for matching', () => {
|
|
45
|
+
const { render, getRootNode } = createRenderer('crm.record.tab');
|
|
46
|
+
render(_jsxs(_Fragment, { children: [_jsx(Button, { variant: "primary", children: "Primary" }), _jsx(Button, { variant: "secondary", children: "Secondary" }), _jsx(Alert, { title: "My Alert" }), "Hello"] }));
|
|
47
|
+
const rootNode = getRootNode();
|
|
48
|
+
const { childNodes } = rootNode;
|
|
49
|
+
const primaryButtonNode = childNodes[0];
|
|
50
|
+
const secondaryButtonNode = childNodes[1];
|
|
51
|
+
const alertNode = childNodes[2];
|
|
52
|
+
const textNode = childNodes[3];
|
|
53
|
+
const matcher = { variant: 'primary' };
|
|
54
|
+
if (isMatch(primaryButtonNode, Button, matcher)) {
|
|
55
|
+
expect(primaryButtonNode.props.variant).toEqual('primary');
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
throw new Error('Expected button node');
|
|
59
|
+
}
|
|
60
|
+
expect(isMatch(secondaryButtonNode, Button, matcher)).toBe(false);
|
|
61
|
+
expect(isMatch(alertNode, Button, matcher)).toBe(false);
|
|
62
|
+
expect(isMatch(textNode, Button, matcher)).toBe(false);
|
|
63
|
+
});
|
|
21
64
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (isMatch(primaryButtonNode, Button, matcher)) {
|
|
32
|
-
expect(primaryButtonNode.props.variant).toEqual('primary');
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
throw new Error('Expected button node');
|
|
36
|
-
}
|
|
37
|
-
expect(isMatch(secondaryButtonNode, Button, matcher)).toBe(false);
|
|
38
|
-
expect(isMatch(alertNode, Button, matcher)).toBe(false);
|
|
39
|
-
expect(isMatch(textNode, Button, matcher)).toBe(false);
|
|
65
|
+
describe('RenderedText.isMatch()', () => {
|
|
66
|
+
it('should work correctly for text nodes', () => {
|
|
67
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
68
|
+
render(_jsx(Button, { variant: "primary", children: "Primary" }));
|
|
69
|
+
const buttonNode = find(Button);
|
|
70
|
+
const textNode = buttonNode.childNodes[0];
|
|
71
|
+
expect(textNode.isMatch(Button)).toBe(false);
|
|
72
|
+
expect(textNode.isMatch(Button) && textNode.props.variant === 'primary').toBe(false);
|
|
73
|
+
});
|
|
40
74
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
75
|
+
describe('RenderedElement.isMatch()', () => {
|
|
76
|
+
it('should work correctly for element nodes', () => {
|
|
77
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
78
|
+
render(_jsx(Button, { variant: "primary", children: "Primary" }));
|
|
79
|
+
const buttonNode = find(Button);
|
|
80
|
+
expect(buttonNode.isMatch(Button)).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
it('should work correctly for element nodes with a custom matcher function', () => {
|
|
83
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
84
|
+
render(_jsx(Button, { variant: "primary", children: "Primary" }));
|
|
85
|
+
const buttonNode = find(Button);
|
|
86
|
+
expect(buttonNode.isMatch(Button, (node) => node.props.variant === 'primary')).toBe(true);
|
|
87
|
+
});
|
|
88
|
+
it('should work correctly for element nodes with a partial props object', () => {
|
|
89
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
90
|
+
render(_jsx(Button, { variant: "primary", children: "Primary" }));
|
|
91
|
+
const buttonNode = find(Button);
|
|
92
|
+
expect(buttonNode.isMatch(Button, { variant: 'primary' })).toBe(true);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe('RenderedFragment.isMatch()', () => {
|
|
96
|
+
it('should work correctly for fragment nodes', () => {
|
|
97
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
98
|
+
render(_jsx(Button, { variant: "primary", overlay: _jsx(_Fragment, { children: "My Overlay" }), children: "Hello" }));
|
|
99
|
+
const buttonNode = find(Button);
|
|
100
|
+
const overlayFragmentNode = buttonNode.props.overlay;
|
|
101
|
+
expect(isRenderedFragmentNode(overlayFragmentNode)).toBe(true);
|
|
102
|
+
expect(overlayFragmentNode.isMatch(Button)).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe('RenderedRoot.isMatch()', () => {
|
|
106
|
+
it('should work correctly for root nodes', () => {
|
|
107
|
+
const { render, getRootNode } = createRenderer('crm.record.tab');
|
|
108
|
+
render(_jsx(Button, { variant: "primary", children: "Primary" }));
|
|
109
|
+
const rootNode = getRootNode();
|
|
110
|
+
expect(rootNode.isMatch(Button)).toBe(false);
|
|
111
|
+
});
|
|
59
112
|
});
|
|
60
113
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { logger } from "../../../logger.js";
|
|
3
|
+
describe('logger in test environment', () => {
|
|
4
|
+
it('should be available', () => {
|
|
5
|
+
expect(logger.debug).toBeInstanceOf(Function);
|
|
6
|
+
expect(logger.info).toBeInstanceOf(Function);
|
|
7
|
+
expect(logger.warn).toBeInstanceOf(Function);
|
|
8
|
+
expect(logger.error).toBeInstanceOf(Function);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -1,56 +1,65 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { Alert, Button, ButtonRow, Text } from
|
|
4
|
-
import {
|
|
3
|
+
import { Alert, Button, ButtonRow, Text } from "../../../index.js";
|
|
4
|
+
import { createRenderer } from "../index.js";
|
|
5
5
|
describe('maybeFind()', () => {
|
|
6
6
|
it('should return the element when found', () => {
|
|
7
|
-
const {
|
|
7
|
+
const { render, maybeFind } = createRenderer('crm.record.tab');
|
|
8
|
+
render(_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: "Button 1" }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
8
9
|
const button = maybeFind(Button);
|
|
9
10
|
expect(button).toBeDefined();
|
|
10
11
|
expect(button?.props).toEqual({ variant: 'primary' });
|
|
11
12
|
});
|
|
12
13
|
it('should return null when element is not found', () => {
|
|
13
|
-
const {
|
|
14
|
+
const { render, maybeFind } = createRenderer('crm.record.tab');
|
|
15
|
+
render(_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: "Button 1" }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
14
16
|
const text = maybeFind(Text);
|
|
15
17
|
expect(text).toBeNull();
|
|
16
18
|
});
|
|
17
19
|
it('should return the first matching element when multiple elements match', () => {
|
|
18
|
-
const {
|
|
20
|
+
const { render, maybeFind } = createRenderer('crm.record.tab');
|
|
21
|
+
render(_jsxs(_Fragment, { children: [_jsx(Alert, { title: "First Alert" }), _jsx(Alert, { title: "Second Alert" }), _jsx(Alert, { title: "Third Alert" })] }));
|
|
19
22
|
const alert = maybeFind(Alert);
|
|
20
23
|
expect(alert).toBeDefined();
|
|
21
24
|
expect(alert?.props).toMatchObject({ title: 'First Alert' });
|
|
22
25
|
});
|
|
23
26
|
it('should support matcher function', () => {
|
|
24
|
-
const { maybeFind } =
|
|
27
|
+
const { render, maybeFind } = createRenderer('crm.record.tab');
|
|
28
|
+
render(_jsx(_Fragment, { children: _jsxs(ButtonRow, { children: [_jsx(Button, { variant: "secondary", children: "Button 1" }), _jsx(Button, { variant: "primary", children: "Button 2" })] }) }));
|
|
25
29
|
const primaryButton = maybeFind(Button, (node) => node.props.variant === 'primary');
|
|
26
30
|
expect(primaryButton).toBeDefined();
|
|
27
31
|
expect(primaryButton?.props).toMatchObject({ variant: 'primary' });
|
|
28
32
|
});
|
|
29
33
|
it('should return null when matcher function does not match any elements', () => {
|
|
30
|
-
const { maybeFind } =
|
|
34
|
+
const { render, maybeFind } = createRenderer('crm.record.tab');
|
|
35
|
+
render(_jsx(_Fragment, { children: _jsxs(ButtonRow, { children: [_jsx(Button, { variant: "secondary", children: "Button 1" }), _jsx(Button, { variant: "secondary", children: "Button 2" })] }) }));
|
|
31
36
|
const primaryButton = maybeFind(Button, (node) => node.props.variant === 'primary');
|
|
32
37
|
expect(primaryButton).toBeNull();
|
|
33
38
|
});
|
|
34
39
|
it('should support matcher object', () => {
|
|
35
|
-
const { maybeFind } =
|
|
40
|
+
const { render, maybeFind } = createRenderer('crm.record.tab');
|
|
41
|
+
render(_jsx(_Fragment, { children: _jsxs(ButtonRow, { children: [_jsx(Button, { variant: "secondary", children: "Button 1" }), _jsx(Button, { variant: "primary", children: "Button 2" })] }) }));
|
|
36
42
|
const primaryButton = maybeFind(Button, { variant: 'primary' });
|
|
37
43
|
expect(primaryButton).toBeDefined();
|
|
38
44
|
expect(primaryButton?.props).toMatchObject({ variant: 'primary' });
|
|
39
45
|
});
|
|
40
46
|
it('should return null when matcher object does not match any elements', () => {
|
|
41
|
-
const { maybeFind } =
|
|
47
|
+
const { render, maybeFind } = createRenderer('crm.record.tab');
|
|
48
|
+
render(_jsx(_Fragment, { children: _jsxs(ButtonRow, { children: [_jsx(Button, { variant: "secondary", children: "Button 1" }), _jsx(Button, { variant: "secondary", children: "Button 2" })] }) }));
|
|
42
49
|
const primaryButton = maybeFind(Button, { variant: 'primary' });
|
|
43
50
|
expect(primaryButton).toBeNull();
|
|
44
51
|
});
|
|
45
52
|
it('should work on nested element nodes', () => {
|
|
46
|
-
const { find } =
|
|
53
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
54
|
+
render(_jsx(_Fragment, { children: _jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: "Button 1" }) }) }));
|
|
47
55
|
const buttonRow = find(ButtonRow);
|
|
48
56
|
const nestedButton = buttonRow.maybeFind(Button);
|
|
49
57
|
expect(nestedButton).toBeDefined();
|
|
50
58
|
expect(nestedButton?.props).toMatchObject({ variant: 'primary' });
|
|
51
59
|
});
|
|
52
60
|
it('should return null on nested element when not found', () => {
|
|
53
|
-
const { find } =
|
|
61
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
62
|
+
render(_jsx(_Fragment, { children: _jsx(ButtonRow, { children: _jsx(Button, { variant: "secondary", children: "Button 1" }) }) }));
|
|
54
63
|
const buttonRow = find(ButtonRow);
|
|
55
64
|
const text = buttonRow.maybeFind(Text);
|
|
56
65
|
expect(text).toBeNull();
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { Alert, Button, ButtonRow } from "../../../index.js";
|
|
4
|
+
import { createRenderer } from "../index.js";
|
|
5
|
+
import { ComponentMismatchedByTestIdError, FindInvalidComponentError, } from "../internal/errors.js";
|
|
6
|
+
describe('maybeFindByTestId()', () => {
|
|
7
|
+
it('should return the element when found by testId', () => {
|
|
8
|
+
const { render, maybeFindByTestId } = createRenderer('crm.record.tab');
|
|
9
|
+
render(_jsx(_Fragment, { children: _jsx(Button, { variant: "primary", testId: "my-button", children: "Click me" }) }));
|
|
10
|
+
const button = maybeFindByTestId(Button, 'my-button');
|
|
11
|
+
expect(button).toBeDefined();
|
|
12
|
+
expect(button?.props).toMatchObject({
|
|
13
|
+
variant: 'primary',
|
|
14
|
+
testId: 'my-button',
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
it('should return null when element with the given testId is not found', () => {
|
|
18
|
+
const { render, maybeFindByTestId } = createRenderer('crm.record.tab');
|
|
19
|
+
render(_jsx(_Fragment, { children: _jsx(Button, { variant: "primary", testId: "my-button", children: "Click me" }) }));
|
|
20
|
+
const button = maybeFindByTestId(Button, 'non-existent-testid');
|
|
21
|
+
expect(button).toBeNull();
|
|
22
|
+
});
|
|
23
|
+
it('should throw ComponentMismatchedByTestIdError when testId exists but component type does not match', () => {
|
|
24
|
+
const { render, maybeFindByTestId } = createRenderer('crm.record.tab');
|
|
25
|
+
render(_jsx(_Fragment, { children: _jsx(Button, { variant: "primary", testId: "my-button", children: "Click me" }) }));
|
|
26
|
+
expect(() => maybeFindByTestId(Alert, 'my-button')).toThrow(ComponentMismatchedByTestIdError);
|
|
27
|
+
});
|
|
28
|
+
it('should throw FindInvalidComponentError when target component is invalid', () => {
|
|
29
|
+
const { render, maybeFindByTestId } = createRenderer('crm.record.tab');
|
|
30
|
+
render(_jsx(_Fragment, { children: _jsx(Button, { variant: "primary", testId: "my-button", children: "Click me" }) }));
|
|
31
|
+
const MyFakeComponent = () => { };
|
|
32
|
+
expect(() => maybeFindByTestId(MyFakeComponent, 'my-button')).toThrow(FindInvalidComponentError);
|
|
33
|
+
});
|
|
34
|
+
it('should return null after re-rendering removes the component', () => {
|
|
35
|
+
const { render, maybeFindByTestId } = createRenderer('crm.record.tab');
|
|
36
|
+
render(_jsx(_Fragment, { children: _jsx(Button, { variant: "primary", testId: "my-button", children: "Click me" }) }));
|
|
37
|
+
let button = maybeFindByTestId(Button, 'my-button');
|
|
38
|
+
expect(button).toBeDefined();
|
|
39
|
+
render(_jsx(_Fragment, { children: _jsx(Alert, { title: "My Alert" }) }));
|
|
40
|
+
button = maybeFindByTestId(Button, 'my-button');
|
|
41
|
+
expect(button).toBeNull();
|
|
42
|
+
});
|
|
43
|
+
it('should handle multiple components with different testIds', () => {
|
|
44
|
+
const { render, maybeFindByTestId } = createRenderer('crm.record.tab');
|
|
45
|
+
render(_jsxs(_Fragment, { children: [_jsx(Button, { variant: "primary", testId: "button-1", children: "Button 1" }), _jsx(Button, { variant: "secondary", testId: "button-2", children: "Button 2" }), _jsx(Button, { variant: "destructive", testId: "button-3", children: "Button 3" })] }));
|
|
46
|
+
const button1 = maybeFindByTestId(Button, 'button-1');
|
|
47
|
+
expect(button1?.props.variant).toEqual('primary');
|
|
48
|
+
const button2 = maybeFindByTestId(Button, 'button-2');
|
|
49
|
+
expect(button2?.props.variant).toEqual('secondary');
|
|
50
|
+
const button3 = maybeFindByTestId(Button, 'button-3');
|
|
51
|
+
expect(button3?.props.variant).toEqual('destructive');
|
|
52
|
+
const button4 = maybeFindByTestId(Button, 'button-4');
|
|
53
|
+
expect(button4).toBeNull();
|
|
54
|
+
});
|
|
55
|
+
it('should work with nested components', () => {
|
|
56
|
+
const { render, maybeFindByTestId } = createRenderer('crm.record.tab');
|
|
57
|
+
render(_jsx(_Fragment, { children: _jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", testId: "nested-button", children: "Nested" }) }) }));
|
|
58
|
+
const button = maybeFindByTestId(Button, 'nested-button');
|
|
59
|
+
expect(button).toBeDefined();
|
|
60
|
+
expect(button?.props).toMatchObject({
|
|
61
|
+
variant: 'primary',
|
|
62
|
+
testId: 'nested-button',
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -1,54 +1,63 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { Alert, Button, ButtonRow, Text } from
|
|
4
|
-
import {
|
|
3
|
+
import { Alert, Button, ButtonRow, Text } from "../../../index.js";
|
|
4
|
+
import { createRenderer } from "../index.js";
|
|
5
5
|
describe('maybeFindChild()', () => {
|
|
6
6
|
it('should return direct child from the root node', () => {
|
|
7
|
-
const {
|
|
7
|
+
const { render, maybeFindChild } = createRenderer('crm.record.tab');
|
|
8
|
+
render(_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: "Button 1" }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
8
9
|
const alert = maybeFindChild(Alert);
|
|
9
10
|
expect(alert).toBeDefined();
|
|
10
11
|
expect(alert?.props).toEqual({ title: 'My Alert' });
|
|
11
12
|
});
|
|
12
13
|
it('should return null when direct child is not found', () => {
|
|
13
|
-
const { maybeFindChild } =
|
|
14
|
+
const { render, maybeFindChild } = createRenderer('crm.record.tab');
|
|
15
|
+
render(_jsx(_Fragment, { children: _jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: "Button 1" }) }) }));
|
|
14
16
|
const text = maybeFindChild(Text);
|
|
15
17
|
expect(text).toBeNull();
|
|
16
18
|
});
|
|
17
19
|
it('should only find direct children, not nested descendants', () => {
|
|
18
|
-
const {
|
|
20
|
+
const { render, maybeFindChild } = createRenderer('crm.record.tab');
|
|
21
|
+
render(_jsxs(_Fragment, { children: [_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: "Button 1" }) }), _jsx(Alert, { title: "My Alert" })] }));
|
|
19
22
|
const button = maybeFindChild(Button);
|
|
20
23
|
expect(button).toBeNull();
|
|
21
24
|
});
|
|
22
25
|
it('should return first direct child when multiple children match', () => {
|
|
23
|
-
const {
|
|
26
|
+
const { render, maybeFindChild } = createRenderer('crm.record.tab');
|
|
27
|
+
render(_jsxs(_Fragment, { children: [_jsx(Alert, { title: "First Alert" }), _jsx(Alert, { title: "Second Alert" }), _jsx(Alert, { title: "Third Alert" })] }));
|
|
24
28
|
const alert = maybeFindChild(Alert);
|
|
25
29
|
expect(alert).toBeDefined();
|
|
26
30
|
expect(alert?.props).toMatchObject({ title: 'First Alert' });
|
|
27
31
|
});
|
|
28
32
|
it('should support matcher function', () => {
|
|
29
|
-
const { maybeFindChild } =
|
|
33
|
+
const { render, maybeFindChild } = createRenderer('crm.record.tab');
|
|
34
|
+
render(_jsxs(_Fragment, { children: [_jsx(Alert, { title: "First Alert" }), _jsx(Alert, { title: "Second Alert" })] }));
|
|
30
35
|
const secondAlert = maybeFindChild(Alert, (node) => node.props.title === 'Second Alert');
|
|
31
36
|
expect(secondAlert).toBeDefined();
|
|
32
37
|
expect(secondAlert?.props).toMatchObject({ title: 'Second Alert' });
|
|
33
38
|
});
|
|
34
39
|
it('should return null when matcher function does not match any children', () => {
|
|
35
|
-
const { maybeFindChild } =
|
|
40
|
+
const { render, maybeFindChild } = createRenderer('crm.record.tab');
|
|
41
|
+
render(_jsxs(_Fragment, { children: [_jsx(Alert, { title: "First Alert" }), _jsx(Alert, { title: "Second Alert" })] }));
|
|
36
42
|
const thirdAlert = maybeFindChild(Alert, (node) => node.props.title === 'Third Alert');
|
|
37
43
|
expect(thirdAlert).toBeNull();
|
|
38
44
|
});
|
|
39
45
|
it('should support matcher object', () => {
|
|
40
|
-
const { maybeFindChild } =
|
|
46
|
+
const { render, maybeFindChild } = createRenderer('crm.record.tab');
|
|
47
|
+
render(_jsxs(_Fragment, { children: [_jsx(Alert, { title: "First Alert" }), _jsx(Alert, { title: "Second Alert" })] }));
|
|
41
48
|
const secondAlert = maybeFindChild(Alert, { title: 'Second Alert' });
|
|
42
49
|
expect(secondAlert).toBeDefined();
|
|
43
50
|
expect(secondAlert?.props).toMatchObject({ title: 'Second Alert' });
|
|
44
51
|
});
|
|
45
52
|
it('should return null when matcher object does not match any children', () => {
|
|
46
|
-
const { maybeFindChild } =
|
|
53
|
+
const { render, maybeFindChild } = createRenderer('crm.record.tab');
|
|
54
|
+
render(_jsxs(_Fragment, { children: [_jsx(Alert, { title: "First Alert" }), _jsx(Alert, { title: "Second Alert" })] }));
|
|
47
55
|
const thirdAlert = maybeFindChild(Alert, { title: 'Third Alert' });
|
|
48
56
|
expect(thirdAlert).toBeNull();
|
|
49
57
|
});
|
|
50
58
|
it('should work on nested element nodes', () => {
|
|
51
|
-
const { find } =
|
|
59
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
60
|
+
render(_jsx(_Fragment, { children: _jsxs(ButtonRow, { children: [_jsx(Button, { variant: "primary", children: "Button 1" }), _jsx(Button, { variant: "secondary", children: "Button 2" })] }) }));
|
|
52
61
|
const buttonRow = find(ButtonRow);
|
|
53
62
|
const primaryButton = buttonRow.maybeFindChild(Button, {
|
|
54
63
|
variant: 'primary',
|
|
@@ -57,7 +66,8 @@ describe('maybeFindChild()', () => {
|
|
|
57
66
|
expect(primaryButton?.props).toMatchObject({ variant: 'primary' });
|
|
58
67
|
});
|
|
59
68
|
it('should return null on nested element when child not found', () => {
|
|
60
|
-
const { find } =
|
|
69
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
70
|
+
render(_jsx(_Fragment, { children: _jsx(ButtonRow, { children: _jsx(Button, { variant: "secondary", children: "Button 1" }) }) }));
|
|
61
71
|
const buttonRow = find(ButtonRow);
|
|
62
72
|
const text = buttonRow.maybeFindChild(Text);
|
|
63
73
|
expect(text).toBeNull();
|