@rancher/shell 3.0.10 → 3.0.12-rc.1
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/assets/styles/base/_mixins.scss +31 -0
- package/assets/styles/base/_variables.scss +2 -0
- package/assets/styles/themes/_modern.scss +6 -5
- package/assets/translations/en-us.yaml +12 -9
- package/assets/translations/zh-hans.yaml +0 -3
- package/chart/__tests__/rancher-backup-index.test.ts +248 -0
- package/chart/rancher-backup/index.vue +41 -2
- package/components/BrandImage.vue +6 -5
- package/components/ConsumptionGauge.vue +12 -4
- package/components/DynamicContent/DynamicContentIcon.vue +3 -2
- package/components/EmptyProductPage.vue +76 -0
- package/components/ExplorerProjectsNamespaces.vue +1 -4
- package/components/LazyImage.vue +2 -1
- package/components/Resource/Detail/Card/Scaler.vue +4 -4
- package/components/Resource/Detail/CopyToClipboard.vue +1 -2
- package/components/Resource/Detail/Metadata/KeyValueRow.vue +9 -3
- package/components/Resource/Detail/TitleBar/__tests__/__snapshots__/index.test.ts.snap +31 -0
- package/components/Resource/Detail/TitleBar/__tests__/index.test.ts +45 -1
- package/components/Resource/Detail/TitleBar/index.vue +1 -1
- package/components/Resource/Detail/ViewOptions/__tests__/__snapshots__/index.test.ts.snap +9 -0
- package/components/Resource/Detail/ViewOptions/__tests__/index.test.ts +62 -0
- package/components/Resource/Detail/ViewOptions/index.vue +2 -1
- package/components/ResourceList/Masthead.vue +25 -2
- package/components/SideNav.vue +13 -0
- package/components/Tabbed/index.vue +6 -0
- package/components/__tests__/ConsumptionGauge.test.ts +31 -0
- package/components/__tests__/PromptModal.test.ts +2 -0
- package/components/fleet/FleetClusters.vue +1 -0
- package/components/fleet/__tests__/FleetClusters.test.ts +71 -0
- package/components/form/NodeScheduling.vue +17 -3
- package/components/form/PrivateRegistry.vue +69 -0
- package/components/form/ProjectMemberEditor.vue +0 -10
- package/components/form/__tests__/PrivateRegistry.test.ts +133 -0
- package/components/formatter/WorkloadHealthScale.vue +3 -1
- package/components/nav/Group.vue +26 -3
- package/components/nav/Header.vue +32 -7
- package/components/nav/TopLevelMenu.helper.ts +7 -79
- package/components/nav/TopLevelMenu.vue +15 -1
- package/components/nav/__tests__/TopLevelMenu.helper.test.ts +2 -53
- package/config/pagination-table-headers.js +8 -1
- package/config/private-label.js +2 -1
- package/config/product/apps.js +3 -1
- package/config/product/auth.js +1 -0
- package/config/product/backup.js +1 -0
- package/config/product/compliance.js +1 -1
- package/config/product/explorer.js +25 -6
- package/config/product/fleet.js +1 -0
- package/config/product/gatekeeper.js +1 -0
- package/config/product/istio.js +1 -0
- package/config/product/logging.js +1 -0
- package/config/product/longhorn.js +2 -1
- package/config/product/manager.js +1 -0
- package/config/product/monitoring.js +1 -0
- package/config/product/navlinks.js +1 -0
- package/config/product/neuvector.js +2 -1
- package/config/product/settings.js +1 -0
- package/config/product/uiplugins.js +1 -0
- package/core/__tests__/extension-manager-impl.test.js +187 -2
- package/core/__tests__/plugin-products-helpers.test.ts +454 -0
- package/core/__tests__/plugin-products.test.ts +3219 -0
- package/core/extension-manager-impl.js +34 -3
- package/core/plugin-helpers.ts +31 -0
- package/core/plugin-products-base.ts +375 -0
- package/core/plugin-products-extending.ts +44 -0
- package/core/plugin-products-helpers.ts +262 -0
- package/core/plugin-products-top-level.ts +66 -0
- package/core/plugin-products-type-guards.ts +33 -0
- package/core/plugin-products.ts +50 -0
- package/core/plugin-types.ts +222 -0
- package/core/plugin.ts +45 -10
- package/core/productDebugger.js +48 -0
- package/core/types.ts +95 -11
- package/detail/__tests__/__snapshots__/fleet.cattle.io.bundle.test.ts.snap +52 -0
- package/detail/__tests__/fleet.cattle.io.bundle.test.ts +171 -0
- package/detail/__tests__/node.test.ts +83 -0
- package/detail/fleet.cattle.io.bundle.vue +21 -34
- package/detail/management.cattle.io.oidcclient.vue +2 -1
- package/detail/node.vue +1 -0
- package/dialog/ExtensionCatalogInstallDialog.vue +1 -1
- package/dialog/InstallExtensionDialog.vue +6 -27
- package/dialog/UninstallExistingExtensionDialog.vue +141 -0
- package/dialog/UninstallExtensionDialog.vue +4 -26
- package/dialog/__tests__/UninstallExistingExtensionDialog.test.ts +114 -0
- package/edit/__tests__/fleet.cattle.io.gitrepo.test.ts +1 -0
- package/edit/catalog.cattle.io.clusterrepo.vue +17 -3
- package/edit/cloudcredential.vue +2 -1
- package/edit/monitoring.coreos.com.alertmanagerconfig/receiverConfig.vue +11 -6
- package/edit/provisioning.cattle.io.cluster/__tests__/Ingress.test.ts +176 -0
- package/edit/provisioning.cattle.io.cluster/index.vue +5 -4
- package/edit/provisioning.cattle.io.cluster/rke2.vue +4 -1
- package/edit/provisioning.cattle.io.cluster/shared.ts +4 -2
- package/edit/provisioning.cattle.io.cluster/tabs/Basics.vue +6 -0
- package/edit/provisioning.cattle.io.cluster/tabs/Ingress.vue +7 -2
- package/edit/secret/generic.vue +1 -0
- package/edit/secret/index.vue +2 -1
- package/edit/service.vue +2 -14
- package/list/management.cattle.io.feature.vue +7 -1
- package/list/provisioning.cattle.io.cluster.vue +0 -50
- package/list/workload.vue +11 -4
- package/mixins/brand.js +2 -1
- package/mixins/resource-fetch.js +12 -3
- package/models/catalog.cattle.io.clusterrepo.js +9 -0
- package/models/cluster.x-k8s.io.machinedeployment.js +8 -3
- package/models/management.cattle.io.authconfig.js +2 -1
- package/models/management.cattle.io.cluster.js +4 -3
- package/models/monitoring.coreos.com.receiver.js +11 -6
- package/models/pod.js +18 -0
- package/models/provisioning.cattle.io.cluster.js +2 -2
- package/models/workload.js +20 -2
- package/package.json +5 -6
- package/pages/c/_cluster/apps/charts/AppChartCardFooter.vue +0 -1
- package/pages/c/_cluster/apps/charts/index.vue +3 -8
- package/pages/c/_cluster/apps/charts/install.vue +8 -9
- package/pages/c/_cluster/istio/index.vue +4 -2
- package/pages/c/_cluster/longhorn/index.vue +2 -1
- package/pages/c/_cluster/monitoring/index.vue +2 -2
- package/pages/c/_cluster/neuvector/index.vue +2 -1
- package/pages/c/_cluster/settings/brand.vue +4 -4
- package/pages/c/_cluster/settings/performance.vue +0 -5
- package/pages/c/_cluster/uiplugins/PluginInfoPanel.vue +2 -1
- package/pages/c/_cluster/uiplugins/__tests__/index.test.ts +231 -13
- package/pages/c/_cluster/uiplugins/index.vue +145 -38
- package/plugins/dashboard-store/__tests__/resource-class.test.ts +1 -0
- package/plugins/dashboard-store/actions.js +3 -2
- package/plugins/dashboard-store/resource-class.js +62 -6
- package/plugins/plugin.js +16 -0
- package/plugins/steve/steve-pagination-utils.ts +8 -2
- package/plugins/steve/subscribe.js +29 -4
- package/rancher-components/RcButton/RcButton.vue +3 -3
- package/rancher-components/RcButtonSplit/RcButtonSplit.test.ts +253 -0
- package/rancher-components/RcButtonSplit/RcButtonSplit.vue +158 -0
- package/rancher-components/RcButtonSplit/index.ts +1 -0
- package/scripts/test-plugins-build.sh +4 -4
- package/scripts/typegen.sh +13 -1
- package/store/__tests__/type-map.test.ts +84 -24
- package/store/type-map.js +42 -3
- package/tsconfig.paths.json +1 -0
- package/types/resources/pod.ts +18 -0
- package/types/shell/index.d.ts +8506 -2908
- package/types/store/dashboard-store.types.ts +5 -0
- package/types/store/pagination.types.ts +6 -0
- package/utils/__tests__/require-asset.test.ts +98 -0
- package/utils/async.ts +1 -5
- package/utils/axios.js +1 -4
- package/utils/brand.ts +3 -1
- package/utils/dynamic-importer.js +3 -2
- package/utils/favicon.js +4 -3
- package/utils/pagination-utils.ts +1 -1
- package/utils/require-asset.ts +95 -0
- package/utils/uiplugins.ts +12 -16
- package/utils/validators/__tests__/private-registry.test.ts +76 -0
- package/utils/validators/private-registry.ts +28 -0
- package/vue.config.js +4 -3
- package/components/HarvesterServiceAddOnConfig.vue +0 -207
|
@@ -0,0 +1,3219 @@
|
|
|
1
|
+
import { PluginProduct } from '@shell/core/plugin-products';
|
|
2
|
+
import {
|
|
3
|
+
ProductMetadata, ProductSinglePage, ProductChildPage,
|
|
4
|
+
ProductChildGroup, StandardProductNames
|
|
5
|
+
} from '@shell/core/plugin-types';
|
|
6
|
+
import { IExtension } from '@shell/core/types';
|
|
7
|
+
|
|
8
|
+
// Mock the helper functions
|
|
9
|
+
jest.mock('@shell/core/plugin-products-helpers', () => ({
|
|
10
|
+
gatherChildrenOrdering: jest.fn((config) => config),
|
|
11
|
+
generateTopLevelExtensionSimpleBaseRoute: jest.fn((name, opts) => ({
|
|
12
|
+
name: `${ name }-simple`,
|
|
13
|
+
path: opts?.omitPath ? '' : `/${ name }`,
|
|
14
|
+
component: opts?.component,
|
|
15
|
+
})),
|
|
16
|
+
generateVirtualTypeRoute: jest.fn((parentName, page, opts) => ({
|
|
17
|
+
name: page ? `${ parentName }-${ page.name }` : `${ parentName }-group`,
|
|
18
|
+
path: opts?.omitPath ? '' : `/${ parentName }/${ page?.name || 'group' }`,
|
|
19
|
+
component: opts?.component,
|
|
20
|
+
})),
|
|
21
|
+
generateConfigureTypeRoute: jest.fn((parentName, page, opts) => {
|
|
22
|
+
const routeName = opts?.extendProduct ? `c-cluster-${ parentName }-resource` : `${ parentName }-c-cluster-resource`;
|
|
23
|
+
const routePath = opts?.extendProduct ? `c/:cluster/${ parentName }/:resource` : `${ parentName }/c/:cluster/:resource`;
|
|
24
|
+
const cluster = opts?.extendProduct ? undefined : '__BLANK_CLUSTER__';
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
name: routeName,
|
|
28
|
+
path: opts?.omitPath ? '' : routePath,
|
|
29
|
+
params: cluster ? {
|
|
30
|
+
product: parentName.replace(/-/g, ''),
|
|
31
|
+
cluster,
|
|
32
|
+
resource: page?.type,
|
|
33
|
+
} : {
|
|
34
|
+
product: parentName,
|
|
35
|
+
resource: page?.type,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}),
|
|
39
|
+
generateResourceRoutes: jest.fn((parentName, child) => [
|
|
40
|
+
{
|
|
41
|
+
name: `${ parentName }-${ child.type }-list`,
|
|
42
|
+
path: `/${ parentName }/${ child.type }`,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: `${ parentName }-${ child.type }-detail`,
|
|
46
|
+
path: `/${ parentName }/${ child.type }/:id`,
|
|
47
|
+
},
|
|
48
|
+
]),
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
jest.mock('@shell/core/productDebugger', () => ({
|
|
52
|
+
DSLRegistrationsPerProduct: jest.fn(),
|
|
53
|
+
registeredRoutes: jest.fn(),
|
|
54
|
+
}));
|
|
55
|
+
|
|
56
|
+
// Create mock factories
|
|
57
|
+
function createMockPlugin(): IExtension {
|
|
58
|
+
return {
|
|
59
|
+
_registerTopLevelProduct: jest.fn(),
|
|
60
|
+
addRoute: jest.fn(),
|
|
61
|
+
DSL: jest.fn((store, productName) => ({
|
|
62
|
+
basicType: jest.fn(),
|
|
63
|
+
labelGroup: jest.fn(),
|
|
64
|
+
setGroupDefaultType: jest.fn(),
|
|
65
|
+
weightGroup: jest.fn(),
|
|
66
|
+
virtualType: jest.fn(),
|
|
67
|
+
configureType: jest.fn(),
|
|
68
|
+
weightType: jest.fn(),
|
|
69
|
+
product: jest.fn(),
|
|
70
|
+
})),
|
|
71
|
+
} as any;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function createMockStore(extendableProducts: string[] = Object.values(StandardProductNames)): any {
|
|
75
|
+
return { getters: { 'type-map/productByName': (productName: string) => (extendableProducts.includes(productName) ? { name: productName, extendable: true } : undefined) } };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
describe('pluginProduct', () => {
|
|
79
|
+
describe('new product scenarios', () => {
|
|
80
|
+
it('should create a new product with config items', () => {
|
|
81
|
+
const mockPlugin = createMockPlugin();
|
|
82
|
+
const productMetadata: ProductMetadata = {
|
|
83
|
+
name: 'test-product',
|
|
84
|
+
label: 'Test Product',
|
|
85
|
+
icon: 'icon-test',
|
|
86
|
+
};
|
|
87
|
+
const config: ProductChildPage[] = [
|
|
88
|
+
{
|
|
89
|
+
name: 'overview',
|
|
90
|
+
label: 'Overview',
|
|
91
|
+
component: { name: 'OverviewPage' },
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'details',
|
|
95
|
+
label: 'Details',
|
|
96
|
+
component: { name: 'DetailsPage' },
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
101
|
+
|
|
102
|
+
expect(pluginProduct.newProduct).toBe(true);
|
|
103
|
+
expect(mockPlugin._registerTopLevelProduct).toHaveBeenCalledTimes(1);
|
|
104
|
+
expect(mockPlugin.addRoute).toHaveBeenCalledTimes(2);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should create a single page product', () => {
|
|
108
|
+
const mockPlugin = createMockPlugin();
|
|
109
|
+
const productSinglePage: ProductSinglePage = {
|
|
110
|
+
name: 'single-page-product',
|
|
111
|
+
label: 'Single Page',
|
|
112
|
+
component: { name: 'SinglePageComponent' },
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const pluginProduct = new PluginProduct(mockPlugin, productSinglePage, []);
|
|
116
|
+
|
|
117
|
+
expect(pluginProduct.newProduct).toBe(true);
|
|
118
|
+
expect(mockPlugin._registerTopLevelProduct).toHaveBeenCalledTimes(1);
|
|
119
|
+
expect(mockPlugin.addRoute).toHaveBeenCalledTimes(1);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should handle product names with dashes by removing them', () => {
|
|
123
|
+
const mockPlugin = createMockPlugin();
|
|
124
|
+
const productMetadata: ProductMetadata = {
|
|
125
|
+
name: 'test-product-name',
|
|
126
|
+
label: 'Test',
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
new PluginProduct(mockPlugin, productMetadata, []);
|
|
130
|
+
|
|
131
|
+
expect(mockPlugin._registerTopLevelProduct).toHaveBeenCalledTimes(1);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('should create default empty page config when no config provided', () => {
|
|
135
|
+
const mockPlugin = createMockPlugin();
|
|
136
|
+
const productMetadata: ProductMetadata = {
|
|
137
|
+
name: 'empty-product',
|
|
138
|
+
label: 'Empty',
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
new PluginProduct(mockPlugin, productMetadata, []);
|
|
142
|
+
|
|
143
|
+
expect(mockPlugin.addRoute).toHaveBeenCalledTimes(1);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should throw error when product object lacks name property', () => {
|
|
147
|
+
const mockPlugin = createMockPlugin();
|
|
148
|
+
const invalidProduct = { label: 'No Name' } as any;
|
|
149
|
+
|
|
150
|
+
expect(() => {
|
|
151
|
+
new PluginProduct(mockPlugin, invalidProduct, []);
|
|
152
|
+
}).toThrow('Invalid product');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should throw error when product type is invalid', () => {
|
|
156
|
+
const mockPlugin = createMockPlugin();
|
|
157
|
+
|
|
158
|
+
expect(() => {
|
|
159
|
+
new PluginProduct(mockPlugin, 123 as any, []);
|
|
160
|
+
}).toThrow('Invalid product');
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('extending standard product', () => {
|
|
165
|
+
it('should extend an existing standard product with valid name', () => {
|
|
166
|
+
const mockPlugin = createMockPlugin();
|
|
167
|
+
const config: ProductChildPage[] = [
|
|
168
|
+
{
|
|
169
|
+
name: 'custom-section',
|
|
170
|
+
label: 'Custom',
|
|
171
|
+
component: { name: 'CustomComponent' },
|
|
172
|
+
},
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
const validStandardProduct = StandardProductNames.EXPLORER;
|
|
176
|
+
|
|
177
|
+
const pluginProduct = new PluginProduct(mockPlugin, validStandardProduct, config);
|
|
178
|
+
|
|
179
|
+
expect(pluginProduct.newProduct).toBe(false);
|
|
180
|
+
expect(mockPlugin.addRoute).toHaveBeenCalledTimes(1);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('should accept any string as product name when extending', () => {
|
|
184
|
+
const mockPlugin = createMockPlugin();
|
|
185
|
+
const customProduct = 'custom-product';
|
|
186
|
+
|
|
187
|
+
const pluginProduct = new PluginProduct(mockPlugin, customProduct, []);
|
|
188
|
+
|
|
189
|
+
expect(pluginProduct.newProduct).toBe(false);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('should throw error during apply when extending a product that is not registered', () => {
|
|
193
|
+
const mockPlugin = createMockPlugin();
|
|
194
|
+
const mockStore = createMockStore([]);
|
|
195
|
+
const mockDSL = {
|
|
196
|
+
product: jest.fn(),
|
|
197
|
+
basicType: jest.fn(),
|
|
198
|
+
labelGroup: jest.fn(),
|
|
199
|
+
setGroupDefaultType: jest.fn(),
|
|
200
|
+
weightGroup: jest.fn(),
|
|
201
|
+
virtualType: jest.fn(),
|
|
202
|
+
configureType: jest.fn(),
|
|
203
|
+
weightType: jest.fn(),
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
207
|
+
|
|
208
|
+
const pluginProduct = new PluginProduct(mockPlugin, 'non-existent-product', []);
|
|
209
|
+
|
|
210
|
+
expect(() => {
|
|
211
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
212
|
+
}).toThrow('is not extendable');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('should apply successfully when extending an extendable product', () => {
|
|
216
|
+
const mockPlugin = createMockPlugin();
|
|
217
|
+
const mockStore = createMockStore(['my-custom-builtin-product']);
|
|
218
|
+
const mockDSL = {
|
|
219
|
+
product: jest.fn(),
|
|
220
|
+
basicType: jest.fn(),
|
|
221
|
+
labelGroup: jest.fn(),
|
|
222
|
+
setGroupDefaultType: jest.fn(),
|
|
223
|
+
weightGroup: jest.fn(),
|
|
224
|
+
virtualType: jest.fn(),
|
|
225
|
+
configureType: jest.fn(),
|
|
226
|
+
weightType: jest.fn(),
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
230
|
+
|
|
231
|
+
const pluginProduct = new PluginProduct(mockPlugin, 'my-custom-builtin-product', []);
|
|
232
|
+
|
|
233
|
+
expect(() => {
|
|
234
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
235
|
+
}).not.toThrow();
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('should throw error during apply when extending a registered product that is not extendable', () => {
|
|
239
|
+
const mockPlugin = createMockPlugin();
|
|
240
|
+
const mockStore = {
|
|
241
|
+
getters: {
|
|
242
|
+
'type-map/productByName': (productName: string) => {
|
|
243
|
+
if (productName === 'other-extension-product') {
|
|
244
|
+
return { name: productName, extendable: false };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return undefined;
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
const mockDSL = {
|
|
252
|
+
product: jest.fn(),
|
|
253
|
+
basicType: jest.fn(),
|
|
254
|
+
labelGroup: jest.fn(),
|
|
255
|
+
setGroupDefaultType: jest.fn(),
|
|
256
|
+
weightGroup: jest.fn(),
|
|
257
|
+
virtualType: jest.fn(),
|
|
258
|
+
configureType: jest.fn(),
|
|
259
|
+
weightType: jest.fn(),
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
263
|
+
|
|
264
|
+
const pluginProduct = new PluginProduct(mockPlugin, 'other-extension-product', []);
|
|
265
|
+
|
|
266
|
+
expect(() => {
|
|
267
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
268
|
+
}).toThrow('is not extendable');
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('should not register new product when extending standard product', () => {
|
|
272
|
+
const mockPlugin = createMockPlugin();
|
|
273
|
+
const validStandardProduct = StandardProductNames.EXPLORER;
|
|
274
|
+
|
|
275
|
+
new PluginProduct(mockPlugin, validStandardProduct, []);
|
|
276
|
+
|
|
277
|
+
expect(mockPlugin._registerTopLevelProduct).not.toHaveBeenCalled();
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
describe('apply stage - product registration', () => {
|
|
282
|
+
it('should register new product via DSL during apply', () => {
|
|
283
|
+
const mockPlugin = createMockPlugin();
|
|
284
|
+
const mockStore = createMockStore();
|
|
285
|
+
const mockDSL = {
|
|
286
|
+
product: jest.fn(),
|
|
287
|
+
basicType: jest.fn(),
|
|
288
|
+
labelGroup: jest.fn(),
|
|
289
|
+
setGroupDefaultType: jest.fn(),
|
|
290
|
+
weightGroup: jest.fn(),
|
|
291
|
+
virtualType: jest.fn(),
|
|
292
|
+
configureType: jest.fn(),
|
|
293
|
+
weightType: jest.fn(),
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
297
|
+
|
|
298
|
+
const productMetadata: ProductMetadata = {
|
|
299
|
+
name: 'new-product',
|
|
300
|
+
label: 'New Product',
|
|
301
|
+
};
|
|
302
|
+
const config: ProductChildPage[] = [
|
|
303
|
+
{
|
|
304
|
+
name: 'page1',
|
|
305
|
+
label: 'Page 1',
|
|
306
|
+
component: { name: 'Page1' },
|
|
307
|
+
},
|
|
308
|
+
];
|
|
309
|
+
|
|
310
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
311
|
+
|
|
312
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
313
|
+
|
|
314
|
+
expect(mockDSL.product).toHaveBeenCalledTimes(1);
|
|
315
|
+
expect(mockDSL.product).toHaveBeenCalledWith(
|
|
316
|
+
expect.objectContaining({
|
|
317
|
+
name: 'newproduct',
|
|
318
|
+
inStore: 'management',
|
|
319
|
+
version: 2,
|
|
320
|
+
showClusterSwitcher: false,
|
|
321
|
+
category: 'global',
|
|
322
|
+
})
|
|
323
|
+
);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('should not register product when extending standard product during apply', () => {
|
|
327
|
+
const mockPlugin = createMockPlugin();
|
|
328
|
+
const mockStore = createMockStore();
|
|
329
|
+
const mockDSL = {
|
|
330
|
+
product: jest.fn(),
|
|
331
|
+
basicType: jest.fn(),
|
|
332
|
+
labelGroup: jest.fn(),
|
|
333
|
+
setGroupDefaultType: jest.fn(),
|
|
334
|
+
weightGroup: jest.fn(),
|
|
335
|
+
virtualType: jest.fn(),
|
|
336
|
+
configureType: jest.fn(),
|
|
337
|
+
weightType: jest.fn(),
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
341
|
+
|
|
342
|
+
const validStandardProduct = StandardProductNames.EXPLORER;
|
|
343
|
+
|
|
344
|
+
const pluginProduct = new PluginProduct(mockPlugin, validStandardProduct, []);
|
|
345
|
+
|
|
346
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
347
|
+
|
|
348
|
+
expect(mockDSL.product).not.toHaveBeenCalled();
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('should configure virtualType items during apply', () => {
|
|
352
|
+
const mockPlugin = createMockPlugin();
|
|
353
|
+
const mockStore = createMockStore();
|
|
354
|
+
const mockDSL = {
|
|
355
|
+
product: jest.fn(),
|
|
356
|
+
basicType: jest.fn(),
|
|
357
|
+
labelGroup: jest.fn(),
|
|
358
|
+
setGroupDefaultType: jest.fn(),
|
|
359
|
+
weightGroup: jest.fn(),
|
|
360
|
+
virtualType: jest.fn(),
|
|
361
|
+
configureType: jest.fn(),
|
|
362
|
+
weightType: jest.fn(),
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
366
|
+
|
|
367
|
+
const productMetadata: ProductMetadata = {
|
|
368
|
+
name: 'product-with-pages',
|
|
369
|
+
label: 'Product',
|
|
370
|
+
};
|
|
371
|
+
const config: ProductChildPage[] = [
|
|
372
|
+
{
|
|
373
|
+
name: 'overview',
|
|
374
|
+
label: 'Overview',
|
|
375
|
+
component: { name: 'OverviewComponent' },
|
|
376
|
+
weight: 10,
|
|
377
|
+
},
|
|
378
|
+
];
|
|
379
|
+
|
|
380
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
381
|
+
|
|
382
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
383
|
+
|
|
384
|
+
expect(mockDSL.virtualType).toHaveBeenCalledTimes(1);
|
|
385
|
+
expect(mockDSL.virtualType).toHaveBeenCalledWith(
|
|
386
|
+
expect.objectContaining({
|
|
387
|
+
name: 'productwithpages-overview',
|
|
388
|
+
label: 'Overview',
|
|
389
|
+
weight: 10,
|
|
390
|
+
})
|
|
391
|
+
);
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it('should configure configureType (resource) items during apply', () => {
|
|
395
|
+
const mockPlugin = createMockPlugin();
|
|
396
|
+
const mockStore = createMockStore();
|
|
397
|
+
const mockDSL = {
|
|
398
|
+
product: jest.fn(),
|
|
399
|
+
basicType: jest.fn(),
|
|
400
|
+
labelGroup: jest.fn(),
|
|
401
|
+
setGroupDefaultType: jest.fn(),
|
|
402
|
+
weightGroup: jest.fn(),
|
|
403
|
+
virtualType: jest.fn(),
|
|
404
|
+
configureType: jest.fn(),
|
|
405
|
+
weightType: jest.fn(),
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
409
|
+
|
|
410
|
+
const productMetadata: ProductMetadata = {
|
|
411
|
+
name: 'resource-product',
|
|
412
|
+
label: 'Resources',
|
|
413
|
+
};
|
|
414
|
+
const config: ProductChildPage[] = [
|
|
415
|
+
{
|
|
416
|
+
type: 'custom.resource',
|
|
417
|
+
weight: 5,
|
|
418
|
+
},
|
|
419
|
+
];
|
|
420
|
+
|
|
421
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
422
|
+
|
|
423
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
424
|
+
|
|
425
|
+
expect(mockDSL.configureType).toHaveBeenCalledWith(
|
|
426
|
+
'custom.resource',
|
|
427
|
+
expect.objectContaining({
|
|
428
|
+
isCreatable: true,
|
|
429
|
+
isEditable: true,
|
|
430
|
+
isRemovable: true,
|
|
431
|
+
canYaml: true,
|
|
432
|
+
})
|
|
433
|
+
);
|
|
434
|
+
expect(mockDSL.weightType).toHaveBeenCalledWith('custom.resource', 5, true);
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
describe('grouped items', () => {
|
|
439
|
+
it('should handle product with grouped items', () => {
|
|
440
|
+
const mockPlugin = createMockPlugin();
|
|
441
|
+
const mockStore = createMockStore();
|
|
442
|
+
const mockDSL = {
|
|
443
|
+
product: jest.fn(),
|
|
444
|
+
basicType: jest.fn(),
|
|
445
|
+
labelGroup: jest.fn(),
|
|
446
|
+
setGroupDefaultType: jest.fn(),
|
|
447
|
+
weightGroup: jest.fn(),
|
|
448
|
+
virtualType: jest.fn(),
|
|
449
|
+
configureType: jest.fn(),
|
|
450
|
+
weightType: jest.fn(),
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
454
|
+
|
|
455
|
+
const productMetadata: ProductMetadata = {
|
|
456
|
+
name: 'grouped-product',
|
|
457
|
+
label: 'Grouped',
|
|
458
|
+
};
|
|
459
|
+
const groupedConfig: ProductChildGroup[] = [
|
|
460
|
+
{
|
|
461
|
+
name: 'settings',
|
|
462
|
+
label: 'Settings',
|
|
463
|
+
children: [
|
|
464
|
+
{
|
|
465
|
+
name: 'general',
|
|
466
|
+
label: 'General',
|
|
467
|
+
component: { name: 'GeneralSettings' },
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
name: 'advanced',
|
|
471
|
+
label: 'Advanced',
|
|
472
|
+
component: { name: 'AdvancedSettings' },
|
|
473
|
+
},
|
|
474
|
+
],
|
|
475
|
+
},
|
|
476
|
+
];
|
|
477
|
+
|
|
478
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, groupedConfig);
|
|
479
|
+
|
|
480
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
481
|
+
|
|
482
|
+
expect(mockDSL.basicType).toHaveBeenCalledTimes(2);
|
|
483
|
+
expect(mockDSL.labelGroup).toHaveBeenCalledWith(
|
|
484
|
+
expect.stringContaining('settings'),
|
|
485
|
+
'Settings',
|
|
486
|
+
undefined
|
|
487
|
+
);
|
|
488
|
+
expect(mockDSL.virtualType).toHaveBeenCalledTimes(2);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it('should set group default type when group has no component', () => {
|
|
492
|
+
const mockPlugin = createMockPlugin();
|
|
493
|
+
const mockStore = createMockStore();
|
|
494
|
+
const mockDSL = {
|
|
495
|
+
product: jest.fn(),
|
|
496
|
+
basicType: jest.fn(),
|
|
497
|
+
labelGroup: jest.fn(),
|
|
498
|
+
setGroupDefaultType: jest.fn(),
|
|
499
|
+
weightGroup: jest.fn(),
|
|
500
|
+
virtualType: jest.fn(),
|
|
501
|
+
configureType: jest.fn(),
|
|
502
|
+
weightType: jest.fn(),
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
506
|
+
|
|
507
|
+
const productMetadata: ProductMetadata = {
|
|
508
|
+
name: 'group-no-component',
|
|
509
|
+
label: 'Group No Component',
|
|
510
|
+
};
|
|
511
|
+
const config: ProductChildGroup[] = [
|
|
512
|
+
{
|
|
513
|
+
name: 'group',
|
|
514
|
+
label: 'Group Without Component',
|
|
515
|
+
children: [
|
|
516
|
+
{
|
|
517
|
+
name: 'child1',
|
|
518
|
+
label: 'Child 1',
|
|
519
|
+
component: { name: 'Child1Component' },
|
|
520
|
+
},
|
|
521
|
+
],
|
|
522
|
+
},
|
|
523
|
+
];
|
|
524
|
+
|
|
525
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
526
|
+
|
|
527
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
528
|
+
|
|
529
|
+
expect(mockDSL.setGroupDefaultType).toHaveBeenCalledWith(
|
|
530
|
+
expect.stringContaining('group'),
|
|
531
|
+
expect.stringContaining('child1')
|
|
532
|
+
);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it('should set group default type to itself when group has component', () => {
|
|
536
|
+
const mockPlugin = createMockPlugin();
|
|
537
|
+
const mockStore = createMockStore();
|
|
538
|
+
const mockDSL = {
|
|
539
|
+
product: jest.fn(),
|
|
540
|
+
basicType: jest.fn(),
|
|
541
|
+
labelGroup: jest.fn(),
|
|
542
|
+
setGroupDefaultType: jest.fn(),
|
|
543
|
+
weightGroup: jest.fn(),
|
|
544
|
+
virtualType: jest.fn(),
|
|
545
|
+
configureType: jest.fn(),
|
|
546
|
+
weightType: jest.fn(),
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
550
|
+
|
|
551
|
+
const productMetadata: ProductMetadata = {
|
|
552
|
+
name: 'group-with-component',
|
|
553
|
+
label: 'Group With Component',
|
|
554
|
+
};
|
|
555
|
+
const config: ProductChildGroup[] = [
|
|
556
|
+
{
|
|
557
|
+
name: 'group',
|
|
558
|
+
label: 'Group With Component',
|
|
559
|
+
component: { name: 'GroupOverviewComponent' },
|
|
560
|
+
children: [
|
|
561
|
+
{
|
|
562
|
+
name: 'child1',
|
|
563
|
+
label: 'Child 1',
|
|
564
|
+
component: { name: 'Child1Component' },
|
|
565
|
+
},
|
|
566
|
+
],
|
|
567
|
+
},
|
|
568
|
+
];
|
|
569
|
+
|
|
570
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
571
|
+
|
|
572
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
573
|
+
|
|
574
|
+
// When a group has a component, setGroupDefaultType should be called with the group name itself
|
|
575
|
+
// This ensures clicking the group in nav routes to the group's page, not bypassing to first child
|
|
576
|
+
expect(mockDSL.setGroupDefaultType).toHaveBeenCalledWith(
|
|
577
|
+
'groupwithcomponent-group',
|
|
578
|
+
'groupwithcomponent-group'
|
|
579
|
+
);
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
it('should apply group weight when specified', () => {
|
|
583
|
+
const mockPlugin = createMockPlugin();
|
|
584
|
+
const mockStore = createMockStore();
|
|
585
|
+
const mockDSL = {
|
|
586
|
+
product: jest.fn(),
|
|
587
|
+
basicType: jest.fn(),
|
|
588
|
+
labelGroup: jest.fn(),
|
|
589
|
+
setGroupDefaultType: jest.fn(),
|
|
590
|
+
weightGroup: jest.fn(),
|
|
591
|
+
virtualType: jest.fn(),
|
|
592
|
+
configureType: jest.fn(),
|
|
593
|
+
weightType: jest.fn(),
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
597
|
+
|
|
598
|
+
const productMetadata: ProductMetadata = {
|
|
599
|
+
name: 'weighted-group',
|
|
600
|
+
label: 'Weighted',
|
|
601
|
+
};
|
|
602
|
+
const config: ProductChildGroup[] = [
|
|
603
|
+
{
|
|
604
|
+
name: 'group',
|
|
605
|
+
label: 'Group',
|
|
606
|
+
weight: 50,
|
|
607
|
+
children: [
|
|
608
|
+
{
|
|
609
|
+
name: 'child',
|
|
610
|
+
label: 'Child',
|
|
611
|
+
component: { name: 'ChildComponent' },
|
|
612
|
+
},
|
|
613
|
+
],
|
|
614
|
+
},
|
|
615
|
+
];
|
|
616
|
+
|
|
617
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
618
|
+
|
|
619
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
620
|
+
|
|
621
|
+
expect(mockDSL.weightGroup).toHaveBeenCalledWith(
|
|
622
|
+
expect.stringContaining('group'),
|
|
623
|
+
50,
|
|
624
|
+
true
|
|
625
|
+
);
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
describe('default route determination', () => {
|
|
630
|
+
it('should use first config item as default route for new product', () => {
|
|
631
|
+
const mockPlugin = createMockPlugin();
|
|
632
|
+
const mockStore = createMockStore();
|
|
633
|
+
const mockDSL = {
|
|
634
|
+
product: jest.fn(),
|
|
635
|
+
basicType: jest.fn(),
|
|
636
|
+
labelGroup: jest.fn(),
|
|
637
|
+
setGroupDefaultType: jest.fn(),
|
|
638
|
+
weightGroup: jest.fn(),
|
|
639
|
+
virtualType: jest.fn(),
|
|
640
|
+
configureType: jest.fn(),
|
|
641
|
+
weightType: jest.fn(),
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
645
|
+
|
|
646
|
+
const productMetadata: ProductMetadata = {
|
|
647
|
+
name: 'default-route-product',
|
|
648
|
+
label: 'Default Route',
|
|
649
|
+
};
|
|
650
|
+
const config: ProductChildPage[] = [
|
|
651
|
+
{
|
|
652
|
+
name: 'first',
|
|
653
|
+
label: 'First',
|
|
654
|
+
component: { name: 'FirstComponent' },
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
name: 'second',
|
|
658
|
+
label: 'Second',
|
|
659
|
+
component: { name: 'SecondComponent' },
|
|
660
|
+
},
|
|
661
|
+
];
|
|
662
|
+
|
|
663
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
664
|
+
|
|
665
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
666
|
+
|
|
667
|
+
expect(mockDSL.product).toHaveBeenCalledWith(
|
|
668
|
+
expect.objectContaining({ to: expect.objectContaining({ name: expect.stringContaining('first') }) })
|
|
669
|
+
);
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
it('should use first group child as default route when first item is group', () => {
|
|
673
|
+
const mockPlugin = createMockPlugin();
|
|
674
|
+
const mockStore = createMockStore();
|
|
675
|
+
const mockDSL = {
|
|
676
|
+
product: jest.fn(),
|
|
677
|
+
basicType: jest.fn(),
|
|
678
|
+
labelGroup: jest.fn(),
|
|
679
|
+
setGroupDefaultType: jest.fn(),
|
|
680
|
+
weightGroup: jest.fn(),
|
|
681
|
+
virtualType: jest.fn(),
|
|
682
|
+
configureType: jest.fn(),
|
|
683
|
+
weightType: jest.fn(),
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
687
|
+
|
|
688
|
+
const productMetadata: ProductMetadata = {
|
|
689
|
+
name: 'group-default-route',
|
|
690
|
+
label: 'Group Default',
|
|
691
|
+
};
|
|
692
|
+
const config: ProductChildGroup[] = [
|
|
693
|
+
{
|
|
694
|
+
name: 'settings',
|
|
695
|
+
label: 'Settings',
|
|
696
|
+
children: [
|
|
697
|
+
{
|
|
698
|
+
name: 'general',
|
|
699
|
+
label: 'General',
|
|
700
|
+
component: { name: 'GeneralComponent' },
|
|
701
|
+
},
|
|
702
|
+
],
|
|
703
|
+
},
|
|
704
|
+
];
|
|
705
|
+
|
|
706
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
707
|
+
|
|
708
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
709
|
+
|
|
710
|
+
expect(mockDSL.product).toHaveBeenCalledWith(
|
|
711
|
+
expect.objectContaining({ to: expect.objectContaining({ name: expect.stringContaining('general') }) })
|
|
712
|
+
);
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
it('should use first group child with resource type as default route when first item is group', () => {
|
|
716
|
+
const mockPlugin = createMockPlugin();
|
|
717
|
+
const mockStore = createMockStore();
|
|
718
|
+
const mockDSL = {
|
|
719
|
+
product: jest.fn(),
|
|
720
|
+
basicType: jest.fn(),
|
|
721
|
+
labelGroup: jest.fn(),
|
|
722
|
+
setGroupDefaultType: jest.fn(),
|
|
723
|
+
weightGroup: jest.fn(),
|
|
724
|
+
virtualType: jest.fn(),
|
|
725
|
+
configureType: jest.fn(),
|
|
726
|
+
weightType: jest.fn(),
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
730
|
+
|
|
731
|
+
const productMetadata: ProductMetadata = {
|
|
732
|
+
name: 'group-resource-default',
|
|
733
|
+
label: 'Group Resource Default',
|
|
734
|
+
};
|
|
735
|
+
const config: ProductChildGroup[] = [
|
|
736
|
+
{
|
|
737
|
+
name: 'resources',
|
|
738
|
+
label: 'Resources',
|
|
739
|
+
children: [
|
|
740
|
+
{ type: 'provisioning.cattle.io.cluster' },
|
|
741
|
+
],
|
|
742
|
+
},
|
|
743
|
+
];
|
|
744
|
+
|
|
745
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
746
|
+
|
|
747
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
748
|
+
|
|
749
|
+
expect(mockDSL.product).toHaveBeenCalledWith(
|
|
750
|
+
expect.objectContaining({
|
|
751
|
+
to: expect.objectContaining({
|
|
752
|
+
name: 'groupresourcedefault-c-cluster-resource',
|
|
753
|
+
params: expect.objectContaining({
|
|
754
|
+
product: 'groupresourcedefault',
|
|
755
|
+
cluster: '__BLANK_CLUSTER__',
|
|
756
|
+
resource: 'provisioning.cattle.io.cluster',
|
|
757
|
+
}),
|
|
758
|
+
}),
|
|
759
|
+
})
|
|
760
|
+
);
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
it('should use resource type as default route when first item is configureType', () => {
|
|
764
|
+
const mockPlugin = createMockPlugin();
|
|
765
|
+
const mockStore = createMockStore();
|
|
766
|
+
const mockDSL = {
|
|
767
|
+
product: jest.fn(),
|
|
768
|
+
basicType: jest.fn(),
|
|
769
|
+
labelGroup: jest.fn(),
|
|
770
|
+
setGroupDefaultType: jest.fn(),
|
|
771
|
+
weightGroup: jest.fn(),
|
|
772
|
+
virtualType: jest.fn(),
|
|
773
|
+
configureType: jest.fn(),
|
|
774
|
+
weightType: jest.fn(),
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
778
|
+
|
|
779
|
+
const productMetadata: ProductMetadata = {
|
|
780
|
+
name: 'resource-first',
|
|
781
|
+
label: 'Resource First',
|
|
782
|
+
};
|
|
783
|
+
const config: ProductChildPage[] = [
|
|
784
|
+
{ type: 'apps.deployment' },
|
|
785
|
+
{
|
|
786
|
+
name: 'overview',
|
|
787
|
+
label: 'Overview',
|
|
788
|
+
component: { name: 'OverviewComponent' },
|
|
789
|
+
},
|
|
790
|
+
];
|
|
791
|
+
|
|
792
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
793
|
+
|
|
794
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
795
|
+
|
|
796
|
+
expect(mockDSL.product).toHaveBeenCalledWith(
|
|
797
|
+
expect.objectContaining({
|
|
798
|
+
to: expect.objectContaining({
|
|
799
|
+
name: 'resourcefirst-c-cluster-resource',
|
|
800
|
+
params: expect.objectContaining({
|
|
801
|
+
product: 'resourcefirst',
|
|
802
|
+
cluster: '__BLANK_CLUSTER__',
|
|
803
|
+
resource: 'apps.deployment',
|
|
804
|
+
}),
|
|
805
|
+
}),
|
|
806
|
+
})
|
|
807
|
+
);
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
it('should use group component as default route when group has component but no children', () => {
|
|
811
|
+
const mockPlugin = createMockPlugin();
|
|
812
|
+
const mockStore = createMockStore();
|
|
813
|
+
const mockDSL = {
|
|
814
|
+
product: jest.fn(),
|
|
815
|
+
basicType: jest.fn(),
|
|
816
|
+
labelGroup: jest.fn(),
|
|
817
|
+
setGroupDefaultType: jest.fn(),
|
|
818
|
+
weightGroup: jest.fn(),
|
|
819
|
+
virtualType: jest.fn(),
|
|
820
|
+
configureType: jest.fn(),
|
|
821
|
+
weightType: jest.fn(),
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
825
|
+
|
|
826
|
+
const productMetadata: ProductMetadata = {
|
|
827
|
+
name: 'empty-group',
|
|
828
|
+
label: 'Empty Group',
|
|
829
|
+
};
|
|
830
|
+
const config: ProductChildGroup[] = [
|
|
831
|
+
{
|
|
832
|
+
name: 'empty-group-with-page',
|
|
833
|
+
label: 'Empty Group With Page',
|
|
834
|
+
component: { name: 'EmptyGroupComponent' },
|
|
835
|
+
children: [],
|
|
836
|
+
},
|
|
837
|
+
];
|
|
838
|
+
|
|
839
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
840
|
+
|
|
841
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
842
|
+
|
|
843
|
+
// Verify default route points to the group's component page (not a child, since there are none)
|
|
844
|
+
expect(mockDSL.product).toHaveBeenCalledWith(
|
|
845
|
+
expect.objectContaining({ to: expect.objectContaining({ name: expect.stringContaining('emptygroup') }) })
|
|
846
|
+
);
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
it('should use group component as default route when group has both component and children', () => {
|
|
850
|
+
const mockPlugin = createMockPlugin();
|
|
851
|
+
const mockStore = createMockStore();
|
|
852
|
+
const mockDSL = {
|
|
853
|
+
product: jest.fn(),
|
|
854
|
+
basicType: jest.fn(),
|
|
855
|
+
labelGroup: jest.fn(),
|
|
856
|
+
setGroupDefaultType: jest.fn(),
|
|
857
|
+
weightGroup: jest.fn(),
|
|
858
|
+
virtualType: jest.fn(),
|
|
859
|
+
configureType: jest.fn(),
|
|
860
|
+
weightType: jest.fn(),
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
864
|
+
|
|
865
|
+
const productMetadata: ProductMetadata = {
|
|
866
|
+
name: 'group-with-page',
|
|
867
|
+
label: 'Group With Page',
|
|
868
|
+
};
|
|
869
|
+
const config: ProductChildGroup[] = [
|
|
870
|
+
{
|
|
871
|
+
name: 'settings',
|
|
872
|
+
label: 'Settings',
|
|
873
|
+
component: { name: 'SettingsOverviewComponent' },
|
|
874
|
+
children: [
|
|
875
|
+
{
|
|
876
|
+
name: 'general',
|
|
877
|
+
label: 'General Settings',
|
|
878
|
+
component: { name: 'GeneralComponent' },
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
name: 'advanced',
|
|
882
|
+
label: 'Advanced Settings',
|
|
883
|
+
component: { name: 'AdvancedComponent' },
|
|
884
|
+
},
|
|
885
|
+
],
|
|
886
|
+
},
|
|
887
|
+
];
|
|
888
|
+
|
|
889
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
890
|
+
|
|
891
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
892
|
+
|
|
893
|
+
// Verify default route points to the group's component page (not first child)
|
|
894
|
+
// When a group has a component, it should route to that component, not the first child
|
|
895
|
+
expect(mockDSL.product).toHaveBeenCalledWith(
|
|
896
|
+
expect.objectContaining({ to: expect.objectContaining({ name: 'groupwithpage-group' }) })
|
|
897
|
+
);
|
|
898
|
+
|
|
899
|
+
// Verify virtualType was still created for the group component
|
|
900
|
+
expect(mockDSL.virtualType).toHaveBeenCalledWith(
|
|
901
|
+
expect.objectContaining({
|
|
902
|
+
name: 'groupwithpage-settings',
|
|
903
|
+
exact: true,
|
|
904
|
+
overview: true,
|
|
905
|
+
})
|
|
906
|
+
);
|
|
907
|
+
});
|
|
908
|
+
});
|
|
909
|
+
|
|
910
|
+
describe('mixed config types', () => {
|
|
911
|
+
it('should handle product with mixed virtualType and configureType items', () => {
|
|
912
|
+
const mockPlugin = createMockPlugin();
|
|
913
|
+
const mockStore = createMockStore();
|
|
914
|
+
const mockDSL = {
|
|
915
|
+
product: jest.fn(),
|
|
916
|
+
basicType: jest.fn(),
|
|
917
|
+
labelGroup: jest.fn(),
|
|
918
|
+
setGroupDefaultType: jest.fn(),
|
|
919
|
+
weightGroup: jest.fn(),
|
|
920
|
+
virtualType: jest.fn(),
|
|
921
|
+
configureType: jest.fn(),
|
|
922
|
+
weightType: jest.fn(),
|
|
923
|
+
};
|
|
924
|
+
|
|
925
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
926
|
+
|
|
927
|
+
const productMetadata: ProductMetadata = {
|
|
928
|
+
name: 'mixed-product',
|
|
929
|
+
label: 'Mixed Content',
|
|
930
|
+
};
|
|
931
|
+
const mixedConfig: ProductChildPage[] = [
|
|
932
|
+
{
|
|
933
|
+
name: 'overview',
|
|
934
|
+
label: 'Overview',
|
|
935
|
+
component: { name: 'OverviewComponent' },
|
|
936
|
+
},
|
|
937
|
+
{ type: 'resources.io' },
|
|
938
|
+
];
|
|
939
|
+
|
|
940
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, mixedConfig);
|
|
941
|
+
|
|
942
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
943
|
+
|
|
944
|
+
expect(mockDSL.virtualType).toHaveBeenCalledTimes(1);
|
|
945
|
+
expect(mockDSL.configureType).toHaveBeenCalledWith('resources.io', expect.any(Object));
|
|
946
|
+
});
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
describe('error handling', () => {
|
|
950
|
+
it('should throw error when config children is not an array', () => {
|
|
951
|
+
const mockPlugin = createMockPlugin();
|
|
952
|
+
const productMetadata: ProductMetadata = {
|
|
953
|
+
name: 'bad-group',
|
|
954
|
+
label: 'Bad Group',
|
|
955
|
+
};
|
|
956
|
+
const badConfig: any[] = [
|
|
957
|
+
{
|
|
958
|
+
name: 'group',
|
|
959
|
+
label: 'Group',
|
|
960
|
+
children: 'not-an-array', // Invalid
|
|
961
|
+
},
|
|
962
|
+
];
|
|
963
|
+
|
|
964
|
+
expect(() => {
|
|
965
|
+
new PluginProduct(mockPlugin, productMetadata, badConfig);
|
|
966
|
+
}).toThrow('forEach');
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
it('should throw when extending standard product and group parent has component', () => {
|
|
970
|
+
const mockPlugin = createMockPlugin();
|
|
971
|
+
const config: ProductChildGroup[] = [
|
|
972
|
+
{
|
|
973
|
+
name: 'parent-group',
|
|
974
|
+
label: 'Parent Group',
|
|
975
|
+
component: { name: 'GroupComponent' },
|
|
976
|
+
children: [
|
|
977
|
+
{
|
|
978
|
+
name: 'child',
|
|
979
|
+
label: 'Child',
|
|
980
|
+
component: { name: 'ChildComponent' },
|
|
981
|
+
},
|
|
982
|
+
],
|
|
983
|
+
},
|
|
984
|
+
];
|
|
985
|
+
|
|
986
|
+
expect(() => {
|
|
987
|
+
new PluginProduct(mockPlugin, StandardProductNames.EXPLORER, config);
|
|
988
|
+
}).toThrow('When extending an existing product, group parent items cannot have a component because of route matching conflicts.');
|
|
989
|
+
});
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
describe('state verification', () => {
|
|
993
|
+
it('should set newProduct flag for new products', () => {
|
|
994
|
+
const mockPlugin = createMockPlugin();
|
|
995
|
+
const productMetadata: ProductMetadata = {
|
|
996
|
+
name: 'new-prod',
|
|
997
|
+
label: 'New',
|
|
998
|
+
};
|
|
999
|
+
|
|
1000
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, []);
|
|
1001
|
+
|
|
1002
|
+
expect(pluginProduct.newProduct).toBe(true);
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
it('should not set newProduct flag for standard product extensions', () => {
|
|
1006
|
+
const mockPlugin = createMockPlugin();
|
|
1007
|
+
const validStandardProduct = StandardProductNames.EXPLORER;
|
|
1008
|
+
|
|
1009
|
+
const pluginProduct = new PluginProduct(mockPlugin, validStandardProduct, []);
|
|
1010
|
+
|
|
1011
|
+
expect(pluginProduct.newProduct).toBe(false);
|
|
1012
|
+
});
|
|
1013
|
+
});
|
|
1014
|
+
|
|
1015
|
+
describe('real-world scenarios from pkg/add-new-prod', () => {
|
|
1016
|
+
describe('scenario 1: simple product with single page component (plain layout)', () => {
|
|
1017
|
+
it('should create single page product with plain layout', () => {
|
|
1018
|
+
const mockPlugin = createMockPlugin();
|
|
1019
|
+
const productSinglePage: ProductSinglePage = {
|
|
1020
|
+
name: 'alex-simple-one-page',
|
|
1021
|
+
weight: -100,
|
|
1022
|
+
label: 'Simple One Page (no sidebar)',
|
|
1023
|
+
component: { name: 'TestComponent' },
|
|
1024
|
+
};
|
|
1025
|
+
|
|
1026
|
+
const pluginProduct = new PluginProduct(mockPlugin, productSinglePage, []);
|
|
1027
|
+
|
|
1028
|
+
expect(pluginProduct.newProduct).toBe(true);
|
|
1029
|
+
expect(mockPlugin.addRoute).toHaveBeenCalledTimes(1);
|
|
1030
|
+
});
|
|
1031
|
+
});
|
|
1032
|
+
|
|
1033
|
+
describe('scenario 2: simple product without children', () => {
|
|
1034
|
+
it('should create product with sidebar but no config children', () => {
|
|
1035
|
+
const mockPlugin = createMockPlugin();
|
|
1036
|
+
const productMetadata: ProductMetadata = {
|
|
1037
|
+
name: 'alex-simple-top-level',
|
|
1038
|
+
weight: -100,
|
|
1039
|
+
label: 'Simple (with sidebar)',
|
|
1040
|
+
};
|
|
1041
|
+
|
|
1042
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, []);
|
|
1043
|
+
|
|
1044
|
+
expect(pluginProduct.newProduct).toBe(true);
|
|
1045
|
+
expect(mockPlugin.addRoute).toHaveBeenCalledTimes(1);
|
|
1046
|
+
});
|
|
1047
|
+
});
|
|
1048
|
+
|
|
1049
|
+
describe('scenario 3: simple product with simple children (virtualTypes)', () => {
|
|
1050
|
+
it('should create product with multiple simple virtualType children', () => {
|
|
1051
|
+
const mockPlugin = createMockPlugin();
|
|
1052
|
+
const mockStore = createMockStore();
|
|
1053
|
+
const mockDSL = {
|
|
1054
|
+
product: jest.fn(),
|
|
1055
|
+
basicType: jest.fn(),
|
|
1056
|
+
labelGroup: jest.fn(),
|
|
1057
|
+
setGroupDefaultType: jest.fn(),
|
|
1058
|
+
weightGroup: jest.fn(),
|
|
1059
|
+
virtualType: jest.fn(),
|
|
1060
|
+
configureType: jest.fn(),
|
|
1061
|
+
weightType: jest.fn(),
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1065
|
+
|
|
1066
|
+
const productMetadata: ProductMetadata = {
|
|
1067
|
+
name: 'alex-simple-children',
|
|
1068
|
+
weight: -100,
|
|
1069
|
+
label: 'Simple with Children',
|
|
1070
|
+
};
|
|
1071
|
+
const config: ProductChildPage[] = [
|
|
1072
|
+
{
|
|
1073
|
+
name: 'page1',
|
|
1074
|
+
label: 'My label for page 1',
|
|
1075
|
+
component: { name: 'TestComponent' },
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
name: 'page2',
|
|
1079
|
+
label: 'My label for page 2',
|
|
1080
|
+
component: { name: 'TestComponent' },
|
|
1081
|
+
},
|
|
1082
|
+
];
|
|
1083
|
+
|
|
1084
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
1085
|
+
|
|
1086
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1087
|
+
|
|
1088
|
+
expect(mockDSL.virtualType).toHaveBeenCalledTimes(2);
|
|
1089
|
+
expect(mockDSL.product).toHaveBeenCalledTimes(1);
|
|
1090
|
+
});
|
|
1091
|
+
});
|
|
1092
|
+
|
|
1093
|
+
describe('scenario 4: product with simple children (virtualTypes) + type (configureType)', () => {
|
|
1094
|
+
it('should handle mix of virtualType pages and resource types', () => {
|
|
1095
|
+
const mockPlugin = createMockPlugin();
|
|
1096
|
+
const mockStore = createMockStore();
|
|
1097
|
+
const mockDSL = {
|
|
1098
|
+
product: jest.fn(),
|
|
1099
|
+
basicType: jest.fn(),
|
|
1100
|
+
labelGroup: jest.fn(),
|
|
1101
|
+
setGroupDefaultType: jest.fn(),
|
|
1102
|
+
weightGroup: jest.fn(),
|
|
1103
|
+
virtualType: jest.fn(),
|
|
1104
|
+
configureType: jest.fn(),
|
|
1105
|
+
weightType: jest.fn(),
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1109
|
+
|
|
1110
|
+
const productMetadata: ProductMetadata = {
|
|
1111
|
+
name: 'alex-simple-children',
|
|
1112
|
+
weight: -100,
|
|
1113
|
+
label: 'Simple with Children',
|
|
1114
|
+
};
|
|
1115
|
+
const config: ProductChildPage[] = [
|
|
1116
|
+
{
|
|
1117
|
+
name: 'page1',
|
|
1118
|
+
label: 'My label for page 1',
|
|
1119
|
+
component: { name: 'TestComponent' },
|
|
1120
|
+
},
|
|
1121
|
+
{
|
|
1122
|
+
name: 'page2',
|
|
1123
|
+
label: 'My label for page 2',
|
|
1124
|
+
component: { name: 'TestComponent' },
|
|
1125
|
+
},
|
|
1126
|
+
{ type: 'upgrade.cattle.io.plan' },
|
|
1127
|
+
];
|
|
1128
|
+
|
|
1129
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
1130
|
+
|
|
1131
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1132
|
+
|
|
1133
|
+
expect(mockDSL.virtualType).toHaveBeenCalledTimes(2);
|
|
1134
|
+
expect(mockDSL.configureType).toHaveBeenCalledWith('upgrade.cattle.io.plan', expect.any(Object));
|
|
1135
|
+
});
|
|
1136
|
+
});
|
|
1137
|
+
|
|
1138
|
+
describe('scenario 5: product with type first, then children with nested groups', () => {
|
|
1139
|
+
it('should handle resource type first, then virtualType pages with nested children', () => {
|
|
1140
|
+
const mockPlugin = createMockPlugin();
|
|
1141
|
+
const mockStore = createMockStore();
|
|
1142
|
+
const mockDSL = {
|
|
1143
|
+
product: jest.fn(),
|
|
1144
|
+
basicType: jest.fn(),
|
|
1145
|
+
labelGroup: jest.fn(),
|
|
1146
|
+
setGroupDefaultType: jest.fn(),
|
|
1147
|
+
weightGroup: jest.fn(),
|
|
1148
|
+
virtualType: jest.fn(),
|
|
1149
|
+
configureType: jest.fn(),
|
|
1150
|
+
weightType: jest.fn(),
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1154
|
+
|
|
1155
|
+
const productMetadata: ProductMetadata = {
|
|
1156
|
+
name: 'alex-simple-children',
|
|
1157
|
+
weight: -100,
|
|
1158
|
+
label: 'Simple with Children',
|
|
1159
|
+
};
|
|
1160
|
+
const config: (ProductChildGroup | ProductChildPage)[] = [
|
|
1161
|
+
{ type: 'fleet.cattle.io.clustergroup' },
|
|
1162
|
+
{
|
|
1163
|
+
name: 'page1',
|
|
1164
|
+
label: 'My label for page 1',
|
|
1165
|
+
component: { name: 'TestComponent' },
|
|
1166
|
+
children: [
|
|
1167
|
+
{
|
|
1168
|
+
name: 'hello0',
|
|
1169
|
+
label: 'Testing 12',
|
|
1170
|
+
labelKey: 'aks.label',
|
|
1171
|
+
component: { name: 'TestComponent' },
|
|
1172
|
+
} as any,
|
|
1173
|
+
{
|
|
1174
|
+
name: 'hello1',
|
|
1175
|
+
label: 'Testing 1',
|
|
1176
|
+
labelKey: 'aks.label',
|
|
1177
|
+
component: { name: 'TestComponent' },
|
|
1178
|
+
},
|
|
1179
|
+
{
|
|
1180
|
+
name: 'hello3',
|
|
1181
|
+
labelKey: 'aks.label',
|
|
1182
|
+
component: { name: 'TestComponent' },
|
|
1183
|
+
},
|
|
1184
|
+
{
|
|
1185
|
+
name: 'hello2',
|
|
1186
|
+
label: 'Testing 2',
|
|
1187
|
+
component: { name: 'TestComponent' },
|
|
1188
|
+
},
|
|
1189
|
+
],
|
|
1190
|
+
},
|
|
1191
|
+
{ type: 'upgrade.cattle.io.plan' },
|
|
1192
|
+
{
|
|
1193
|
+
name: 'page2',
|
|
1194
|
+
label: 'My label for page 2',
|
|
1195
|
+
component: { name: 'TestComponent' },
|
|
1196
|
+
},
|
|
1197
|
+
];
|
|
1198
|
+
|
|
1199
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
1200
|
+
|
|
1201
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1202
|
+
|
|
1203
|
+
expect(mockDSL.configureType).toHaveBeenCalledWith('fleet.cattle.io.clustergroup', expect.any(Object));
|
|
1204
|
+
expect(mockDSL.virtualType).toHaveBeenCalledTimes(6);
|
|
1205
|
+
expect(mockDSL.labelGroup).toHaveBeenCalledTimes(1);
|
|
1206
|
+
expect(mockDSL.product).toHaveBeenCalledTimes(1);
|
|
1207
|
+
});
|
|
1208
|
+
});
|
|
1209
|
+
|
|
1210
|
+
describe('scenario 6: extend standard product without configuring children', () => {
|
|
1211
|
+
it('should extend existing standard product with empty config', () => {
|
|
1212
|
+
const mockPlugin = createMockPlugin();
|
|
1213
|
+
const validStandardProduct = StandardProductNames.EXPLORER;
|
|
1214
|
+
|
|
1215
|
+
const pluginProduct = new PluginProduct(mockPlugin, validStandardProduct, []);
|
|
1216
|
+
|
|
1217
|
+
expect(pluginProduct.newProduct).toBe(false);
|
|
1218
|
+
expect(mockPlugin._registerTopLevelProduct).not.toHaveBeenCalled();
|
|
1219
|
+
expect(mockPlugin.addRoute).toHaveBeenCalledTimes(1);
|
|
1220
|
+
});
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
describe('scenario 7: extend standard product with simple virtualType children', () => {
|
|
1224
|
+
it('should extend standard product adding simple virtualType page', () => {
|
|
1225
|
+
const mockPlugin = createMockPlugin();
|
|
1226
|
+
const mockStore = createMockStore();
|
|
1227
|
+
const mockDSL = {
|
|
1228
|
+
product: jest.fn(),
|
|
1229
|
+
basicType: jest.fn(),
|
|
1230
|
+
labelGroup: jest.fn(),
|
|
1231
|
+
setGroupDefaultType: jest.fn(),
|
|
1232
|
+
weightGroup: jest.fn(),
|
|
1233
|
+
virtualType: jest.fn(),
|
|
1234
|
+
configureType: jest.fn(),
|
|
1235
|
+
weightType: jest.fn(),
|
|
1236
|
+
};
|
|
1237
|
+
|
|
1238
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1239
|
+
|
|
1240
|
+
const validStandardProduct = StandardProductNames.EXPLORER;
|
|
1241
|
+
const config: ProductChildPage[] = [
|
|
1242
|
+
{
|
|
1243
|
+
name: 'mysettings',
|
|
1244
|
+
label: 'Custom',
|
|
1245
|
+
weight: 97,
|
|
1246
|
+
component: { name: 'TestComponent' },
|
|
1247
|
+
},
|
|
1248
|
+
];
|
|
1249
|
+
|
|
1250
|
+
const pluginProduct = new PluginProduct(mockPlugin, validStandardProduct, config);
|
|
1251
|
+
|
|
1252
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1253
|
+
|
|
1254
|
+
expect(mockDSL.virtualType).toHaveBeenCalledTimes(1);
|
|
1255
|
+
expect(mockDSL.product).not.toHaveBeenCalled();
|
|
1256
|
+
});
|
|
1257
|
+
});
|
|
1258
|
+
|
|
1259
|
+
describe('scenario 8: extend standard product with mixed types and nested groups', () => {
|
|
1260
|
+
it('should extend standard product adding mixed virtualTypes and resource types with nested groups', () => {
|
|
1261
|
+
const mockPlugin = createMockPlugin();
|
|
1262
|
+
const mockStore = createMockStore();
|
|
1263
|
+
const mockDSL = {
|
|
1264
|
+
product: jest.fn(),
|
|
1265
|
+
basicType: jest.fn(),
|
|
1266
|
+
labelGroup: jest.fn(),
|
|
1267
|
+
setGroupDefaultType: jest.fn(),
|
|
1268
|
+
weightGroup: jest.fn(),
|
|
1269
|
+
virtualType: jest.fn(),
|
|
1270
|
+
configureType: jest.fn(),
|
|
1271
|
+
weightType: jest.fn(),
|
|
1272
|
+
};
|
|
1273
|
+
|
|
1274
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1275
|
+
|
|
1276
|
+
const validStandardProduct = StandardProductNames.EXPLORER;
|
|
1277
|
+
const config: (ProductChildGroup | ProductChildPage)[] = [
|
|
1278
|
+
{
|
|
1279
|
+
name: 'page1',
|
|
1280
|
+
label: 'My label for page 1',
|
|
1281
|
+
weight: -10,
|
|
1282
|
+
children: [
|
|
1283
|
+
{
|
|
1284
|
+
name: 'hello0',
|
|
1285
|
+
label: 'Testing 12',
|
|
1286
|
+
labelKey: 'aks.label',
|
|
1287
|
+
component: { name: 'TestComponent' },
|
|
1288
|
+
} as any,
|
|
1289
|
+
{
|
|
1290
|
+
name: 'hello1',
|
|
1291
|
+
label: 'Testing 1',
|
|
1292
|
+
component: { name: 'TestComponent' },
|
|
1293
|
+
},
|
|
1294
|
+
{
|
|
1295
|
+
name: 'hello3',
|
|
1296
|
+
labelKey: 'generic.unified',
|
|
1297
|
+
component: { name: 'TestComponent' },
|
|
1298
|
+
},
|
|
1299
|
+
{
|
|
1300
|
+
name: 'hello2',
|
|
1301
|
+
label: 'Testing 2',
|
|
1302
|
+
component: { name: 'TestComponent' },
|
|
1303
|
+
},
|
|
1304
|
+
],
|
|
1305
|
+
},
|
|
1306
|
+
{ type: 'upgrade.cattle.io.plan' },
|
|
1307
|
+
{
|
|
1308
|
+
name: 'page2',
|
|
1309
|
+
label: 'My label for page 2',
|
|
1310
|
+
component: { name: 'TestComponent' },
|
|
1311
|
+
},
|
|
1312
|
+
];
|
|
1313
|
+
|
|
1314
|
+
const pluginProduct = new PluginProduct(mockPlugin, validStandardProduct, config);
|
|
1315
|
+
|
|
1316
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1317
|
+
|
|
1318
|
+
expect(mockDSL.virtualType).toHaveBeenCalledTimes(5);
|
|
1319
|
+
expect(mockDSL.configureType).toHaveBeenCalledWith('upgrade.cattle.io.plan', expect.any(Object));
|
|
1320
|
+
expect(mockDSL.labelGroup).toHaveBeenCalledTimes(1);
|
|
1321
|
+
expect(mockDSL.product).not.toHaveBeenCalled();
|
|
1322
|
+
});
|
|
1323
|
+
});
|
|
1324
|
+
});
|
|
1325
|
+
|
|
1326
|
+
describe('side menu structure and ordering', () => {
|
|
1327
|
+
describe('new product - virtualType ordering', () => {
|
|
1328
|
+
it('should register virtualTypes in config array order when no weights specified', () => {
|
|
1329
|
+
const mockPlugin = createMockPlugin();
|
|
1330
|
+
const mockStore = createMockStore();
|
|
1331
|
+
const virtualTypeCalls: any[] = [];
|
|
1332
|
+
const mockDSL = {
|
|
1333
|
+
product: jest.fn(),
|
|
1334
|
+
basicType: jest.fn(),
|
|
1335
|
+
labelGroup: jest.fn(),
|
|
1336
|
+
setGroupDefaultType: jest.fn(),
|
|
1337
|
+
weightGroup: jest.fn(),
|
|
1338
|
+
virtualType: jest.fn((...args) => virtualTypeCalls.push(args)),
|
|
1339
|
+
configureType: jest.fn(),
|
|
1340
|
+
weightType: jest.fn(),
|
|
1341
|
+
};
|
|
1342
|
+
|
|
1343
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1344
|
+
|
|
1345
|
+
const productMetadata: ProductMetadata = {
|
|
1346
|
+
name: 'test-ordering',
|
|
1347
|
+
label: 'Test Ordering',
|
|
1348
|
+
};
|
|
1349
|
+
const config: ProductChildPage[] = [
|
|
1350
|
+
{
|
|
1351
|
+
name: 'first-page',
|
|
1352
|
+
label: 'First Page',
|
|
1353
|
+
component: { name: 'FirstComponent' },
|
|
1354
|
+
},
|
|
1355
|
+
{
|
|
1356
|
+
name: 'second-page',
|
|
1357
|
+
label: 'Second Page',
|
|
1358
|
+
component: { name: 'SecondComponent' },
|
|
1359
|
+
},
|
|
1360
|
+
{
|
|
1361
|
+
name: 'third-page',
|
|
1362
|
+
label: 'Third Page',
|
|
1363
|
+
component: { name: 'ThirdComponent' },
|
|
1364
|
+
},
|
|
1365
|
+
];
|
|
1366
|
+
|
|
1367
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
1368
|
+
|
|
1369
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1370
|
+
|
|
1371
|
+
// Verify order - virtualType calls should match config order
|
|
1372
|
+
expect(virtualTypeCalls).toHaveLength(3);
|
|
1373
|
+
expect(virtualTypeCalls[0][0]).toMatchObject({ name: 'testordering-first-page' });
|
|
1374
|
+
expect(virtualTypeCalls[1][0]).toMatchObject({ name: 'testordering-second-page' });
|
|
1375
|
+
expect(virtualTypeCalls[2][0]).toMatchObject({ name: 'testordering-third-page' });
|
|
1376
|
+
});
|
|
1377
|
+
|
|
1378
|
+
it('should register virtualTypes with weight parameter for menu ordering', () => {
|
|
1379
|
+
const mockPlugin = createMockPlugin();
|
|
1380
|
+
const mockStore = createMockStore();
|
|
1381
|
+
const virtualTypeCalls: any[] = [];
|
|
1382
|
+
const mockDSL = {
|
|
1383
|
+
product: jest.fn(),
|
|
1384
|
+
basicType: jest.fn(),
|
|
1385
|
+
labelGroup: jest.fn(),
|
|
1386
|
+
setGroupDefaultType: jest.fn(),
|
|
1387
|
+
weightGroup: jest.fn(),
|
|
1388
|
+
virtualType: jest.fn((...args) => virtualTypeCalls.push(args)),
|
|
1389
|
+
configureType: jest.fn(),
|
|
1390
|
+
weightType: jest.fn(),
|
|
1391
|
+
};
|
|
1392
|
+
|
|
1393
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1394
|
+
|
|
1395
|
+
const productMetadata: ProductMetadata = {
|
|
1396
|
+
name: 'test-weights',
|
|
1397
|
+
label: 'Test Weights',
|
|
1398
|
+
};
|
|
1399
|
+
const config: ProductChildPage[] = [
|
|
1400
|
+
{
|
|
1401
|
+
name: 'low-priority',
|
|
1402
|
+
label: 'Low Priority',
|
|
1403
|
+
component: { name: 'Component1' },
|
|
1404
|
+
weight: 100,
|
|
1405
|
+
},
|
|
1406
|
+
{
|
|
1407
|
+
name: 'high-priority',
|
|
1408
|
+
label: 'High Priority',
|
|
1409
|
+
component: { name: 'Component2' },
|
|
1410
|
+
weight: 1,
|
|
1411
|
+
},
|
|
1412
|
+
{
|
|
1413
|
+
name: 'medium-priority',
|
|
1414
|
+
label: 'Medium Priority',
|
|
1415
|
+
component: { name: 'Component3' },
|
|
1416
|
+
weight: 50,
|
|
1417
|
+
},
|
|
1418
|
+
];
|
|
1419
|
+
|
|
1420
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
1421
|
+
|
|
1422
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1423
|
+
|
|
1424
|
+
// Verify weight is passed to virtualType
|
|
1425
|
+
expect(virtualTypeCalls[0][0].weight).toBe(100);
|
|
1426
|
+
expect(virtualTypeCalls[1][0].weight).toBe(1);
|
|
1427
|
+
expect(virtualTypeCalls[2][0].weight).toBe(50);
|
|
1428
|
+
});
|
|
1429
|
+
});
|
|
1430
|
+
|
|
1431
|
+
describe('new product - mixed types ordering', () => {
|
|
1432
|
+
it('should maintain order of virtualTypes and configureTypes as specified in config', () => {
|
|
1433
|
+
const mockPlugin = createMockPlugin();
|
|
1434
|
+
const mockStore = createMockStore();
|
|
1435
|
+
const dslCallOrder: string[] = [];
|
|
1436
|
+
const mockDSL = {
|
|
1437
|
+
product: jest.fn(),
|
|
1438
|
+
basicType: jest.fn((...args) => dslCallOrder.push(`basicType:${ args[0] }`)),
|
|
1439
|
+
labelGroup: jest.fn(),
|
|
1440
|
+
setGroupDefaultType: jest.fn(),
|
|
1441
|
+
weightGroup: jest.fn(),
|
|
1442
|
+
virtualType: jest.fn((...args) => dslCallOrder.push(`virtualType:${ args[0].name }`)),
|
|
1443
|
+
configureType: jest.fn((...args) => dslCallOrder.push(`configureType:${ args[0] }`)),
|
|
1444
|
+
weightType: jest.fn(),
|
|
1445
|
+
};
|
|
1446
|
+
|
|
1447
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1448
|
+
|
|
1449
|
+
const productMetadata: ProductMetadata = {
|
|
1450
|
+
name: 'mixed-types',
|
|
1451
|
+
label: 'Mixed Types Product',
|
|
1452
|
+
};
|
|
1453
|
+
const config: ProductChildPage[] = [
|
|
1454
|
+
{ type: 'fleet.cattle.io.clustergroup' },
|
|
1455
|
+
{
|
|
1456
|
+
name: 'custom-page',
|
|
1457
|
+
label: 'Custom Page',
|
|
1458
|
+
component: { name: 'CustomComponent' },
|
|
1459
|
+
},
|
|
1460
|
+
{ type: 'upgrade.cattle.io.plan' },
|
|
1461
|
+
];
|
|
1462
|
+
|
|
1463
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
1464
|
+
|
|
1465
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1466
|
+
|
|
1467
|
+
// Verify DSL methods called in correct order
|
|
1468
|
+
const relevantCalls = dslCallOrder.filter((call) => call.startsWith('configureType:') || call.startsWith('virtualType:')
|
|
1469
|
+
);
|
|
1470
|
+
|
|
1471
|
+
expect(relevantCalls).toStrictEqual([
|
|
1472
|
+
'configureType:fleet.cattle.io.clustergroup',
|
|
1473
|
+
'virtualType:mixedtypes-custom-page',
|
|
1474
|
+
'configureType:upgrade.cattle.io.plan',
|
|
1475
|
+
]);
|
|
1476
|
+
});
|
|
1477
|
+
});
|
|
1478
|
+
|
|
1479
|
+
describe('new product - group menu structure', () => {
|
|
1480
|
+
it('should create nested side menu structure with groups', () => {
|
|
1481
|
+
const mockPlugin = createMockPlugin();
|
|
1482
|
+
const mockStore = createMockStore();
|
|
1483
|
+
const basicTypeCalls: any[] = [];
|
|
1484
|
+
const labelGroupCalls: any[] = [];
|
|
1485
|
+
const weightGroupCalls: any[] = [];
|
|
1486
|
+
const virtualTypeCalls: any[] = [];
|
|
1487
|
+
|
|
1488
|
+
const mockDSL = {
|
|
1489
|
+
product: jest.fn(),
|
|
1490
|
+
basicType: jest.fn((...args) => basicTypeCalls.push(args)),
|
|
1491
|
+
labelGroup: jest.fn((...args) => labelGroupCalls.push(args)),
|
|
1492
|
+
setGroupDefaultType: jest.fn(),
|
|
1493
|
+
weightGroup: jest.fn((...args) => weightGroupCalls.push(args)),
|
|
1494
|
+
virtualType: jest.fn((...args) => virtualTypeCalls.push(args)),
|
|
1495
|
+
configureType: jest.fn(),
|
|
1496
|
+
weightType: jest.fn(),
|
|
1497
|
+
};
|
|
1498
|
+
|
|
1499
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1500
|
+
|
|
1501
|
+
const productMetadata: ProductMetadata = {
|
|
1502
|
+
name: 'grouped-product',
|
|
1503
|
+
label: 'Grouped Product',
|
|
1504
|
+
};
|
|
1505
|
+
const config: ProductChildGroup[] = [
|
|
1506
|
+
{
|
|
1507
|
+
name: 'settings-group',
|
|
1508
|
+
label: 'Settings',
|
|
1509
|
+
weight: 10,
|
|
1510
|
+
children: [
|
|
1511
|
+
{
|
|
1512
|
+
name: 'general',
|
|
1513
|
+
label: 'General',
|
|
1514
|
+
component: { name: 'GeneralComponent' },
|
|
1515
|
+
},
|
|
1516
|
+
{
|
|
1517
|
+
name: 'advanced',
|
|
1518
|
+
label: 'Advanced',
|
|
1519
|
+
component: { name: 'AdvancedComponent' },
|
|
1520
|
+
},
|
|
1521
|
+
],
|
|
1522
|
+
},
|
|
1523
|
+
];
|
|
1524
|
+
|
|
1525
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
1526
|
+
|
|
1527
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1528
|
+
|
|
1529
|
+
// Verify group label was set
|
|
1530
|
+
expect(labelGroupCalls.length).toBeGreaterThan(0);
|
|
1531
|
+
expect(labelGroupCalls[0]).toStrictEqual(['groupedproduct-settings-group', 'Settings', undefined]);
|
|
1532
|
+
|
|
1533
|
+
// Verify group weight was set
|
|
1534
|
+
expect(weightGroupCalls.length).toBeGreaterThan(0);
|
|
1535
|
+
expect(weightGroupCalls[0]).toStrictEqual(['groupedproduct-settings-group', 10, true]);
|
|
1536
|
+
|
|
1537
|
+
// Verify basicType was called for navigation with group children
|
|
1538
|
+
// basicType is called twice: once for top-level items (excluding groups), once for group children
|
|
1539
|
+
expect(basicTypeCalls.length).toBeGreaterThan(1);
|
|
1540
|
+
// Check the second call which includes group children
|
|
1541
|
+
expect(basicTypeCalls[1][0]).toStrictEqual(expect.arrayContaining([
|
|
1542
|
+
expect.stringContaining('general'),
|
|
1543
|
+
expect.stringContaining('advanced')
|
|
1544
|
+
]));
|
|
1545
|
+
|
|
1546
|
+
// Verify nested virtualTypes were created
|
|
1547
|
+
expect(virtualTypeCalls).toHaveLength(2);
|
|
1548
|
+
});
|
|
1549
|
+
|
|
1550
|
+
it('should set label for groups without explicit label via labelGroup', () => {
|
|
1551
|
+
const mockPlugin = createMockPlugin();
|
|
1552
|
+
const mockStore = createMockStore();
|
|
1553
|
+
const labelGroupCalls: any[] = [];
|
|
1554
|
+
|
|
1555
|
+
const mockDSL = {
|
|
1556
|
+
product: jest.fn(),
|
|
1557
|
+
basicType: jest.fn(),
|
|
1558
|
+
labelGroup: jest.fn((...args) => labelGroupCalls.push(args)),
|
|
1559
|
+
setGroupDefaultType: jest.fn(),
|
|
1560
|
+
weightGroup: jest.fn(),
|
|
1561
|
+
virtualType: jest.fn(),
|
|
1562
|
+
configureType: jest.fn(),
|
|
1563
|
+
weightType: jest.fn(),
|
|
1564
|
+
};
|
|
1565
|
+
|
|
1566
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1567
|
+
|
|
1568
|
+
const productMetadata: ProductMetadata = {
|
|
1569
|
+
name: 'product-with-groups',
|
|
1570
|
+
label: 'Product',
|
|
1571
|
+
};
|
|
1572
|
+
const config: ProductChildGroup[] = [
|
|
1573
|
+
{
|
|
1574
|
+
name: 'my-group',
|
|
1575
|
+
label: 'My Group Label',
|
|
1576
|
+
children: [
|
|
1577
|
+
{
|
|
1578
|
+
name: 'child1',
|
|
1579
|
+
label: 'Child 1',
|
|
1580
|
+
component: { name: 'Child1Component' },
|
|
1581
|
+
},
|
|
1582
|
+
],
|
|
1583
|
+
},
|
|
1584
|
+
];
|
|
1585
|
+
|
|
1586
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
1587
|
+
|
|
1588
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1589
|
+
|
|
1590
|
+
// Verify labelGroup was called with the group's label
|
|
1591
|
+
expect(labelGroupCalls[0]).toStrictEqual(['productwithgroups-my-group', 'My Group Label', undefined]);
|
|
1592
|
+
});
|
|
1593
|
+
});
|
|
1594
|
+
|
|
1595
|
+
describe('extending product - side menu additions', () => {
|
|
1596
|
+
it('should add virtualType to existing product navigation in order specified', () => {
|
|
1597
|
+
const mockPlugin = createMockPlugin();
|
|
1598
|
+
const mockStore = createMockStore();
|
|
1599
|
+
const virtualTypeCalls: any[] = [];
|
|
1600
|
+
const mockDSL = {
|
|
1601
|
+
product: jest.fn(),
|
|
1602
|
+
basicType: jest.fn(),
|
|
1603
|
+
labelGroup: jest.fn(),
|
|
1604
|
+
setGroupDefaultType: jest.fn(),
|
|
1605
|
+
weightGroup: jest.fn(),
|
|
1606
|
+
virtualType: jest.fn((...args) => virtualTypeCalls.push(args)),
|
|
1607
|
+
configureType: jest.fn(),
|
|
1608
|
+
weightType: jest.fn(),
|
|
1609
|
+
};
|
|
1610
|
+
|
|
1611
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1612
|
+
|
|
1613
|
+
const validStandardProduct = StandardProductNames.EXPLORER;
|
|
1614
|
+
const config: ProductChildPage[] = [
|
|
1615
|
+
{
|
|
1616
|
+
name: 'custom-section-1',
|
|
1617
|
+
label: 'Custom Section 1',
|
|
1618
|
+
weight: 99,
|
|
1619
|
+
component: { name: 'CustomComponent1' },
|
|
1620
|
+
},
|
|
1621
|
+
{
|
|
1622
|
+
name: 'custom-section-2',
|
|
1623
|
+
label: 'Custom Section 2',
|
|
1624
|
+
weight: 98,
|
|
1625
|
+
component: { name: 'CustomComponent2' },
|
|
1626
|
+
},
|
|
1627
|
+
];
|
|
1628
|
+
|
|
1629
|
+
const pluginProduct = new PluginProduct(mockPlugin, validStandardProduct, config);
|
|
1630
|
+
|
|
1631
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1632
|
+
|
|
1633
|
+
// Verify virtualTypes added in order with weights
|
|
1634
|
+
expect(virtualTypeCalls).toHaveLength(2);
|
|
1635
|
+
expect(virtualTypeCalls[0][0]).toMatchObject({ name: 'explorer-custom-section-1' });
|
|
1636
|
+
expect(virtualTypeCalls[0][0].weight).toBe(99);
|
|
1637
|
+
expect(virtualTypeCalls[1][0]).toMatchObject({ name: 'explorer-custom-section-2' });
|
|
1638
|
+
expect(virtualTypeCalls[1][0].weight).toBe(98);
|
|
1639
|
+
});
|
|
1640
|
+
|
|
1641
|
+
it('should add groups to existing product with proper navigation structure', () => {
|
|
1642
|
+
const mockPlugin = createMockPlugin();
|
|
1643
|
+
const mockStore = createMockStore();
|
|
1644
|
+
const basicTypeCalls: any[] = [];
|
|
1645
|
+
const labelGroupCalls: any[] = [];
|
|
1646
|
+
|
|
1647
|
+
const mockDSL = {
|
|
1648
|
+
product: jest.fn(),
|
|
1649
|
+
basicType: jest.fn((...args) => basicTypeCalls.push(args)),
|
|
1650
|
+
labelGroup: jest.fn((...args) => labelGroupCalls.push(args)),
|
|
1651
|
+
setGroupDefaultType: jest.fn(),
|
|
1652
|
+
weightGroup: jest.fn(),
|
|
1653
|
+
virtualType: jest.fn(),
|
|
1654
|
+
configureType: jest.fn(),
|
|
1655
|
+
weightType: jest.fn(),
|
|
1656
|
+
};
|
|
1657
|
+
|
|
1658
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1659
|
+
|
|
1660
|
+
const validStandardProduct = StandardProductNames.SETTINGS;
|
|
1661
|
+
const config: ProductChildGroup[] = [
|
|
1662
|
+
{
|
|
1663
|
+
name: 'extension-settings',
|
|
1664
|
+
label: 'Extension Settings',
|
|
1665
|
+
weight: 5,
|
|
1666
|
+
children: [
|
|
1667
|
+
{
|
|
1668
|
+
name: 'config-page',
|
|
1669
|
+
label: 'Configuration',
|
|
1670
|
+
component: { name: 'ConfigComponent' },
|
|
1671
|
+
},
|
|
1672
|
+
{
|
|
1673
|
+
name: 'advanced-page',
|
|
1674
|
+
label: 'Advanced',
|
|
1675
|
+
component: { name: 'AdvancedComponent' },
|
|
1676
|
+
},
|
|
1677
|
+
],
|
|
1678
|
+
},
|
|
1679
|
+
];
|
|
1680
|
+
|
|
1681
|
+
const pluginProduct = new PluginProduct(mockPlugin, validStandardProduct, config);
|
|
1682
|
+
|
|
1683
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1684
|
+
|
|
1685
|
+
// Verify group label was set for the extended product
|
|
1686
|
+
expect(labelGroupCalls.length).toBeGreaterThan(0);
|
|
1687
|
+
expect(labelGroupCalls[0]).toStrictEqual(['settings-extension-settings', 'Extension Settings', undefined]);
|
|
1688
|
+
|
|
1689
|
+
// Verify basicType includes children for navigation
|
|
1690
|
+
// basicType is called multiple times: first for top-level items, then for each group's children
|
|
1691
|
+
expect(basicTypeCalls.length).toBeGreaterThan(0);
|
|
1692
|
+
// Check the call that includes group children (should be in basicTypeCalls)
|
|
1693
|
+
const groupChildrenCall = basicTypeCalls.find((call) => call[0] && Array.isArray(call[0]) && call[0].some((name: string) => name.includes('config-page'))
|
|
1694
|
+
);
|
|
1695
|
+
|
|
1696
|
+
expect(groupChildrenCall).toBeDefined();
|
|
1697
|
+
expect(groupChildrenCall![0]).toStrictEqual(expect.arrayContaining([
|
|
1698
|
+
expect.stringContaining('config-page'),
|
|
1699
|
+
expect.stringContaining('advanced-page')
|
|
1700
|
+
]));
|
|
1701
|
+
});
|
|
1702
|
+
});
|
|
1703
|
+
|
|
1704
|
+
describe('navigation and default route determination', () => {
|
|
1705
|
+
it('should pass correct default route to product registration', () => {
|
|
1706
|
+
const mockPlugin = createMockPlugin();
|
|
1707
|
+
const mockStore = createMockStore();
|
|
1708
|
+
let productConfig: any;
|
|
1709
|
+
const mockDSL = {
|
|
1710
|
+
product: jest.fn((config) => {
|
|
1711
|
+
productConfig = config;
|
|
1712
|
+
}),
|
|
1713
|
+
basicType: jest.fn(),
|
|
1714
|
+
labelGroup: jest.fn(),
|
|
1715
|
+
setGroupDefaultType: jest.fn(),
|
|
1716
|
+
weightGroup: jest.fn(),
|
|
1717
|
+
virtualType: jest.fn(),
|
|
1718
|
+
configureType: jest.fn(),
|
|
1719
|
+
weightType: jest.fn(),
|
|
1720
|
+
};
|
|
1721
|
+
|
|
1722
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1723
|
+
|
|
1724
|
+
const productMetadata: ProductMetadata = {
|
|
1725
|
+
name: 'test-default-route',
|
|
1726
|
+
label: 'Test Default Route',
|
|
1727
|
+
};
|
|
1728
|
+
const config: ProductChildPage[] = [
|
|
1729
|
+
{
|
|
1730
|
+
name: 'overview',
|
|
1731
|
+
label: 'Overview',
|
|
1732
|
+
component: { name: 'OverviewComponent' },
|
|
1733
|
+
},
|
|
1734
|
+
{
|
|
1735
|
+
name: 'details',
|
|
1736
|
+
label: 'Details',
|
|
1737
|
+
component: { name: 'DetailsComponent' },
|
|
1738
|
+
},
|
|
1739
|
+
];
|
|
1740
|
+
|
|
1741
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
1742
|
+
|
|
1743
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1744
|
+
|
|
1745
|
+
// Verify product registration includes default route (first config item)
|
|
1746
|
+
expect(productConfig).toBeDefined();
|
|
1747
|
+
expect(productConfig.to).toBeDefined();
|
|
1748
|
+
});
|
|
1749
|
+
|
|
1750
|
+
it('should use first group child as default route when first config item is a group', () => {
|
|
1751
|
+
const mockPlugin = createMockPlugin();
|
|
1752
|
+
const mockStore = createMockStore();
|
|
1753
|
+
let productConfig: any;
|
|
1754
|
+
const mockDSL = {
|
|
1755
|
+
product: jest.fn((config) => {
|
|
1756
|
+
productConfig = config;
|
|
1757
|
+
}),
|
|
1758
|
+
basicType: jest.fn(),
|
|
1759
|
+
labelGroup: jest.fn(),
|
|
1760
|
+
setGroupDefaultType: jest.fn(),
|
|
1761
|
+
weightGroup: jest.fn(),
|
|
1762
|
+
virtualType: jest.fn(),
|
|
1763
|
+
configureType: jest.fn(),
|
|
1764
|
+
weightType: jest.fn(),
|
|
1765
|
+
};
|
|
1766
|
+
|
|
1767
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1768
|
+
|
|
1769
|
+
const productMetadata: ProductMetadata = {
|
|
1770
|
+
name: 'test-group-default',
|
|
1771
|
+
label: 'Test Group Default',
|
|
1772
|
+
};
|
|
1773
|
+
const config: ProductChildGroup[] = [
|
|
1774
|
+
{
|
|
1775
|
+
name: 'main-group',
|
|
1776
|
+
label: 'Main Group',
|
|
1777
|
+
children: [
|
|
1778
|
+
{
|
|
1779
|
+
name: 'first-child',
|
|
1780
|
+
label: 'First Child',
|
|
1781
|
+
component: { name: 'FirstChildComponent' },
|
|
1782
|
+
},
|
|
1783
|
+
{
|
|
1784
|
+
name: 'second-child',
|
|
1785
|
+
label: 'Second Child',
|
|
1786
|
+
component: { name: 'SecondChildComponent' },
|
|
1787
|
+
},
|
|
1788
|
+
],
|
|
1789
|
+
},
|
|
1790
|
+
];
|
|
1791
|
+
|
|
1792
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
1793
|
+
|
|
1794
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1795
|
+
|
|
1796
|
+
// Verify default route points to first child of the group
|
|
1797
|
+
expect(productConfig).toBeDefined();
|
|
1798
|
+
expect(productConfig.to).toBeDefined();
|
|
1799
|
+
});
|
|
1800
|
+
});
|
|
1801
|
+
|
|
1802
|
+
describe('comprehensive ordering scenario', () => {
|
|
1803
|
+
it('should maintain complex menu structure with proper ordering of mixed items', () => {
|
|
1804
|
+
const mockPlugin = createMockPlugin();
|
|
1805
|
+
const mockStore = createMockStore();
|
|
1806
|
+
const dslCallOrder: string[] = [];
|
|
1807
|
+
const weightTypeCalls: any[] = [];
|
|
1808
|
+
|
|
1809
|
+
const mockDSL = {
|
|
1810
|
+
product: jest.fn(),
|
|
1811
|
+
basicType: jest.fn((...args) => dslCallOrder.push(`basicType`)),
|
|
1812
|
+
labelGroup: jest.fn((...args) => dslCallOrder.push(`labelGroup:${ args[0] }`)),
|
|
1813
|
+
setGroupDefaultType: jest.fn(),
|
|
1814
|
+
weightGroup: jest.fn((...args) => dslCallOrder.push(`weightGroup:${ args[0] }`)),
|
|
1815
|
+
virtualType: jest.fn((...args) => dslCallOrder.push(`virtualType:${ args[0].name }`)),
|
|
1816
|
+
configureType: jest.fn((...args) => dslCallOrder.push(`configureType:${ args[0] }`)),
|
|
1817
|
+
weightType: jest.fn((...args) => weightTypeCalls.push(args)),
|
|
1818
|
+
};
|
|
1819
|
+
|
|
1820
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1821
|
+
|
|
1822
|
+
const productMetadata: ProductMetadata = {
|
|
1823
|
+
name: 'complex-product',
|
|
1824
|
+
label: 'Complex Product',
|
|
1825
|
+
};
|
|
1826
|
+
const config: (ProductChildGroup | ProductChildPage)[] = [
|
|
1827
|
+
{ type: 'fleet.cattle.io.clustergroup' }, // Resource type first
|
|
1828
|
+
{
|
|
1829
|
+
name: 'overview',
|
|
1830
|
+
label: 'Overview',
|
|
1831
|
+
weight: 1,
|
|
1832
|
+
component: { name: 'OverviewComponent' },
|
|
1833
|
+
},
|
|
1834
|
+
{
|
|
1835
|
+
name: 'settings',
|
|
1836
|
+
label: 'Settings',
|
|
1837
|
+
weight: 50,
|
|
1838
|
+
children: [
|
|
1839
|
+
{
|
|
1840
|
+
name: 'general',
|
|
1841
|
+
label: 'General',
|
|
1842
|
+
component: { name: 'GeneralComponent' },
|
|
1843
|
+
},
|
|
1844
|
+
{
|
|
1845
|
+
name: 'advanced',
|
|
1846
|
+
label: 'Advanced',
|
|
1847
|
+
component: { name: 'AdvancedComponent' },
|
|
1848
|
+
},
|
|
1849
|
+
],
|
|
1850
|
+
},
|
|
1851
|
+
{ type: 'upgrade.cattle.io.plan' }, // Another resource type
|
|
1852
|
+
{
|
|
1853
|
+
name: 'monitoring',
|
|
1854
|
+
label: 'Monitoring',
|
|
1855
|
+
weight: 100,
|
|
1856
|
+
component: { name: 'MonitoringComponent' },
|
|
1857
|
+
},
|
|
1858
|
+
];
|
|
1859
|
+
|
|
1860
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
1861
|
+
|
|
1862
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1863
|
+
|
|
1864
|
+
// Verify configureTypes were registered
|
|
1865
|
+
const configureTypeCalls = dslCallOrder.filter((call) => call.startsWith('configureType:'));
|
|
1866
|
+
|
|
1867
|
+
expect(configureTypeCalls).toContain('configureType:fleet.cattle.io.clustergroup');
|
|
1868
|
+
expect(configureTypeCalls).toContain('configureType:upgrade.cattle.io.plan');
|
|
1869
|
+
|
|
1870
|
+
// Verify virtualTypes were registered
|
|
1871
|
+
const virtualTypeCalls = dslCallOrder.filter((call) => call.startsWith('virtualType:'));
|
|
1872
|
+
|
|
1873
|
+
expect(virtualTypeCalls).toContain('virtualType:complexproduct-overview');
|
|
1874
|
+
expect(virtualTypeCalls).toContain('virtualType:complexproduct-monitoring');
|
|
1875
|
+
expect(virtualTypeCalls).toContain('virtualType:complexproduct-settings-general');
|
|
1876
|
+
expect(virtualTypeCalls).toContain('virtualType:complexproduct-settings-advanced');
|
|
1877
|
+
|
|
1878
|
+
// Verify group was configured
|
|
1879
|
+
const labelGroupCalls = dslCallOrder.filter((call) => call.startsWith('labelGroup:'));
|
|
1880
|
+
|
|
1881
|
+
expect(labelGroupCalls).toContain('labelGroup:complexproduct-settings');
|
|
1882
|
+
});
|
|
1883
|
+
});
|
|
1884
|
+
});
|
|
1885
|
+
|
|
1886
|
+
describe('sideNav menu structure rendering', () => {
|
|
1887
|
+
describe('new product - menu structure validation', () => {
|
|
1888
|
+
it('should create correct menu structure with proper ordering and names for simple virtualTypes', () => {
|
|
1889
|
+
const mockPlugin = createMockPlugin();
|
|
1890
|
+
const mockStore = createMockStore();
|
|
1891
|
+
|
|
1892
|
+
// Capture the menu structure that would be created
|
|
1893
|
+
const menuStructure: any = {
|
|
1894
|
+
basicTypes: [],
|
|
1895
|
+
virtualTypes: [],
|
|
1896
|
+
groupLabels: {},
|
|
1897
|
+
groupWeights: {},
|
|
1898
|
+
};
|
|
1899
|
+
|
|
1900
|
+
const mockDSL = {
|
|
1901
|
+
product: jest.fn(),
|
|
1902
|
+
basicType: jest.fn((types, group) => {
|
|
1903
|
+
menuStructure.basicTypes.push({ types, group });
|
|
1904
|
+
}),
|
|
1905
|
+
labelGroup: jest.fn((group, label, labelKey) => {
|
|
1906
|
+
menuStructure.groupLabels[group] = { label, labelKey };
|
|
1907
|
+
}),
|
|
1908
|
+
setGroupDefaultType: jest.fn(),
|
|
1909
|
+
weightGroup: jest.fn((group, weight) => {
|
|
1910
|
+
menuStructure.groupWeights[group] = weight;
|
|
1911
|
+
}),
|
|
1912
|
+
virtualType: jest.fn((config) => {
|
|
1913
|
+
menuStructure.virtualTypes.push(config);
|
|
1914
|
+
}),
|
|
1915
|
+
configureType: jest.fn(),
|
|
1916
|
+
weightType: jest.fn(),
|
|
1917
|
+
};
|
|
1918
|
+
|
|
1919
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
1920
|
+
|
|
1921
|
+
const productMetadata: ProductMetadata = {
|
|
1922
|
+
name: 'my-product',
|
|
1923
|
+
label: 'My Product',
|
|
1924
|
+
};
|
|
1925
|
+
const config: ProductChildPage[] = [
|
|
1926
|
+
{
|
|
1927
|
+
name: 'overview',
|
|
1928
|
+
label: 'Overview',
|
|
1929
|
+
weight: 100,
|
|
1930
|
+
component: { name: 'OverviewComponent' },
|
|
1931
|
+
},
|
|
1932
|
+
{
|
|
1933
|
+
name: 'settings',
|
|
1934
|
+
label: 'Settings',
|
|
1935
|
+
weight: 50,
|
|
1936
|
+
component: { name: 'SettingsComponent' },
|
|
1937
|
+
},
|
|
1938
|
+
{
|
|
1939
|
+
name: 'monitoring',
|
|
1940
|
+
label: 'Monitoring',
|
|
1941
|
+
weight: 25,
|
|
1942
|
+
component: { name: 'MonitoringComponent' },
|
|
1943
|
+
},
|
|
1944
|
+
];
|
|
1945
|
+
|
|
1946
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
1947
|
+
|
|
1948
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
1949
|
+
|
|
1950
|
+
// Verify menu structure ordering (virtualTypes are registered in config order but with weights)
|
|
1951
|
+
expect(menuStructure.virtualTypes).toHaveLength(3);
|
|
1952
|
+
|
|
1953
|
+
// Menu items should have concatenated product-page names
|
|
1954
|
+
expect(menuStructure.virtualTypes[0].name).toBe('myproduct-overview');
|
|
1955
|
+
expect(menuStructure.virtualTypes[0].label).toBe('Overview');
|
|
1956
|
+
expect(menuStructure.virtualTypes[0].weight).toBe(100);
|
|
1957
|
+
|
|
1958
|
+
expect(menuStructure.virtualTypes[1].name).toBe('myproduct-settings');
|
|
1959
|
+
expect(menuStructure.virtualTypes[1].label).toBe('Settings');
|
|
1960
|
+
expect(menuStructure.virtualTypes[1].weight).toBe(50);
|
|
1961
|
+
|
|
1962
|
+
expect(menuStructure.virtualTypes[2].name).toBe('myproduct-monitoring');
|
|
1963
|
+
expect(menuStructure.virtualTypes[2].label).toBe('Monitoring');
|
|
1964
|
+
expect(menuStructure.virtualTypes[2].weight).toBe(25);
|
|
1965
|
+
|
|
1966
|
+
// Verify basicType creates flat navigation structure (no groups for simple pages)
|
|
1967
|
+
expect(menuStructure.basicTypes.length).toBeGreaterThan(0);
|
|
1968
|
+
expect(menuStructure.basicTypes[0].types).toStrictEqual(expect.arrayContaining([
|
|
1969
|
+
'myproduct-overview',
|
|
1970
|
+
'myproduct-settings',
|
|
1971
|
+
'myproduct-monitoring',
|
|
1972
|
+
]));
|
|
1973
|
+
});
|
|
1974
|
+
|
|
1975
|
+
it('should create correct menu structure with groups and nested items', () => {
|
|
1976
|
+
const mockPlugin = createMockPlugin();
|
|
1977
|
+
const mockStore = createMockStore();
|
|
1978
|
+
|
|
1979
|
+
const menuStructure: any = {
|
|
1980
|
+
basicTypes: [],
|
|
1981
|
+
virtualTypes: [],
|
|
1982
|
+
groupLabels: {},
|
|
1983
|
+
groupWeights: {},
|
|
1984
|
+
};
|
|
1985
|
+
|
|
1986
|
+
const mockDSL = {
|
|
1987
|
+
product: jest.fn(),
|
|
1988
|
+
basicType: jest.fn((types, group) => {
|
|
1989
|
+
menuStructure.basicTypes.push({ types, group });
|
|
1990
|
+
}),
|
|
1991
|
+
labelGroup: jest.fn((group, label, labelKey) => {
|
|
1992
|
+
menuStructure.groupLabels[group] = { label, labelKey };
|
|
1993
|
+
}),
|
|
1994
|
+
setGroupDefaultType: jest.fn(),
|
|
1995
|
+
weightGroup: jest.fn((group, weight) => {
|
|
1996
|
+
menuStructure.groupWeights[group] = weight;
|
|
1997
|
+
}),
|
|
1998
|
+
virtualType: jest.fn((config) => {
|
|
1999
|
+
menuStructure.virtualTypes.push(config);
|
|
2000
|
+
}),
|
|
2001
|
+
configureType: jest.fn(),
|
|
2002
|
+
weightType: jest.fn(),
|
|
2003
|
+
};
|
|
2004
|
+
|
|
2005
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
2006
|
+
|
|
2007
|
+
const productMetadata: ProductMetadata = {
|
|
2008
|
+
name: 'grouped-product',
|
|
2009
|
+
label: 'Grouped Product',
|
|
2010
|
+
};
|
|
2011
|
+
const config: (ProductChildPage | ProductChildGroup)[] = [
|
|
2012
|
+
{
|
|
2013
|
+
name: 'overview',
|
|
2014
|
+
label: 'Overview',
|
|
2015
|
+
weight: 100,
|
|
2016
|
+
component: { name: 'OverviewComponent' },
|
|
2017
|
+
},
|
|
2018
|
+
{
|
|
2019
|
+
name: 'admin',
|
|
2020
|
+
label: 'Administration',
|
|
2021
|
+
weight: 50,
|
|
2022
|
+
children: [
|
|
2023
|
+
{
|
|
2024
|
+
name: 'users',
|
|
2025
|
+
label: 'Users',
|
|
2026
|
+
component: { name: 'UsersComponent' },
|
|
2027
|
+
},
|
|
2028
|
+
{
|
|
2029
|
+
name: 'roles',
|
|
2030
|
+
label: 'Roles',
|
|
2031
|
+
component: { name: 'RolesComponent' },
|
|
2032
|
+
},
|
|
2033
|
+
],
|
|
2034
|
+
},
|
|
2035
|
+
{
|
|
2036
|
+
name: 'reports',
|
|
2037
|
+
label: 'Reports',
|
|
2038
|
+
weight: 25,
|
|
2039
|
+
component: { name: 'ReportsComponent' },
|
|
2040
|
+
},
|
|
2041
|
+
];
|
|
2042
|
+
|
|
2043
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
2044
|
+
|
|
2045
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
2046
|
+
|
|
2047
|
+
// Verify group structure
|
|
2048
|
+
expect(menuStructure.groupLabels['groupedproduct-admin']).toStrictEqual({
|
|
2049
|
+
label: 'Administration',
|
|
2050
|
+
labelKey: undefined,
|
|
2051
|
+
});
|
|
2052
|
+
expect(menuStructure.groupWeights['groupedproduct-admin']).toBe(50);
|
|
2053
|
+
|
|
2054
|
+
// Verify nested items in group have correct names
|
|
2055
|
+
const adminGroupItems = menuStructure.virtualTypes.filter((vt: any) => vt.name.includes('admin')
|
|
2056
|
+
);
|
|
2057
|
+
|
|
2058
|
+
expect(adminGroupItems).toHaveLength(2);
|
|
2059
|
+
expect(adminGroupItems.some((item: any) => item.name === 'groupedproduct-admin-users')).toBe(true);
|
|
2060
|
+
expect(adminGroupItems.some((item: any) => item.name === 'groupedproduct-admin-roles')).toBe(true);
|
|
2061
|
+
|
|
2062
|
+
// Verify top-level items ordering via basicType
|
|
2063
|
+
const topLevelCall = menuStructure.basicTypes.find((bt: any) => !bt.group);
|
|
2064
|
+
|
|
2065
|
+
expect(topLevelCall).toBeDefined();
|
|
2066
|
+
expect(topLevelCall.types).toContain('groupedproduct-overview');
|
|
2067
|
+
expect(topLevelCall.types).toContain('groupedproduct-reports');
|
|
2068
|
+
});
|
|
2069
|
+
|
|
2070
|
+
it('should render mixed virtualTypes and configureTypes in correct order', () => {
|
|
2071
|
+
const mockPlugin = createMockPlugin();
|
|
2072
|
+
const mockStore = createMockStore();
|
|
2073
|
+
|
|
2074
|
+
const menuStructure: any = {
|
|
2075
|
+
basicTypes: [],
|
|
2076
|
+
virtualTypes: [],
|
|
2077
|
+
configureTypes: [],
|
|
2078
|
+
};
|
|
2079
|
+
|
|
2080
|
+
const mockDSL = {
|
|
2081
|
+
product: jest.fn(),
|
|
2082
|
+
basicType: jest.fn((types, group) => {
|
|
2083
|
+
menuStructure.basicTypes.push({ types, group });
|
|
2084
|
+
}),
|
|
2085
|
+
labelGroup: jest.fn(),
|
|
2086
|
+
setGroupDefaultType: jest.fn(),
|
|
2087
|
+
weightGroup: jest.fn(),
|
|
2088
|
+
virtualType: jest.fn((config) => {
|
|
2089
|
+
menuStructure.virtualTypes.push({ name: config.name, weight: config.weight });
|
|
2090
|
+
}),
|
|
2091
|
+
configureType: jest.fn((type, config) => {
|
|
2092
|
+
menuStructure.configureTypes.push({ type, config });
|
|
2093
|
+
}),
|
|
2094
|
+
weightType: jest.fn((type, weight) => {
|
|
2095
|
+
// Find existing configureType and add weight
|
|
2096
|
+
const existing = menuStructure.configureTypes.find((ct: any) => ct.type === type);
|
|
2097
|
+
|
|
2098
|
+
if (existing) {
|
|
2099
|
+
existing.weight = weight;
|
|
2100
|
+
}
|
|
2101
|
+
}),
|
|
2102
|
+
};
|
|
2103
|
+
|
|
2104
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
2105
|
+
|
|
2106
|
+
const productMetadata: ProductMetadata = {
|
|
2107
|
+
name: 'mixed-product',
|
|
2108
|
+
label: 'Mixed Product',
|
|
2109
|
+
};
|
|
2110
|
+
const config: ProductChildPage[] = [
|
|
2111
|
+
{ type: 'fleet.cattle.io.clustergroup', weight: 100 },
|
|
2112
|
+
{
|
|
2113
|
+
name: 'overview',
|
|
2114
|
+
label: 'Overview',
|
|
2115
|
+
weight: 75,
|
|
2116
|
+
component: { name: 'OverviewComponent' },
|
|
2117
|
+
},
|
|
2118
|
+
{ type: 'workload.io.deployment', weight: 50 },
|
|
2119
|
+
{
|
|
2120
|
+
name: 'settings',
|
|
2121
|
+
label: 'Settings',
|
|
2122
|
+
weight: 25,
|
|
2123
|
+
component: { name: 'SettingsComponent' },
|
|
2124
|
+
},
|
|
2125
|
+
];
|
|
2126
|
+
|
|
2127
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
2128
|
+
|
|
2129
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
2130
|
+
|
|
2131
|
+
// In SideNav, items are sorted by weight descending
|
|
2132
|
+
// Verify that the menu structure reflects the intended ordering
|
|
2133
|
+
|
|
2134
|
+
// ConfigureTypes (resources)
|
|
2135
|
+
expect(menuStructure.configureTypes[0]).toMatchObject({
|
|
2136
|
+
type: 'fleet.cattle.io.clustergroup',
|
|
2137
|
+
weight: 100,
|
|
2138
|
+
});
|
|
2139
|
+
expect(menuStructure.configureTypes[1]).toMatchObject({
|
|
2140
|
+
type: 'workload.io.deployment',
|
|
2141
|
+
weight: 50,
|
|
2142
|
+
});
|
|
2143
|
+
|
|
2144
|
+
// VirtualTypes (custom pages)
|
|
2145
|
+
expect(menuStructure.virtualTypes[0]).toMatchObject({
|
|
2146
|
+
name: 'mixedproduct-overview',
|
|
2147
|
+
weight: 75,
|
|
2148
|
+
});
|
|
2149
|
+
expect(menuStructure.virtualTypes[1]).toMatchObject({
|
|
2150
|
+
name: 'mixedproduct-settings',
|
|
2151
|
+
weight: 25,
|
|
2152
|
+
});
|
|
2153
|
+
|
|
2154
|
+
// Verify basicType call includes all items for navigation
|
|
2155
|
+
const allItems = menuStructure.basicTypes[0].types;
|
|
2156
|
+
|
|
2157
|
+
expect(allItems).toContain('fleet.cattle.io.clustergroup');
|
|
2158
|
+
expect(allItems).toContain('mixedproduct-overview');
|
|
2159
|
+
expect(allItems).toContain('workload.io.deployment');
|
|
2160
|
+
expect(allItems).toContain('mixedproduct-settings');
|
|
2161
|
+
});
|
|
2162
|
+
});
|
|
2163
|
+
|
|
2164
|
+
describe('extending product - menu structure validation', () => {
|
|
2165
|
+
it('should add items to existing product menu with correct naming', () => {
|
|
2166
|
+
const mockPlugin = createMockPlugin();
|
|
2167
|
+
const mockStore = createMockStore();
|
|
2168
|
+
|
|
2169
|
+
const menuStructure: any = {
|
|
2170
|
+
basicTypes: [],
|
|
2171
|
+
virtualTypes: [],
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
const mockDSL = {
|
|
2175
|
+
product: jest.fn(),
|
|
2176
|
+
basicType: jest.fn((types, group) => {
|
|
2177
|
+
menuStructure.basicTypes.push({ types, group });
|
|
2178
|
+
}),
|
|
2179
|
+
labelGroup: jest.fn(),
|
|
2180
|
+
setGroupDefaultType: jest.fn(),
|
|
2181
|
+
weightGroup: jest.fn(),
|
|
2182
|
+
virtualType: jest.fn((config) => {
|
|
2183
|
+
menuStructure.virtualTypes.push({
|
|
2184
|
+
name: config.name,
|
|
2185
|
+
label: config.label,
|
|
2186
|
+
weight: config.weight,
|
|
2187
|
+
});
|
|
2188
|
+
}),
|
|
2189
|
+
configureType: jest.fn(),
|
|
2190
|
+
weightType: jest.fn(),
|
|
2191
|
+
};
|
|
2192
|
+
|
|
2193
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
2194
|
+
|
|
2195
|
+
const validStandardProduct = StandardProductNames.EXPLORER;
|
|
2196
|
+
const config: ProductChildPage[] = [
|
|
2197
|
+
{
|
|
2198
|
+
name: 'my-custom-page',
|
|
2199
|
+
label: 'My Custom Page',
|
|
2200
|
+
weight: 99,
|
|
2201
|
+
component: { name: 'CustomComponent' },
|
|
2202
|
+
},
|
|
2203
|
+
{
|
|
2204
|
+
name: 'another-page',
|
|
2205
|
+
label: 'Another Page',
|
|
2206
|
+
weight: 98,
|
|
2207
|
+
component: { name: 'AnotherComponent' },
|
|
2208
|
+
},
|
|
2209
|
+
];
|
|
2210
|
+
|
|
2211
|
+
const pluginProduct = new PluginProduct(mockPlugin, validStandardProduct, config);
|
|
2212
|
+
|
|
2213
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
2214
|
+
|
|
2215
|
+
// When extending EXPLORER, names are prefixed with product name
|
|
2216
|
+
expect(menuStructure.virtualTypes[0]).toMatchObject({
|
|
2217
|
+
name: 'explorer-my-custom-page',
|
|
2218
|
+
label: 'My Custom Page',
|
|
2219
|
+
weight: 99,
|
|
2220
|
+
});
|
|
2221
|
+
expect(menuStructure.virtualTypes[1]).toMatchObject({
|
|
2222
|
+
name: 'explorer-another-page',
|
|
2223
|
+
label: 'Another Page',
|
|
2224
|
+
weight: 98,
|
|
2225
|
+
});
|
|
2226
|
+
|
|
2227
|
+
// These should be added to EXPLORER's existing navigation
|
|
2228
|
+
const explorerItems = menuStructure.basicTypes[0].types;
|
|
2229
|
+
|
|
2230
|
+
expect(explorerItems).toContain('explorer-my-custom-page');
|
|
2231
|
+
expect(explorerItems).toContain('explorer-another-page');
|
|
2232
|
+
});
|
|
2233
|
+
|
|
2234
|
+
it('should add groups to existing product with correct hierarchy', () => {
|
|
2235
|
+
const mockPlugin = createMockPlugin();
|
|
2236
|
+
const mockStore = createMockStore();
|
|
2237
|
+
|
|
2238
|
+
const menuStructure: any = {
|
|
2239
|
+
basicTypes: [],
|
|
2240
|
+
virtualTypes: [],
|
|
2241
|
+
groupLabels: {},
|
|
2242
|
+
groupWeights: {},
|
|
2243
|
+
};
|
|
2244
|
+
|
|
2245
|
+
const mockDSL = {
|
|
2246
|
+
product: jest.fn(),
|
|
2247
|
+
basicType: jest.fn((types, group) => {
|
|
2248
|
+
menuStructure.basicTypes.push({ types, group });
|
|
2249
|
+
}),
|
|
2250
|
+
labelGroup: jest.fn((group, label, labelKey) => {
|
|
2251
|
+
menuStructure.groupLabels[group] = { label, labelKey };
|
|
2252
|
+
}),
|
|
2253
|
+
setGroupDefaultType: jest.fn(),
|
|
2254
|
+
weightGroup: jest.fn((group, weight) => {
|
|
2255
|
+
menuStructure.groupWeights[group] = weight;
|
|
2256
|
+
}),
|
|
2257
|
+
virtualType: jest.fn((config) => {
|
|
2258
|
+
menuStructure.virtualTypes.push({
|
|
2259
|
+
name: config.name,
|
|
2260
|
+
label: config.label,
|
|
2261
|
+
weight: config.weight,
|
|
2262
|
+
});
|
|
2263
|
+
}),
|
|
2264
|
+
configureType: jest.fn(),
|
|
2265
|
+
weightType: jest.fn(),
|
|
2266
|
+
};
|
|
2267
|
+
|
|
2268
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
2269
|
+
|
|
2270
|
+
const validStandardProduct = StandardProductNames.SETTINGS;
|
|
2271
|
+
const config: ProductChildGroup[] = [
|
|
2272
|
+
{
|
|
2273
|
+
name: 'extensions',
|
|
2274
|
+
label: 'Extensions',
|
|
2275
|
+
weight: 80,
|
|
2276
|
+
children: [
|
|
2277
|
+
{
|
|
2278
|
+
name: 'marketplace',
|
|
2279
|
+
label: 'Marketplace',
|
|
2280
|
+
component: { name: 'MarketplaceComponent' },
|
|
2281
|
+
},
|
|
2282
|
+
{
|
|
2283
|
+
name: 'installed',
|
|
2284
|
+
label: 'Installed',
|
|
2285
|
+
component: { name: 'InstalledComponent' },
|
|
2286
|
+
},
|
|
2287
|
+
],
|
|
2288
|
+
},
|
|
2289
|
+
];
|
|
2290
|
+
|
|
2291
|
+
const pluginProduct = new PluginProduct(mockPlugin, validStandardProduct, config);
|
|
2292
|
+
|
|
2293
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
2294
|
+
|
|
2295
|
+
// Verify group is added with correct naming (settings-extensions)
|
|
2296
|
+
expect(menuStructure.groupLabels['settings-extensions']).toStrictEqual({
|
|
2297
|
+
label: 'Extensions',
|
|
2298
|
+
labelKey: undefined,
|
|
2299
|
+
});
|
|
2300
|
+
expect(menuStructure.groupWeights['settings-extensions']).toBe(80);
|
|
2301
|
+
|
|
2302
|
+
// Verify child items have correct hierarchy in their names
|
|
2303
|
+
const extensionItems = menuStructure.virtualTypes.filter((vt: any) => vt.name.includes('extensions')
|
|
2304
|
+
);
|
|
2305
|
+
|
|
2306
|
+
expect(extensionItems).toHaveLength(2);
|
|
2307
|
+
expect(extensionItems.some((item: any) => item.name === 'settings-extensions-marketplace')).toBe(true);
|
|
2308
|
+
expect(extensionItems.some((item: any) => item.name === 'settings-extensions-installed')).toBe(true);
|
|
2309
|
+
|
|
2310
|
+
// Verify group navigation structure
|
|
2311
|
+
const groupNavCall = menuStructure.basicTypes.find((bt: any) => bt.group === 'settings-extensions'
|
|
2312
|
+
);
|
|
2313
|
+
|
|
2314
|
+
expect(groupNavCall).toBeDefined();
|
|
2315
|
+
expect(groupNavCall.types).toStrictEqual(expect.arrayContaining([
|
|
2316
|
+
'settings-extensions-marketplace',
|
|
2317
|
+
'settings-extensions-installed',
|
|
2318
|
+
'settings-extensions', // Group itself is also in the nav
|
|
2319
|
+
]));
|
|
2320
|
+
});
|
|
2321
|
+
});
|
|
2322
|
+
|
|
2323
|
+
describe('comprehensive menu rendering scenario', () => {
|
|
2324
|
+
it('should create complete menu structure matching SideNav expectations', () => {
|
|
2325
|
+
const mockPlugin = createMockPlugin();
|
|
2326
|
+
const mockStore = createMockStore();
|
|
2327
|
+
|
|
2328
|
+
// Simulate the complete menu structure as SideNav would build it
|
|
2329
|
+
const menuStructure: any = {
|
|
2330
|
+
groups: [],
|
|
2331
|
+
items: [],
|
|
2332
|
+
};
|
|
2333
|
+
|
|
2334
|
+
const mockDSL = {
|
|
2335
|
+
product: jest.fn(),
|
|
2336
|
+
basicType: jest.fn((types, group) => {
|
|
2337
|
+
if (group) {
|
|
2338
|
+
// This is a group with children
|
|
2339
|
+
const existingGroup = menuStructure.groups.find((g: any) => g.name === group);
|
|
2340
|
+
|
|
2341
|
+
if (existingGroup) {
|
|
2342
|
+
existingGroup.children = types.filter((t: string) => t !== group);
|
|
2343
|
+
} else {
|
|
2344
|
+
menuStructure.groups.push({
|
|
2345
|
+
name: group,
|
|
2346
|
+
children: types.filter((t: string) => t !== group),
|
|
2347
|
+
});
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
}),
|
|
2351
|
+
labelGroup: jest.fn((group, label, labelKey) => {
|
|
2352
|
+
const existingGroup = menuStructure.groups.find((g: any) => g.name === group);
|
|
2353
|
+
|
|
2354
|
+
if (existingGroup) {
|
|
2355
|
+
existingGroup.label = label;
|
|
2356
|
+
existingGroup.labelKey = labelKey;
|
|
2357
|
+
} else {
|
|
2358
|
+
menuStructure.groups.push({
|
|
2359
|
+
name: group,
|
|
2360
|
+
label,
|
|
2361
|
+
labelKey,
|
|
2362
|
+
});
|
|
2363
|
+
}
|
|
2364
|
+
}),
|
|
2365
|
+
setGroupDefaultType: jest.fn(),
|
|
2366
|
+
weightGroup: jest.fn((group, weight) => {
|
|
2367
|
+
const existingGroup = menuStructure.groups.find((g: any) => g.name === group);
|
|
2368
|
+
|
|
2369
|
+
if (existingGroup) {
|
|
2370
|
+
existingGroup.weight = weight;
|
|
2371
|
+
}
|
|
2372
|
+
}),
|
|
2373
|
+
virtualType: jest.fn((config) => {
|
|
2374
|
+
menuStructure.items.push({
|
|
2375
|
+
name: config.name,
|
|
2376
|
+
label: config.label,
|
|
2377
|
+
weight: config.weight,
|
|
2378
|
+
type: 'virtual',
|
|
2379
|
+
});
|
|
2380
|
+
}),
|
|
2381
|
+
configureType: jest.fn((type) => {
|
|
2382
|
+
menuStructure.items.push({
|
|
2383
|
+
name: type,
|
|
2384
|
+
type: 'configure',
|
|
2385
|
+
weight: 0, // Will be set by weightType if provided
|
|
2386
|
+
});
|
|
2387
|
+
}),
|
|
2388
|
+
weightType: jest.fn((type, weight) => {
|
|
2389
|
+
const item = menuStructure.items.find((i: any) => i.name === type);
|
|
2390
|
+
|
|
2391
|
+
if (item) {
|
|
2392
|
+
item.weight = weight;
|
|
2393
|
+
}
|
|
2394
|
+
}),
|
|
2395
|
+
};
|
|
2396
|
+
|
|
2397
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
2398
|
+
|
|
2399
|
+
const productMetadata: ProductMetadata = {
|
|
2400
|
+
name: 'complete-app',
|
|
2401
|
+
label: 'Complete App',
|
|
2402
|
+
};
|
|
2403
|
+
const config: (ProductChildGroup | ProductChildPage)[] = [
|
|
2404
|
+
{
|
|
2405
|
+
name: 'dashboard',
|
|
2406
|
+
label: 'Dashboard',
|
|
2407
|
+
weight: 100,
|
|
2408
|
+
component: { name: 'DashboardComponent' },
|
|
2409
|
+
},
|
|
2410
|
+
{
|
|
2411
|
+
name: 'workloads',
|
|
2412
|
+
label: 'Workloads',
|
|
2413
|
+
weight: 90,
|
|
2414
|
+
children: [
|
|
2415
|
+
{ type: 'workload.io.deployment', weight: 50 },
|
|
2416
|
+
{ type: 'workload.io.pod', weight: 45 },
|
|
2417
|
+
{
|
|
2418
|
+
name: 'jobs',
|
|
2419
|
+
label: 'Jobs',
|
|
2420
|
+
component: { name: 'JobsComponent' },
|
|
2421
|
+
},
|
|
2422
|
+
],
|
|
2423
|
+
},
|
|
2424
|
+
{ type: 'config.io.configmap', weight: 80 },
|
|
2425
|
+
{
|
|
2426
|
+
name: 'settings',
|
|
2427
|
+
label: 'Settings',
|
|
2428
|
+
weight: 70,
|
|
2429
|
+
children: [
|
|
2430
|
+
{
|
|
2431
|
+
name: 'general',
|
|
2432
|
+
label: 'General',
|
|
2433
|
+
component: { name: 'GeneralComponent' },
|
|
2434
|
+
},
|
|
2435
|
+
{
|
|
2436
|
+
name: 'advanced',
|
|
2437
|
+
label: 'Advanced',
|
|
2438
|
+
component: { name: 'AdvancedComponent' },
|
|
2439
|
+
},
|
|
2440
|
+
],
|
|
2441
|
+
},
|
|
2442
|
+
];
|
|
2443
|
+
|
|
2444
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
2445
|
+
|
|
2446
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
2447
|
+
|
|
2448
|
+
// Verify groups were created with correct structure
|
|
2449
|
+
const workloadsGroup = menuStructure.groups.find((g: any) => g.name === 'completeapp-workloads');
|
|
2450
|
+
|
|
2451
|
+
expect(workloadsGroup).toBeDefined();
|
|
2452
|
+
expect(workloadsGroup.label).toBe('Workloads');
|
|
2453
|
+
expect(workloadsGroup.weight).toBe(90);
|
|
2454
|
+
expect(workloadsGroup.children).toStrictEqual(expect.arrayContaining([
|
|
2455
|
+
'workload.io.deployment',
|
|
2456
|
+
'workload.io.pod',
|
|
2457
|
+
'completeapp-workloads-jobs',
|
|
2458
|
+
]));
|
|
2459
|
+
|
|
2460
|
+
const settingsGroup = menuStructure.groups.find((g: any) => g.name === 'completeapp-settings');
|
|
2461
|
+
|
|
2462
|
+
expect(settingsGroup).toBeDefined();
|
|
2463
|
+
expect(settingsGroup.label).toBe('Settings');
|
|
2464
|
+
expect(settingsGroup.weight).toBe(70);
|
|
2465
|
+
expect(settingsGroup.children).toStrictEqual(expect.arrayContaining([
|
|
2466
|
+
'completeapp-settings-general',
|
|
2467
|
+
'completeapp-settings-advanced',
|
|
2468
|
+
]));
|
|
2469
|
+
|
|
2470
|
+
// Verify all menu items were created with correct properties
|
|
2471
|
+
const virtualItems = menuStructure.items.filter((i: any) => i.type === 'virtual');
|
|
2472
|
+
const configureItems = menuStructure.items.filter((i: any) => i.type === 'configure');
|
|
2473
|
+
|
|
2474
|
+
// Check dashboard (top-level virtual type)
|
|
2475
|
+
const dashboardItem = virtualItems.find((i: any) => i.name === 'completeapp-dashboard');
|
|
2476
|
+
|
|
2477
|
+
expect(dashboardItem).toBeDefined();
|
|
2478
|
+
expect(dashboardItem.label).toBe('Dashboard');
|
|
2479
|
+
expect(dashboardItem.weight).toBe(100);
|
|
2480
|
+
|
|
2481
|
+
// Check configmap (top-level configure type)
|
|
2482
|
+
const configMapItem = configureItems.find((i: any) => i.name === 'config.io.configmap');
|
|
2483
|
+
|
|
2484
|
+
expect(configMapItem).toBeDefined();
|
|
2485
|
+
expect(configMapItem.weight).toBe(80);
|
|
2486
|
+
|
|
2487
|
+
// Verify group items
|
|
2488
|
+
const jobsItem = virtualItems.find((i: any) => i.name === 'completeapp-workloads-jobs');
|
|
2489
|
+
|
|
2490
|
+
expect(jobsItem).toBeDefined();
|
|
2491
|
+
expect(jobsItem.label).toBe('Jobs');
|
|
2492
|
+
|
|
2493
|
+
const generalItem = virtualItems.find((i: any) => i.name === 'completeapp-settings-general');
|
|
2494
|
+
|
|
2495
|
+
expect(generalItem).toBeDefined();
|
|
2496
|
+
expect(generalItem.label).toBe('General');
|
|
2497
|
+
|
|
2498
|
+
const advancedItem = virtualItems.find((i: any) => i.name === 'completeapp-settings-advanced');
|
|
2499
|
+
|
|
2500
|
+
expect(advancedItem).toBeDefined();
|
|
2501
|
+
expect(advancedItem.label).toBe('Advanced');
|
|
2502
|
+
|
|
2503
|
+
// Verify resource types in workloads group
|
|
2504
|
+
const deploymentsItem = configureItems.find((i: any) => i.name === 'workload.io.deployment');
|
|
2505
|
+
|
|
2506
|
+
expect(deploymentsItem).toBeDefined();
|
|
2507
|
+
expect(deploymentsItem.weight).toBe(50);
|
|
2508
|
+
|
|
2509
|
+
const podsItem = configureItems.find((i: any) => i.name === 'workload.io.pod');
|
|
2510
|
+
|
|
2511
|
+
expect(podsItem).toBeDefined();
|
|
2512
|
+
expect(podsItem.weight).toBe(45);
|
|
2513
|
+
|
|
2514
|
+
// Verify total counts
|
|
2515
|
+
expect(virtualItems.length).toBeGreaterThanOrEqual(4); // dashboard, jobs, general, advanced
|
|
2516
|
+
expect(configureItems.length).toBeGreaterThanOrEqual(3); // configmap, deployment, pod
|
|
2517
|
+
expect(menuStructure.groups).toHaveLength(2); // workloads, settings
|
|
2518
|
+
});
|
|
2519
|
+
});
|
|
2520
|
+
|
|
2521
|
+
describe('deeply nested groups (groups within groups)', () => {
|
|
2522
|
+
it('should handle 2-level nested groups with correct hierarchical paths', () => {
|
|
2523
|
+
const mockPlugin = createMockPlugin();
|
|
2524
|
+
const mockStore = createMockStore();
|
|
2525
|
+
const basicTypeCalls: any[] = [];
|
|
2526
|
+
|
|
2527
|
+
const mockDSL = {
|
|
2528
|
+
product: jest.fn(),
|
|
2529
|
+
basicType: jest.fn((...args) => basicTypeCalls.push(args)),
|
|
2530
|
+
labelGroup: jest.fn(),
|
|
2531
|
+
setGroupDefaultType: jest.fn(),
|
|
2532
|
+
weightGroup: jest.fn(),
|
|
2533
|
+
virtualType: jest.fn(),
|
|
2534
|
+
configureType: jest.fn(),
|
|
2535
|
+
weightType: jest.fn(),
|
|
2536
|
+
};
|
|
2537
|
+
|
|
2538
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
2539
|
+
|
|
2540
|
+
const productMetadata: ProductMetadata = {
|
|
2541
|
+
name: 'nested-product',
|
|
2542
|
+
label: 'Nested Product',
|
|
2543
|
+
};
|
|
2544
|
+
const config: ProductChildGroup[] = [
|
|
2545
|
+
{
|
|
2546
|
+
name: 'root-group',
|
|
2547
|
+
label: 'Root Group',
|
|
2548
|
+
weight: 100,
|
|
2549
|
+
children: [
|
|
2550
|
+
{
|
|
2551
|
+
name: 'page1',
|
|
2552
|
+
label: 'Page 1',
|
|
2553
|
+
component: { name: 'Page1Component' },
|
|
2554
|
+
},
|
|
2555
|
+
{
|
|
2556
|
+
name: 'nested-group',
|
|
2557
|
+
label: 'Nested Group',
|
|
2558
|
+
weight: 50,
|
|
2559
|
+
children: [
|
|
2560
|
+
{
|
|
2561
|
+
name: 'nested-page1',
|
|
2562
|
+
label: 'Nested Page 1',
|
|
2563
|
+
component: { name: 'NestedPage1Component' },
|
|
2564
|
+
},
|
|
2565
|
+
{
|
|
2566
|
+
name: 'nested-page2',
|
|
2567
|
+
label: 'Nested Page 2',
|
|
2568
|
+
component: { name: 'NestedPage2Component' },
|
|
2569
|
+
},
|
|
2570
|
+
],
|
|
2571
|
+
},
|
|
2572
|
+
{
|
|
2573
|
+
name: 'page2',
|
|
2574
|
+
label: 'Page 2',
|
|
2575
|
+
component: { name: 'Page2Component' },
|
|
2576
|
+
},
|
|
2577
|
+
],
|
|
2578
|
+
},
|
|
2579
|
+
];
|
|
2580
|
+
|
|
2581
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
2582
|
+
|
|
2583
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
2584
|
+
|
|
2585
|
+
// Verify basicType calls include hierarchical paths with :: separators
|
|
2586
|
+
// First call should be for root group items
|
|
2587
|
+
const rootGroupCall = basicTypeCalls.find((call) => call[1] === 'nestedproduct-root-group');
|
|
2588
|
+
|
|
2589
|
+
expect(rootGroupCall).toBeDefined();
|
|
2590
|
+
expect(rootGroupCall[0]).toContain('nestedproduct-root-group-page1');
|
|
2591
|
+
expect(rootGroupCall[0]).toContain('nestedproduct-root-group-page2');
|
|
2592
|
+
expect(rootGroupCall[0]).toContain('nestedproduct-root-group-nested-group');
|
|
2593
|
+
expect(rootGroupCall[0]).toContain('nestedproduct-root-group'); // Root group itself
|
|
2594
|
+
|
|
2595
|
+
// Second call should be for nested group with hierarchical path
|
|
2596
|
+
const nestedGroupCall = basicTypeCalls.find((call) => call[1] === 'nestedproduct-root-group::nestedproduct-root-group-nested-group');
|
|
2597
|
+
|
|
2598
|
+
expect(nestedGroupCall).toBeDefined();
|
|
2599
|
+
expect(nestedGroupCall[0]).toContain('nestedproduct-root-group-nested-group-nested-page1');
|
|
2600
|
+
expect(nestedGroupCall[0]).toContain('nestedproduct-root-group-nested-group-nested-page2');
|
|
2601
|
+
});
|
|
2602
|
+
|
|
2603
|
+
it('should handle 3-level nested groups with correct hierarchical paths', () => {
|
|
2604
|
+
const mockPlugin = createMockPlugin();
|
|
2605
|
+
const mockStore = createMockStore();
|
|
2606
|
+
const basicTypeCalls: any[] = [];
|
|
2607
|
+
|
|
2608
|
+
const mockDSL = {
|
|
2609
|
+
product: jest.fn(),
|
|
2610
|
+
basicType: jest.fn((...args) => basicTypeCalls.push(args)),
|
|
2611
|
+
labelGroup: jest.fn(),
|
|
2612
|
+
setGroupDefaultType: jest.fn(),
|
|
2613
|
+
weightGroup: jest.fn(),
|
|
2614
|
+
virtualType: jest.fn(),
|
|
2615
|
+
configureType: jest.fn(),
|
|
2616
|
+
weightType: jest.fn(),
|
|
2617
|
+
};
|
|
2618
|
+
|
|
2619
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
2620
|
+
|
|
2621
|
+
const productMetadata: ProductMetadata = {
|
|
2622
|
+
name: 'deep-nested',
|
|
2623
|
+
label: 'Deep Nested',
|
|
2624
|
+
};
|
|
2625
|
+
const config: ProductChildGroup[] = [
|
|
2626
|
+
{
|
|
2627
|
+
name: 'level1',
|
|
2628
|
+
label: 'Level 1',
|
|
2629
|
+
children: [
|
|
2630
|
+
{
|
|
2631
|
+
name: 'level2',
|
|
2632
|
+
label: 'Level 2',
|
|
2633
|
+
children: [
|
|
2634
|
+
{
|
|
2635
|
+
name: 'level3',
|
|
2636
|
+
label: 'Level 3',
|
|
2637
|
+
children: [
|
|
2638
|
+
{
|
|
2639
|
+
name: 'deep-page',
|
|
2640
|
+
label: 'Deep Page',
|
|
2641
|
+
component: { name: 'DeepPageComponent' },
|
|
2642
|
+
},
|
|
2643
|
+
],
|
|
2644
|
+
},
|
|
2645
|
+
],
|
|
2646
|
+
},
|
|
2647
|
+
],
|
|
2648
|
+
},
|
|
2649
|
+
];
|
|
2650
|
+
|
|
2651
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
2652
|
+
|
|
2653
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
2654
|
+
|
|
2655
|
+
// Verify level 1 (root)
|
|
2656
|
+
const level1Call = basicTypeCalls.find((call) => call[1] === 'deepnested-level1');
|
|
2657
|
+
|
|
2658
|
+
expect(level1Call).toBeDefined();
|
|
2659
|
+
expect(level1Call[0]).toContain('deepnested-level1-level2');
|
|
2660
|
+
|
|
2661
|
+
// Verify level 2 (nested in level1)
|
|
2662
|
+
const level2Call = basicTypeCalls.find((call) => call[1] === 'deepnested-level1::deepnested-level1-level2');
|
|
2663
|
+
|
|
2664
|
+
expect(level2Call).toBeDefined();
|
|
2665
|
+
expect(level2Call[0]).toContain('deepnested-level1-level2-level3');
|
|
2666
|
+
|
|
2667
|
+
// Verify level 3 (nested in level2)
|
|
2668
|
+
const level3Call = basicTypeCalls.find((call) => call[1] === 'deepnested-level1::deepnested-level1-level2::deepnested-level1-level2-level3');
|
|
2669
|
+
|
|
2670
|
+
expect(level3Call).toBeDefined();
|
|
2671
|
+
expect(level3Call[0]).toContain('deepnested-level1-level2-level3-deep-page');
|
|
2672
|
+
});
|
|
2673
|
+
|
|
2674
|
+
it('should handle mixed nested groups and pages in standard product extension', () => {
|
|
2675
|
+
const mockPlugin = createMockPlugin();
|
|
2676
|
+
const mockStore = createMockStore();
|
|
2677
|
+
const basicTypeCalls: any[] = [];
|
|
2678
|
+
|
|
2679
|
+
const mockDSL = {
|
|
2680
|
+
product: jest.fn(),
|
|
2681
|
+
basicType: jest.fn((...args) => basicTypeCalls.push(args)),
|
|
2682
|
+
labelGroup: jest.fn(),
|
|
2683
|
+
setGroupDefaultType: jest.fn(),
|
|
2684
|
+
weightGroup: jest.fn(),
|
|
2685
|
+
virtualType: jest.fn(),
|
|
2686
|
+
configureType: jest.fn(),
|
|
2687
|
+
weightType: jest.fn(),
|
|
2688
|
+
};
|
|
2689
|
+
|
|
2690
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
2691
|
+
|
|
2692
|
+
const validStandardProduct = StandardProductNames.EXPLORER;
|
|
2693
|
+
const config: (ProductChildGroup | ProductChildPage)[] = [
|
|
2694
|
+
{
|
|
2695
|
+
name: 'top-page',
|
|
2696
|
+
label: 'Top Page',
|
|
2697
|
+
component: { name: 'TopPageComponent' },
|
|
2698
|
+
},
|
|
2699
|
+
{
|
|
2700
|
+
name: 'parent-group',
|
|
2701
|
+
label: 'Parent Group',
|
|
2702
|
+
weight: 90,
|
|
2703
|
+
children: [
|
|
2704
|
+
{
|
|
2705
|
+
name: 'sibling-page',
|
|
2706
|
+
label: 'Sibling Page',
|
|
2707
|
+
component: { name: 'SiblingPageComponent' },
|
|
2708
|
+
},
|
|
2709
|
+
{
|
|
2710
|
+
name: 'child-group',
|
|
2711
|
+
label: 'Child Group',
|
|
2712
|
+
weight: 80,
|
|
2713
|
+
children: [
|
|
2714
|
+
{
|
|
2715
|
+
name: 'nested-page',
|
|
2716
|
+
label: 'Nested Page',
|
|
2717
|
+
component: { name: 'NestedPageComponent' },
|
|
2718
|
+
},
|
|
2719
|
+
],
|
|
2720
|
+
},
|
|
2721
|
+
],
|
|
2722
|
+
},
|
|
2723
|
+
];
|
|
2724
|
+
|
|
2725
|
+
const pluginProduct = new PluginProduct(mockPlugin, validStandardProduct, config);
|
|
2726
|
+
|
|
2727
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
2728
|
+
|
|
2729
|
+
// Verify parent group has both pages and nested groups
|
|
2730
|
+
const parentGroupCall = basicTypeCalls.find((call) => call[1] === 'explorer-parent-group');
|
|
2731
|
+
|
|
2732
|
+
expect(parentGroupCall).toBeDefined();
|
|
2733
|
+
expect(parentGroupCall[0]).toContain('explorer-parent-group-sibling-page');
|
|
2734
|
+
expect(parentGroupCall[0]).toContain('explorer-parent-group-child-group');
|
|
2735
|
+
|
|
2736
|
+
// Verify child group uses hierarchical path
|
|
2737
|
+
const childGroupCall = basicTypeCalls.find((call) => call[1] === 'explorer-parent-group::explorer-parent-group-child-group');
|
|
2738
|
+
|
|
2739
|
+
expect(childGroupCall).toBeDefined();
|
|
2740
|
+
expect(childGroupCall[0]).toContain('explorer-parent-group-child-group-nested-page');
|
|
2741
|
+
});
|
|
2742
|
+
|
|
2743
|
+
it('should only add root-level groups to their own basicType list', () => {
|
|
2744
|
+
const mockPlugin = createMockPlugin();
|
|
2745
|
+
const mockStore = createMockStore();
|
|
2746
|
+
const basicTypeCalls: any[] = [];
|
|
2747
|
+
|
|
2748
|
+
const mockDSL = {
|
|
2749
|
+
product: jest.fn(),
|
|
2750
|
+
basicType: jest.fn((...args) => basicTypeCalls.push(args)),
|
|
2751
|
+
labelGroup: jest.fn(),
|
|
2752
|
+
setGroupDefaultType: jest.fn(),
|
|
2753
|
+
weightGroup: jest.fn(),
|
|
2754
|
+
virtualType: jest.fn(),
|
|
2755
|
+
configureType: jest.fn(),
|
|
2756
|
+
weightType: jest.fn(),
|
|
2757
|
+
};
|
|
2758
|
+
|
|
2759
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
2760
|
+
|
|
2761
|
+
const productMetadata: ProductMetadata = {
|
|
2762
|
+
name: 'test-self-ref',
|
|
2763
|
+
label: 'Test Self Reference',
|
|
2764
|
+
};
|
|
2765
|
+
const config: ProductChildGroup[] = [
|
|
2766
|
+
{
|
|
2767
|
+
name: 'root',
|
|
2768
|
+
label: 'Root',
|
|
2769
|
+
children: [
|
|
2770
|
+
{
|
|
2771
|
+
name: 'nested',
|
|
2772
|
+
label: 'Nested',
|
|
2773
|
+
children: [
|
|
2774
|
+
{
|
|
2775
|
+
name: 'page',
|
|
2776
|
+
label: 'Page',
|
|
2777
|
+
component: { name: 'PageComponent' },
|
|
2778
|
+
},
|
|
2779
|
+
],
|
|
2780
|
+
},
|
|
2781
|
+
],
|
|
2782
|
+
},
|
|
2783
|
+
];
|
|
2784
|
+
|
|
2785
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
2786
|
+
|
|
2787
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
2788
|
+
|
|
2789
|
+
// Root group should include itself in its basicType call
|
|
2790
|
+
const rootCall = basicTypeCalls.find((call) => call[1] === 'testselfref-root');
|
|
2791
|
+
|
|
2792
|
+
expect(rootCall).toBeDefined();
|
|
2793
|
+
expect(rootCall[0]).toContain('testselfref-root'); // Self-reference
|
|
2794
|
+
|
|
2795
|
+
// Nested group should NOT include itself (would create wrong hierarchy)
|
|
2796
|
+
const nestedCall = basicTypeCalls.find((call) => call[1] === 'testselfref-root::testselfref-root-nested');
|
|
2797
|
+
|
|
2798
|
+
expect(nestedCall).toBeDefined();
|
|
2799
|
+
expect(nestedCall[0]).not.toContain('testselfref-root-nested'); // No self-reference for nested
|
|
2800
|
+
expect(nestedCall[0]).toContain('testselfref-root-nested-page'); // Contains its child page
|
|
2801
|
+
});
|
|
2802
|
+
|
|
2803
|
+
it('should handle multiple nested groups at the same level', () => {
|
|
2804
|
+
const mockPlugin = createMockPlugin();
|
|
2805
|
+
const mockStore = createMockStore();
|
|
2806
|
+
const basicTypeCalls: any[] = [];
|
|
2807
|
+
|
|
2808
|
+
const mockDSL = {
|
|
2809
|
+
product: jest.fn(),
|
|
2810
|
+
basicType: jest.fn((...args) => basicTypeCalls.push(args)),
|
|
2811
|
+
labelGroup: jest.fn(),
|
|
2812
|
+
setGroupDefaultType: jest.fn(),
|
|
2813
|
+
weightGroup: jest.fn(),
|
|
2814
|
+
virtualType: jest.fn(),
|
|
2815
|
+
configureType: jest.fn(),
|
|
2816
|
+
weightType: jest.fn(),
|
|
2817
|
+
};
|
|
2818
|
+
|
|
2819
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
2820
|
+
|
|
2821
|
+
const productMetadata: ProductMetadata = {
|
|
2822
|
+
name: 'multi-nested',
|
|
2823
|
+
label: 'Multi Nested',
|
|
2824
|
+
};
|
|
2825
|
+
const config: ProductChildGroup[] = [
|
|
2826
|
+
{
|
|
2827
|
+
name: 'parent',
|
|
2828
|
+
label: 'Parent',
|
|
2829
|
+
children: [
|
|
2830
|
+
{
|
|
2831
|
+
name: 'child1',
|
|
2832
|
+
label: 'Child 1',
|
|
2833
|
+
children: [
|
|
2834
|
+
{
|
|
2835
|
+
name: 'page1',
|
|
2836
|
+
label: 'Page 1',
|
|
2837
|
+
component: { name: 'Page1Component' },
|
|
2838
|
+
},
|
|
2839
|
+
],
|
|
2840
|
+
},
|
|
2841
|
+
{
|
|
2842
|
+
name: 'child2',
|
|
2843
|
+
label: 'Child 2',
|
|
2844
|
+
children: [
|
|
2845
|
+
{
|
|
2846
|
+
name: 'page2',
|
|
2847
|
+
label: 'Page 2',
|
|
2848
|
+
component: { name: 'Page2Component' },
|
|
2849
|
+
},
|
|
2850
|
+
],
|
|
2851
|
+
},
|
|
2852
|
+
],
|
|
2853
|
+
},
|
|
2854
|
+
];
|
|
2855
|
+
|
|
2856
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
2857
|
+
|
|
2858
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
2859
|
+
|
|
2860
|
+
// Verify both child groups have correct hierarchical paths
|
|
2861
|
+
const child1Call = basicTypeCalls.find((call) => call[1] === 'multinested-parent::multinested-parent-child1');
|
|
2862
|
+
|
|
2863
|
+
expect(child1Call).toBeDefined();
|
|
2864
|
+
expect(child1Call[0]).toContain('multinested-parent-child1-page1');
|
|
2865
|
+
|
|
2866
|
+
const child2Call = basicTypeCalls.find((call) => call[1] === 'multinested-parent::multinested-parent-child2');
|
|
2867
|
+
|
|
2868
|
+
expect(child2Call).toBeDefined();
|
|
2869
|
+
expect(child2Call[0]).toContain('multinested-parent-child2-page2');
|
|
2870
|
+
|
|
2871
|
+
// Verify parent includes both child groups
|
|
2872
|
+
const parentCall = basicTypeCalls.find((call) => call[1] === 'multinested-parent');
|
|
2873
|
+
|
|
2874
|
+
expect(parentCall).toBeDefined();
|
|
2875
|
+
expect(parentCall[0]).toContain('multinested-parent-child1');
|
|
2876
|
+
expect(parentCall[0]).toContain('multinested-parent-child2');
|
|
2877
|
+
});
|
|
2878
|
+
});
|
|
2879
|
+
|
|
2880
|
+
describe('group default type behavior with components', () => {
|
|
2881
|
+
it('should set correct default types for mixed groups (with and without components)', () => {
|
|
2882
|
+
const mockPlugin = createMockPlugin();
|
|
2883
|
+
const mockStore = createMockStore();
|
|
2884
|
+
const setGroupDefaultTypeCalls: any[] = [];
|
|
2885
|
+
|
|
2886
|
+
const mockDSL = {
|
|
2887
|
+
product: jest.fn(),
|
|
2888
|
+
basicType: jest.fn(),
|
|
2889
|
+
labelGroup: jest.fn(),
|
|
2890
|
+
setGroupDefaultType: jest.fn((...args) => setGroupDefaultTypeCalls.push(args)),
|
|
2891
|
+
weightGroup: jest.fn(),
|
|
2892
|
+
virtualType: jest.fn(),
|
|
2893
|
+
configureType: jest.fn(),
|
|
2894
|
+
weightType: jest.fn(),
|
|
2895
|
+
};
|
|
2896
|
+
|
|
2897
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
2898
|
+
|
|
2899
|
+
const productMetadata: ProductMetadata = {
|
|
2900
|
+
name: 'mixed-groups',
|
|
2901
|
+
label: 'Mixed Groups',
|
|
2902
|
+
};
|
|
2903
|
+
const config: ProductChildGroup[] = [
|
|
2904
|
+
{
|
|
2905
|
+
name: 'group-with-page',
|
|
2906
|
+
label: 'Group With Page',
|
|
2907
|
+
component: { name: 'GroupPageComponent' },
|
|
2908
|
+
children: [
|
|
2909
|
+
{
|
|
2910
|
+
name: 'child1',
|
|
2911
|
+
label: 'Child 1',
|
|
2912
|
+
component: { name: 'Child1Component' },
|
|
2913
|
+
},
|
|
2914
|
+
],
|
|
2915
|
+
},
|
|
2916
|
+
{
|
|
2917
|
+
name: 'group-without-page',
|
|
2918
|
+
label: 'Group Without Page',
|
|
2919
|
+
children: [
|
|
2920
|
+
{
|
|
2921
|
+
name: 'child2',
|
|
2922
|
+
label: 'Child 2',
|
|
2923
|
+
component: { name: 'Child2Component' },
|
|
2924
|
+
},
|
|
2925
|
+
],
|
|
2926
|
+
},
|
|
2927
|
+
];
|
|
2928
|
+
|
|
2929
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
2930
|
+
|
|
2931
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
2932
|
+
|
|
2933
|
+
// Group WITH component should have defaultType pointing to itself
|
|
2934
|
+
const groupWithPageCall = setGroupDefaultTypeCalls.find((call) => call[0] === 'mixedgroups-group-with-page');
|
|
2935
|
+
|
|
2936
|
+
expect(groupWithPageCall).toBeDefined();
|
|
2937
|
+
expect(groupWithPageCall[0]).toBe('mixedgroups-group-with-page');
|
|
2938
|
+
expect(groupWithPageCall[1]).toBe('mixedgroups-group-with-page'); // Points to itself
|
|
2939
|
+
|
|
2940
|
+
// Group WITHOUT component should have defaultType pointing to first child
|
|
2941
|
+
const groupWithoutPageCall = setGroupDefaultTypeCalls.find((call) => call[0] === 'mixedgroups-group-without-page');
|
|
2942
|
+
|
|
2943
|
+
expect(groupWithoutPageCall).toBeDefined();
|
|
2944
|
+
expect(groupWithoutPageCall[0]).toBe('mixedgroups-group-without-page');
|
|
2945
|
+
expect(groupWithoutPageCall[1]).toBe('mixedgroups-group-without-page-child2'); // Points to first child
|
|
2946
|
+
});
|
|
2947
|
+
|
|
2948
|
+
it('should handle nested groups where both parent and child have components', () => {
|
|
2949
|
+
const mockPlugin = createMockPlugin();
|
|
2950
|
+
const mockStore = createMockStore();
|
|
2951
|
+
const setGroupDefaultTypeCalls: any[] = [];
|
|
2952
|
+
|
|
2953
|
+
const mockDSL = {
|
|
2954
|
+
product: jest.fn(),
|
|
2955
|
+
basicType: jest.fn(),
|
|
2956
|
+
labelGroup: jest.fn(),
|
|
2957
|
+
setGroupDefaultType: jest.fn((...args) => setGroupDefaultTypeCalls.push(args)),
|
|
2958
|
+
weightGroup: jest.fn(),
|
|
2959
|
+
virtualType: jest.fn(),
|
|
2960
|
+
configureType: jest.fn(),
|
|
2961
|
+
weightType: jest.fn(),
|
|
2962
|
+
};
|
|
2963
|
+
|
|
2964
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
2965
|
+
|
|
2966
|
+
const productMetadata: ProductMetadata = {
|
|
2967
|
+
name: 'nested-with-pages',
|
|
2968
|
+
label: 'Nested With Pages',
|
|
2969
|
+
};
|
|
2970
|
+
const config: ProductChildGroup[] = [
|
|
2971
|
+
{
|
|
2972
|
+
name: 'parent',
|
|
2973
|
+
label: 'Parent',
|
|
2974
|
+
component: { name: 'ParentComponent' },
|
|
2975
|
+
children: [
|
|
2976
|
+
{
|
|
2977
|
+
name: 'child-group',
|
|
2978
|
+
label: 'Child Group',
|
|
2979
|
+
component: { name: 'ChildGroupComponent' },
|
|
2980
|
+
children: [
|
|
2981
|
+
{
|
|
2982
|
+
name: 'grandchild',
|
|
2983
|
+
label: 'Grandchild',
|
|
2984
|
+
component: { name: 'GrandchildComponent' },
|
|
2985
|
+
},
|
|
2986
|
+
],
|
|
2987
|
+
},
|
|
2988
|
+
],
|
|
2989
|
+
},
|
|
2990
|
+
];
|
|
2991
|
+
|
|
2992
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
2993
|
+
|
|
2994
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
2995
|
+
|
|
2996
|
+
// Parent group with component should point to itself
|
|
2997
|
+
const parentCall = setGroupDefaultTypeCalls.find((call) => call[0] === 'nestedwithpages-parent');
|
|
2998
|
+
|
|
2999
|
+
expect(parentCall).toBeDefined();
|
|
3000
|
+
expect(parentCall[1]).toBe('nestedwithpages-parent');
|
|
3001
|
+
|
|
3002
|
+
// Nested child group with component should also point to itself
|
|
3003
|
+
const childCall = setGroupDefaultTypeCalls.find((call) => call[0] === 'nestedwithpages-parent-child-group');
|
|
3004
|
+
|
|
3005
|
+
expect(childCall).toBeDefined();
|
|
3006
|
+
expect(childCall[1]).toBe('nestedwithpages-parent-child-group');
|
|
3007
|
+
});
|
|
3008
|
+
|
|
3009
|
+
it('should reproduce user bug: group with component and children routes to group page not first child', () => {
|
|
3010
|
+
const mockPlugin = createMockPlugin();
|
|
3011
|
+
const mockStore = createMockStore();
|
|
3012
|
+
const setGroupDefaultTypeCalls: any[] = [];
|
|
3013
|
+
const virtualTypeCalls: any[] = [];
|
|
3014
|
+
|
|
3015
|
+
const mockDSL = {
|
|
3016
|
+
product: jest.fn(),
|
|
3017
|
+
basicType: jest.fn(),
|
|
3018
|
+
labelGroup: jest.fn(),
|
|
3019
|
+
setGroupDefaultType: jest.fn((...args) => setGroupDefaultTypeCalls.push(args)),
|
|
3020
|
+
weightGroup: jest.fn(),
|
|
3021
|
+
virtualType: jest.fn((...args) => virtualTypeCalls.push(args)),
|
|
3022
|
+
configureType: jest.fn(),
|
|
3023
|
+
weightType: jest.fn(),
|
|
3024
|
+
};
|
|
3025
|
+
|
|
3026
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
3027
|
+
|
|
3028
|
+
// Exact scenario from user's bug report
|
|
3029
|
+
const productMetadata: ProductMetadata = {
|
|
3030
|
+
name: 'group-with-page',
|
|
3031
|
+
label: 'Group With Page',
|
|
3032
|
+
};
|
|
3033
|
+
const config: (ProductChildGroup | ProductChildPage)[] = [
|
|
3034
|
+
{
|
|
3035
|
+
name: 'general1',
|
|
3036
|
+
label: 'General Settings1',
|
|
3037
|
+
component: { name: 'GeneralComponent' },
|
|
3038
|
+
},
|
|
3039
|
+
{
|
|
3040
|
+
name: 'settings',
|
|
3041
|
+
label: 'Settings',
|
|
3042
|
+
component: { name: 'SettingsOverviewComponent' },
|
|
3043
|
+
children: [
|
|
3044
|
+
{
|
|
3045
|
+
name: 'general',
|
|
3046
|
+
label: 'General Settings',
|
|
3047
|
+
component: { name: 'GeneralComponent' },
|
|
3048
|
+
},
|
|
3049
|
+
{
|
|
3050
|
+
name: 'advanced',
|
|
3051
|
+
label: 'Advanced Settings',
|
|
3052
|
+
component: { name: 'AdvancedComponent' },
|
|
3053
|
+
},
|
|
3054
|
+
],
|
|
3055
|
+
},
|
|
3056
|
+
{
|
|
3057
|
+
name: 'general2',
|
|
3058
|
+
label: 'General Settings2',
|
|
3059
|
+
component: { name: 'GeneralComponent' },
|
|
3060
|
+
},
|
|
3061
|
+
];
|
|
3062
|
+
|
|
3063
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
3064
|
+
|
|
3065
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
3066
|
+
|
|
3067
|
+
// Verify the settings group (which has component + children) has defaultType pointing to itself
|
|
3068
|
+
const settingsCall = setGroupDefaultTypeCalls.find((call) => call[0] === 'groupwithpage-settings');
|
|
3069
|
+
|
|
3070
|
+
expect(settingsCall).toBeDefined();
|
|
3071
|
+
expect(settingsCall[0]).toBe('groupwithpage-settings');
|
|
3072
|
+
expect(settingsCall[1]).toBe('groupwithpage-settings'); // Should point to itself, NOT 'groupwithpage-settings-general'
|
|
3073
|
+
|
|
3074
|
+
// Verify the settings virtualType was created with exact + overview flags
|
|
3075
|
+
const settingsVirtualType = virtualTypeCalls.find((call) => call[0].name === 'groupwithpage-settings');
|
|
3076
|
+
|
|
3077
|
+
expect(settingsVirtualType).toBeDefined();
|
|
3078
|
+
expect(settingsVirtualType[0].exact).toBe(true);
|
|
3079
|
+
expect(settingsVirtualType[0].overview).toBe(true);
|
|
3080
|
+
});
|
|
3081
|
+
|
|
3082
|
+
it('should handle empty children array with component (group page, no children)', () => {
|
|
3083
|
+
const mockPlugin = createMockPlugin();
|
|
3084
|
+
const mockStore = createMockStore();
|
|
3085
|
+
const setGroupDefaultTypeCalls: any[] = [];
|
|
3086
|
+
|
|
3087
|
+
const mockDSL = {
|
|
3088
|
+
product: jest.fn(),
|
|
3089
|
+
basicType: jest.fn(),
|
|
3090
|
+
labelGroup: jest.fn(),
|
|
3091
|
+
setGroupDefaultType: jest.fn((...args) => setGroupDefaultTypeCalls.push(args)),
|
|
3092
|
+
weightGroup: jest.fn(),
|
|
3093
|
+
virtualType: jest.fn(),
|
|
3094
|
+
configureType: jest.fn(),
|
|
3095
|
+
weightType: jest.fn(),
|
|
3096
|
+
};
|
|
3097
|
+
|
|
3098
|
+
(mockPlugin.DSL as jest.Mock).mockReturnValue(mockDSL);
|
|
3099
|
+
|
|
3100
|
+
const productMetadata: ProductMetadata = {
|
|
3101
|
+
name: 'empty-children',
|
|
3102
|
+
label: 'Empty Children',
|
|
3103
|
+
};
|
|
3104
|
+
const config: ProductChildGroup[] = [
|
|
3105
|
+
{
|
|
3106
|
+
name: 'standalone-group',
|
|
3107
|
+
label: 'Standalone Group',
|
|
3108
|
+
component: { name: 'StandaloneComponent' },
|
|
3109
|
+
children: [],
|
|
3110
|
+
},
|
|
3111
|
+
];
|
|
3112
|
+
|
|
3113
|
+
const pluginProduct = new PluginProduct(mockPlugin, productMetadata, config);
|
|
3114
|
+
|
|
3115
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
3116
|
+
|
|
3117
|
+
// Group with component but empty children should still point to itself
|
|
3118
|
+
const groupCall = setGroupDefaultTypeCalls.find((call) => call[0] === 'emptychildren-standalone-group');
|
|
3119
|
+
|
|
3120
|
+
expect(groupCall).toBeDefined();
|
|
3121
|
+
expect(groupCall[1]).toBe('emptychildren-standalone-group');
|
|
3122
|
+
});
|
|
3123
|
+
});
|
|
3124
|
+
});
|
|
3125
|
+
|
|
3126
|
+
describe('fromName convenience method', () => {
|
|
3127
|
+
it('should create a new top-level product from a string name', () => {
|
|
3128
|
+
const mockPlugin = createMockPlugin();
|
|
3129
|
+
const pluginProduct = PluginProduct.fromName(mockPlugin, 'my-first-product');
|
|
3130
|
+
|
|
3131
|
+
expect(pluginProduct.newProduct).toBe(true);
|
|
3132
|
+
expect(mockPlugin._registerTopLevelProduct).toHaveBeenCalledTimes(1);
|
|
3133
|
+
});
|
|
3134
|
+
|
|
3135
|
+
it('should register a route with EmptyProductPage when created from a string name', () => {
|
|
3136
|
+
const mockPlugin = createMockPlugin();
|
|
3137
|
+
|
|
3138
|
+
PluginProduct.fromName(mockPlugin, 'my-first-product');
|
|
3139
|
+
|
|
3140
|
+
expect(mockPlugin.addRoute).toHaveBeenCalledTimes(1);
|
|
3141
|
+
});
|
|
3142
|
+
|
|
3143
|
+
it('should use the string as both name and label for the product', () => {
|
|
3144
|
+
const mockPlugin = createMockPlugin();
|
|
3145
|
+
const mockStore = createMockStore();
|
|
3146
|
+
const productCalls: any[] = [];
|
|
3147
|
+
const mockDSL = {
|
|
3148
|
+
product: jest.fn((...args: any[]) => productCalls.push(args)),
|
|
3149
|
+
basicType: jest.fn(),
|
|
3150
|
+
labelGroup: jest.fn(),
|
|
3151
|
+
setGroupDefaultType: jest.fn(),
|
|
3152
|
+
weightGroup: jest.fn(),
|
|
3153
|
+
virtualType: jest.fn(),
|
|
3154
|
+
configureType: jest.fn(),
|
|
3155
|
+
weightType: jest.fn(),
|
|
3156
|
+
};
|
|
3157
|
+
|
|
3158
|
+
jest.spyOn(mockPlugin, 'DSL').mockReturnValue(mockDSL);
|
|
3159
|
+
|
|
3160
|
+
const pluginProduct = PluginProduct.fromName(mockPlugin, 'my-first-product');
|
|
3161
|
+
|
|
3162
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
3163
|
+
|
|
3164
|
+
expect(productCalls).toHaveLength(1);
|
|
3165
|
+
expect(productCalls[0][0]).toStrictEqual(expect.objectContaining({
|
|
3166
|
+
name: 'myfirstproduct',
|
|
3167
|
+
label: 'my-first-product',
|
|
3168
|
+
}));
|
|
3169
|
+
});
|
|
3170
|
+
|
|
3171
|
+
it('should handle product names with dashes by removing them for the internal name', () => {
|
|
3172
|
+
const mockPlugin = createMockPlugin();
|
|
3173
|
+
const mockStore = createMockStore();
|
|
3174
|
+
const productCalls: any[] = [];
|
|
3175
|
+
const mockDSL = {
|
|
3176
|
+
product: jest.fn((...args: any[]) => productCalls.push(args)),
|
|
3177
|
+
basicType: jest.fn(),
|
|
3178
|
+
labelGroup: jest.fn(),
|
|
3179
|
+
setGroupDefaultType: jest.fn(),
|
|
3180
|
+
weightGroup: jest.fn(),
|
|
3181
|
+
virtualType: jest.fn(),
|
|
3182
|
+
configureType: jest.fn(),
|
|
3183
|
+
weightType: jest.fn(),
|
|
3184
|
+
};
|
|
3185
|
+
|
|
3186
|
+
jest.spyOn(mockPlugin, 'DSL').mockReturnValue(mockDSL);
|
|
3187
|
+
|
|
3188
|
+
const pluginProduct = PluginProduct.fromName(mockPlugin, 'test-product-name');
|
|
3189
|
+
|
|
3190
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
3191
|
+
|
|
3192
|
+
expect(productCalls[0][0]).toStrictEqual(expect.objectContaining({ name: 'testproductname' }));
|
|
3193
|
+
});
|
|
3194
|
+
|
|
3195
|
+
it('should handle product names without dashes', () => {
|
|
3196
|
+
const mockPlugin = createMockPlugin();
|
|
3197
|
+
const mockStore = createMockStore();
|
|
3198
|
+
const productCalls: any[] = [];
|
|
3199
|
+
const mockDSL = {
|
|
3200
|
+
product: jest.fn((...args: any[]) => productCalls.push(args)),
|
|
3201
|
+
basicType: jest.fn(),
|
|
3202
|
+
labelGroup: jest.fn(),
|
|
3203
|
+
setGroupDefaultType: jest.fn(),
|
|
3204
|
+
weightGroup: jest.fn(),
|
|
3205
|
+
virtualType: jest.fn(),
|
|
3206
|
+
configureType: jest.fn(),
|
|
3207
|
+
weightType: jest.fn(),
|
|
3208
|
+
};
|
|
3209
|
+
|
|
3210
|
+
jest.spyOn(mockPlugin, 'DSL').mockReturnValue(mockDSL);
|
|
3211
|
+
|
|
3212
|
+
const pluginProduct = PluginProduct.fromName(mockPlugin, 'myproduct');
|
|
3213
|
+
|
|
3214
|
+
pluginProduct.apply(mockPlugin, mockStore);
|
|
3215
|
+
|
|
3216
|
+
expect(productCalls[0][0]).toStrictEqual(expect.objectContaining({ name: 'myproduct' }));
|
|
3217
|
+
});
|
|
3218
|
+
});
|
|
3219
|
+
});
|