@myparcel-dev/pdk-admin-component-tests 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +260 -0
- package/dist/TestSuite.d.ts +21 -0
- package/dist/common/index.d.ts +4 -0
- package/dist/common/runCommonComponentTests.d.ts +1 -0
- package/dist/common/runCommonInputTests.d.ts +2 -0
- package/dist/common/runHasPropTest.d.ts +1 -0
- package/dist/common/runHasSlotTest.d.ts +4 -0
- package/dist/components/index.d.ts +36 -0
- package/dist/components/runBadgeTest.d.ts +1 -0
- package/dist/components/runBoxTest.d.ts +1 -0
- package/dist/components/runButtonTest.d.ts +1 -0
- package/dist/components/runCheckboxGroupTest.d.ts +1 -0
- package/dist/components/runCheckboxInputTest.d.ts +1 -0
- package/dist/components/runCodeEditorTest.d.ts +1 -0
- package/dist/components/runColTest.d.ts +1 -0
- package/dist/components/runCurrencyInputTest.d.ts +1 -0
- package/dist/components/runDropDownButtonTest.d.ts +1 -0
- package/dist/components/runDropOffInputTest.d.ts +1 -0
- package/dist/components/runFormGroupTest.d.ts +1 -0
- package/dist/components/runHeadingTest.d.ts +1 -0
- package/dist/components/runIconTest.d.ts +1 -0
- package/dist/components/runImageTest.d.ts +1 -0
- package/dist/components/runLinkTest.d.ts +1 -0
- package/dist/components/runLoaderTest.d.ts +1 -0
- package/dist/components/runModalTest.d.ts +1 -0
- package/dist/components/runMultiDateInputTest.d.ts +1 -0
- package/dist/components/runMultiSelectInputTest.d.ts +1 -0
- package/dist/components/runNotificationTest.d.ts +1 -0
- package/dist/components/runNumberInputTest.d.ts +1 -0
- package/dist/components/runPlainWrapperTest.d.ts +1 -0
- package/dist/components/runRadioGroupTest.d.ts +1 -0
- package/dist/components/runRadioInputTest.d.ts +1 -0
- package/dist/components/runRowTest.d.ts +1 -0
- package/dist/components/runSelectInputTest.d.ts +1 -0
- package/dist/components/runSettingsDividerTest.d.ts +1 -0
- package/dist/components/runShippingMethodsInputTest.d.ts +1 -0
- package/dist/components/runTabNavButtonTest.d.ts +1 -0
- package/dist/components/runTableColTest.d.ts +1 -0
- package/dist/components/runTableRowTest.d.ts +1 -0
- package/dist/components/runTableTest.d.ts +1 -0
- package/dist/components/runTextAreaTest.d.ts +1 -0
- package/dist/components/runTextInputTest.d.ts +1 -0
- package/dist/components/runTimeInputTest.d.ts +1 -0
- package/dist/components/runToggleInputTest.d.ts +1 -0
- package/dist/components/runTriStateInputTest.d.ts +1 -0
- package/dist/helpers/createInputOptions.d.ts +4 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/wrapperPlugin.d.ts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/setup.d.ts +1 -0
- package/dist/tests/executeAdminComponentTest.d.ts +3 -0
- package/dist/tests/executePdkComponentTests.d.ts +2 -0
- package/dist/tests/index.d.ts +3 -0
- package/dist/tests/testMap.d.ts +4 -0
- package/dist/types.d.ts +10 -0
- package/package.json +62 -0
- package/src/TestSuite.ts +147 -0
- package/src/__tests__/__snapshots__/exports.spec.ts.snap +177 -0
- package/src/__tests__/exports.spec.ts +8 -0
- package/src/common/index.ts +4 -0
- package/src/common/runCommonComponentTests.ts +15 -0
- package/src/common/runCommonInputTests.ts +66 -0
- package/src/common/runHasPropTest.ts +17 -0
- package/src/common/runHasSlotTest.ts +25 -0
- package/src/components/index.ts +36 -0
- package/src/components/runBadgeTest.ts +9 -0
- package/src/components/runBoxTest.ts +17 -0
- package/src/components/runButtonTest.ts +37 -0
- package/src/components/runCheckboxGroupTest.ts +29 -0
- package/src/components/runCheckboxInputTest.ts +13 -0
- package/src/components/runCodeEditorTest.ts +11 -0
- package/src/components/runColTest.ts +11 -0
- package/src/components/runCurrencyInputTest.ts +13 -0
- package/src/components/runDropDownButtonTest.ts +81 -0
- package/src/components/runDropOffInputTest.ts +32 -0
- package/src/components/runFormGroupTest.ts +17 -0
- package/src/components/runHeadingTest.ts +12 -0
- package/src/components/runIconTest.ts +16 -0
- package/src/components/runImageTest.ts +22 -0
- package/src/components/runLinkTest.ts +12 -0
- package/src/components/runLoaderTest.ts +9 -0
- package/src/components/runModalTest.ts +28 -0
- package/src/components/runMultiDateInputTest.ts +10 -0
- package/src/components/runMultiSelectInputTest.ts +17 -0
- package/src/components/runNotificationTest.ts +40 -0
- package/src/components/runNumberInputTest.ts +13 -0
- package/src/components/runPlainWrapperTest.ts +12 -0
- package/src/components/runRadioGroupTest.ts +26 -0
- package/src/components/runRadioInputTest.ts +13 -0
- package/src/components/runRowTest.ts +11 -0
- package/src/components/runSelectInputTest.ts +30 -0
- package/src/components/runSettingsDividerTest.ts +16 -0
- package/src/components/runShippingMethodsInputTest.ts +23 -0
- package/src/components/runTabNavButtonTest.ts +17 -0
- package/src/components/runTableColTest.ts +11 -0
- package/src/components/runTableRowTest.ts +11 -0
- package/src/components/runTableTest.ts +13 -0
- package/src/components/runTextAreaTest.ts +12 -0
- package/src/components/runTextInputTest.ts +12 -0
- package/src/components/runTimeInputTest.ts +13 -0
- package/src/components/runToggleInputTest.ts +16 -0
- package/src/components/runTriStateInputTest.ts +15 -0
- package/src/helpers/createInputOptions.ts +19 -0
- package/src/helpers/index.ts +1 -0
- package/src/helpers/wrapperPlugin.ts +20 -0
- package/src/index.ts +5 -0
- package/src/setup.ts +4 -0
- package/src/tests/executeAdminComponentTest.ts +47 -0
- package/src/tests/executePdkComponentTests.ts +19 -0
- package/src/tests/index.ts +3 -0
- package/src/tests/testMap.ts +111 -0
- package/src/types.ts +24 -0
- package/src/vue.shims.d.ts +26 -0
package/src/TestSuite.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/* eslint-disable max-lines-per-function */
|
|
2
|
+
import {type Component as ComponentType, ref} from 'vue';
|
|
3
|
+
import {expect, it} from 'vitest';
|
|
4
|
+
import {merge} from 'lodash-unified';
|
|
5
|
+
import {type DOMWrapper, flushPromises, mount, type VueWrapper} from '@vue/test-utils';
|
|
6
|
+
import {type AdminComponent} from '@myparcel-dev/pdk-admin';
|
|
7
|
+
import {type InteractiveElementConfiguration} from '@myparcel-dev/vue-form-builder';
|
|
8
|
+
import {type AdditionalOptions, type ComponentTestOptions, type TestComponentMountingOptions} from './types';
|
|
9
|
+
import {createInputOptions} from './helpers';
|
|
10
|
+
import {runCommonComponentTests, runHasPropTest, runHasSlotTest} from './common';
|
|
11
|
+
|
|
12
|
+
const UPDATE_EVENT = 'update:modelValue';
|
|
13
|
+
|
|
14
|
+
export class TestSuite<
|
|
15
|
+
TestOptions extends ComponentTestOptions = ComponentTestOptions,
|
|
16
|
+
Component extends ComponentType = ComponentType,
|
|
17
|
+
> {
|
|
18
|
+
private defaultOptions: TestComponentMountingOptions<Component, TestOptions> | undefined = undefined;
|
|
19
|
+
|
|
20
|
+
private readonly component: Component;
|
|
21
|
+
|
|
22
|
+
private readonly componentName: AdminComponent | string;
|
|
23
|
+
|
|
24
|
+
public constructor(componentName: AdminComponent | string, component: Component) {
|
|
25
|
+
this.componentName = componentName;
|
|
26
|
+
this.component = {name: componentName, ...component};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public runCommonComponentTests(options?: TestComponentMountingOptions<Component, TestOptions> | undefined): void {
|
|
30
|
+
runCommonComponentTests(this.component, this.resolveOptions(options));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public runHasSlotTest(slot = 'default'): void {
|
|
34
|
+
runHasSlotTest(this.component, this.resolveOptions(), slot);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public runHasPropTest(prop: string, value: unknown = 'value'): void {
|
|
38
|
+
runHasPropTest(this.component, this.resolveOptions(), prop, value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public runCommonInputTests(additionalOptions: AdditionalOptions = {}): void {
|
|
42
|
+
const resolvedOptions = this.resolveOptions();
|
|
43
|
+
|
|
44
|
+
this.runHasPropTest('element', resolvedOptions?.props?.element);
|
|
45
|
+
|
|
46
|
+
it('can be disabled', () => {
|
|
47
|
+
const wrapper = mount(
|
|
48
|
+
this.component,
|
|
49
|
+
merge({}, resolvedOptions, {
|
|
50
|
+
props: {
|
|
51
|
+
element: {
|
|
52
|
+
...resolvedOptions?.props?.element,
|
|
53
|
+
isDisabled: ref(true),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const select = this.getSelectWrapper(wrapper);
|
|
60
|
+
const input = this.getInputWrapper(wrapper);
|
|
61
|
+
|
|
62
|
+
if (select.exists()) {
|
|
63
|
+
expect(select.attributes('disabled')).toBeDefined();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (input.exists()) {
|
|
67
|
+
expect(input.attributes('disabled')).toBeDefined();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it(`emits ${UPDATE_EVENT} event`, async () => {
|
|
72
|
+
expect.assertions(2);
|
|
73
|
+
const wrapper = mount(this.component, resolvedOptions);
|
|
74
|
+
|
|
75
|
+
const select = this.getSelectWrapper(wrapper);
|
|
76
|
+
const input = this.getInputWrapper(wrapper);
|
|
77
|
+
|
|
78
|
+
const valueToSet = additionalOptions?.value ?? 'test';
|
|
79
|
+
|
|
80
|
+
if (select.exists()) {
|
|
81
|
+
await select.setValue(valueToSet);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (input.exists()) {
|
|
85
|
+
await input.setValue(valueToSet);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
await flushPromises();
|
|
89
|
+
|
|
90
|
+
const emitted = wrapper.emitted();
|
|
91
|
+
|
|
92
|
+
expect(emitted).toHaveProperty(UPDATE_EVENT);
|
|
93
|
+
expect(emitted[UPDATE_EVENT]).toHaveLength(1);
|
|
94
|
+
/** @todo fix this */
|
|
95
|
+
// expect(emitted[UPDATE_EVENT][0]).toEqual([valueToSet]);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public createInputOptions<T>(
|
|
100
|
+
modelValue?: T,
|
|
101
|
+
options?: Partial<InteractiveElementConfiguration>,
|
|
102
|
+
): TestComponentMountingOptions<Component, TestOptions> {
|
|
103
|
+
this.defaultOptions = createInputOptions<T, Component, TestOptions>(modelValue, options);
|
|
104
|
+
|
|
105
|
+
return this.resolveOptions();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public getInputWrapper<NodeType extends Node>(wrapper: VueWrapper<Component>): DOMWrapper<NodeType> {
|
|
109
|
+
return this.getElementWrapper('input', wrapper);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public getSelectWrapper<NodeType extends Node>(wrapper: VueWrapper<Component>): DOMWrapper<NodeType> {
|
|
113
|
+
return this.getElementWrapper('select', wrapper);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public setOptions(
|
|
117
|
+
options: TestComponentMountingOptions<Component, TestOptions>,
|
|
118
|
+
): TestComponentMountingOptions<Component, TestOptions> {
|
|
119
|
+
this.defaultOptions = options;
|
|
120
|
+
|
|
121
|
+
return this.resolveOptions();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private getElementWrapper<NodeType extends Node>(
|
|
125
|
+
element: string,
|
|
126
|
+
wrapper: VueWrapper<Component>,
|
|
127
|
+
): DOMWrapper<NodeType> {
|
|
128
|
+
const byComponentName = wrapper.findByTestId(this.componentName);
|
|
129
|
+
|
|
130
|
+
return (byComponentName.exists()
|
|
131
|
+
? byComponentName?.find(element)
|
|
132
|
+
: wrapper.find(element)) as unknown as DOMWrapper<NodeType>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private resolveOptions(
|
|
136
|
+
options?: TestComponentMountingOptions<Component, TestOptions> | undefined,
|
|
137
|
+
): TestComponentMountingOptions<Component, TestOptions> {
|
|
138
|
+
return {
|
|
139
|
+
...this.defaultOptions,
|
|
140
|
+
...options,
|
|
141
|
+
props: {
|
|
142
|
+
...this.defaultOptions?.props,
|
|
143
|
+
...options?.props,
|
|
144
|
+
},
|
|
145
|
+
} as TestComponentMountingOptions<Component, TestOptions>;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`exports > exports from index.ts 1`] = `
|
|
4
|
+
[
|
|
5
|
+
"ActionButton",
|
|
6
|
+
"AdminAction",
|
|
7
|
+
"AdminComponent",
|
|
8
|
+
"AdminContextKey",
|
|
9
|
+
"AdminIcon",
|
|
10
|
+
"AdminInstanceContextKey",
|
|
11
|
+
"AdminModalKey",
|
|
12
|
+
"AdminView",
|
|
13
|
+
"BackendEndpoint",
|
|
14
|
+
"BulkSelectCheckbox",
|
|
15
|
+
"ChildProductSettingsView",
|
|
16
|
+
"FORM_KEYS",
|
|
17
|
+
"FORM_KEY_ACCOUNT_SETTINGS",
|
|
18
|
+
"FORM_KEY_CHILD_PRODUCT_SETTINGS",
|
|
19
|
+
"FORM_KEY_MODAL",
|
|
20
|
+
"FORM_KEY_MODAL_PRINT_OPTIONS",
|
|
21
|
+
"FORM_KEY_MODAL_RETURN_OPTIONS",
|
|
22
|
+
"FORM_KEY_MODAL_SHIPMENT_OPTIONS",
|
|
23
|
+
"FORM_KEY_PLUGIN_SETTINGS",
|
|
24
|
+
"FORM_KEY_PRODUCT_SETTINGS",
|
|
25
|
+
"FormHook",
|
|
26
|
+
"FrontendEndpoint",
|
|
27
|
+
"INJECT_ADMIN_INSTANCE",
|
|
28
|
+
"INJECT_GLOBAL_PDK_ADMIN",
|
|
29
|
+
"LogLevel",
|
|
30
|
+
"ModalsView",
|
|
31
|
+
"NotificationCategory",
|
|
32
|
+
"NotificationContainer",
|
|
33
|
+
"NotificationsView",
|
|
34
|
+
"OrderBoxView",
|
|
35
|
+
"OrderListItemView",
|
|
36
|
+
"PackageType",
|
|
37
|
+
"PdkAdmin",
|
|
38
|
+
"PlainElement",
|
|
39
|
+
"PluginSettingsView",
|
|
40
|
+
"ProductSettingsView",
|
|
41
|
+
"QUERY_KEY_ORDER",
|
|
42
|
+
"QUERY_KEY_SHIPMENT",
|
|
43
|
+
"ResetButton",
|
|
44
|
+
"ReturnsForm",
|
|
45
|
+
"ShipmentBarcode",
|
|
46
|
+
"ShipmentOptionsForm",
|
|
47
|
+
"ShipmentStatus",
|
|
48
|
+
"Size",
|
|
49
|
+
"SortType",
|
|
50
|
+
"Status",
|
|
51
|
+
"StatusIndicator",
|
|
52
|
+
"StopActionHandler",
|
|
53
|
+
"SubmitButton",
|
|
54
|
+
"TabNavigation",
|
|
55
|
+
"TestSuite",
|
|
56
|
+
"TriState",
|
|
57
|
+
"Variant",
|
|
58
|
+
"allAdminComponentNames",
|
|
59
|
+
"createAdminConfig",
|
|
60
|
+
"createFormElement",
|
|
61
|
+
"createHandlerWithParameters",
|
|
62
|
+
"createLogger",
|
|
63
|
+
"createMutationHandler",
|
|
64
|
+
"createOrdersMutationHandler",
|
|
65
|
+
"createPdkAdmin",
|
|
66
|
+
"createPdkAdminPlugin",
|
|
67
|
+
"createQueryHandler",
|
|
68
|
+
"createShipmentsMutationHandler",
|
|
69
|
+
"defineAction",
|
|
70
|
+
"deleteAccountAction",
|
|
71
|
+
"doMutate",
|
|
72
|
+
"downloadLogsAction",
|
|
73
|
+
"executeAction",
|
|
74
|
+
"executeAdminComponentTest",
|
|
75
|
+
"executeAfterHandle",
|
|
76
|
+
"executeBeforeHandle",
|
|
77
|
+
"executeHandler",
|
|
78
|
+
"executeNextAction",
|
|
79
|
+
"executePdkComponentTests",
|
|
80
|
+
"fetchDynamicContextAction",
|
|
81
|
+
"fetchPluginSettingsViewContextAction",
|
|
82
|
+
"generateFieldId",
|
|
83
|
+
"getActionIdentifier",
|
|
84
|
+
"modalCloseAction",
|
|
85
|
+
"modalSubmitFormAction",
|
|
86
|
+
"openOrPrintPdf",
|
|
87
|
+
"optionalAdminActionContainerComponentNames",
|
|
88
|
+
"optionalAdminComponentNames",
|
|
89
|
+
"optionalAdminPlainWrapperComponentNames",
|
|
90
|
+
"orderExportAction",
|
|
91
|
+
"orderExportToShipmentsAction",
|
|
92
|
+
"orderViewInBackofficeAction",
|
|
93
|
+
"ordersEditAction",
|
|
94
|
+
"ordersExportPrintShipmentsAction",
|
|
95
|
+
"ordersFetchAction",
|
|
96
|
+
"ordersPrintAction",
|
|
97
|
+
"ordersUpdateAction",
|
|
98
|
+
"pluginSettingsUpdateAction",
|
|
99
|
+
"prefixComponent",
|
|
100
|
+
"refreshAccountAction",
|
|
101
|
+
"requiredAdminComponentNames",
|
|
102
|
+
"resolveFormComponent",
|
|
103
|
+
"resolveOrderParameters",
|
|
104
|
+
"resolvePrintParameters",
|
|
105
|
+
"resolveQuerySuffix",
|
|
106
|
+
"shipmentActions",
|
|
107
|
+
"shipmentsDeleteAction",
|
|
108
|
+
"shipmentsExportReturnAction",
|
|
109
|
+
"shipmentsPrintAction",
|
|
110
|
+
"shipmentsUpdateAction",
|
|
111
|
+
"switchToAcceptanceApiAction",
|
|
112
|
+
"switchToProductionApiAction",
|
|
113
|
+
"updateAccountAction",
|
|
114
|
+
"useActionStore",
|
|
115
|
+
"useAdminConfig",
|
|
116
|
+
"useAppInfo",
|
|
117
|
+
"useCheckboxGroupContext",
|
|
118
|
+
"useCreateWebhooksMutation",
|
|
119
|
+
"useDeleteAccountMutation",
|
|
120
|
+
"useDeleteShipmentsMutation",
|
|
121
|
+
"useDeleteWebhooksMutation",
|
|
122
|
+
"useDownloadLogsMutation",
|
|
123
|
+
"useDropOffInputContext",
|
|
124
|
+
"useDropdownButtonContext",
|
|
125
|
+
"useDropdownData",
|
|
126
|
+
"useElement",
|
|
127
|
+
"useElementContext",
|
|
128
|
+
"useElementOptions",
|
|
129
|
+
"useExportOrdersMutation",
|
|
130
|
+
"useExportReturnMutation",
|
|
131
|
+
"useFetchContextQuery",
|
|
132
|
+
"useFetchOrdersQuery",
|
|
133
|
+
"useFetchProductsQuery",
|
|
134
|
+
"useFetchShipmentsQuery",
|
|
135
|
+
"useFetchWebhooksQuery",
|
|
136
|
+
"useForm",
|
|
137
|
+
"useFormBuilder",
|
|
138
|
+
"useFormatter",
|
|
139
|
+
"useGlobalContext",
|
|
140
|
+
"useGlobalPdkAdmin",
|
|
141
|
+
"useInputWithOptionsContext",
|
|
142
|
+
"useLanguage",
|
|
143
|
+
"useLoadMore",
|
|
144
|
+
"useLogger",
|
|
145
|
+
"useModalContext",
|
|
146
|
+
"useModalElementContext",
|
|
147
|
+
"useModalStore",
|
|
148
|
+
"useMultiSelectInputContext",
|
|
149
|
+
"useNotificationStore",
|
|
150
|
+
"useOrderData",
|
|
151
|
+
"useOrdersData",
|
|
152
|
+
"usePdkMutation",
|
|
153
|
+
"usePrintOrdersMutation",
|
|
154
|
+
"usePrintShipmentsMutation",
|
|
155
|
+
"useProductData",
|
|
156
|
+
"useQueryStore",
|
|
157
|
+
"useRadioGroupContext",
|
|
158
|
+
"useSelectInputContext",
|
|
159
|
+
"useShippingMethodsInputContext",
|
|
160
|
+
"useStoreQuery",
|
|
161
|
+
"useSwitchToAcceptanceApiMutation",
|
|
162
|
+
"useSwitchToProductionApiMutation",
|
|
163
|
+
"useTableContext",
|
|
164
|
+
"useToggleInputContext",
|
|
165
|
+
"useTriStateInputContext",
|
|
166
|
+
"useUpdateAccountMutation",
|
|
167
|
+
"useUpdateOrdersMutation",
|
|
168
|
+
"useUpdatePluginSettingsMutation",
|
|
169
|
+
"useUpdateProductSettingsMutation",
|
|
170
|
+
"useUpdateShipmentsMutation",
|
|
171
|
+
"useWeekdays",
|
|
172
|
+
"waitForLabelPrompt",
|
|
173
|
+
"webhooksCreateAction",
|
|
174
|
+
"webhooksDeleteAction",
|
|
175
|
+
"webhooksFetchAction",
|
|
176
|
+
]
|
|
177
|
+
`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import {expect, it} from 'vitest';
|
|
3
|
+
import {mount} from '@vue/test-utils';
|
|
4
|
+
import {type PartialComponentTest} from '../types';
|
|
5
|
+
|
|
6
|
+
export const runCommonComponentTests = ((component, options = undefined): void => {
|
|
7
|
+
it('can be rendered', () => {
|
|
8
|
+
expect(() => mount(component as any, options as any)).not.toThrow();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('is visible', () => {
|
|
12
|
+
const wrapper = mount(component as any, options as any);
|
|
13
|
+
expect(wrapper.isVisible()).toBeTruthy();
|
|
14
|
+
});
|
|
15
|
+
}) satisfies PartialComponentTest;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
import {ref} from 'vue';
|
|
3
|
+
import {expect, it} from 'vitest';
|
|
4
|
+
import {merge} from 'lodash-unified';
|
|
5
|
+
import {flushPromises, mount} from '@vue/test-utils';
|
|
6
|
+
import {type AdditionalOptions, type PartialComponentTest} from '../types';
|
|
7
|
+
import {runHasPropTest} from './runHasPropTest';
|
|
8
|
+
|
|
9
|
+
const UPDATE_EVENT = 'update:modelValue';
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line max-lines-per-function
|
|
12
|
+
export const runCommonInputTests = ((component, options = undefined, additionalOptions: AdditionalOptions = {}) => {
|
|
13
|
+
runHasPropTest(component, {}, 'element', options?.props?.element);
|
|
14
|
+
|
|
15
|
+
it('can be disabled', () => {
|
|
16
|
+
const wrapper = mount(
|
|
17
|
+
component,
|
|
18
|
+
merge({}, options, {
|
|
19
|
+
props: {
|
|
20
|
+
element: {
|
|
21
|
+
...options?.props?.element,
|
|
22
|
+
isDisabled: ref(true),
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const select = wrapper.find('select');
|
|
29
|
+
const input = wrapper.find('input');
|
|
30
|
+
|
|
31
|
+
if (select.exists()) {
|
|
32
|
+
expect(select.attributes('disabled')).toBeDefined();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (input.exists()) {
|
|
36
|
+
expect(input.attributes('disabled')).toBeDefined();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it(`emits ${UPDATE_EVENT} event`, async () => {
|
|
41
|
+
expect.assertions(2);
|
|
42
|
+
const wrapper = mount(component, options);
|
|
43
|
+
|
|
44
|
+
const select = wrapper.find('select');
|
|
45
|
+
const input = wrapper.find('input');
|
|
46
|
+
|
|
47
|
+
const valueToSet = additionalOptions?.value ?? 'test';
|
|
48
|
+
|
|
49
|
+
if (select.exists()) {
|
|
50
|
+
await select.setValue(valueToSet);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (input.exists()) {
|
|
54
|
+
await input.setValue(valueToSet);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
await flushPromises();
|
|
58
|
+
|
|
59
|
+
const emitted = wrapper.emitted();
|
|
60
|
+
|
|
61
|
+
expect(emitted).toHaveProperty(UPDATE_EVENT);
|
|
62
|
+
expect(emitted[UPDATE_EVENT]).toHaveLength(1);
|
|
63
|
+
/** @todo fix this */
|
|
64
|
+
// expect(emitted[UPDATE_EVENT][0]).toEqual([valueToSet]);
|
|
65
|
+
});
|
|
66
|
+
}) satisfies PartialComponentTest<[AdditionalOptions]>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {expect, it} from 'vitest';
|
|
2
|
+
import {mount} from '@vue/test-utils';
|
|
3
|
+
import {type PartialComponentTest} from '../types';
|
|
4
|
+
|
|
5
|
+
export const runHasPropTest = ((component, options, prop, value = 'value') => {
|
|
6
|
+
it(`has prop ${prop}`, () => {
|
|
7
|
+
const wrapper = mount(component, {
|
|
8
|
+
...options,
|
|
9
|
+
props: {
|
|
10
|
+
...(options?.props as any),
|
|
11
|
+
[prop]: value,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
expect(wrapper.props()).toHaveProperty(prop);
|
|
16
|
+
});
|
|
17
|
+
}) satisfies PartialComponentTest<[string] | [string, unknown]>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {expect, it} from 'vitest';
|
|
2
|
+
import {flushPromises, mount} from '@vue/test-utils';
|
|
3
|
+
import {type PartialComponentTest} from '../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks if the html content passed to the slot exists anywhere in the component.
|
|
7
|
+
*/
|
|
8
|
+
export const runHasSlotTest = ((component, options = undefined, slot = 'default') => {
|
|
9
|
+
it(`has slot #${slot}`, async () => {
|
|
10
|
+
expect.assertions(1);
|
|
11
|
+
const content = `SLOT CONTENT ${Math.ceil(Math.random() * 100)}`;
|
|
12
|
+
|
|
13
|
+
const wrapper = mount(component as any, {
|
|
14
|
+
...options,
|
|
15
|
+
slots: {
|
|
16
|
+
...(options?.slots as any),
|
|
17
|
+
[slot]: () => content,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
await flushPromises();
|
|
22
|
+
|
|
23
|
+
expect(wrapper.element.innerHTML).toContain(content);
|
|
24
|
+
});
|
|
25
|
+
}) satisfies PartialComponentTest<[] | [string]>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export * from './runBadgeTest';
|
|
2
|
+
export * from './runBoxTest';
|
|
3
|
+
export * from './runButtonTest';
|
|
4
|
+
export * from './runCheckboxGroupTest';
|
|
5
|
+
export * from './runCheckboxInputTest';
|
|
6
|
+
export * from './runCodeEditorTest';
|
|
7
|
+
export * from './runColTest';
|
|
8
|
+
export * from './runCurrencyInputTest';
|
|
9
|
+
export * from './runDropDownButtonTest';
|
|
10
|
+
export * from './runDropOffInputTest';
|
|
11
|
+
export * from './runFormGroupTest';
|
|
12
|
+
export * from './runHeadingTest';
|
|
13
|
+
export * from './runIconTest';
|
|
14
|
+
export * from './runImageTest';
|
|
15
|
+
export * from './runLinkTest';
|
|
16
|
+
export * from './runLoaderTest';
|
|
17
|
+
export * from './runModalTest';
|
|
18
|
+
export * from './runMultiSelectInputTest';
|
|
19
|
+
export * from './runNotificationTest';
|
|
20
|
+
export * from './runNumberInputTest';
|
|
21
|
+
export * from './runPlainWrapperTest';
|
|
22
|
+
export * from './runRadioGroupTest';
|
|
23
|
+
export * from './runRadioInputTest';
|
|
24
|
+
export * from './runRowTest';
|
|
25
|
+
export * from './runSelectInputTest';
|
|
26
|
+
export * from './runSettingsDividerTest';
|
|
27
|
+
export * from './runShippingMethodsInputTest';
|
|
28
|
+
export * from './runTabNavButtonTest';
|
|
29
|
+
export * from './runTableColTest';
|
|
30
|
+
export * from './runTableRowTest';
|
|
31
|
+
export * from './runTableTest';
|
|
32
|
+
export * from './runTextAreaTest';
|
|
33
|
+
export * from './runTextInputTest';
|
|
34
|
+
export * from './runTimeInputTest';
|
|
35
|
+
export * from './runToggleInputTest';
|
|
36
|
+
export * from './runTriStateInputTest';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {AdminComponent} from '@myparcel-dev/pdk-admin';
|
|
2
|
+
import {type AdminComponentTest} from '../tests';
|
|
3
|
+
import {TestSuite} from '../TestSuite';
|
|
4
|
+
|
|
5
|
+
export const runBadgeTest = ((component) => {
|
|
6
|
+
const suite = new TestSuite(AdminComponent.Badge, component);
|
|
7
|
+
|
|
8
|
+
suite.runCommonComponentTests();
|
|
9
|
+
}) satisfies AdminComponentTest;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {AdminComponent} from '@myparcel-dev/pdk-admin';
|
|
2
|
+
import {type AdminComponentTest} from '../tests';
|
|
3
|
+
import {TestSuite} from '../TestSuite';
|
|
4
|
+
|
|
5
|
+
export const runBoxTest = ((component) => {
|
|
6
|
+
const suite = new TestSuite(AdminComponent.Box, component);
|
|
7
|
+
|
|
8
|
+
suite.createInputOptions();
|
|
9
|
+
|
|
10
|
+
suite.runCommonComponentTests();
|
|
11
|
+
|
|
12
|
+
suite.runHasSlotTest('default');
|
|
13
|
+
suite.runHasSlotTest('header');
|
|
14
|
+
suite.runHasSlotTest('footer');
|
|
15
|
+
|
|
16
|
+
suite.runHasPropTest('loading', true);
|
|
17
|
+
}) satisfies AdminComponentTest;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {expect, it} from 'vitest';
|
|
2
|
+
import {mount} from '@vue/test-utils';
|
|
3
|
+
import {AdminComponent} from '@myparcel-dev/pdk-admin';
|
|
4
|
+
import {type AdminComponentTest} from '../tests';
|
|
5
|
+
import {TestSuite} from '../TestSuite';
|
|
6
|
+
|
|
7
|
+
export const runButtonTest = ((component) => {
|
|
8
|
+
const suite = new TestSuite(AdminComponent.Button, component);
|
|
9
|
+
|
|
10
|
+
suite.runCommonComponentTests();
|
|
11
|
+
|
|
12
|
+
it('handles click event', async () => {
|
|
13
|
+
expect.assertions(1);
|
|
14
|
+
const wrapper = mount(component);
|
|
15
|
+
const button = wrapper.find('button');
|
|
16
|
+
|
|
17
|
+
button.element.click();
|
|
18
|
+
await wrapper.vm.$nextTick();
|
|
19
|
+
expect(wrapper.emitted().click).toHaveLength(1);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('can be disabled', async () => {
|
|
23
|
+
expect.assertions(2);
|
|
24
|
+
const wrapper = mount(component, {props: {disabled: true}});
|
|
25
|
+
const button = wrapper.find('button');
|
|
26
|
+
expect(button.attributes('disabled')).toBeDefined();
|
|
27
|
+
|
|
28
|
+
button.element.click();
|
|
29
|
+
await wrapper.vm.$nextTick();
|
|
30
|
+
expect(wrapper.emitted().click).toBeUndefined();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('can display custom content', () => {
|
|
34
|
+
const wrapper = mount(component, {slots: {default: 'Test'}});
|
|
35
|
+
expect(wrapper.findAll('*').map((wrapper) => wrapper.text())).toContain('Test');
|
|
36
|
+
});
|
|
37
|
+
}) satisfies AdminComponentTest;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {AdminComponent, type SelectOption} from '@myparcel-dev/pdk-admin';
|
|
2
|
+
import {type AdminComponentTest} from '../tests';
|
|
3
|
+
import {TestSuite} from '../TestSuite';
|
|
4
|
+
|
|
5
|
+
export const runCheckboxGroupTest = ((component) => {
|
|
6
|
+
const suite = new TestSuite(AdminComponent.CheckboxGroup, component);
|
|
7
|
+
|
|
8
|
+
suite.createInputOptions(['appel', 'boom'], {
|
|
9
|
+
props: {
|
|
10
|
+
options: [
|
|
11
|
+
{
|
|
12
|
+
value: 'appel',
|
|
13
|
+
label: 'Appel',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
value: 'boom',
|
|
17
|
+
label: 'Boom',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
value: 'citroen',
|
|
21
|
+
label: 'Citroen',
|
|
22
|
+
},
|
|
23
|
+
] satisfies SelectOption[],
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
suite.runCommonComponentTests();
|
|
28
|
+
// TODO: write more tests
|
|
29
|
+
}) satisfies AdminComponentTest;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {AdminComponent} from '@myparcel-dev/pdk-admin';
|
|
2
|
+
import {type AdminComponentTest} from '../tests';
|
|
3
|
+
import {TestSuite} from '../TestSuite';
|
|
4
|
+
|
|
5
|
+
export const runCheckboxInputTest = ((component) => {
|
|
6
|
+
const suite = new TestSuite(AdminComponent.CheckboxInput, component);
|
|
7
|
+
|
|
8
|
+
suite.createInputOptions(true);
|
|
9
|
+
|
|
10
|
+
suite.runCommonComponentTests();
|
|
11
|
+
suite.runCommonInputTests({value: false});
|
|
12
|
+
// TODO write more tests
|
|
13
|
+
}) satisfies AdminComponentTest;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {AdminComponent} from '@myparcel-dev/pdk-admin';
|
|
2
|
+
import {type AdminComponentTest} from '../tests';
|
|
3
|
+
import {TestSuite} from '../TestSuite';
|
|
4
|
+
|
|
5
|
+
export const runCodeEditorTest = ((component) => {
|
|
6
|
+
const suite = new TestSuite(AdminComponent.CodeEditor, component);
|
|
7
|
+
|
|
8
|
+
suite.createInputOptions('test');
|
|
9
|
+
|
|
10
|
+
suite.runCommonComponentTests();
|
|
11
|
+
}) satisfies AdminComponentTest;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {AdminComponent} from '@myparcel-dev/pdk-admin';
|
|
2
|
+
import {type AdminComponentTest} from '../tests';
|
|
3
|
+
import {TestSuite} from '../TestSuite';
|
|
4
|
+
|
|
5
|
+
export const runColTest = ((component) => {
|
|
6
|
+
const suite = new TestSuite(AdminComponent.Col, component);
|
|
7
|
+
|
|
8
|
+
suite.runCommonComponentTests();
|
|
9
|
+
|
|
10
|
+
suite.runHasSlotTest();
|
|
11
|
+
}) satisfies AdminComponentTest;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {AdminComponent} from '@myparcel-dev/pdk-admin';
|
|
2
|
+
import {type AdminComponentTest} from '../tests';
|
|
3
|
+
import {TestSuite} from '../TestSuite';
|
|
4
|
+
|
|
5
|
+
export const runCurrencyInputTest = ((component) => {
|
|
6
|
+
const suite = new TestSuite(AdminComponent.CurrencyInput, component);
|
|
7
|
+
|
|
8
|
+
suite.createInputOptions(1.42);
|
|
9
|
+
|
|
10
|
+
suite.runCommonComponentTests();
|
|
11
|
+
suite.runCommonInputTests({value: 1.5});
|
|
12
|
+
// TODO write more tests
|
|
13
|
+
}) satisfies AdminComponentTest;
|