@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.
Files changed (113) hide show
  1. package/CHANGELOG.md +260 -0
  2. package/dist/TestSuite.d.ts +21 -0
  3. package/dist/common/index.d.ts +4 -0
  4. package/dist/common/runCommonComponentTests.d.ts +1 -0
  5. package/dist/common/runCommonInputTests.d.ts +2 -0
  6. package/dist/common/runHasPropTest.d.ts +1 -0
  7. package/dist/common/runHasSlotTest.d.ts +4 -0
  8. package/dist/components/index.d.ts +36 -0
  9. package/dist/components/runBadgeTest.d.ts +1 -0
  10. package/dist/components/runBoxTest.d.ts +1 -0
  11. package/dist/components/runButtonTest.d.ts +1 -0
  12. package/dist/components/runCheckboxGroupTest.d.ts +1 -0
  13. package/dist/components/runCheckboxInputTest.d.ts +1 -0
  14. package/dist/components/runCodeEditorTest.d.ts +1 -0
  15. package/dist/components/runColTest.d.ts +1 -0
  16. package/dist/components/runCurrencyInputTest.d.ts +1 -0
  17. package/dist/components/runDropDownButtonTest.d.ts +1 -0
  18. package/dist/components/runDropOffInputTest.d.ts +1 -0
  19. package/dist/components/runFormGroupTest.d.ts +1 -0
  20. package/dist/components/runHeadingTest.d.ts +1 -0
  21. package/dist/components/runIconTest.d.ts +1 -0
  22. package/dist/components/runImageTest.d.ts +1 -0
  23. package/dist/components/runLinkTest.d.ts +1 -0
  24. package/dist/components/runLoaderTest.d.ts +1 -0
  25. package/dist/components/runModalTest.d.ts +1 -0
  26. package/dist/components/runMultiDateInputTest.d.ts +1 -0
  27. package/dist/components/runMultiSelectInputTest.d.ts +1 -0
  28. package/dist/components/runNotificationTest.d.ts +1 -0
  29. package/dist/components/runNumberInputTest.d.ts +1 -0
  30. package/dist/components/runPlainWrapperTest.d.ts +1 -0
  31. package/dist/components/runRadioGroupTest.d.ts +1 -0
  32. package/dist/components/runRadioInputTest.d.ts +1 -0
  33. package/dist/components/runRowTest.d.ts +1 -0
  34. package/dist/components/runSelectInputTest.d.ts +1 -0
  35. package/dist/components/runSettingsDividerTest.d.ts +1 -0
  36. package/dist/components/runShippingMethodsInputTest.d.ts +1 -0
  37. package/dist/components/runTabNavButtonTest.d.ts +1 -0
  38. package/dist/components/runTableColTest.d.ts +1 -0
  39. package/dist/components/runTableRowTest.d.ts +1 -0
  40. package/dist/components/runTableTest.d.ts +1 -0
  41. package/dist/components/runTextAreaTest.d.ts +1 -0
  42. package/dist/components/runTextInputTest.d.ts +1 -0
  43. package/dist/components/runTimeInputTest.d.ts +1 -0
  44. package/dist/components/runToggleInputTest.d.ts +1 -0
  45. package/dist/components/runTriStateInputTest.d.ts +1 -0
  46. package/dist/helpers/createInputOptions.d.ts +4 -0
  47. package/dist/helpers/index.d.ts +1 -0
  48. package/dist/helpers/wrapperPlugin.d.ts +2 -0
  49. package/dist/index.d.ts +3 -0
  50. package/dist/setup.d.ts +1 -0
  51. package/dist/tests/executeAdminComponentTest.d.ts +3 -0
  52. package/dist/tests/executePdkComponentTests.d.ts +2 -0
  53. package/dist/tests/index.d.ts +3 -0
  54. package/dist/tests/testMap.d.ts +4 -0
  55. package/dist/types.d.ts +10 -0
  56. package/package.json +62 -0
  57. package/src/TestSuite.ts +147 -0
  58. package/src/__tests__/__snapshots__/exports.spec.ts.snap +177 -0
  59. package/src/__tests__/exports.spec.ts +8 -0
  60. package/src/common/index.ts +4 -0
  61. package/src/common/runCommonComponentTests.ts +15 -0
  62. package/src/common/runCommonInputTests.ts +66 -0
  63. package/src/common/runHasPropTest.ts +17 -0
  64. package/src/common/runHasSlotTest.ts +25 -0
  65. package/src/components/index.ts +36 -0
  66. package/src/components/runBadgeTest.ts +9 -0
  67. package/src/components/runBoxTest.ts +17 -0
  68. package/src/components/runButtonTest.ts +37 -0
  69. package/src/components/runCheckboxGroupTest.ts +29 -0
  70. package/src/components/runCheckboxInputTest.ts +13 -0
  71. package/src/components/runCodeEditorTest.ts +11 -0
  72. package/src/components/runColTest.ts +11 -0
  73. package/src/components/runCurrencyInputTest.ts +13 -0
  74. package/src/components/runDropDownButtonTest.ts +81 -0
  75. package/src/components/runDropOffInputTest.ts +32 -0
  76. package/src/components/runFormGroupTest.ts +17 -0
  77. package/src/components/runHeadingTest.ts +12 -0
  78. package/src/components/runIconTest.ts +16 -0
  79. package/src/components/runImageTest.ts +22 -0
  80. package/src/components/runLinkTest.ts +12 -0
  81. package/src/components/runLoaderTest.ts +9 -0
  82. package/src/components/runModalTest.ts +28 -0
  83. package/src/components/runMultiDateInputTest.ts +10 -0
  84. package/src/components/runMultiSelectInputTest.ts +17 -0
  85. package/src/components/runNotificationTest.ts +40 -0
  86. package/src/components/runNumberInputTest.ts +13 -0
  87. package/src/components/runPlainWrapperTest.ts +12 -0
  88. package/src/components/runRadioGroupTest.ts +26 -0
  89. package/src/components/runRadioInputTest.ts +13 -0
  90. package/src/components/runRowTest.ts +11 -0
  91. package/src/components/runSelectInputTest.ts +30 -0
  92. package/src/components/runSettingsDividerTest.ts +16 -0
  93. package/src/components/runShippingMethodsInputTest.ts +23 -0
  94. package/src/components/runTabNavButtonTest.ts +17 -0
  95. package/src/components/runTableColTest.ts +11 -0
  96. package/src/components/runTableRowTest.ts +11 -0
  97. package/src/components/runTableTest.ts +13 -0
  98. package/src/components/runTextAreaTest.ts +12 -0
  99. package/src/components/runTextInputTest.ts +12 -0
  100. package/src/components/runTimeInputTest.ts +13 -0
  101. package/src/components/runToggleInputTest.ts +16 -0
  102. package/src/components/runTriStateInputTest.ts +15 -0
  103. package/src/helpers/createInputOptions.ts +19 -0
  104. package/src/helpers/index.ts +1 -0
  105. package/src/helpers/wrapperPlugin.ts +20 -0
  106. package/src/index.ts +5 -0
  107. package/src/setup.ts +4 -0
  108. package/src/tests/executeAdminComponentTest.ts +47 -0
  109. package/src/tests/executePdkComponentTests.ts +19 -0
  110. package/src/tests/index.ts +3 -0
  111. package/src/tests/testMap.ts +111 -0
  112. package/src/types.ts +24 -0
  113. package/src/vue.shims.d.ts +26 -0
@@ -0,0 +1,47 @@
1
+ /* eslint-disable no-magic-numbers */
2
+ import {type Component} from 'vue';
3
+ import {afterAll, beforeAll, beforeEach, describe, vi} from 'vitest';
4
+ import {
5
+ type AdminComponent,
6
+ type AdminInstance,
7
+ type AdminView,
8
+ createAdminConfig,
9
+ createLogger,
10
+ } from '@myparcel-dev/pdk-admin';
11
+ import {testMap} from './testMap';
12
+
13
+ export const executeAdminComponentTest = (name: AdminComponent, component: Omit<Component, 'props'>): void => {
14
+ const componentTest = testMap[name];
15
+
16
+ if (!componentTest) {
17
+ // eslint-disable-next-line no-console
18
+ console.warn(`No test found for component: ${name}`);
19
+ return;
20
+ }
21
+
22
+ describe(name, () => {
23
+ beforeEach(() => {
24
+ vi.spyOn(console, 'warn').mockImplementation(() => undefined);
25
+ });
26
+
27
+ beforeAll(() => {
28
+ vi.mock('../usePdkInstance', () => ({
29
+ usePdkInstance: (): AdminInstance => ({
30
+ appName: 'test',
31
+ config: createAdminConfig(),
32
+ context: {},
33
+ logger: createLogger('test'),
34
+ view: 'test' as AdminView,
35
+ }),
36
+ }));
37
+ });
38
+
39
+ describe(name, () => {
40
+ componentTest(component);
41
+ });
42
+
43
+ afterAll(() => {
44
+ vi.restoreAllMocks();
45
+ });
46
+ });
47
+ };
@@ -0,0 +1,19 @@
1
+ import {config} from '@vue/test-utils';
2
+ import {doComponentTestSetup} from '@myparcel-dev/pdk-admin/testing';
3
+ import {type AdminComponent, type AdminComponentMap} from '@myparcel-dev/pdk-admin';
4
+ import {wrapperPlugin} from '../helpers/wrapperPlugin';
5
+ import {executeAdminComponentTest} from './executeAdminComponentTest';
6
+
7
+ export const executePdkComponentTests = (components: Partial<AdminComponentMap> = {}): void => {
8
+ config.plugins.VueWrapper.install(wrapperPlugin);
9
+
10
+ doComponentTestSetup(components);
11
+
12
+ Object.entries(components).forEach(([name, component]) => {
13
+ if (!component) {
14
+ return;
15
+ }
16
+
17
+ executeAdminComponentTest(name as AdminComponent, component);
18
+ });
19
+ };
@@ -0,0 +1,3 @@
1
+ export * from './executeAdminComponentTest';
2
+ export * from './executePdkComponentTests';
3
+ export * from './testMap';
@@ -0,0 +1,111 @@
1
+ import {type Component} from 'vue';
2
+ import {AdminComponent} from '@myparcel-dev/pdk-admin';
3
+ import {runMultiDateInputTest} from '../components/runMultiDateInputTest';
4
+ import {
5
+ runBadgeTest,
6
+ runBoxTest,
7
+ runButtonTest,
8
+ runCheckboxGroupTest,
9
+ runCheckboxInputTest,
10
+ runCodeEditorTest,
11
+ runColTest,
12
+ runCurrencyInputTest,
13
+ runDropDownButtonTest,
14
+ runDropOffInputTest,
15
+ runFormGroupTest,
16
+ runHeadingTest,
17
+ runIconTest,
18
+ runImageTest,
19
+ runLinkTest,
20
+ runLoaderTest,
21
+ runModalTest,
22
+ runMultiSelectInputTest,
23
+ runNotificationTest,
24
+ runNumberInputTest,
25
+ runPlainWrapperTest,
26
+ runRadioGroupTest,
27
+ runRadioInputTest,
28
+ runRowTest,
29
+ runSelectInputTest,
30
+ runSettingsDividerTest,
31
+ runShippingMethodsInputTest,
32
+ runTableColTest,
33
+ runTableRowTest,
34
+ runTableTest,
35
+ runTabNavButtonTest,
36
+ runTextAreaTest,
37
+ runTextInputTest,
38
+ runTimeInputTest,
39
+ runToggleInputTest,
40
+ } from '../components';
41
+
42
+ export type AdminComponentTest = (component: Omit<Component, 'props'>) => void;
43
+
44
+ export const testMap: Readonly<Record<AdminComponent, AdminComponentTest>> = Object.freeze({
45
+ /**
46
+ * Inputs
47
+ */
48
+ [AdminComponent.CheckboxGroup]: runCheckboxGroupTest,
49
+ [AdminComponent.CheckboxInput]: runCheckboxInputTest,
50
+ [AdminComponent.CodeEditor]: runCodeEditorTest,
51
+ [AdminComponent.CurrencyInput]: runCurrencyInputTest,
52
+ [AdminComponent.DropOffInput]: runDropOffInputTest,
53
+ [AdminComponent.MultiSelectInput]: runMultiSelectInputTest,
54
+ [AdminComponent.NumberInput]: runNumberInputTest,
55
+ [AdminComponent.RadioGroup]: runRadioGroupTest,
56
+ [AdminComponent.RadioInput]: runRadioInputTest,
57
+ [AdminComponent.SelectInput]: runSelectInputTest,
58
+ [AdminComponent.ShippingMethodsInput]: runShippingMethodsInputTest,
59
+ [AdminComponent.TextArea]: runTextAreaTest,
60
+ [AdminComponent.TextInput]: runTextInputTest,
61
+ [AdminComponent.TimeInput]: runTimeInputTest,
62
+ [AdminComponent.ToggleInput]: runToggleInputTest,
63
+ [AdminComponent.MultiDateInput]: runMultiDateInputTest,
64
+ /**
65
+ * @TODO: fix test for TriStateInput
66
+ */
67
+ [AdminComponent.TriStateInput]: () => undefined,
68
+
69
+ /**
70
+ * Plain wrappers
71
+ */
72
+ [AdminComponent.ButtonGroup]: runPlainWrapperTest,
73
+ [AdminComponent.ConceptBoxWrapper]: runPlainWrapperTest,
74
+ [AdminComponent.PluginSettingsWrapper]: runPlainWrapperTest,
75
+ [AdminComponent.ShipmentLabelWrapper]: runPlainWrapperTest,
76
+ [AdminComponent.TabNavButtonWrapper]: runPlainWrapperTest,
77
+ [AdminComponent.TabNavContentWrapper]: runPlainWrapperTest,
78
+
79
+ /**
80
+ * Layout
81
+ */
82
+ [AdminComponent.Box]: runBoxTest,
83
+ [AdminComponent.Col]: runColTest,
84
+ [AdminComponent.Row]: runRowTest,
85
+
86
+ [AdminComponent.Table]: runTableTest,
87
+ [AdminComponent.TableCol]: runTableColTest,
88
+ [AdminComponent.TableRow]: runTableRowTest,
89
+
90
+ [AdminComponent.FormGroup]: runFormGroupTest,
91
+
92
+ /**
93
+ * Interactive components
94
+ */
95
+ [AdminComponent.Button]: runButtonTest,
96
+ [AdminComponent.DropdownButton]: runDropDownButtonTest,
97
+ [AdminComponent.Link]: runLinkTest,
98
+ [AdminComponent.Modal]: runModalTest,
99
+ [AdminComponent.TabNavButton]: runTabNavButtonTest,
100
+
101
+ /**
102
+ * Other
103
+ */
104
+ [AdminComponent.Badge]: runBadgeTest,
105
+ [AdminComponent.Heading]: runHeadingTest,
106
+ [AdminComponent.Icon]: runIconTest,
107
+ [AdminComponent.Image]: runImageTest,
108
+ [AdminComponent.Loader]: runLoaderTest,
109
+ [AdminComponent.Notification]: runNotificationTest,
110
+ [AdminComponent.SettingsDivider]: runSettingsDividerTest,
111
+ });
package/src/types.ts ADDED
@@ -0,0 +1,24 @@
1
+ import {type Component as ComponentType, type Component} from 'vue';
2
+ import {type ComponentMountingOptions} from '@vue/test-utils';
3
+
4
+ export type ComponentTestOptions = {
5
+ $slots?: Record<string, unknown>;
6
+ };
7
+
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/ban-types
9
+ export type PartialComponentTest<Args extends unknown[] = unknown[]> = <
10
+ T extends ComponentTestOptions = ComponentTestOptions,
11
+ >(
12
+ component: Component,
13
+ options?: ComponentMountingOptions<T>,
14
+ ...args: Args
15
+ ) => void;
16
+
17
+ export interface AdditionalOptions {
18
+ value?: unknown;
19
+ }
20
+
21
+ export type TestComponentMountingOptions<
22
+ Component extends ComponentType = ComponentType,
23
+ Options extends ComponentTestOptions = ComponentTestOptions,
24
+ > = ComponentMountingOptions<Component> & Options;
@@ -0,0 +1,26 @@
1
+ /* eslint-disable import/consistent-type-specifier-style,@typescript-eslint/no-explicit-any,@typescript-eslint/ban-types,@typescript-eslint/naming-convention,no-underscore-dangle */
2
+
3
+ import type {DOMWrapper} from '@vue/test-utils';
4
+
5
+ declare module '*.vue' {
6
+ import type {DefineComponent} from 'vue';
7
+
8
+ const component: DefineComponent<{}, {}, any>;
9
+ export default component;
10
+ }
11
+
12
+ declare const __VUE_PROD_DEVTOOLS__: boolean;
13
+
14
+ declare module '@vue/test-utils' {
15
+ export class VueWrapper {
16
+ public findByTestId<K extends keyof HTMLElementTagNameMap>(
17
+ selector: string | string[],
18
+ ): DOMWrapper<HTMLElementTagNameMap[K]>;
19
+
20
+ public findByTestId<K extends keyof SVGElementTagNameMap>(
21
+ selector: string | string[],
22
+ ): DOMWrapper<SVGElementTagNameMap[K]>;
23
+
24
+ public findByTestId<T extends Element | Node = Node>(selector: string | string[]): DOMWrapper<T>;
25
+ }
26
+ }