@hubspot/ui-extensions 0.11.2 → 0.11.3
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 +5 -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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, it } from 'vitest';
|
|
2
|
+
import { createRenderer } from "../index.js";
|
|
3
|
+
describe('mock actions', () => {
|
|
4
|
+
it('should provide the ability to spy on the actions for the "crm.record.tab" extension point', () => {
|
|
5
|
+
const { mocks } = createRenderer('crm.record.tab');
|
|
6
|
+
const { actions } = mocks;
|
|
7
|
+
actions.reloadPage();
|
|
8
|
+
expect(actions.reloadPage.callCount).toBe(1);
|
|
9
|
+
actions.onCrmPropertiesUpdate(['firstname', 'lastname'], () => { });
|
|
10
|
+
expect(actions.onCrmPropertiesUpdate.callCount).toBe(1);
|
|
11
|
+
});
|
|
12
|
+
it('should provide the ability to spy on the actions for the "settings" extension point', () => {
|
|
13
|
+
const { mocks } = createRenderer('settings');
|
|
14
|
+
const { actions } = mocks;
|
|
15
|
+
actions.addAlert({
|
|
16
|
+
message: 'Test Alert',
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describe, it } from 'vitest';
|
|
2
|
+
import { createRenderer } from "../index.js";
|
|
3
|
+
describe('mock context', () => {
|
|
4
|
+
it('should provide reasonable mock data for the "crm.record.tab" extension point', () => {
|
|
5
|
+
const { mocks } = createRenderer('crm.record.tab');
|
|
6
|
+
const { context } = mocks;
|
|
7
|
+
expect(context.location).toBe('crm.record.tab');
|
|
8
|
+
expect(context.user.email).toBe('fake_email@example.com');
|
|
9
|
+
expect(context.user.firstName).toBe('fake_firstName');
|
|
10
|
+
expect(context.user.lastName).toBe('fake_lastName');
|
|
11
|
+
expect(context.portal.id).toBe(123);
|
|
12
|
+
expect(context.portal.timezone).toBe('America/New_York');
|
|
13
|
+
expect(context.crm.objectId).toBe(123);
|
|
14
|
+
expect(context.crm.objectTypeId).toBe('0-1');
|
|
15
|
+
expect(context.variables).toEqual({ fake_variable: 'fake_value' });
|
|
16
|
+
});
|
|
17
|
+
it('should provide reasonable mock data for the "settings" extension point', () => {
|
|
18
|
+
const { mocks } = createRenderer('settings');
|
|
19
|
+
const { context } = mocks;
|
|
20
|
+
expect(context.location).toBe('settings');
|
|
21
|
+
expect(context.portal.id).toBe(123);
|
|
22
|
+
expect(context.portal.timezone).toBe('America/New_York');
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, it } from 'vitest';
|
|
2
|
+
import { createRenderer } from "../index.js";
|
|
3
|
+
import { ServerlessExecutionStatus, } from "../../../shared/types/http-requests.js";
|
|
4
|
+
describe('mock runServerlessFunction', () => {
|
|
5
|
+
it('should provide the ability to spy on the runServerlessFunction function', async () => {
|
|
6
|
+
const { mocks } = createRenderer('crm.record.tab');
|
|
7
|
+
const { runServerlessFunction } = mocks;
|
|
8
|
+
const serverlessExecutionResult = {
|
|
9
|
+
status: ServerlessExecutionStatus.Success,
|
|
10
|
+
response: {
|
|
11
|
+
myFakeData: 'hello',
|
|
12
|
+
anotherFakeData: 'bye',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
runServerlessFunction.nextResult(Promise.resolve(serverlessExecutionResult));
|
|
16
|
+
const result = await runServerlessFunction({
|
|
17
|
+
name: 'fake_function',
|
|
18
|
+
parameters: {
|
|
19
|
+
param1: 'value1',
|
|
20
|
+
},
|
|
21
|
+
propertiesToSend: ['prop1', 'prop2'],
|
|
22
|
+
});
|
|
23
|
+
expect(result).toEqual(serverlessExecutionResult);
|
|
24
|
+
expect(runServerlessFunction.callCount).toBe(1);
|
|
25
|
+
expect(runServerlessFunction.calls[0]).toEqual([
|
|
26
|
+
{
|
|
27
|
+
name: 'fake_function',
|
|
28
|
+
parameters: {
|
|
29
|
+
param1: 'value1',
|
|
30
|
+
},
|
|
31
|
+
propertiesToSend: ['prop1', 'prop2'],
|
|
32
|
+
},
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { Text } from "../../../index.js";
|
|
4
|
+
import { createRenderer } from "../index.js";
|
|
5
|
+
import { useAssociations } from "../../../crm/index.js";
|
|
6
|
+
function MyComponent() {
|
|
7
|
+
const { results, isLoading, error } = useAssociations({
|
|
8
|
+
toObjectType: '0-1',
|
|
9
|
+
properties: ['firstname', 'lastname'],
|
|
10
|
+
pageLength: 10,
|
|
11
|
+
});
|
|
12
|
+
if (isLoading) {
|
|
13
|
+
return _jsx(Text, { children: "Loading..." });
|
|
14
|
+
}
|
|
15
|
+
if (error) {
|
|
16
|
+
return _jsx(Text, { children: "Something went wrong!" });
|
|
17
|
+
}
|
|
18
|
+
return (_jsx(_Fragment, { children: results.map((result) => (_jsxs(Text, { children: [result.properties.firstname, " ", result.properties.lastname] }, result.toObjectId))) }));
|
|
19
|
+
}
|
|
20
|
+
describe('mock useAssociations', () => {
|
|
21
|
+
it('should provide a default mock implementation', () => {
|
|
22
|
+
const { render } = createRenderer('crm.record.tab');
|
|
23
|
+
const { findAll } = render(_jsx(MyComponent, {}));
|
|
24
|
+
const textNodes = findAll(Text);
|
|
25
|
+
expect(textNodes.length).toEqual(1);
|
|
26
|
+
expect(textNodes[0].text).toEqual('fake_firstname fake_lastname');
|
|
27
|
+
});
|
|
28
|
+
it('should allow mocking the next function result', () => {
|
|
29
|
+
const { render, mocks } = createRenderer('crm.record.tab');
|
|
30
|
+
mocks.useAssociations.nextResult({
|
|
31
|
+
results: [],
|
|
32
|
+
error: new Error('Something went wrong!'),
|
|
33
|
+
isLoading: false,
|
|
34
|
+
pagination: {
|
|
35
|
+
hasNextPage: false,
|
|
36
|
+
hasPreviousPage: false,
|
|
37
|
+
currentPage: 1,
|
|
38
|
+
pageSize: 10,
|
|
39
|
+
nextPage: () => { },
|
|
40
|
+
previousPage: () => { },
|
|
41
|
+
reset: () => { },
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const { find } = render(_jsx(MyComponent, {}));
|
|
45
|
+
expect(find(Text).text).toEqual('Something went wrong!');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { Text } from "../../../index.js";
|
|
4
|
+
import { createRenderer } from "../index.js";
|
|
5
|
+
import { useCrmProperties } from "../../../crm/index.js";
|
|
6
|
+
function MyComponent() {
|
|
7
|
+
const { properties, isLoading, error } = useCrmProperties([
|
|
8
|
+
'firstname',
|
|
9
|
+
'lastname',
|
|
10
|
+
]);
|
|
11
|
+
if (isLoading) {
|
|
12
|
+
return _jsx(Text, { children: "Loading..." });
|
|
13
|
+
}
|
|
14
|
+
if (error) {
|
|
15
|
+
return _jsx(Text, { children: "Something went wrong!" });
|
|
16
|
+
}
|
|
17
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Text, { children: ["First name: ", properties.firstname] }), _jsxs(Text, { children: ["Last name: ", properties.lastname] })] }));
|
|
18
|
+
}
|
|
19
|
+
describe('mock useCrmProperties', () => {
|
|
20
|
+
it('should provide a default mock implementation', () => {
|
|
21
|
+
const { render } = createRenderer('crm.record.tab');
|
|
22
|
+
const { findAll } = render(_jsx(MyComponent, {}));
|
|
23
|
+
const textNodes = findAll(Text);
|
|
24
|
+
expect(textNodes.length).toEqual(2);
|
|
25
|
+
expect(textNodes[0].text).toEqual('First name: fake_firstname');
|
|
26
|
+
expect(textNodes[1].text).toEqual('Last name: fake_lastname');
|
|
27
|
+
});
|
|
28
|
+
it('should allow mocking the next function result', () => {
|
|
29
|
+
const { render, mocks } = createRenderer('crm.record.tab');
|
|
30
|
+
mocks.useCrmProperties.nextResult({
|
|
31
|
+
properties: {},
|
|
32
|
+
error: new Error('Something went wrong!'),
|
|
33
|
+
isLoading: false,
|
|
34
|
+
});
|
|
35
|
+
const { find } = render(_jsx(MyComponent, {}));
|
|
36
|
+
expect(find(Text).text).toEqual('Something went wrong!');
|
|
37
|
+
});
|
|
38
|
+
it('should allow providing a custom mock function', () => {
|
|
39
|
+
const { render, mocks, findAll } = createRenderer('crm.record.tab');
|
|
40
|
+
mocks.useCrmProperties.willCall((propertyNames) => {
|
|
41
|
+
const properties = propertyNames.reduce((acc, propertyName) => {
|
|
42
|
+
acc[propertyName] = propertyName.toUpperCase();
|
|
43
|
+
return acc;
|
|
44
|
+
}, {});
|
|
45
|
+
return {
|
|
46
|
+
properties,
|
|
47
|
+
error: null,
|
|
48
|
+
isLoading: false,
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
render(_jsx(MyComponent, {}));
|
|
52
|
+
const textNodes = findAll(Text);
|
|
53
|
+
const firstNameText = textNodes[0];
|
|
54
|
+
const lastNameText = textNodes[1];
|
|
55
|
+
expect(firstNameText.isMatch(Text) && firstNameText.text).toEqual('First name: FIRSTNAME');
|
|
56
|
+
expect(lastNameText.isMatch(Text) && lastNameText.text).toEqual('Last name: LASTNAME');
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { Button, ButtonRow } from "../../../index.js";
|
|
4
|
+
import { createRenderer } from "../index.js";
|
|
5
|
+
describe('props', () => {
|
|
6
|
+
it('should remove the children prop from the props object', () => {
|
|
7
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
8
|
+
render(_jsx(_Fragment, { children: _jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: "Click me!" }) }) }));
|
|
9
|
+
const buttonRow = find(ButtonRow);
|
|
10
|
+
// @ts-expect-error - children should not be exposed in props
|
|
11
|
+
expect(buttonRow.props.children).toBeUndefined();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from "../../../index.js";
|
|
3
|
+
import { createRenderer } from "../index.js";
|
|
4
|
+
import { DuplicateTestIdError } from "../internal/errors.js";
|
|
5
|
+
describe('testId', () => {
|
|
6
|
+
it('should throw DuplicateTestIdError when testId is already in use', () => {
|
|
7
|
+
const { render } = createRenderer('crm.record.tab');
|
|
8
|
+
let error = null;
|
|
9
|
+
try {
|
|
10
|
+
render(_jsxs(_Fragment, { children: [_jsx(Button, { variant: "primary", testId: "my-button", children: "Click me" }), _jsx(Button, { variant: "secondary", testId: "my-button", children: "Click me" })] }));
|
|
11
|
+
}
|
|
12
|
+
catch (_error) {
|
|
13
|
+
error = _error;
|
|
14
|
+
}
|
|
15
|
+
expect(error).toBeInstanceOf(DuplicateTestIdError);
|
|
16
|
+
expect(error?.message).toMatchSnapshot();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { describe, expect, it } from 'vitest';
|
|
4
|
-
import { Button } from
|
|
5
|
-
import {
|
|
6
|
-
import { InvalidEventFunctionError, MissingEventFunctionError, } from
|
|
4
|
+
import { Button } from "../../../index.js";
|
|
5
|
+
import { createRenderer } from "../index.js";
|
|
6
|
+
import { InvalidEventFunctionError, MissingEventFunctionError, } from "../internal/errors.js";
|
|
7
7
|
describe('trigger()', () => {
|
|
8
8
|
it('should allow events to be triggered', () => {
|
|
9
9
|
function Counter() {
|
|
@@ -13,7 +13,8 @@ describe('trigger()', () => {
|
|
|
13
13
|
};
|
|
14
14
|
return (_jsxs(Button, { variant: "primary", onClick: handleClick, children: ["Clicked ", count, " times"] }));
|
|
15
15
|
}
|
|
16
|
-
const { find } =
|
|
16
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
17
|
+
render(_jsx(Counter, {}));
|
|
17
18
|
expect(find(Button).text).toEqual('Clicked 0 times');
|
|
18
19
|
find(Button).trigger('onClick');
|
|
19
20
|
expect(find(Button).text).toEqual('Clicked 1 times');
|
|
@@ -22,7 +23,8 @@ describe('trigger()', () => {
|
|
|
22
23
|
function Counter() {
|
|
23
24
|
return _jsx(Button, { variant: "primary", children: "Click me!" });
|
|
24
25
|
}
|
|
25
|
-
const { find } =
|
|
26
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
27
|
+
render(_jsx(Counter, {}));
|
|
26
28
|
expect(() => {
|
|
27
29
|
find(Button).trigger('onClick');
|
|
28
30
|
}).toThrow(MissingEventFunctionError);
|
|
@@ -32,7 +34,8 @@ describe('trigger()', () => {
|
|
|
32
34
|
const handleClick = {};
|
|
33
35
|
return (_jsx(Button, { variant: "primary", onClick: handleClick, children: "Click me!" }));
|
|
34
36
|
}
|
|
35
|
-
const { find } =
|
|
37
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
38
|
+
render(_jsx(Counter, {}));
|
|
36
39
|
expect(() => {
|
|
37
40
|
find(Button).trigger('onClick');
|
|
38
41
|
}).toThrow(InvalidEventFunctionError);
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { Button, ButtonRow, Text } from
|
|
4
|
-
import {
|
|
5
|
-
import { isRenderedElementNode, isRenderedFragmentNode, isRenderedRootNode, isRenderedTextNode, } from
|
|
6
|
-
import { RenderedNodeType } from
|
|
3
|
+
import { Button, ButtonRow, Text } from "../../../index.js";
|
|
4
|
+
import { createRenderer } from "../index.js";
|
|
5
|
+
import { isRenderedElementNode, isRenderedFragmentNode, isRenderedRootNode, isRenderedTextNode, } from "../type-utils.js";
|
|
6
|
+
import { RenderedNodeType } from "../types.js";
|
|
7
7
|
const TestComponent = () => (_jsx(Button, { overlay: _jsx(Text, { children: "Hello" }), children: "Text content" }));
|
|
8
8
|
const setupTestNodes = () => {
|
|
9
|
-
const { find, getRootNode } =
|
|
9
|
+
const { render, find, getRootNode } = createRenderer('crm.record.tab');
|
|
10
|
+
render(_jsx(TestComponent, {}));
|
|
10
11
|
const elementNode = find(Button);
|
|
11
12
|
const rootNode = getRootNode();
|
|
12
|
-
const textNode = find(Button).
|
|
13
|
+
const textNode = find(Button).childNodes[0];
|
|
13
14
|
const fragmentNode = find(Button).props.overlay;
|
|
14
15
|
return {
|
|
15
16
|
elementNode,
|
|
@@ -121,9 +122,10 @@ describe('type guard functions', () => {
|
|
|
121
122
|
});
|
|
122
123
|
describe('type narrowing', () => {
|
|
123
124
|
it('should correctly narrow types for element nodes', () => {
|
|
124
|
-
const { find } =
|
|
125
|
+
const { render, find } = createRenderer('crm.record.tab');
|
|
126
|
+
render(_jsx(ButtonRow, { children: _jsx(Button, { variant: "primary", children: "Click me" }) }));
|
|
125
127
|
const buttonRow = find(ButtonRow);
|
|
126
|
-
const firstChild = buttonRow.
|
|
128
|
+
const firstChild = buttonRow.childNodes[0];
|
|
127
129
|
if (isRenderedElementNode(firstChild)) {
|
|
128
130
|
expect(firstChild.name).toBe('Button');
|
|
129
131
|
expect(firstChild.props.variant).toBe('primary');
|
|
@@ -144,7 +146,7 @@ describe('type guard functions', () => {
|
|
|
144
146
|
it('should correctly narrow types for root nodes', () => {
|
|
145
147
|
const { rootNode } = setupTestNodes();
|
|
146
148
|
if (isRenderedRootNode(rootNode)) {
|
|
147
|
-
expect(rootNode.
|
|
149
|
+
expect(rootNode.childNodes.length).toBeGreaterThan(0);
|
|
148
150
|
}
|
|
149
151
|
else {
|
|
150
152
|
throw new Error('Expected root node');
|
|
@@ -153,7 +155,7 @@ describe('type guard functions', () => {
|
|
|
153
155
|
it('should correctly narrow types for fragment nodes', () => {
|
|
154
156
|
const { fragmentNode } = setupTestNodes();
|
|
155
157
|
if (isRenderedFragmentNode(fragmentNode)) {
|
|
156
|
-
expect(fragmentNode.
|
|
158
|
+
expect(fragmentNode.childNodes.length).toBe(1);
|
|
157
159
|
}
|
|
158
160
|
else {
|
|
159
161
|
throw new Error('Expected fragment node');
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
import { Button } from
|
|
5
|
-
import {
|
|
6
|
-
import { WaitForTimeoutError } from
|
|
4
|
+
import { Button } from "../../../index.js";
|
|
5
|
+
import { createRenderer } from "../index.js";
|
|
6
|
+
import { WaitForTimeoutError } from "../internal/errors.js";
|
|
7
7
|
describe('waitFor()', () => {
|
|
8
8
|
beforeEach(() => {
|
|
9
9
|
// tell vitest we use mocked time
|
|
@@ -23,7 +23,8 @@ describe('waitFor()', () => {
|
|
|
23
23
|
}, []);
|
|
24
24
|
return _jsxs(Button, { variant: "primary", children: ["Count: ", count] });
|
|
25
25
|
}
|
|
26
|
-
const { find, waitFor } =
|
|
26
|
+
const { render, find, waitFor } = createRenderer('crm.record.tab');
|
|
27
|
+
render(_jsx(AsyncCounter, {}));
|
|
27
28
|
expect(find(Button).text).toEqual('Count: 0');
|
|
28
29
|
const waitForPromise = waitFor(() => {
|
|
29
30
|
expect(find(Button).text).toEqual('Count: 1');
|
|
@@ -42,7 +43,8 @@ describe('waitFor()', () => {
|
|
|
42
43
|
}, []);
|
|
43
44
|
return _jsxs(Button, { variant: "primary", children: ["Count: ", count] });
|
|
44
45
|
}
|
|
45
|
-
const { find, waitFor } =
|
|
46
|
+
const { render, find, waitFor } = createRenderer('crm.record.tab');
|
|
47
|
+
render(_jsx(AsyncCounter, {}));
|
|
46
48
|
expect(find(Button).text).toEqual('Count: 0');
|
|
47
49
|
const waitForPromise = waitFor(() => {
|
|
48
50
|
expect(find(Button).text).toEqual('Count: 1');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from './type-utils';
|
|
2
|
-
export * from './render';
|
|
3
|
-
export * from './types';
|
|
1
|
+
export * from './type-utils.ts';
|
|
2
|
+
export * from './render.tsx';
|
|
3
|
+
export * from './types.ts';
|
|
4
|
+
export * from './utils.ts';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./type-utils.js";
|
|
2
|
+
export * from "./render.js";
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
export * from "./utils.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type RenderedChildNode } from '../types';
|
|
2
|
-
export declare const
|
|
1
|
+
import { type RenderedChildNode } from '../types.ts';
|
|
2
|
+
export declare const EMPTY_RENDERED_CHILD_NODES: RenderedChildNode[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const EMPTY_RENDERED_CHILD_NODES = [];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type RemoteRoot } from '@remote-ui/core';
|
|
2
|
-
import type { RenderedRootNodeInternal } from './types-internal';
|
|
2
|
+
import type { RenderedRootNodeInternal } from './types-internal.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Converts a remote root node to a rendered root node. After conversion, the rendered root node will
|
|
5
|
-
* have its
|
|
5
|
+
* have its `childNodes` property set to the converted child nodes.
|
|
6
6
|
*
|
|
7
7
|
* @param rootNode The rendered root node to convert.
|
|
8
8
|
* @param remoteRoot The remote root node to convert.
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { KIND_COMPONENT, KIND_FRAGMENT, KIND_TEXT, } from '@remote-ui/core';
|
|
2
|
-
import { createElementNode } from
|
|
3
|
-
import { InvalidFragmentPropArrayError } from
|
|
4
|
-
import { createFragmentNode } from
|
|
5
|
-
import { createTextNode } from
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
2
|
+
import { createElementNode } from "./element.js";
|
|
3
|
+
import { DuplicateTestIdError, InvalidFragmentPropArrayError, } from "./errors.js";
|
|
4
|
+
import { createFragmentNode } from "./fragment.js";
|
|
5
|
+
import { createTextNode } from "./text.js";
|
|
6
|
+
import { __hubSpotComponentRegistry } from "../../../shared/remoteComponents.js";
|
|
7
|
+
import { isRenderedTextNode } from "../type-utils.js";
|
|
8
|
+
import { EMPTY_RENDERED_CHILD_NODES } from "./constants.js";
|
|
9
|
+
import { asRenderedParentNode } from "./type-utils-internal.js";
|
|
9
10
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
10
11
|
/**
|
|
11
12
|
* Converts a remote props object to a props object that can be attached to a rendered element node.
|
|
@@ -31,15 +32,15 @@ const convertRemoteProps = (document, componentName, remoteProps) => {
|
|
|
31
32
|
}
|
|
32
33
|
const fragmentNode = createFragmentNode(document);
|
|
33
34
|
if (remotePropValue == null) {
|
|
34
|
-
fragmentNode.
|
|
35
|
+
fragmentNode.childNodes = EMPTY_RENDERED_CHILD_NODES;
|
|
35
36
|
}
|
|
36
37
|
else if (typeof remotePropValue === 'string') {
|
|
37
38
|
const text = remotePropValue;
|
|
38
39
|
fragmentNode.text = text;
|
|
39
|
-
fragmentNode.
|
|
40
|
+
fragmentNode.childNodes = [createTextNode(document, text)];
|
|
40
41
|
}
|
|
41
42
|
else if (remotePropValue.kind === KIND_FRAGMENT) {
|
|
42
|
-
convertRemoteChildren(fragmentNode, remotePropValue);
|
|
43
|
+
convertRemoteChildren(document, fragmentNode, remotePropValue);
|
|
43
44
|
}
|
|
44
45
|
convertedProps[propName] = fragmentNode;
|
|
45
46
|
}
|
|
@@ -59,7 +60,7 @@ const convertRemoteProps = (document, componentName, remoteProps) => {
|
|
|
59
60
|
*/
|
|
60
61
|
const convertChildNode = (document, remoteChild) => {
|
|
61
62
|
if (remoteChild.kind === KIND_TEXT) {
|
|
62
|
-
return createTextNode(remoteChild);
|
|
63
|
+
return createTextNode(document, remoteChild);
|
|
63
64
|
}
|
|
64
65
|
else if (remoteChild.kind === KIND_COMPONENT) {
|
|
65
66
|
const name = remoteChild.type;
|
|
@@ -68,7 +69,23 @@ const convertChildNode = (document, remoteChild) => {
|
|
|
68
69
|
if (!__hubSpotComponentRegistry.isAllowedComponentName(name)) {
|
|
69
70
|
document.addInvalidComponentName(name);
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
+
const { testId } = props;
|
|
73
|
+
if (testId) {
|
|
74
|
+
// If the element has a test ID we will put the element in a lookup map for
|
|
75
|
+
// efficient queries using `findByTestId()`/`maybeFindByTestId()`.
|
|
76
|
+
// First, we need to check if it is already in use and throw an error if it is.
|
|
77
|
+
const existingElement = document.testIdToElementMap.get(testId);
|
|
78
|
+
if (existingElement) {
|
|
79
|
+
throw new DuplicateTestIdError({
|
|
80
|
+
testId,
|
|
81
|
+
previousElement: existingElement,
|
|
82
|
+
newElement: elementNode,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// If the test ID is not already in use, we can add the element to the lookup map.
|
|
86
|
+
document.testIdToElementMap.set(testId, elementNode);
|
|
87
|
+
}
|
|
88
|
+
convertRemoteChildren(document, elementNode, remoteChild);
|
|
72
89
|
return elementNode;
|
|
73
90
|
}
|
|
74
91
|
else {
|
|
@@ -76,14 +93,14 @@ const convertChildNode = (document, remoteChild) => {
|
|
|
76
93
|
}
|
|
77
94
|
};
|
|
78
95
|
/**
|
|
79
|
-
* Converts the children a remote parent node to
|
|
80
|
-
*
|
|
96
|
+
* Converts the children of a remote parent node to our rendered child nodes.
|
|
97
|
+
* After conversion, the rendered parent node will have its `childNodes` property set
|
|
98
|
+
* to the converted child nodes.
|
|
81
99
|
*
|
|
82
100
|
* @param parentNode The rendered parent node to convert.
|
|
83
101
|
* @param remoteParentNode The remote parent node to convert.
|
|
84
102
|
*/
|
|
85
|
-
const convertRemoteChildren = (parentNode, remoteParentNode) => {
|
|
86
|
-
const { document } = parentNode;
|
|
103
|
+
const convertRemoteChildren = (document, parentNode, remoteParentNode) => {
|
|
87
104
|
const remoteChildren = remoteParentNode.children;
|
|
88
105
|
if (remoteChildren == null) {
|
|
89
106
|
return;
|
|
@@ -91,11 +108,11 @@ const convertRemoteChildren = (parentNode, remoteParentNode) => {
|
|
|
91
108
|
if (typeof remoteChildren === 'string') {
|
|
92
109
|
const text = remoteChildren;
|
|
93
110
|
parentNode.text = text;
|
|
94
|
-
parentNode.
|
|
111
|
+
parentNode.childNodes = [createTextNode(document, text)];
|
|
95
112
|
return;
|
|
96
113
|
}
|
|
97
114
|
let text = null;
|
|
98
|
-
const
|
|
115
|
+
const convertedChildNodes = [];
|
|
99
116
|
let lastRenderedChild;
|
|
100
117
|
for (const remoteChild of remoteChildren) {
|
|
101
118
|
if (remoteChild.kind === KIND_TEXT) {
|
|
@@ -112,20 +129,21 @@ const convertRemoteChildren = (parentNode, remoteParentNode) => {
|
|
|
112
129
|
continue;
|
|
113
130
|
}
|
|
114
131
|
}
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
lastRenderedChild =
|
|
132
|
+
const renderedChildNode = convertChildNode(document, remoteChild);
|
|
133
|
+
convertedChildNodes.push(renderedChildNode);
|
|
134
|
+
lastRenderedChild = renderedChildNode;
|
|
118
135
|
}
|
|
119
136
|
parentNode.text = text;
|
|
120
|
-
parentNode.
|
|
137
|
+
parentNode.childNodes = convertedChildNodes;
|
|
121
138
|
};
|
|
122
139
|
/**
|
|
123
140
|
* Converts a remote root node to a rendered root node. After conversion, the rendered root node will
|
|
124
|
-
* have its
|
|
141
|
+
* have its `childNodes` property set to the converted child nodes.
|
|
125
142
|
*
|
|
126
143
|
* @param rootNode The rendered root node to convert.
|
|
127
144
|
* @param remoteRoot The remote root node to convert.
|
|
128
145
|
*/
|
|
129
146
|
export const convertRemoteRoot = (rootNode, remoteRoot) => {
|
|
130
|
-
|
|
147
|
+
const { document } = rootNode;
|
|
148
|
+
convertRemoteChildren(document, asRenderedParentNode(rootNode), remoteRoot);
|
|
131
149
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RenderedNode } from '../types.ts';
|
|
2
2
|
/**
|
|
3
3
|
* Logs a rendered node tree to the console for debugging purposes.
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
5
|
+
* @param node The node to log.
|
|
6
6
|
* @param label Optional label to display before the node tree.
|
|
7
7
|
*/
|
|
8
|
-
export declare const debugLog: (
|
|
8
|
+
export declare const debugLog: (node: RenderedNode, label?: string) => void;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { printNode } from
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
1
|
+
import { printNode } from "./print.js";
|
|
3
2
|
/**
|
|
4
3
|
* Logs a rendered node tree to the console for debugging purposes.
|
|
5
4
|
*
|
|
6
|
-
* @param
|
|
5
|
+
* @param node The node to log.
|
|
7
6
|
* @param label Optional label to display before the node tree.
|
|
8
7
|
*/
|
|
9
|
-
export const debugLog = (
|
|
10
|
-
const componentTreeString = printNode(
|
|
8
|
+
export const debugLog = (node, label) => {
|
|
9
|
+
const componentTreeString = printNode(node);
|
|
11
10
|
const separator = ''.padEnd(label?.length ?? 20, '=');
|
|
12
11
|
const logLines = [separator];
|
|
13
12
|
if (label) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RenderedDocumentInternal, RenderedRootNodeInternal } from './types-internal';
|
|
1
|
+
import type { RenderedDocumentInternal, RenderedRootNodeInternal } from './types-internal.ts';
|
|
2
2
|
export interface CreateDocumentOptions {
|
|
3
3
|
/**
|
|
4
4
|
* A function that can be called to get the latest rendered root node.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { act as reactAct } from 'react';
|
|
2
|
-
import { InvalidComponentsError } from
|
|
2
|
+
import { InvalidComponentsError } from "./errors.js";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a rendered document.
|
|
5
5
|
*
|
|
@@ -9,8 +9,11 @@ import { InvalidComponentsError } from './errors';
|
|
|
9
9
|
export const createDocument = (options) => {
|
|
10
10
|
const { getLatestRootNode } = options;
|
|
11
11
|
const invalidComponentNames = new Set();
|
|
12
|
+
// A lookup map of test IDs to elements.
|
|
13
|
+
const testIdToElementMap = new Map();
|
|
12
14
|
const document = {
|
|
13
15
|
rootNode: null,
|
|
16
|
+
testIdToElementMap,
|
|
14
17
|
batchUpdate: (run) => {
|
|
15
18
|
reactAct(run);
|
|
16
19
|
const latestRootNode = getLatestRootNode();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { UnknownComponentProps } from '../../../
|
|
2
|
-
import
|
|
1
|
+
import type { UnknownComponentProps } from '../../../shared/types/shared.ts';
|
|
2
|
+
import { RenderedElementNode } from '../types.ts';
|
|
3
|
+
import type { RenderedDocumentInternal } from './types-internal.ts';
|
|
3
4
|
/**
|
|
4
5
|
* Creates a rendered element node.
|
|
5
6
|
*
|
|
@@ -8,4 +9,4 @@ import type { RenderedDocumentInternal, RenderedElementNodeInternal } from './ty
|
|
|
8
9
|
* @param props The props of the element.
|
|
9
10
|
* @returns A rendered element node.
|
|
10
11
|
*/
|
|
11
|
-
export declare const createElementNode: (document: RenderedDocumentInternal, name: string, props: UnknownComponentProps) =>
|
|
12
|
+
export declare const createElementNode: (document: RenderedDocumentInternal, name: string, props: UnknownComponentProps) => RenderedElementNode;
|