@rancher/shell 3.0.5-rc.6 → 3.0.5-rc.8

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 (243) hide show
  1. package/assets/brand/classic/metadata.json +3 -0
  2. package/assets/styles/app.scss +1 -0
  3. package/assets/styles/base/_color.scss +16 -0
  4. package/assets/styles/base/_helpers.scss +10 -0
  5. package/assets/styles/base/_variables.scss +18 -12
  6. package/assets/styles/fonts/_icons.scss +1 -32
  7. package/assets/styles/global/_layout.scss +1 -1
  8. package/assets/styles/themes/_dark.scss +262 -258
  9. package/assets/styles/themes/_light.scss +538 -509
  10. package/assets/styles/themes/_modern.scss +914 -0
  11. package/assets/translations/en-us.yaml +110 -29
  12. package/chart/__tests__/S3.test.ts +2 -1
  13. package/cloud-credential/generic.vue +18 -10
  14. package/cloud-credential/harvester.vue +1 -9
  15. package/components/AdvancedSection.vue +8 -0
  16. package/components/ChartReadme.vue +17 -7
  17. package/components/CodeMirror.vue +1 -1
  18. package/components/Drawer/Chrome.vue +0 -1
  19. package/components/Drawer/ResourceDetailDrawer/__tests__/composables.test.ts +27 -28
  20. package/components/Drawer/ResourceDetailDrawer/composables.ts +4 -24
  21. package/components/Drawer/ResourceDetailDrawer/index.vue +18 -4
  22. package/components/InstallHelmCharts.vue +656 -0
  23. package/components/LazyImage.vue +60 -4
  24. package/components/Loading.vue +1 -1
  25. package/components/LocaleSelector.vue +7 -2
  26. package/components/Markdown.vue +4 -0
  27. package/components/PaginatedResourceTable.vue +46 -1
  28. package/components/PromptRestore.vue +22 -44
  29. package/components/Resource/Detail/Masthead/composable.ts +16 -0
  30. package/components/Resource/Detail/Masthead/index.vue +37 -0
  31. package/components/Resource/Detail/Metadata/IdentifyingInformation/composable.ts +10 -2
  32. package/components/Resource/Detail/Metadata/IdentifyingInformation/identifying-fields.ts +26 -7
  33. package/components/Resource/Detail/Metadata/IdentifyingInformation/index.vue +8 -1
  34. package/components/Resource/Detail/Metadata/KeyValue.vue +12 -10
  35. package/components/Resource/Detail/Metadata/Rectangle.vue +3 -1
  36. package/components/Resource/Detail/Metadata/__tests__/composables.test.ts +10 -17
  37. package/components/Resource/Detail/Metadata/composables.ts +9 -7
  38. package/components/Resource/Detail/Metadata/index.vue +17 -2
  39. package/components/Resource/Detail/Page.vue +35 -21
  40. package/components/Resource/Detail/SpacedRow.vue +1 -1
  41. package/components/Resource/Detail/TitleBar/__tests__/composables.test.ts +8 -9
  42. package/components/Resource/Detail/TitleBar/composables.ts +5 -5
  43. package/components/Resource/Detail/TitleBar/index.vue +12 -3
  44. package/components/ResourceDetail/Masthead/legacy.vue +1 -1
  45. package/components/ResourceDetail/index.vue +569 -72
  46. package/components/ResourceList/index.vue +1 -0
  47. package/components/ResourceTable.vue +6 -1
  48. package/components/ResourceYaml.vue +1 -1
  49. package/components/RichTranslation.vue +106 -0
  50. package/components/SlideInPanelManager.vue +13 -10
  51. package/components/SortableTable/index.vue +5 -5
  52. package/components/SortableTable/selection.js +0 -1
  53. package/components/Tabbed/index.vue +35 -4
  54. package/components/__tests__/LazyImage.spec.ts +121 -0
  55. package/components/__tests__/PromptRestore.test.ts +1 -65
  56. package/components/__tests__/RichTranslation.test.ts +115 -0
  57. package/components/fleet/FleetStatus.vue +4 -0
  58. package/components/fleet/dashboard/ResourcePanel.vue +2 -1
  59. package/components/form/ClusterAppearance.vue +5 -0
  60. package/components/form/FileImageSelector.vue +1 -1
  61. package/components/form/Members/ClusterPermissionsEditor.vue +1 -1
  62. package/components/form/NameNsDescription.vue +1 -0
  63. package/components/form/Networking.vue +24 -19
  64. package/components/form/ProjectMemberEditor.vue +1 -1
  65. package/components/form/ResourceLabeledSelect.vue +22 -8
  66. package/components/form/ResourceTabs/index.vue +20 -0
  67. package/components/form/SecretSelector.vue +9 -0
  68. package/components/form/SelectOrCreateAuthSecret.vue +6 -3
  69. package/components/form/__tests__/Networking.test.ts +116 -0
  70. package/components/form/labeled-select-utils/labeled-select-pagination.ts +3 -38
  71. package/components/formatter/FleetApplicationSource.vue +25 -17
  72. package/components/formatter/PodImages.vue +1 -1
  73. package/components/formatter/__tests__/LiveDate.test.ts +10 -2
  74. package/components/google/AccountAccess.vue +44 -46
  75. package/components/nav/Favorite.vue +4 -0
  76. package/components/nav/Group.vue +4 -1
  77. package/components/nav/NotificationCenter/Notification.vue +1 -27
  78. package/components/nav/WindowManager/index.vue +3 -3
  79. package/composables/resources.ts +2 -2
  80. package/config/labels-annotations.js +3 -2
  81. package/config/pagination-table-headers.js +8 -1
  82. package/config/product/explorer.js +27 -2
  83. package/config/product/manager.js +0 -1
  84. package/config/query-params.js +10 -0
  85. package/config/router/routes.js +21 -1
  86. package/config/system-namespaces.js +1 -1
  87. package/config/table-headers.js +30 -1
  88. package/config/types.js +1 -1
  89. package/config/version.js +1 -1
  90. package/detail/__tests__/provisioning.cattle.io.cluster.test.ts +11 -0
  91. package/detail/__tests__/workload.test.ts +164 -0
  92. package/detail/configmap.vue +33 -75
  93. package/detail/projectsecret.vue +11 -0
  94. package/detail/provisioning.cattle.io.cluster.vue +351 -369
  95. package/detail/secret.vue +49 -308
  96. package/detail/workload/index.vue +38 -21
  97. package/dialog/InstallExtensionDialog.vue +8 -5
  98. package/dialog/RotateEncryptionKeyDialog.vue +10 -30
  99. package/edit/__tests__/fleet.cattle.io.helmop.test.ts +224 -0
  100. package/edit/auth/ldap/__tests__/config.test.ts +14 -0
  101. package/edit/auth/ldap/config.vue +24 -0
  102. package/edit/compliance.cattle.io.clusterscan.vue +1 -1
  103. package/edit/configmap.vue +4 -1
  104. package/edit/fleet.cattle.io.gitrepo.vue +5 -6
  105. package/edit/fleet.cattle.io.helmop.vue +78 -56
  106. package/edit/logging.banzaicloud.io.output/index.vue +1 -1
  107. package/edit/logging.banzaicloud.io.output/providers/awsElasticsearch.vue +5 -6
  108. package/edit/networking.k8s.io.ingress/Certificate.vue +20 -22
  109. package/edit/networking.k8s.io.ingress/DefaultBackend.vue +8 -3
  110. package/edit/networking.k8s.io.ingress/Rule.vue +2 -5
  111. package/edit/networking.k8s.io.ingress/RulePath.vue +17 -11
  112. package/edit/networking.k8s.io.ingress/__tests__/Certificate.test.ts +165 -0
  113. package/edit/networking.k8s.io.networkpolicy/PolicyRuleTarget.vue +11 -10
  114. package/edit/networking.k8s.io.networkpolicy/PolicyRules.vue +1 -3
  115. package/edit/networking.k8s.io.networkpolicy/index.vue +17 -17
  116. package/edit/provisioning.cattle.io.cluster/__tests__/rke2.test.ts +3 -2
  117. package/edit/provisioning.cattle.io.cluster/rke2.vue +123 -61
  118. package/edit/provisioning.cattle.io.cluster/tabs/AgentConfiguration.vue +9 -7
  119. package/edit/provisioning.cattle.io.cluster/tabs/Basics.vue +22 -13
  120. package/edit/provisioning.cattle.io.cluster/tabs/DirectoryConfig.vue +10 -12
  121. package/edit/provisioning.cattle.io.cluster/tabs/MachinePool.vue +39 -38
  122. package/edit/provisioning.cattle.io.cluster/tabs/etcd/S3Config.vue +41 -19
  123. package/edit/provisioning.cattle.io.cluster/tabs/etcd/index.vue +16 -3
  124. package/edit/provisioning.cattle.io.cluster/tabs/registries/RegistryConfigs.vue +32 -33
  125. package/edit/provisioning.cattle.io.cluster/tabs/registries/RegistryMirrors.vue +9 -10
  126. package/edit/provisioning.cattle.io.cluster/tabs/registries/index.vue +1 -3
  127. package/edit/provisioning.cattle.io.cluster/tabs/upgrade/DrainOptions.vue +16 -9
  128. package/edit/secret/basic.vue +1 -0
  129. package/edit/secret/index.vue +126 -15
  130. package/edit/workload/index.vue +5 -14
  131. package/list/projectsecret.vue +345 -0
  132. package/list/provisioning.cattle.io.cluster.vue +1 -69
  133. package/list/secret.vue +109 -0
  134. package/machine-config/__tests__/vmwarevsphere.test.ts +5 -7
  135. package/machine-config/google.vue +9 -1
  136. package/machine-config/vmwarevsphere.vue +7 -17
  137. package/mixins/__tests__/brand.spec.ts +2 -2
  138. package/mixins/chart.js +0 -2
  139. package/mixins/create-edit-view/impl.js +10 -1
  140. package/mixins/resource-fetch-api-pagination.js +11 -12
  141. package/mixins/resource-fetch.js +3 -1
  142. package/models/__tests__/chart.test.ts +111 -80
  143. package/models/__tests__/fleet.cattle.io.helmop.test.ts +224 -0
  144. package/models/__tests__/node.test.ts +7 -63
  145. package/models/catalog.cattle.io.app.js +1 -1
  146. package/models/catalog.cattle.io.operation.js +1 -1
  147. package/models/chart.js +36 -20
  148. package/models/cloudcredential.js +2 -163
  149. package/models/cluster/node.js +7 -7
  150. package/models/cluster.x-k8s.io.machine.js +3 -3
  151. package/models/cluster.x-k8s.io.machinedeployment.js +11 -2
  152. package/models/compliance.cattle.io.clusterscan.js +2 -2
  153. package/models/configmap.js +4 -0
  154. package/models/constraints.gatekeeper.sh.constraint.js +1 -1
  155. package/models/fleet-application.js +0 -17
  156. package/models/fleet.cattle.io.cluster.js +2 -2
  157. package/models/fleet.cattle.io.gitrepo.js +15 -1
  158. package/models/fleet.cattle.io.helmop.js +26 -22
  159. package/models/management.cattle.io.setting.js +4 -0
  160. package/models/persistentvolumeclaim.js +1 -1
  161. package/models/pod.js +2 -2
  162. package/models/provisioning.cattle.io.cluster.js +39 -67
  163. package/models/rke.cattle.io.etcdsnapshot.js +1 -1
  164. package/models/secret.js +161 -2
  165. package/models/storage.k8s.io.storageclass.js +2 -2
  166. package/models/workload.js +3 -3
  167. package/package.json +11 -10
  168. package/pages/c/_cluster/apps/charts/AppChartCardFooter.vue +1 -0
  169. package/pages/c/_cluster/apps/charts/AppChartCardSubHeader.vue +4 -1
  170. package/pages/c/_cluster/apps/charts/__tests__/AppChartCardFooter.spec.js +41 -0
  171. package/pages/c/_cluster/apps/charts/chart.vue +422 -174
  172. package/pages/c/_cluster/apps/charts/index.vue +46 -35
  173. package/pages/c/_cluster/apps/charts/install.vue +1 -1
  174. package/pages/c/_cluster/explorer/projectsecret.vue +24 -0
  175. package/pages/c/_cluster/fleet/__tests__/index.test.ts +608 -314
  176. package/pages/c/_cluster/fleet/index.vue +103 -45
  177. package/pages/c/_cluster/manager/cloudCredential/index.vue +2 -59
  178. package/pages/c/_cluster/uiplugins/PluginInfoPanel.vue +10 -3
  179. package/pages/c/_cluster/uiplugins/index.vue +36 -25
  180. package/plugins/dashboard-store/__tests__/normalize.test.ts +223 -0
  181. package/plugins/dashboard-store/__tests__/resource-class.test.ts +191 -0
  182. package/plugins/dashboard-store/__tests__/utils/normalize-usecases.ts +1526 -0
  183. package/plugins/dashboard-store/actions.js +42 -22
  184. package/plugins/dashboard-store/normalize.js +29 -17
  185. package/plugins/dashboard-store/resource-class.js +83 -17
  186. package/plugins/steve/__tests__/getters.test.ts +1 -1
  187. package/plugins/steve/__tests__/subscribe.spec.ts +259 -1
  188. package/plugins/steve/getters.js +8 -2
  189. package/plugins/steve/resourceWatcher.js +10 -3
  190. package/plugins/steve/steve-pagination-utils.ts +14 -3
  191. package/plugins/steve/subscribe.js +192 -19
  192. package/plugins/steve/worker/web-worker.advanced.js +2 -0
  193. package/rancher-components/Card/Card.vue +0 -18
  194. package/rancher-components/Pill/RcStatusBadge/RcStatusBadge.test.ts +15 -0
  195. package/rancher-components/Pill/RcStatusBadge/RcStatusBadge.vue +65 -0
  196. package/rancher-components/Pill/RcStatusBadge/index.ts +2 -0
  197. package/rancher-components/Pill/RcStatusBadge/types.ts +5 -0
  198. package/rancher-components/Pill/RcStatusIndicator/RcStatusIndicator.test.ts +33 -0
  199. package/rancher-components/Pill/RcStatusIndicator/RcStatusIndicator.vue +75 -0
  200. package/rancher-components/Pill/RcStatusIndicator/index.ts +2 -0
  201. package/rancher-components/Pill/RcStatusIndicator/types.ts +7 -0
  202. package/rancher-components/Pill/types.ts +2 -0
  203. package/rancher-components/RcButton/RcButton.vue +1 -1
  204. package/rancher-components/RcDropdown/RcDropdown.test.ts +98 -0
  205. package/rancher-components/RcDropdown/RcDropdown.vue +5 -0
  206. package/rancher-components/RcDropdown/RcDropdownItem.vue +7 -1
  207. package/rancher-components/RcDropdown/RcDropdownItemCheckbox.vue +2 -1
  208. package/rancher-components/RcDropdown/RcDropdownItemSelect.vue +2 -1
  209. package/rancher-components/RcDropdown/useDropdownContext.ts +21 -0
  210. package/rancher-components/RcDropdown/useDropdownItem.ts +30 -1
  211. package/rancher-components/RcItemCard/RcItemCard.test.ts +20 -0
  212. package/rancher-components/RcItemCard/RcItemCard.vue +40 -6
  213. package/store/__tests__/catalog.test.ts +93 -1
  214. package/store/aws.js +19 -8
  215. package/store/catalog.js +8 -3
  216. package/types/kube/kube-api.ts +12 -0
  217. package/types/resources/settings.d.ts +1 -1
  218. package/types/shell/index.d.ts +643 -585
  219. package/types/store/pagination.types.ts +16 -6
  220. package/types/uiplugins.ts +73 -0
  221. package/utils/__tests__/back-off.test.ts +354 -0
  222. package/utils/__tests__/create-yaml.test.ts +235 -0
  223. package/utils/__tests__/kontainer.test.ts +19 -0
  224. package/utils/__tests__/uiplugins.test.ts +84 -0
  225. package/utils/back-off.ts +176 -0
  226. package/utils/create-yaml.js +103 -9
  227. package/utils/dynamic-importer.js +8 -0
  228. package/utils/kontainer.ts +3 -5
  229. package/utils/pagination-utils.ts +18 -0
  230. package/utils/style.ts +3 -0
  231. package/utils/uiplugins.ts +29 -2
  232. package/utils/validators/__tests__/setting.test.js +92 -0
  233. package/utils/validators/formRules/__tests__/index.test.ts +88 -7
  234. package/utils/validators/formRules/index.ts +83 -8
  235. package/utils/validators/setting.js +17 -0
  236. package/cloud-credential/__tests__/harvester.test.ts +0 -18
  237. package/components/ResourceDetail/__tests__/index.test.ts +0 -135
  238. package/components/ResourceDetail/legacy.vue +0 -562
  239. package/components/formatter/CloudCredExpired.vue +0 -69
  240. package/models/etcdbackup.js +0 -45
  241. package/pages/explorer/resource/detail/configmap.vue +0 -42
  242. package/pages/explorer/resource/detail/secret.vue +0 -50
  243. package/utils/aws.js +0 -0
@@ -0,0 +1,223 @@
1
+ import { handleConflict } from '@shell/plugins/dashboard-store/normalize';
2
+ import { handleConflictUseCases } from '@shell/plugins/dashboard-store/__tests__/utils/normalize-usecases';
3
+ import actions from '@shell/plugins/steve/actions.js';
4
+ import cloneDeep from 'lodash/cloneDeep';
5
+
6
+ describe('fn: handleConflict', () => {
7
+ let mockStore: any;
8
+ let mockToJSON: any;
9
+
10
+ beforeEach(() => {
11
+ jest.clearAllMocks();
12
+
13
+ mockStore = {
14
+ dispatch: jest.fn((action, payload) => Promise.resolve(payload)),
15
+ getters: { 'i18n/t': jest.fn((key, params) => `${ key } - ${ JSON.stringify(params) }`) },
16
+ };
17
+
18
+ mockToJSON = jest.fn((x) => x);
19
+ });
20
+
21
+ it('should resolve conflict and return false if no actual conflicts (integration)', async() => {
22
+ const initialValue = {
23
+ metadata: { resourceVersion: '1' },
24
+ spec: {
25
+ replicas: 1,
26
+ containers: [{
27
+ name: 'app',
28
+ image: 'image1'
29
+ }]
30
+ }
31
+ };
32
+ // User modifies 'replicas'
33
+ const value = {
34
+ metadata: { resourceVersion: '1' },
35
+ spec: {
36
+ replicas: 2,
37
+ containers: [{
38
+ name: 'app',
39
+ image: 'image1'
40
+ }]
41
+ }
42
+ };
43
+ // Server did not modify 'replicas', but changed something else (e.g., added a label)
44
+ const liveValue = {
45
+ metadata: {
46
+ resourceVersion: '2',
47
+ labels: { env: 'prod' }
48
+ },
49
+ spec: {
50
+ replicas: 1, // Same replicas as initialValue, so no conflict with userChange on replicas
51
+ containers: [{
52
+ name: 'app',
53
+ image: 'image1'
54
+ }]
55
+ }
56
+ };
57
+
58
+ const result = await handleConflict(initialValue, value, liveValue, mockStore, 'namespace', mockToJSON);
59
+
60
+ // resourceVersion should be updated from liveValue
61
+ expect(value.metadata.resourceVersion).toStrictEqual('2');
62
+ // Background changes (labels added) should have been applied to 'value'
63
+ expect((value.metadata as any).labels).toStrictEqual({ env: 'prod' });
64
+ // User's change (replicas) should have remained, as there was no conflict
65
+ expect(value.spec.replicas).toStrictEqual(2);
66
+
67
+ expect(result).toStrictEqual(false); // No conflict, save can continue
68
+ });
69
+
70
+ it('should return conflict errors if actual conflicts exist (integration)', async() => {
71
+ const initialValue = {
72
+ metadata: { resourceVersion: '1' },
73
+ spec: {
74
+ replicas: 1,
75
+ containers: [{
76
+ name: 'app',
77
+ image: 'image1'
78
+ }]
79
+ }
80
+ };
81
+ // User modifies 'replicas' to 2
82
+ const value = {
83
+ metadata: { resourceVersion: '1' },
84
+ spec: {
85
+ replicas: 2,
86
+ containers: [{
87
+ name: 'app',
88
+ image: 'image1'
89
+ }]
90
+ }
91
+ };
92
+ // Server modified 'replicas' to 3
93
+ const liveValue = {
94
+ metadata: { resourceVersion: '2' },
95
+ spec: {
96
+ replicas: 3, // Conflict with user's modification
97
+ containers: [{
98
+ name: 'app',
99
+ image: 'image1'
100
+ }]
101
+ }
102
+ };
103
+
104
+ const result = await handleConflict(initialValue, value, liveValue, mockStore, 'namespace', mockToJSON);
105
+
106
+ // resourceVersion should be updated
107
+ expect(value.metadata.resourceVersion).toStrictEqual('2');
108
+ expect(value.spec.replicas).toStrictEqual(3);
109
+
110
+ // We expect an error message due to the conflict on 'spec.replicas'
111
+ expect(result).toStrictEqual([
112
+ 'validation.conflict - {"fields":"spec.replicas","fieldCount":1}'
113
+ ]);
114
+ expect(mockStore.getters['i18n/t']).toHaveBeenCalledWith('validation.conflict', {
115
+ fields: 'spec.replicas',
116
+ fieldCount: 1
117
+ });
118
+ });
119
+
120
+ it('should handle nested object changes and conflicts', async() => {
121
+ const initialValue = {
122
+ metadata: { resourceVersion: '1' },
123
+ spec: {
124
+ selector: {
125
+ matchLabels: {
126
+ app: 'nginx',
127
+ env: 'dev'
128
+ }
129
+ }
130
+ }
131
+ };
132
+ // User modifies 'env' to 'prod'
133
+ const value = {
134
+ metadata: { resourceVersion: '1' },
135
+ spec: {
136
+ selector: {
137
+ matchLabels: {
138
+ app: 'nginx',
139
+ env: 'prod'
140
+ }
141
+ }
142
+ }
143
+ };
144
+ // Live modifies 'app' to 'httpd'
145
+ const liveValue = {
146
+ metadata: { resourceVersion: '2' },
147
+ spec: {
148
+ selector: {
149
+ matchLabels: {
150
+ app: 'httpd',
151
+ env: 'dev'
152
+ }
153
+ }
154
+ }
155
+ };
156
+
157
+ const result = await handleConflict(initialValue, value, liveValue, mockStore, 'namespace', mockToJSON);
158
+
159
+ expect(mockStore.dispatch).toHaveBeenCalledTimes(3);
160
+
161
+ // Should apply newest resource version
162
+ expect(value.metadata.resourceVersion).toStrictEqual('2');
163
+
164
+ // Background change on 'app' should be applied
165
+ expect(value.spec.selector.matchLabels.app).toStrictEqual('httpd');
166
+ // User's change on 'env' should have remained
167
+ expect(value.spec.selector.matchLabels.env).toStrictEqual('prod');
168
+
169
+ expect(result).toStrictEqual(false); // No direct conflict on a single field
170
+ });
171
+
172
+ it('should detect add/remove conflicts (integration)', async() => {
173
+ const initialValue = {
174
+ metadata: { resourceVersion: '1' },
175
+ spec: { ports: [{ port: 80 }, { port: 90 }] }
176
+ };
177
+ // Remove port 90 and add 443
178
+ const value = {
179
+ metadata: { resourceVersion: '1' },
180
+ spec: { ports: [{ port: 80 }, { port: 443 }] }
181
+ };
182
+ // Remove port 80
183
+ const liveValue = {
184
+ metadata: { resourceVersion: '2' },
185
+ spec: { ports: [{ port: 80 }, { port: 90 }] }
186
+ };
187
+
188
+ await handleConflict(initialValue, value, liveValue, mockStore, 'myNamespace', mockToJSON);
189
+
190
+ expect(mockStore.dispatch).toHaveBeenCalledTimes(3);
191
+ expect(value.metadata.resourceVersion).toStrictEqual('2');
192
+
193
+ expect(value.spec.ports).toStrictEqual([{ port: 80 }, { port: 443 }]);
194
+ });
195
+
196
+ const testArr = handleConflictUseCases.map((usecase: any) => [usecase.description, usecase.data, usecase.result, usecase.outputValidation]);
197
+
198
+ it.each(testArr)('should handleConflict correctly for usecase ::: %s', async(_, usecaseData, res, validationData) => {
199
+ const storeName = 'management';
200
+
201
+ const mocks = {
202
+ storeName,
203
+ dispatch: async(arg1: any, arg2: any) => {
204
+ return Promise.resolve(actions.cleanForDiff({}, arg2));
205
+ },
206
+ rootGetters: { 'i18n/t': () => jest.fn().mockReturnValue('some-conflicts') }
207
+ };
208
+
209
+ const initialValue = cloneDeep(usecaseData.initialConfig as any);
210
+ const currUserValue = cloneDeep(usecaseData.currentConfig as any);
211
+ const serverValue = cloneDeep(usecaseData.latestConfig as any);
212
+
213
+ initialValue.toJSON = () => Object.assign({}, initialValue);
214
+ currUserValue.toJSON = () => Object.assign({}, currUserValue);
215
+ serverValue.toJSON = () => Object.assign({}, serverValue);
216
+
217
+ // export async function handleConflict(initialValueJSON, value, liveValue, rootGetters, store, storeNamespace) {
218
+ const result: any = await handleConflict(initialValue, currUserValue, serverValue, { dispatch: mocks.dispatch, getters: mocks.rootGetters }, storeName);
219
+
220
+ expect(typeof res !== 'boolean' ? result?.length : result).toStrictEqual(res);
221
+ expect(currUserValue).toStrictEqual(expect.objectContaining(validationData));
222
+ });
223
+ });
@@ -1,3 +1,4 @@
1
+ import jsyaml from 'js-yaml';
1
2
  import Resource from '@shell/plugins/dashboard-store/resource-class.js';
2
3
  import { resourceClassJunkObject } from '@shell/plugins/dashboard-store/__tests__/utils/store-mocks';
3
4
 
@@ -46,4 +47,194 @@ describe('class: Resource', () => {
46
47
  });
47
48
  });
48
49
  });
50
+
51
+ describe('method: _saveYaml', () => {
52
+ let mockStore: any;
53
+ let resourceInstance: any;
54
+
55
+ beforeEach(() => {
56
+ mockStore = {
57
+ dispatch: jest.fn((action, payload) => {
58
+ if (action.endsWith('/cleanForDiff')) {
59
+ return Promise.resolve(payload);
60
+ }
61
+
62
+ return Promise.resolve();
63
+ }),
64
+ rootGetters: {
65
+ currentStore: jest.fn(() => 'testStore'),
66
+ 'testStore/byId': jest.fn((type, id) => {
67
+ if (type === 'testType' && id === 'test-id-conflict-unresolved') {
68
+ return {
69
+ id: 'test-id-conflict-unresolved',
70
+ type: 'testType',
71
+ metadata: {
72
+ namespace: 'aaa', resourceVersion: 2, name: 'test-id-conflict-unresolved'
73
+ },
74
+ spec: { replicas: 5 },
75
+ };
76
+ }
77
+ if (type === 'testType' && id === 'test-id-auto-resolve') {
78
+ return {
79
+ id: 'test-id-auto-resolve',
80
+ type: 'testType',
81
+ metadata: {
82
+ namespace: 'aaa', resourceVersion: 2, name: 'test-id-auto-resolve', owner: 'admin'
83
+ },
84
+ spec: { replicas: 3, labels: { env: 'dev' } },
85
+ };
86
+ }
87
+ if (id) {
88
+ return {
89
+ id,
90
+ type,
91
+ metadata: {
92
+ namespace: 'aaa', resourceVersion: '5', name: id
93
+ },
94
+ };
95
+ }
96
+
97
+ return null;
98
+ }),
99
+ },
100
+ getters: {
101
+ 'i18n/t': jest.fn((key, params) => ` ${ key } - ${ JSON.stringify(params) }`),
102
+ currentStore: jest.fn(() => 'testStore'),
103
+ 'testStore/byId': jest.fn((type, id) => {
104
+ if (id) {
105
+ return {
106
+ id,
107
+ type,
108
+ };
109
+ }
110
+
111
+ return null;
112
+ }),
113
+ schemaFor: jest.fn((type) => {
114
+ if (type === 'testType' || type === 'namespaced-type') {
115
+ return { attributes: { namespaced: true } };
116
+ }
117
+
118
+ return null;
119
+ }),
120
+ },
121
+ };
122
+
123
+ resourceInstance = new Resource({
124
+ id: 'default-id',
125
+ type: 'default-type',
126
+ }, mockStore);
127
+
128
+ jest.spyOn(resourceInstance, 'followLink').mockImplementation();
129
+ });
130
+
131
+ it('should successfully perform a PUT operation and dispatch load', async() => {
132
+ const initialYaml = jsyaml.dump({
133
+ metadata: {
134
+ namespace: 'aaa', name: 'my-resource', resourceVersion: 1
135
+ },
136
+ spec: { replicas: 3 }
137
+ });
138
+ const updatedYaml = jsyaml.dump({
139
+ metadata: {
140
+ namespace: 'aaa', name: 'my-resource', resourceVersion: 1
141
+ },
142
+ });
143
+ const expectedResponseData = {
144
+ id: 'test-id',
145
+ type: 'testType',
146
+ metadata: {
147
+ namespace: 'aaa', name: 'my-resource', resourceVersion: 3
148
+ },
149
+ };
150
+
151
+ resourceInstance.followLink.mockResolvedValueOnce(expectedResponseData);
152
+
153
+ await resourceInstance._saveYaml(updatedYaml, initialYaml);
154
+
155
+ expect(resourceInstance.followLink).toHaveBeenCalledTimes(1);
156
+ expect(resourceInstance.followLink).toHaveBeenCalledWith('update', {
157
+ method: 'PUT',
158
+ headers: {
159
+ 'content-type': 'application/yaml',
160
+ accept: 'application/json',
161
+ },
162
+ data: updatedYaml
163
+ });
164
+
165
+ expect(mockStore.dispatch).toHaveBeenCalledWith('load', {
166
+ data: expectedResponseData,
167
+ existing: undefined
168
+ });
169
+ });
170
+
171
+ it('should resolve 409 conflict automatically and re-save if no actual conflicts', async() => {
172
+ resourceInstance.id = 'test-id-auto-resolve';
173
+ resourceInstance.type = 'testType';
174
+
175
+ const initialYamlAutoResolve = jsyaml.dump({ metadata: { name: 'test-id-auto-resolve', resourceVersion: 1 } });
176
+ const userYamlAutoResolve = jsyaml.dump({
177
+ metadata: {
178
+ namespace: 'aaa', name: 'test-id-auto-resolve', resourceVersion: 1
179
+ },
180
+ });
181
+
182
+ resourceInstance.followLink.mockRejectedValueOnce({
183
+ status: 409,
184
+ response: { text: () => Promise.resolve('Conflict: Resource changed in background') }
185
+ });
186
+
187
+ const finalExpectedResponseAutoResolve = {
188
+ id: 'test-id-auto-resolve',
189
+ type: 'testType',
190
+ metadata: {
191
+ namespace: 'aaa', name: 'test-id-auto-resolve', resourceVersion: 'final-v3', owner: 'admin'
192
+ },
193
+ };
194
+
195
+ resourceInstance.followLink.mockResolvedValueOnce(finalExpectedResponseAutoResolve);
196
+
197
+ await resourceInstance._saveYaml(userYamlAutoResolve, initialYamlAutoResolve);
198
+
199
+ expect(resourceInstance.followLink).toHaveBeenCalledTimes(2);
200
+
201
+ expect(resourceInstance.followLink).toHaveBeenCalledWith('update', {
202
+ method: 'PUT',
203
+ headers: expect.any(Object),
204
+ data: userYamlAutoResolve
205
+ });
206
+
207
+ expect(mockStore.dispatch).toHaveBeenCalledWith('load', {
208
+ data: finalExpectedResponseAutoResolve,
209
+ existing: undefined
210
+ });
211
+ });
212
+
213
+ it('should throw error on 409 conflict if handleConflict returns errors', async() => {
214
+ resourceInstance.id = 'test-id-conflict-unresolved';
215
+ resourceInstance.type = 'testType';
216
+
217
+ const initialYaml = jsyaml.dump({
218
+ metadata: {
219
+ namespace: 'aaa', name: 'test-id-conflict-unresolved', resourceVersion: 1
220
+ },
221
+ });
222
+ const userYaml = jsyaml.dump({
223
+ metadata: {
224
+ namespace: 'aaa', name: 'test-id-conflict-unresolved', resourceVersion: 1
225
+ },
226
+ spec: { replicas: 4 }
227
+ });
228
+
229
+ resourceInstance.followLink.mockRejectedValueOnce({
230
+ _status: 409,
231
+ response: { text: () => Promise.resolve('Conflict: Replicas changed') }
232
+ });
233
+
234
+ await expect(resourceInstance._saveYaml(userYaml, initialYaml)).rejects.toBeDefined();
235
+
236
+ expect(resourceInstance.followLink).toHaveBeenCalledTimes(1);
237
+ expect(mockStore.dispatch).not.toHaveBeenCalledWith('load', expect.any(Object));
238
+ });
239
+ });
49
240
  });