slice-machine-ui 1.22.2 → 1.22.3-alpha.chore-introduce-css-modules.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/.depcheckrc +4 -1
  2. package/.eslintignore +1 -0
  3. package/components/DeleteVariationModal/index.tsx +12 -11
  4. package/components/Forms/CreateSliceModal/CreateSliceModal.tsx +2 -5
  5. package/components/Forms/RenameCustomTypeModal/RenameCustomTypeModal.tsx +9 -5
  6. package/components/Forms/RenameVariationModal/RenameVariationModal.tsx +12 -11
  7. package/components/ItemHeader/index.tsx +1 -0
  8. package/components/ListItem/index.tsx +5 -2
  9. package/components/ScreenshotChangesModal/VariationDropZone.tsx +31 -9
  10. package/components/ScreenshotChangesModal/index.tsx +3 -0
  11. package/components/ScreenshotChangesModal/useCustomScreenshot.tsx +5 -5
  12. package/components/Simulator/index.tsx +9 -3
  13. package/lib/builders/CustomTypeBuilder/SliceZone/SlicesTemplatesModal.tsx +2 -2
  14. package/lib/builders/CustomTypeBuilder/SliceZone/UpdateSliceZoneModal.tsx +2 -2
  15. package/lib/builders/CustomTypeBuilder/SliceZone/index.tsx +12 -20
  16. package/lib/builders/CustomTypeBuilder/TabModal/update.tsx +3 -1
  17. package/lib/builders/CustomTypeBuilder/TabZone/index.tsx +119 -52
  18. package/lib/builders/CustomTypeBuilder/index.tsx +39 -42
  19. package/lib/builders/SliceBuilder/FieldZones/index.tsx +81 -56
  20. package/lib/builders/SliceBuilder/Sidebar/AddVariationModal.tsx +24 -16
  21. package/lib/builders/SliceBuilder/Sidebar/index.tsx +44 -46
  22. package/lib/builders/SliceBuilder/SimulatorButton/index.tsx +4 -28
  23. package/lib/builders/SliceBuilder/index.tsx +10 -96
  24. package/lib/builders/common/Zone/Card/components/Hints/CodeBlock.tsx +5 -1
  25. package/lib/builders/common/Zone/Card/components/NewField.tsx +16 -15
  26. package/lib/builders/common/Zone/Card/index.jsx +2 -0
  27. package/lib/builders/common/Zone/index.jsx +3 -1
  28. package/lib/models/common/ComponentUI.ts +0 -14
  29. package/lib/models/common/CustomType/sliceZone.ts +0 -29
  30. package/lib/models/common/CustomType/tab.ts +10 -142
  31. package/lib/models/common/widgets/Group/ListItem/index.jsx +61 -23
  32. package/out/404.html +1 -1
  33. package/out/_next/static/QLcban0JdGEoFu6NgapR9/_buildManifest.js +1 -0
  34. package/out/_next/static/chunks/065a3ddb-9a38ca0d60f0bf2f.js +1 -0
  35. package/out/_next/static/chunks/183-4feb6bb3eddbc768.js +1 -0
  36. package/out/_next/static/chunks/18539003-7b2711e6c51d6fac.js +97 -0
  37. package/out/_next/static/chunks/1cc2734a-2c5b6c0367fcde86.js +1 -0
  38. package/out/_next/static/chunks/25-8fedd33ad9b6de5b.js +1 -0
  39. package/out/_next/static/chunks/286-ed90373e9a469944.js +1 -0
  40. package/out/_next/static/chunks/318-541db69860d31138.js +1 -0
  41. package/out/_next/static/chunks/{505-3f1cf09a086dcba8.js → 376-0ed5822f8afcaa7c.js} +3 -3
  42. package/out/_next/static/chunks/4c744e84-e3161d754618373f.js +1 -0
  43. package/out/_next/static/chunks/50-cfc2514205b86001.js +1 -0
  44. package/out/_next/static/chunks/543-f8766685f7f451e2.js +1 -0
  45. package/out/_next/static/chunks/59b4e022-7a3b5554b806349f.js +1 -0
  46. package/out/_next/static/chunks/696-b12edad30a3617e5.js +31 -0
  47. package/out/_next/static/chunks/727-15cf3f2fea9a37e5.js +1 -0
  48. package/out/_next/static/chunks/731-501990ebe6a71b32.js +1 -0
  49. package/out/_next/static/chunks/904-ccd8ca3368ce29fc.js +1 -0
  50. package/out/_next/static/chunks/{918-38d08f1e885b222d.js → 918-5bb55fb464e34768.js} +1 -1
  51. package/out/_next/static/chunks/f36c6662-03bb5e9d9aa0b0aa.js +1 -0
  52. package/out/_next/static/chunks/pages/_app-3bb7f58b43c87166.js +430 -0
  53. package/out/_next/static/chunks/pages/changelog-68d115a14f1423d7.js +1 -0
  54. package/out/_next/static/chunks/pages/{changes-52c9d917808d1461.js → changes-1cf9e7888029f113.js} +1 -1
  55. package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-3a37eb3373bb8823.js → [customTypeId]-3f862ad6111a1fc0.js} +1 -1
  56. package/out/_next/static/chunks/pages/{custom-types-2f5664d9492b13fb.js → custom-types-94b8f8dbf7727412.js} +1 -1
  57. package/out/_next/static/chunks/pages/{index-d8e3a2c0d712904f.js → index-64cfb8b0948ba8ef.js} +1 -1
  58. package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-733f3890c0466a05.js → [pageTypeId]-d1ffca11c42f2603.js} +1 -1
  59. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-897ca93c114a1435.js +1 -0
  60. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-73dd999915509965.js +1 -0
  61. package/out/_next/static/chunks/pages/slices-7b09cb5130c63bb3.js +1 -0
  62. package/out/_next/static/css/37153180c3b0dd66.css +1 -0
  63. package/out/_next/static/css/538ecf581b0e7c11.css +1 -0
  64. package/out/_next/static/css/{5da5d3cd7a87c3cf.css → 72465cc1225f28a2.css} +1 -1
  65. package/out/_next/static/css/{77abb01eee0e43a7.css → b22c0750c14cc089.css} +1 -1
  66. package/out/_next/static/css/f8eb526e10bc2441.css +1 -0
  67. package/out/changelog.html +1 -1
  68. package/out/changes.html +1 -1
  69. package/out/custom-types/[customTypeId].html +1 -1
  70. package/out/custom-types.html +1 -1
  71. package/out/index.html +1 -1
  72. package/out/labs.html +1 -1
  73. package/out/page-types/[pageTypeId].html +1 -1
  74. package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
  75. package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
  76. package/out/slices.html +1 -1
  77. package/package.json +21 -11
  78. package/pages/slices/[lib]/[sliceName]/[variation]/index.tsx +25 -11
  79. package/pages/slices/[lib]/[sliceName]/[variation]/simulator.tsx +12 -9
  80. package/src/apiClient.ts +7 -6
  81. package/src/components/CodeBlock/CodeBlock.tsx +1 -0
  82. package/src/components/Kbd/Kbd.module.css +10 -0
  83. package/src/components/Kbd/Kbd.module.css.d.ts +5 -0
  84. package/src/components/Kbd/Kbd.tsx +1 -1
  85. package/src/components/Window/Window.tsx +7 -1
  86. package/src/domain/__tests__/customType.test.ts +785 -0
  87. package/src/domain/customType.ts +519 -6
  88. package/src/domain/slice.ts +166 -1
  89. package/src/features/autoSave/AutoSaveStatusIndicator.tsx +43 -0
  90. package/src/features/autoSave/useAutoSave.tsx +177 -0
  91. package/src/features/customTypes/EditDropdown.tsx +3 -0
  92. package/src/features/customTypes/actions/convertCustomToPageType.ts +2 -4
  93. package/src/features/customTypes/customTypesBuilder/CustomTypeProvider.tsx +90 -0
  94. package/src/features/customTypes/customTypesBuilder/CustomTypesBuilderPage.tsx +46 -79
  95. package/src/features/customTypes/customTypesMessages.ts +4 -0
  96. package/src/features/slices/actions/addSlicesToSliceZone.ts +2 -7
  97. package/src/features/slices/actions/uploadSliceScreenshot.ts +45 -0
  98. package/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewVariationDialog.tsx +5 -5
  99. package/src/features/slices/convertLegacySlice/ConvertLegacySliceButton.tsx +4 -10
  100. package/src/features/slices/sliceBuilder/SliceBuilderProvider.tsx +110 -0
  101. package/src/features/slices/sliceBuilder/actions/deleteVariation.ts +8 -24
  102. package/src/features/slices/sliceBuilder/actions/renameVariation.ts +8 -24
  103. package/src/features/slices/sliceCards/SharedSliceCard.tsx +1 -0
  104. package/src/hooks/useCurrentSlice.tsx +4 -16
  105. package/src/hooks/useScreenshotChangesModal.ts +1 -0
  106. package/src/hooks/useServerState.ts +1 -58
  107. package/src/modules/availableCustomTypes/index.ts +8 -3
  108. package/src/modules/simulator/index.ts +0 -2
  109. package/src/modules/slices/index.ts +32 -25
  110. package/src/modules/slices/selector.ts +30 -0
  111. package/src/modules/useSliceMachineActions.ts +20 -270
  112. package/src/redux/reducer.ts +0 -4
  113. package/src/redux/saga.ts +0 -6
  114. package/src/redux/type.ts +0 -4
  115. package/stylelint.config.js +17 -0
  116. package/test/src/modules/availableCustomTypes/index.test.ts +8 -10
  117. package/test/src/modules/simulator.test.ts +0 -2
  118. package/lib/models/common/CustomType/group.ts +0 -80
  119. package/lib/models/common/Variation.ts +0 -100
  120. package/out/_next/static/3vLhj_JZ10e4rwC2sTZNQ/_buildManifest.js +0 -1
  121. package/out/_next/static/chunks/18539003-4460ccbfe3109578.js +0 -97
  122. package/out/_next/static/chunks/482-49264466566eac99.js +0 -1
  123. package/out/_next/static/chunks/550-c80fd46fb64d1eef.js +0 -1
  124. package/out/_next/static/chunks/80-7b8a97d0122ff74a.js +0 -1
  125. package/out/_next/static/chunks/840-163f8a1040e6820d.js +0 -1
  126. package/out/_next/static/chunks/904-fe1af089657fb0cc.js +0 -1
  127. package/out/_next/static/chunks/958-3d829456f4f5632c.js +0 -1
  128. package/out/_next/static/chunks/pages/_app-f88a66f6532a8e87.js +0 -458
  129. package/out/_next/static/chunks/pages/changelog-4d0f2f1222e403fe.js +0 -1
  130. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-7b17cb59d0db03b5.js +0 -1
  131. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-ef11594ce026b650.js +0 -1
  132. package/out/_next/static/chunks/pages/slices-884a936a9a062a65.js +0 -1
  133. package/out/_next/static/css/1bbf650dfd37ce69.css +0 -1
  134. package/out/_next/static/css/7d650bca12dc4061.css +0 -1
  135. package/out/_next/static/css/cb33580e45d01b59.css +0 -1
  136. package/postcss.config.js +0 -2
  137. package/src/components/Kbd/Kbd.css.ts +0 -16
  138. package/src/domain/__tests__/CustomTypeModel.test.ts +0 -247
  139. package/src/layouts/WithSlice.tsx +0 -26
  140. package/src/modules/screenshots/actions.ts +0 -21
  141. package/src/modules/screenshots/sagas.ts +0 -70
  142. package/src/modules/selectedCustomType/actions.ts +0 -147
  143. package/src/modules/selectedCustomType/index.ts +0 -11
  144. package/src/modules/selectedCustomType/reducer.ts +0 -287
  145. package/src/modules/selectedCustomType/sagas.ts +0 -72
  146. package/src/modules/selectedCustomType/selectors.ts +0 -33
  147. package/src/modules/selectedCustomType/stateHelpers.ts +0 -42
  148. package/src/modules/selectedCustomType/types.ts +0 -9
  149. package/src/modules/selectedSlice/actions.ts +0 -106
  150. package/src/modules/selectedSlice/reducer.ts +0 -175
  151. package/src/modules/selectedSlice/sagas.ts +0 -72
  152. package/src/modules/selectedSlice/selectors.ts +0 -55
  153. package/src/modules/selectedSlice/types.ts +0 -3
  154. package/src/modules/toaster/utils.tsx +0 -23
  155. package/test/lib/models/common/CustomType/sliceZone.test.ts +0 -49
  156. package/test/pages/custom-types.test.tsx +0 -625
  157. package/test/src/modules/selectedCustomType/__fixtures__/model.json +0 -119
  158. package/test/src/modules/selectedCustomType/reducer.test.ts +0 -322
  159. package/test/src/modules/selectedCustomType/sagas.test.ts +0 -89
  160. package/test/src/modules/selectedCustomType/selectors.test.ts +0 -54
  161. package/test/src/modules/selectedSlice/__fixtures__/mocks.json +0 -171
  162. package/test/src/modules/selectedSlice/__fixtures__/model.json +0 -35
  163. package/test/src/modules/selectedSlice/__testutils__/getRefreshStateCreatorPayloadData.ts +0 -72
  164. package/test/src/modules/selectedSlice/__testutils__/getSelectedSliceDummyData.ts +0 -30
  165. package/test/src/modules/selectedSlice/reducer.test.ts +0 -170
  166. package/test/src/modules/selectedSlice/sagas.test.ts +0 -82
  167. package/test/src/modules/toaster/utils.test.ts +0 -50
  168. /package/out/_next/static/{3vLhj_JZ10e4rwC2sTZNQ → QLcban0JdGEoFu6NgapR9}/_ssgManifest.js +0 -0
@@ -1,625 +0,0 @@
1
- // @vitest-environment jsdom
2
-
3
- import { describe, test, afterEach, beforeEach, expect, vi } from "vitest";
4
- import Router from "next/router";
5
- import mockRouter from "next-router-mock";
6
- import { Analytics } from "@segment/analytics-node";
7
- import userEvent from "@testing-library/user-event";
8
-
9
- import { createSliceMachineManager } from "@slicemachine/manager";
10
- import { createSliceMachineManagerMSWHandler } from "@slicemachine/manager/test";
11
- import pkg from "../../package.json";
12
- import {
13
- render,
14
- fireEvent,
15
- act,
16
- screen,
17
- waitFor,
18
- within,
19
- } from "../__testutils__";
20
- import { createTestPlugin } from "../__testutils__/createTestPlugin";
21
- import { createTestProject } from "../__testutils__/createTestProject";
22
-
23
- import CreateCustomTypeBuilder from "../../pages/custom-types/[customTypeId]";
24
-
25
- vi.mock("next/router", () => import("next-router-mock"));
26
-
27
- describe("Custom Type Builder", () => {
28
- afterEach(() => {
29
- vi.clearAllMocks();
30
- });
31
-
32
- beforeEach(() => {
33
- mockRouter.setCurrentUrl("/");
34
- });
35
-
36
- const libraries = [
37
- {
38
- path: "./slices",
39
- isLocal: true,
40
- name: "slices",
41
- meta: {
42
- isNodeModule: false,
43
- isDownloaded: false,
44
- isManual: true,
45
- },
46
- components: [
47
- {
48
- from: "slices",
49
- href: "slices",
50
- pathToSlice: "./slices",
51
- fileName: "index",
52
- extension: "js",
53
- screenshots: {},
54
- mocks: [
55
- {
56
- variation: "default",
57
- name: "Default",
58
- slice_type: "test_slice",
59
- items: [],
60
- primary: {
61
- title: [
62
- {
63
- type: "heading1",
64
- text: "Cultivate granular e-services",
65
- spans: [],
66
- },
67
- ],
68
- description: [
69
- {
70
- type: "paragraph",
71
- text: "Anim in commodo exercitation qui. Elit cillum officia mollit dolore. Commodo voluptate sit est proident ea proident dolor esse ad.",
72
- spans: [],
73
- },
74
- ],
75
- },
76
- },
77
- ],
78
- model: {
79
- id: "test_slice",
80
- type: "SharedSlice",
81
- name: "TestSlice",
82
- description: "TestSlice",
83
- variations: [
84
- {
85
- id: "default",
86
- name: "Default",
87
- docURL: "...",
88
- version: "sktwi1xtmkfgx8626",
89
- description: "TestSlice",
90
- primary: [
91
- {
92
- key: "title",
93
- value: {
94
- type: "StructuredText",
95
- config: {
96
- single: "heading1",
97
- label: "Title",
98
- placeholder: "This is where it all begins...",
99
- },
100
- },
101
- },
102
- {
103
- key: "description",
104
- value: {
105
- type: "StructuredText",
106
- config: {
107
- single: "paragraph",
108
- label: "Description",
109
- placeholder: "A nice description of your feature",
110
- },
111
- },
112
- },
113
- ],
114
- items: [],
115
- imageUrl:
116
- "https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format",
117
- },
118
- ],
119
- },
120
- screenshotUrls: {},
121
- },
122
- ],
123
- },
124
- ];
125
-
126
- test("should send a tracking event when the user adds a field", async () => {
127
- const customTypeId = "a-page";
128
-
129
- void Router.push({
130
- pathname: "custom-types/[customTypeId]",
131
- query: { customTypeId },
132
- });
133
-
134
- render(<CreateCustomTypeBuilder />, {
135
- preloadedState: {
136
- availableCustomTypes: {
137
- [customTypeId]: {
138
- local: {
139
- id: customTypeId,
140
- label: customTypeId,
141
- repeatable: true,
142
- format: "custom",
143
- status: true,
144
- tabs: [
145
- {
146
- key: "Main",
147
- value: [],
148
- },
149
- ],
150
- },
151
- },
152
- },
153
- // @ts-expect-error TS2739: Type '{ manifest: { apiEndpoint: string; }; }' is missing the following properties from type 'FrontEndEnvironment': repo, packageManager, supportsSliceSimulator, endpoints
154
- environment: {
155
- manifest: { apiEndpoint: "https://foo.cdn.prismic.io/api/v2" },
156
- },
157
- // @ts-expect-error TS(2741) FIXME: Property 'remoteModel' is missing in type '{ model... Remove this comment to see the full error message
158
- selectedCustomType: {
159
- model: {
160
- id: "a-page",
161
- label: "a-page",
162
- repeatable: true,
163
- format: "custom",
164
- status: true,
165
- tabs: [
166
- {
167
- key: "Main",
168
- value: [],
169
- },
170
- ],
171
- },
172
- initialModel: {
173
- id: "a-page",
174
- label: "a-page",
175
- repeatable: true,
176
- format: "custom",
177
- status: true,
178
- tabs: [
179
- {
180
- key: "Main",
181
- value: [],
182
- },
183
- ],
184
- },
185
- },
186
- slices: {
187
- remoteSlices: [],
188
- // @ts-expect-error TS(2322) FIXME: Type '{ path: string; isLocal: boolean; name: stri... Remove this comment to see the full error message
189
- libraries: libraries,
190
- },
191
- },
192
- });
193
-
194
- const addButton = await screen.findByText("Add a new field");
195
- fireEvent.click(addButton);
196
-
197
- const richText = screen.getByText("Rich Text");
198
- fireEvent.click(richText);
199
-
200
- const nameInput = screen.getByLabelText("label-input");
201
- fireEvent.change(nameInput, { target: { value: "New Field" } });
202
-
203
- const saveFieldButton = screen.getByText("Add");
204
-
205
- // eslint-disable-next-line @typescript-eslint/await-thenable
206
- await act(() => {
207
- fireEvent.click(saveFieldButton);
208
- });
209
-
210
- // eslint-disable-next-line @typescript-eslint/unbound-method
211
- expect(Analytics.prototype.track).toHaveBeenCalledOnce();
212
- // eslint-disable-next-line @typescript-eslint/unbound-method
213
- expect(Analytics.prototype.track).toHaveBeenCalledWith(
214
- expect.objectContaining({
215
- event: "SliceMachine Custom Type Field Added",
216
- properties: {
217
- id: "new_field",
218
- name: "a-page",
219
- type: "StructuredText",
220
- zone: "static",
221
- nodeVersion: process.versions.node,
222
- },
223
- }),
224
- expect.any(Function),
225
- );
226
- });
227
-
228
- test("should send a tracking event when the user adds a slice", async () => {
229
- const customTypeId = "a-page";
230
-
231
- void Router.push({
232
- pathname: "custom-types/[customTypeId]",
233
- query: { customTypeId },
234
- });
235
-
236
- // duplicated state for library context :/
237
-
238
- render(<CreateCustomTypeBuilder />, {
239
- preloadedState: {
240
- availableCustomTypes: {
241
- [customTypeId]: {
242
- local: {
243
- id: customTypeId,
244
- label: customTypeId,
245
- repeatable: true,
246
- status: true,
247
- format: "custom",
248
- tabs: [
249
- {
250
- key: "Main",
251
- value: [],
252
- sliceZone: {
253
- key: "slices",
254
- value: [],
255
- },
256
- },
257
- ],
258
- },
259
- },
260
- },
261
- // @ts-expect-error TS2739: Type '{ manifest: { apiEndpoint: string; }; }' is missing the following properties from type 'FrontEndEnvironment': repo, packageManager, supportsSliceSimulator, endpoints
262
- environment: {
263
- manifest: { apiEndpoint: "https://foo.cdn.prismic.io/api/v2" },
264
- },
265
- // @ts-expect-error TS(2741) FIXME: Property 'remoteModel' is missing in type '{ model... Remove this comment to see the full error message
266
- selectedCustomType: {
267
- model: {
268
- id: "a-page",
269
- label: "a-page",
270
- repeatable: true,
271
- status: true,
272
- format: "custom",
273
- tabs: [
274
- {
275
- key: "Main",
276
- value: [],
277
- },
278
- ],
279
- },
280
- initialModel: {
281
- id: "a-page",
282
- label: "a-page",
283
- repeatable: true,
284
- status: true,
285
- format: "custom",
286
- tabs: [
287
- {
288
- key: "Main",
289
- value: [],
290
- },
291
- ],
292
- },
293
- },
294
- slices: {
295
- // @ts-expect-error TS(2322) FIXME: Type '{ path: string; isLocal: boolean; name: stri... Remove this comment to see the full error message
296
- libraries,
297
- remoteSlices: [],
298
- },
299
- },
300
- });
301
-
302
- const user = userEvent.setup();
303
- await user.click(screen.getByText("Select existing"));
304
-
305
- const slicesToSelect = screen.getAllByTestId("shared-slice-card");
306
-
307
- for (const elem of slicesToSelect) {
308
- // eslint-disable-next-line @typescript-eslint/await-thenable
309
- await act(() => {
310
- fireEvent.click(elem);
311
- });
312
- }
313
-
314
- const saveButton = within(screen.getByRole("dialog")).getByText("Add");
315
-
316
- // eslint-disable-next-line @typescript-eslint/await-thenable
317
- await act(() => {
318
- fireEvent.click(saveButton);
319
- });
320
-
321
- // eslint-disable-next-line @typescript-eslint/unbound-method
322
- expect(Analytics.prototype.track).toHaveBeenCalledOnce();
323
- // eslint-disable-next-line @typescript-eslint/unbound-method
324
- expect(Analytics.prototype.track).toHaveBeenCalledWith(
325
- expect.objectContaining({
326
- event: "SliceMachine Slicezone Updated",
327
- properties: { customTypeId, nodeVersion: process.versions.node },
328
- }),
329
- expect.any(Function),
330
- );
331
- });
332
-
333
- // FIXME: events happening out of order
334
- test.skip("it should send a tracking event when the user saves a custom-type", async (ctx) => {
335
- const adapter = createTestPlugin({
336
- setup: ({ hook }) => {
337
- hook("custom-type:update", () => void 0);
338
- },
339
- });
340
- const cwd = await createTestProject({ adapter });
341
- const manager = createSliceMachineManager({
342
- nativePlugins: { [adapter.meta.name]: adapter },
343
- cwd,
344
- });
345
-
346
- await manager.telemetry.initTelemetry({
347
- appName: pkg.name,
348
- appVersion: pkg.version,
349
- });
350
- await manager.plugins.initPlugins();
351
-
352
- ctx.msw.use(
353
- createSliceMachineManagerMSWHandler({
354
- url: "http://localhost:3000/_manager",
355
- sliceMachineManager: manager,
356
- }),
357
- );
358
-
359
- const customTypeId = "a-page";
360
-
361
- void Router.push({
362
- pathname: "custom-types/[customTypeId]",
363
- query: { customTypeId },
364
- });
365
-
366
- render(<CreateCustomTypeBuilder />, {
367
- preloadedState: {
368
- availableCustomTypes: {
369
- [customTypeId]: {
370
- local: {
371
- id: customTypeId,
372
- label: customTypeId,
373
- repeatable: true,
374
- status: true,
375
- format: "custom",
376
- tabs: [
377
- {
378
- key: "Main",
379
- value: [],
380
- },
381
- ],
382
- },
383
- },
384
- },
385
- // @ts-expect-error TS(2741) FIXME: Property 'remoteModel' is missing in type '{ model... Remove this comment to see the full error message
386
- selectedCustomType: {
387
- model: {
388
- id: "a-page",
389
- label: "a-page",
390
- repeatable: true,
391
- status: true,
392
- format: "custom",
393
- tabs: [
394
- {
395
- key: "Main",
396
- value: [],
397
- },
398
- ],
399
- },
400
- initialModel: {
401
- id: "a-page",
402
- label: "a-page",
403
- repeatable: true,
404
- status: true,
405
- format: "custom",
406
- tabs: [
407
- {
408
- key: "Main",
409
- value: [],
410
- },
411
- ],
412
- },
413
- },
414
- slices: {
415
- // @ts-expect-error TS(2322) FIXME: Type '{ path: string; isLocal: boolean; name: stri... Remove this comment to see the full error message
416
- libraries: libraries,
417
- remoteSlices: [],
418
- },
419
- },
420
- });
421
-
422
- const addButton = screen.getByText("Add a new field");
423
- fireEvent.click(addButton);
424
-
425
- const richText = screen.getByText("Rich Text");
426
- fireEvent.click(richText);
427
-
428
- const nameInput = screen.getByLabelText("label-input");
429
- fireEvent.change(nameInput, { target: { value: "New Field" } });
430
-
431
- const saveFieldButton = screen.getByText("Add");
432
-
433
- act(() => {
434
- fireEvent.click(saveFieldButton);
435
- });
436
-
437
- // eslint-disable-next-line @typescript-eslint/unbound-method
438
- expect(Analytics.prototype.track).toHaveBeenCalledOnce();
439
- // eslint-disable-next-line @typescript-eslint/unbound-method
440
- expect(Analytics.prototype.track).toHaveBeenCalledWith(
441
- expect.objectContaining({
442
- event: "SliceMachine Custom Type Field Added",
443
- properties: {
444
- id: "new_field",
445
- name: "a-page",
446
- type: "StructuredText",
447
- zone: "static",
448
- nodeVersion: process.versions.node,
449
- },
450
- }),
451
- expect.any(Function),
452
- );
453
-
454
- const saveCustomType = screen.getByTestId("builder-save-button");
455
-
456
- act(() => {
457
- fireEvent.click(saveCustomType);
458
- });
459
-
460
- await waitFor(() => {
461
- // eslint-disable-next-line @typescript-eslint/unbound-method
462
- expect(Analytics.prototype.track).toHaveBeenCalledTimes(2);
463
- // eslint-disable-next-line @typescript-eslint/unbound-method
464
- expect(Analytics.prototype.track).toHaveBeenCalledWith(
465
- expect.objectContaining({
466
- event: "SliceMachine Custom Type Saved",
467
- properties: {
468
- type: "repeatable",
469
- id: customTypeId,
470
- name: customTypeId,
471
- nodeVersion: process.versions.node,
472
- },
473
- }),
474
- expect.any(Function),
475
- );
476
- });
477
- });
478
-
479
- test("if saving fails a it should not send the save event", async (ctx) => {
480
- const adapter = createTestPlugin({
481
- setup: ({ hook }) => {
482
- hook("custom-type:update", () => {
483
- throw new Error("forced failure");
484
- });
485
- },
486
- });
487
- const cwd = await createTestProject({ adapter });
488
- const manager = createSliceMachineManager({
489
- nativePlugins: { [adapter.meta.name]: adapter },
490
- cwd,
491
- });
492
-
493
- await manager.telemetry.initTelemetry({
494
- appName: pkg.name,
495
- appVersion: pkg.version,
496
- });
497
- await manager.plugins.initPlugins();
498
-
499
- ctx.msw.use(
500
- createSliceMachineManagerMSWHandler({
501
- url: "http://localhost:3000/_manager",
502
- sliceMachineManager: manager,
503
- }),
504
- );
505
-
506
- const customTypeId = "a-page";
507
-
508
- void Router.push({
509
- pathname: "custom-types/[customTypeId]",
510
- query: { customTypeId },
511
- });
512
-
513
- render(<CreateCustomTypeBuilder />, {
514
- preloadedState: {
515
- availableCustomTypes: {
516
- [customTypeId]: {
517
- local: {
518
- id: customTypeId,
519
- label: customTypeId,
520
- repeatable: true,
521
- status: true,
522
- format: "custom",
523
- tabs: [
524
- {
525
- key: "Main",
526
- value: [],
527
- },
528
- ],
529
- },
530
- },
531
- },
532
- // @ts-expect-error TS2739: Type '{ manifest: { apiEndpoint: string; }; }' is missing the following properties from type 'FrontEndEnvironment': repo, packageManager, supportsSliceSimulator, endpoints
533
- environment: {
534
- manifest: { apiEndpoint: "https://foo.cdn.prismic.io/api/v2" },
535
- },
536
- // @ts-expect-error TS(2741) FIXME: Property 'remoteModel' is missing in type '{ model... Remove this comment to see the full error message
537
- selectedCustomType: {
538
- model: {
539
- id: "a-page",
540
- label: "a-page",
541
- repeatable: true,
542
- status: true,
543
- format: "custom",
544
- tabs: [
545
- {
546
- key: "Main",
547
- value: [],
548
- },
549
- ],
550
- },
551
- initialModel: {
552
- id: "a-page",
553
- label: "a-page",
554
- repeatable: true,
555
- status: true,
556
- format: "custom",
557
- tabs: [
558
- {
559
- key: "Main",
560
- value: [],
561
- },
562
- ],
563
- },
564
- },
565
- slices: {
566
- // @ts-expect-error TS(2322) FIXME: Type '{ path: string; isLocal: boolean; name: stri... Remove this comment to see the full error message
567
- libraries,
568
- remoteSlices: [],
569
- },
570
- },
571
- });
572
-
573
- const addButton = screen.getByText("Add a new field");
574
- // eslint-disable-next-line @typescript-eslint/await-thenable
575
- await act(() => {
576
- fireEvent.click(addButton);
577
- });
578
-
579
- const richText = screen.getByText("Rich Text");
580
- // eslint-disable-next-line @typescript-eslint/await-thenable
581
- await act(() => {
582
- fireEvent.click(richText);
583
- });
584
-
585
- const nameInput = screen.getByLabelText("label-input");
586
- // eslint-disable-next-line @typescript-eslint/await-thenable
587
- await act(() => {
588
- fireEvent.change(nameInput, { target: { value: "New Field" } });
589
- });
590
-
591
- const saveFieldButton = screen.getByText("Add");
592
- // eslint-disable-next-line @typescript-eslint/await-thenable
593
- await act(() => {
594
- fireEvent.click(saveFieldButton);
595
- });
596
-
597
- // eslint-disable-next-line @typescript-eslint/unbound-method
598
- expect(Analytics.prototype.track).toHaveBeenCalledOnce();
599
- // eslint-disable-next-line @typescript-eslint/unbound-method
600
- expect(Analytics.prototype.track).toHaveBeenCalledWith(
601
- expect.objectContaining({
602
- event: "SliceMachine Custom Type Field Added",
603
- properties: {
604
- id: "new_field",
605
- name: "a-page",
606
- type: "StructuredText",
607
- zone: "static",
608
- nodeVersion: process.versions.node,
609
- },
610
- }),
611
- expect.any(Function),
612
- );
613
-
614
- const saveCustomType = screen.getByTestId("builder-save-button");
615
-
616
- act(() => {
617
- fireEvent.click(saveCustomType);
618
- });
619
-
620
- await new Promise((r) => setTimeout(r, 500));
621
-
622
- // eslint-disable-next-line @typescript-eslint/unbound-method
623
- expect(Analytics.prototype.track).toHaveBeenCalledOnce();
624
- });
625
- });