slice-machine-ui 1.23.2-alpha.bmo-add-github-settings-page.5 → 1.23.2-alpha.bmo-add-github-settings-page.7

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 (74) hide show
  1. package/components/DeleteSliceModal/index.tsx +34 -24
  2. package/components/Forms/CreateCustomTypeModal/CreateCustomTypeModal.tsx +61 -38
  3. package/components/Forms/RenameCustomTypeModal/RenameCustomTypeModal.tsx +2 -2
  4. package/components/Forms/RenameSliceModal/RenameSliceModal.tsx +33 -21
  5. package/components/Navigation/ChangesListItem.tsx +14 -32
  6. package/lib/models/common/widgets/StructuredText/index.ts +1 -1
  7. package/out/404.html +1 -1
  8. package/out/_next/static/{eWuPXMHFhmgmq_6O409zA → T-um-aWXK8w7MVWXz2AL0}/_buildManifest.js +1 -1
  9. package/out/_next/static/chunks/25-01f422cea8066349.js +1 -0
  10. package/out/_next/static/chunks/{318-bd030cc1725e23b5.js → 318-99b5914b60bf1d17.js} +1 -1
  11. package/out/_next/static/chunks/727-f8fefdd3e50cab2a.js +1 -0
  12. package/out/_next/static/chunks/799-b467582de0a7254f.js +1 -0
  13. package/out/_next/static/chunks/904-4653b7a849f4db94.js +1 -0
  14. package/out/_next/static/chunks/pages/{_app-0556263ae30802aa.js → _app-8d17c36db86b1fa1.js} +26 -26
  15. package/out/_next/static/chunks/pages/{changes-8de69920dfb5a48f.js → changes-ac7d64fc8ec82b39.js} +1 -1
  16. package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-3f862ad6111a1fc0.js → [customTypeId]-97ab3b90b85d645d.js} +1 -1
  17. package/out/_next/static/chunks/pages/{custom-types-94b8f8dbf7727412.js → custom-types-3c8e721ec6802127.js} +1 -1
  18. package/out/_next/static/chunks/pages/index-cf93d16e9c63b6db.js +1 -0
  19. package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-d1ffca11c42f2603.js → [pageTypeId]-84a22c5e480d3fa9.js} +1 -1
  20. package/out/_next/static/chunks/pages/{settings-0961cf5b601e4baf.js → settings-197a424739e72b83.js} +1 -1
  21. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/{simulator-b12346e58ac9abea.js → simulator-c498e9c80cae8cce.js} +1 -1
  22. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-8038454f751ad0b9.js +1 -0
  23. package/out/_next/static/chunks/pages/slices-4522d604117d8c66.js +1 -0
  24. package/out/changelog.html +1 -1
  25. package/out/changes.html +1 -1
  26. package/out/custom-types/[customTypeId].html +1 -1
  27. package/out/custom-types.html +1 -1
  28. package/out/index.html +1 -1
  29. package/out/labs.html +1 -1
  30. package/out/page-types/[pageTypeId].html +1 -1
  31. package/out/settings.html +1 -1
  32. package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
  33. package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
  34. package/out/slices.html +1 -1
  35. package/package.json +3 -3
  36. package/pages/slices.tsx +20 -8
  37. package/src/apiClient.ts +1 -22
  38. package/src/domain/__tests__/customType.test.ts +179 -0
  39. package/src/domain/customType.ts +110 -2
  40. package/src/domain/slice.ts +38 -0
  41. package/src/features/customTypes/PageTypeOnboarding.tsx +21 -26
  42. package/src/features/customTypes/actions/convertCustomToPageType.ts +14 -10
  43. package/src/features/customTypes/actions/createCustomType.ts +69 -0
  44. package/src/features/customTypes/actions/deleteCustomType.ts +13 -3
  45. package/src/features/customTypes/actions/renameCustomType.ts +10 -4
  46. package/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx +3 -1
  47. package/src/features/customTypes/customTypesTable/CustomTypesTable.tsx +8 -8
  48. package/src/features/customTypes/customTypesTable/CustomTypesTablePage.tsx +18 -17
  49. package/src/features/settings/git/ConnectGitRepository.tsx +10 -7
  50. package/src/features/slices/actions/createSlice.ts +5 -29
  51. package/src/features/slices/actions/deleteSlice.ts +33 -0
  52. package/src/features/slices/actions/renameSlice.ts +37 -0
  53. package/src/hooks/useUser.ts +14 -0
  54. package/src/modules/availableCustomTypes/index.ts +29 -135
  55. package/src/modules/loading/types.ts +0 -5
  56. package/src/modules/modal/types.ts +0 -3
  57. package/src/modules/slices/index.ts +27 -193
  58. package/src/modules/slices/selector.ts +0 -14
  59. package/src/modules/useSliceMachineActions.ts +70 -89
  60. package/src/modules/userContext/index.ts +3 -3
  61. package/src/redux/saga.ts +0 -4
  62. package/test/src/modules/availableCustomTypes/index.test.ts +2 -243
  63. package/test/src/modules/slices.test.ts +1 -267
  64. package/out/_next/static/chunks/25-37d6fa7f064be04b.js +0 -1
  65. package/out/_next/static/chunks/727-2235967a881f9035.js +0 -1
  66. package/out/_next/static/chunks/731-a9b66ccdc3fae2c2.js +0 -1
  67. package/out/_next/static/chunks/904-6d6937d53ea2761e.js +0 -1
  68. package/out/_next/static/chunks/pages/index-64cfb8b0948ba8ef.js +0 -1
  69. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-62b55bae7f1b3793.js +0 -1
  70. package/out/_next/static/chunks/pages/slices-81e382c3374273df.js +0 -1
  71. package/src/features/customTypes/__tests__/createCustomType.test.ts +0 -159
  72. package/src/features/customTypes/customTypesTable/createCustomType.ts +0 -107
  73. package/test/components/CreateCustomTypeModal.test.tsx +0 -73
  74. /package/out/_next/static/{eWuPXMHFhmgmq_6O409zA → T-um-aWXK8w7MVWXz2AL0}/_ssgManifest.js +0 -0
@@ -10,7 +10,7 @@ import {
10
10
  hasSeenTutorialsToolTipCreator,
11
11
  hasSeenSimulatorToolTipCreator,
12
12
  hasSeenChangesToolTipCreator,
13
- changesPushSuccessCreator,
13
+ changesPushSuccess,
14
14
  } from "./userContext";
15
15
  import { getChangelogCreator, refreshStateCreator } from "./environment";
16
16
  import {
@@ -19,17 +19,17 @@ import {
19
19
  } from "./simulator";
20
20
  import ServerState from "@models/server/ServerState";
21
21
  import {
22
- createCustomTypeCreator,
23
- deleteCustomTypeCreator,
24
- renameAvailableCustomType,
25
- saveCustomTypeCreator,
22
+ customTypeCreateSuccess,
23
+ customTypeDeleteSuccess,
24
+ customTypeRenameSuccess,
25
+ customTypeSaveSuccess,
26
26
  } from "./availableCustomTypes";
27
27
  import {
28
- createSlice,
29
- deleteSliceCreator,
30
- generateSliceCustomScreenshotCreator,
31
- renameSliceCreator,
32
- updateSliceCreator,
28
+ sliceCreateSuccess,
29
+ sliceDeleteSuccess,
30
+ sliceGenerateCustomScreenshotSuccess,
31
+ sliceUpdateSuccess,
32
+ sliceRenameSuccess,
33
33
  } from "./slices";
34
34
  import { UserContextStoreType, UserReviewType } from "./userContext/types";
35
35
  import { GenericToastTypes, openToasterCreator } from "./toaster";
@@ -38,8 +38,8 @@ import { CustomType } from "@prismicio/types-internal/lib/customtypes";
38
38
  import { ComponentUI, ScreenshotUI } from "../../lib/models/common/ComponentUI";
39
39
  import { saveSliceMockCreator } from "./simulator";
40
40
  import { SaveSliceMockRequest } from "@src/apiClient";
41
- import { CustomTypeFormat } from "@slicemachine/manager";
42
41
  import { LibraryUI } from "@lib/models/common/LibraryUI";
42
+ import { SliceSM } from "@lib/models/common/Slice";
43
43
 
44
44
  const useSliceMachineActions = () => {
45
45
  const dispatch = useDispatch();
@@ -62,14 +62,8 @@ const useSliceMachineActions = () => {
62
62
  dispatch(modalOpenCreator({ modalKey: ModalKeysEnum.LOGIN }));
63
63
  const openScreenshotsModal = () =>
64
64
  dispatch(modalOpenCreator({ modalKey: ModalKeysEnum.SCREENSHOTS }));
65
- const openRenameSliceModal = () =>
66
- dispatch(modalOpenCreator({ modalKey: ModalKeysEnum.RENAME_SLICE }));
67
- const openCreateCustomTypeModal = () =>
68
- dispatch(modalOpenCreator({ modalKey: ModalKeysEnum.CREATE_CUSTOM_TYPE }));
69
65
  const openScreenshotPreviewModal = () =>
70
66
  dispatch(modalOpenCreator({ modalKey: ModalKeysEnum.SCREENSHOT_PREVIEW }));
71
- const openDeleteSliceModal = () =>
72
- dispatch(modalOpenCreator({ modalKey: ModalKeysEnum.DELETE_SLICE }));
73
67
  const openSimulatorSetupModal = () =>
74
68
  dispatch(modalOpenCreator({ modalKey: ModalKeysEnum.SIMULATOR_SETUP }));
75
69
 
@@ -104,122 +98,112 @@ const useSliceMachineActions = () => {
104
98
  dispatch(hasSeenTutorialsToolTipCreator());
105
99
  const setSeenChangesToolTip = () => dispatch(hasSeenChangesToolTipCreator());
106
100
 
107
- // Custom types module
108
- const createCustomType = (
109
- id: string,
110
- label: string,
111
- repeatable: boolean,
112
- format: CustomTypeFormat,
113
- ) =>
101
+ // Toaster store
102
+ const openToaster = (
103
+ content: string | React.ReactNode,
104
+ type: GenericToastTypes,
105
+ ) => dispatch(openToasterCreator({ content, type }));
106
+
107
+ // Simulator
108
+ const saveSliceMock = (payload: SaveSliceMockRequest) =>
109
+ dispatch(saveSliceMockCreator.request(payload));
110
+
111
+ // State Action (used by multiple stores)
112
+ const refreshState = (serverState: ServerState) => {
114
113
  dispatch(
115
- createCustomTypeCreator.request({ id, label, repeatable, format }),
114
+ refreshStateCreator({
115
+ env: serverState.env,
116
+ remoteCustomTypes: serverState.remoteCustomTypes,
117
+ localCustomTypes: serverState.customTypes,
118
+ libraries: serverState.libraries,
119
+ remoteSlices: serverState.remoteSlices,
120
+ clientError: serverState.clientError,
121
+ }),
116
122
  );
123
+ };
124
+
125
+ const getChangelog = () => {
126
+ dispatch(getChangelogCreator.request());
127
+ };
117
128
 
118
129
  /**
119
130
  * Success actions = sync store state from external actions. If its name
120
131
  * contains "Creator", it means it is still used in a saga and that `.request`
121
132
  * and `.failure` need to be preserved
122
133
  */
134
+
135
+ /**
136
+ * Custom Type module
137
+ */
138
+ const createCustomTypeSuccess = (newCustomType: CustomType) =>
139
+ dispatch(
140
+ customTypeCreateSuccess({
141
+ newCustomType: CustomTypes.toSM(newCustomType),
142
+ }),
143
+ );
123
144
  const saveCustomTypeSuccess = (customType: CustomType) =>
124
145
  dispatch(
125
- saveCustomTypeCreator.success({
126
- customType: CustomTypes.toSM(customType),
146
+ customTypeSaveSuccess({
147
+ newCustomType: CustomTypes.toSM(customType),
127
148
  }),
128
149
  );
129
-
130
150
  const deleteCustomTypeSuccess = (id: string) =>
131
151
  dispatch(
132
- deleteCustomTypeCreator.success({
152
+ customTypeDeleteSuccess({
133
153
  customTypeId: id,
134
154
  }),
135
155
  );
136
-
137
- const renameAvailableCustomTypeSuccess = (customType: CustomType) =>
156
+ const renameCustomTypeSuccess = (customType: CustomType) =>
138
157
  dispatch(
139
- renameAvailableCustomType({
158
+ customTypeRenameSuccess({
140
159
  renamedCustomType: CustomTypes.toSM(customType),
141
160
  }),
142
161
  );
143
162
 
144
- /** End of sucess actions */
145
-
146
- // Slice module
163
+ /**
164
+ * Slice module
165
+ */
147
166
  const saveSliceSuccess = (component: ComponentUI) => {
148
167
  dispatch(
149
- updateSliceCreator.success({
168
+ sliceUpdateSuccess({
150
169
  component,
151
170
  }),
152
171
  );
153
172
  };
154
-
155
173
  const saveSliceCustomScreenshotSuccess = (
156
174
  variationId: string,
157
175
  screenshot: ScreenshotUI,
158
176
  component: ComponentUI,
159
177
  ) => {
160
178
  dispatch(
161
- generateSliceCustomScreenshotCreator.success({
179
+ sliceGenerateCustomScreenshotSuccess({
162
180
  variationId,
163
181
  screenshot,
164
182
  component,
165
183
  }),
166
184
  );
167
185
  };
168
-
169
186
  const createSliceSuccess = (libraries: readonly LibraryUI[]) =>
170
- dispatch(createSlice({ libraries }));
171
-
172
- const renameSlice = (
173
- libName: string,
174
- sliceId: string,
175
- newSliceName: string,
176
- ) =>
187
+ dispatch(sliceCreateSuccess({ libraries }));
188
+ const deleteSliceSuccess = (sliceId: string, libName: string) =>
177
189
  dispatch(
178
- renameSliceCreator.request({
190
+ sliceDeleteSuccess({
179
191
  sliceId,
180
- newSliceName,
181
192
  libName,
182
193
  }),
183
194
  );
184
-
185
- const deleteSlice = (sliceId: string, sliceName: string, libName: string) =>
195
+ const renameSliceSuccess = (libName: string, renamedSlice: SliceSM) =>
186
196
  dispatch(
187
- deleteSliceCreator.request({
188
- sliceId,
189
- sliceName,
197
+ sliceRenameSuccess({
198
+ renamedSlice,
190
199
  libName,
191
200
  }),
192
201
  );
193
202
 
194
- const pushChangesSuccess = () => dispatch(changesPushSuccessCreator());
195
-
196
- // Toaster store
197
- const openToaster = (
198
- content: string | React.ReactNode,
199
- type: GenericToastTypes,
200
- ) => dispatch(openToasterCreator({ content, type }));
201
-
202
- // Simulator
203
- const saveSliceMock = (payload: SaveSliceMockRequest) =>
204
- dispatch(saveSliceMockCreator.request(payload));
205
-
206
- // State Action (used by multiple stores)
207
- const refreshState = (serverState: ServerState) => {
208
- dispatch(
209
- refreshStateCreator({
210
- env: serverState.env,
211
- remoteCustomTypes: serverState.remoteCustomTypes,
212
- localCustomTypes: serverState.customTypes,
213
- libraries: serverState.libraries,
214
- remoteSlices: serverState.remoteSlices,
215
- clientError: serverState.clientError,
216
- }),
217
- );
218
- };
219
-
220
- const getChangelog = () => {
221
- dispatch(getChangelogCreator.request());
222
- };
203
+ /**
204
+ * Changes module
205
+ */
206
+ const pushChangesSuccess = () => dispatch(changesPushSuccess());
223
207
 
224
208
  return {
225
209
  checkSimulatorSetup,
@@ -233,31 +217,28 @@ const useSliceMachineActions = () => {
233
217
  stopLoadingLogin,
234
218
  stopLoadingReview,
235
219
  startLoadingReview,
236
- createCustomType,
237
220
  deleteCustomTypeSuccess,
238
- renameAvailableCustomTypeSuccess,
221
+ renameCustomTypeSuccess,
239
222
  saveCustomTypeSuccess,
240
223
  saveSliceSuccess,
241
224
  saveSliceCustomScreenshotSuccess,
242
225
  createSliceSuccess,
243
- renameSlice,
244
- deleteSlice,
226
+ renameSliceSuccess,
227
+ deleteSliceSuccess,
245
228
  sendAReview,
246
229
  skipReview,
247
230
  setUpdatesViewed,
248
231
  setSeenTutorialsToolTip,
249
232
  setSeenSimulatorToolTip,
250
233
  setSeenChangesToolTip,
251
- openCreateCustomTypeModal,
252
234
  openScreenshotPreviewModal,
253
- openDeleteSliceModal,
254
235
  openSimulatorSetupModal,
255
- openRenameSliceModal,
256
236
  closeModals,
257
237
  openToaster,
258
238
  saveSliceMock,
259
239
  getChangelog,
260
240
  pushChangesSuccess,
241
+ createCustomTypeSuccess,
261
242
  };
262
243
  };
263
244
 
@@ -53,7 +53,7 @@ export const hasSeenChangesToolTipCreator = createAction(
53
53
  "USER_CONTEXT/VIEW_CHANGES_TOOL_TIP",
54
54
  )();
55
55
 
56
- export const changesPushSuccessCreator = createAction(
56
+ export const changesPushSuccess = createAction(
57
57
  "USER_CONTEXT/CHANGES_PUSH_SUCCESS",
58
58
  )();
59
59
 
@@ -65,7 +65,7 @@ type userContextActions = ActionType<
65
65
  | typeof hasSeenSimulatorToolTipCreator
66
66
  | typeof hasSeenChangesToolTipCreator
67
67
  | typeof refreshStateCreator
68
- | typeof changesPushSuccessCreator
68
+ | typeof changesPushSuccess
69
69
  >;
70
70
 
71
71
  // Selectors
@@ -140,7 +140,7 @@ export const userContextReducer: Reducer<
140
140
  authStatus: getAuthStatus(action.payload.clientError),
141
141
  };
142
142
  }
143
- case getType(changesPushSuccessCreator): {
143
+ case getType(changesPushSuccess): {
144
144
  return {
145
145
  ...state,
146
146
  lastSyncChange: Date.now(),
package/src/redux/saga.ts CHANGED
@@ -1,16 +1,12 @@
1
1
  import { fork } from "redux-saga/effects";
2
2
 
3
3
  import { watchSimulatorSagas } from "@src/modules/simulator";
4
- import { watchAvailableCustomTypesSagas } from "@src/modules/availableCustomTypes";
5
- import { watchSliceSagas } from "@src/modules/slices";
6
4
  import { watchToasterSagas } from "@src/modules/toaster";
7
5
  import { watchChangelogSagas } from "@src/modules/environment";
8
6
 
9
7
  // Single entry point to start all Sagas at once
10
8
  export default function* rootSaga() {
11
9
  yield fork(watchSimulatorSagas);
12
- yield fork(watchAvailableCustomTypesSagas);
13
- yield fork(watchSliceSagas);
14
10
  yield fork(watchToasterSagas);
15
11
  yield fork(watchChangelogSagas);
16
12
  }
@@ -1,22 +1,10 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import {
3
- createCustomTypeSaga,
4
- createCustomTypeCreator,
5
- availableCustomTypesReducer,
6
- deleteCustomTypeCreator,
7
- } from "@src/modules/availableCustomTypes";
8
- import { testSaga } from "redux-saga-test-plan";
2
+
3
+ import { availableCustomTypesReducer } from "@src/modules/availableCustomTypes";
9
4
  import { AvailableCustomTypesStoreType } from "@src/modules/availableCustomTypes/types";
10
5
  import { refreshStateCreator } from "@src/modules/environment";
11
6
 
12
7
  import { dummyServerState } from "../__fixtures__/serverState";
13
- import { updateCustomType } from "@src/apiClient";
14
- import { createCustomType } from "@src/features/customTypes/customTypesTable/createCustomType";
15
- import { push } from "connected-next-router";
16
- import { modalCloseCreator } from "@src/modules/modal";
17
- import { openToasterCreator, ToasterType } from "@src/modules/toaster";
18
- import { CustomTypeSM, CustomTypes } from "@lib/models/common/CustomType";
19
- import { deleteSliceCreator } from "@src/modules/slices";
20
8
 
21
9
  const dummyCustomTypesState: AvailableCustomTypesStoreType = {};
22
10
 
@@ -57,234 +45,5 @@ describe("[Available Custom types module]", () => {
57
45
  },
58
46
  });
59
47
  });
60
- it("should update the custom types state given CUSTOM_TYPES/CREATE.SUCCESS action", () => {
61
- const createdCustomType: CustomTypeSM = {
62
- id: "id",
63
- label: "lama",
64
- repeatable: false,
65
- status: true,
66
- format: "custom",
67
- tabs: [
68
- {
69
- key: "Main",
70
- value: [],
71
- },
72
- ],
73
- };
74
-
75
- const action = createCustomTypeCreator.success({
76
- newCustomType: createdCustomType,
77
- });
78
-
79
- expect(
80
- availableCustomTypesReducer(dummyCustomTypesState, action),
81
- ).toEqual({
82
- ...dummyCustomTypesState,
83
- [createdCustomType.id]: {
84
- local: createdCustomType,
85
- },
86
- });
87
- });
88
-
89
- it("should update the custom types state given CUSTOM_TYPES/DELETE.SUCCESS action", () => {
90
- const customTypeIdToDelete = "id";
91
- const mockCustomTypeToDelete: CustomTypeSM = {
92
- id: "id",
93
- label: "lama",
94
- repeatable: false,
95
- status: true,
96
- format: "custom",
97
- tabs: [
98
- {
99
- key: "Main",
100
- value: [],
101
- },
102
- ],
103
- };
104
-
105
- const originalState = { ...dummyCustomTypesState };
106
-
107
- originalState[customTypeIdToDelete] = {
108
- local: mockCustomTypeToDelete,
109
- };
110
- mockCustomTypeToDelete.id = "another_ct";
111
- originalState["another_ct"] = { local: mockCustomTypeToDelete };
112
-
113
- const action = deleteCustomTypeCreator.success({
114
- customTypeId: customTypeIdToDelete,
115
- });
116
-
117
- const result = availableCustomTypesReducer(originalState, action);
118
-
119
- const expectState = { ...originalState };
120
- delete expectState[customTypeIdToDelete];
121
-
122
- expect(result).toEqual(expectState);
123
- });
124
-
125
- it("should update the custom types state given SLICES/DELETE.SUCCESS action", () => {
126
- const sliceToDeleteId = "slice_id";
127
- const mockCustomTypeToUpdate: CustomTypeSM = {
128
- id: "id",
129
- label: "lama",
130
- repeatable: false,
131
- status: true,
132
- format: "custom",
133
- tabs: [
134
- {
135
- key: "Main",
136
- value: [],
137
- sliceZone: {
138
- key: "slices",
139
- value: [
140
- {
141
- key: sliceToDeleteId,
142
- value: {
143
- type: "SharedSlice",
144
- },
145
- },
146
- {
147
- key: "slice_2",
148
- value: {
149
- type: "SharedSlice",
150
- },
151
- },
152
- ],
153
- },
154
- },
155
- ],
156
- };
157
-
158
- const originalState = { ...dummyCustomTypesState };
159
-
160
- originalState["id"] = {
161
- local: mockCustomTypeToUpdate,
162
- remote: mockCustomTypeToUpdate,
163
- };
164
- const action = deleteSliceCreator.success({
165
- sliceId: sliceToDeleteId,
166
- sliceName: "slice_name",
167
- libName: "lib",
168
- });
169
-
170
- const result = availableCustomTypesReducer(
171
- originalState,
172
- action,
173
- ) as AvailableCustomTypesStoreType;
174
-
175
- expect(
176
- Object.values(result).flatMap((localAndRemote) => {
177
- return Object.values(localAndRemote);
178
- }),
179
- ).not.toContain(undefined);
180
-
181
- expect(result).toEqual({
182
- id: {
183
- local: {
184
- id: "id",
185
- label: "lama",
186
- repeatable: false,
187
- status: true,
188
- format: "custom",
189
- tabs: [
190
- {
191
- key: "Main",
192
- value: [],
193
- sliceZone: {
194
- key: "slices",
195
- value: [
196
- {
197
- key: "slice_2",
198
- value: {
199
- type: "SharedSlice",
200
- },
201
- },
202
- ],
203
- },
204
- },
205
- ],
206
- },
207
- remote: mockCustomTypeToUpdate,
208
- },
209
- });
210
- });
211
- });
212
-
213
- describe("[createCustomTypeSaga]", () => {
214
- it("should call the api and dispatch the good actions on success", () => {
215
- const actionPayload = {
216
- format: "custom" as const, // CustomTypeFormat,
217
- id: "id",
218
- label: "label",
219
- repeatable: true,
220
- };
221
- const customTypeCreated = CustomTypes.toSM(
222
- createCustomType(
223
- actionPayload.id,
224
- actionPayload.label,
225
- actionPayload.repeatable,
226
- actionPayload.format,
227
- ),
228
- );
229
- const saga = testSaga(
230
- createCustomTypeSaga,
231
- createCustomTypeCreator.request(actionPayload),
232
- );
233
-
234
- saga.next().call(updateCustomType, CustomTypes.fromSM(customTypeCreated));
235
- saga
236
- .next()
237
- .put(
238
- createCustomTypeCreator.success({ newCustomType: customTypeCreated }),
239
- );
240
- saga.next().put(modalCloseCreator());
241
- saga.next().put(
242
- push({
243
- pathname: "/custom-types/id",
244
- query: undefined,
245
- }),
246
- );
247
- saga
248
- .next()
249
- .inspect(
250
- (action: {
251
- payload: { action: { type: string; payload: { type: string } } };
252
- }) => {
253
- expect(action.payload.action.type).toBe("TOASTER/OPEN");
254
- expect(action.payload.action.payload.type).toBe(
255
- ToasterType.SUCCESS,
256
- );
257
- },
258
- );
259
- saga.next().isDone();
260
- });
261
-
262
- it("should call the api and dispatch the good actions on failure", () => {
263
- const actionPayload = {
264
- id: "id",
265
- label: "label",
266
- repeatable: true,
267
- format: "custom" as const,
268
- };
269
- const customTypeCreated = createCustomType(
270
- actionPayload.id,
271
- actionPayload.label,
272
- actionPayload.repeatable,
273
- actionPayload.format,
274
- );
275
- const saga = testSaga(
276
- createCustomTypeSaga,
277
- createCustomTypeCreator.request(actionPayload),
278
- );
279
-
280
- saga.next().call(updateCustomType, customTypeCreated);
281
- saga.throw(new Error()).put(
282
- openToasterCreator({
283
- content: "Internal Error: Custom type not saved",
284
- type: ToasterType.ERROR,
285
- }),
286
- );
287
- saga.next().isDone();
288
- });
289
48
  });
290
49
  });