@rancher/shell 3.0.11 → 3.0.12-rc.2

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