@contentful/field-editor-slug 3.3.0 → 3.3.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.
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
6
6
  const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
7
7
  const _react1 = require("@testing-library/react");
8
- require("@testing-library/jest-dom/extend-expect");
8
+ const _vitest = require("vitest");
9
9
  const _SlugEditor = require("./SlugEditor");
10
10
  const _SlugEditorField = require("./SlugEditorField");
11
11
  function _getRequireWildcardCache(nodeInterop) {
@@ -52,7 +52,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
52
52
  (0, _react1.configure)({
53
53
  testIdAttribute: 'data-test-id'
54
54
  });
55
- jest.mock('use-debounce', ()=>({
55
+ _vitest.vi.mock('use-debounce', ()=>({
56
56
  useDebounce: (text)=>[
57
57
  text
58
58
  ]
@@ -66,34 +66,34 @@ function createMocks(initialValues = {}) {
66
66
  unique: true
67
67
  }
68
68
  ],
69
- onValueChanged: jest.fn().mockImplementation(field.onValueChanged),
70
- setValue: jest.fn().mockImplementation(field.setValue)
69
+ onValueChanged: _vitest.vi.fn().mockImplementation(field.onValueChanged),
70
+ setValue: _vitest.vi.fn().mockImplementation(field.setValue)
71
71
  }), initialValues.field || '');
72
72
  const [titleField] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>({
73
73
  ...field,
74
74
  id: 'title-id',
75
- setValue: jest.fn().mockImplementation(field.setValue),
76
- getValue: jest.fn().mockImplementation(field.getValue),
77
- onValueChanged: jest.fn().mockImplementation(field.onValueChanged)
75
+ setValue: _vitest.vi.fn().mockImplementation(field.setValue),
76
+ getValue: _vitest.vi.fn().mockImplementation(field.getValue),
77
+ onValueChanged: _vitest.vi.fn().mockImplementation(field.onValueChanged)
78
78
  }), initialValues.titleField || '');
79
79
  const [descriptionField] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>({
80
80
  ...field,
81
81
  id: 'description-id',
82
- setValue: jest.fn().mockImplementation(field.setValue),
83
- getValue: jest.fn().mockImplementation(field.getValue),
84
- onValueChanged: jest.fn().mockImplementation(field.onValueChanged)
82
+ setValue: _vitest.vi.fn().mockImplementation(field.setValue),
83
+ getValue: _vitest.vi.fn().mockImplementation(field.getValue),
84
+ onValueChanged: _vitest.vi.fn().mockImplementation(field.onValueChanged)
85
85
  }), initialValues.descriptionField || '');
86
86
  const sdk = {
87
87
  locales: (0, _fieldeditortestutils.createFakeLocalesAPI)(),
88
88
  cma: {
89
89
  entry: {
90
- getMany: jest.fn().mockResolvedValue({
90
+ getMany: _vitest.vi.fn().mockResolvedValue({
91
91
  total: 0
92
92
  })
93
93
  }
94
94
  },
95
95
  entry: {
96
- getSys: jest.fn().mockReturnValue({
96
+ getSys: _vitest.vi.fn().mockReturnValue({
97
97
  id: 'entry-id',
98
98
  publishedVersion: undefined,
99
99
  createdAt: '2020-01-24T15:33:47.906Z',
@@ -103,7 +103,7 @@ function createMocks(initialValues = {}) {
103
103
  }
104
104
  }
105
105
  }),
106
- onSysChanged: jest.fn(),
106
+ onSysChanged: _vitest.vi.fn(),
107
107
  fields: {
108
108
  'title-id': titleField,
109
109
  'entry-id': field,
@@ -121,10 +121,10 @@ function createMocks(initialValues = {}) {
121
121
  sdk
122
122
  };
123
123
  }
124
- describe('SlugEditor', ()=>{
125
- afterEach(_react1.cleanup);
126
- describe('should not subscribe to title changes', ()=>{
127
- it('when entry is published', async ()=>{
124
+ (0, _vitest.describe)('SlugEditor', ()=>{
125
+ (0, _vitest.afterEach)(_react1.cleanup);
126
+ (0, _vitest.describe)('should not subscribe to title changes', ()=>{
127
+ (0, _vitest.it)('when entry is published', async ()=>{
128
128
  const { field, titleField, sdk } = createMocks();
129
129
  sdk.entry.getSys.mockReturnValue({
130
130
  publishedVersion: 2
@@ -135,14 +135,14 @@ describe('SlugEditor', ()=>{
135
135
  isInitiallyDisabled: false
136
136
  }));
137
137
  await (0, _react1.waitFor)(()=>{
138
- expect(field.setValue).not.toHaveBeenCalled();
139
- expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
140
- expect(sdk.cma.entry.getMany).not.toHaveBeenCalled();
141
- expect(sdk.entry.fields['title-id'].getValue).toHaveBeenCalledTimes(1);
142
- expect(sdk.entry.getSys).toHaveBeenCalledTimes(2);
138
+ (0, _vitest.expect)(field.setValue).not.toHaveBeenCalled();
139
+ (0, _vitest.expect)(titleField.onValueChanged).toHaveBeenCalledWith('en-US', _vitest.expect.any(Function));
140
+ (0, _vitest.expect)(sdk.cma.entry.getMany).not.toHaveBeenCalled();
141
+ (0, _vitest.expect)(sdk.entry.fields['title-id'].getValue).toHaveBeenCalledTimes(1);
142
+ (0, _vitest.expect)(sdk.entry.getSys).toHaveBeenCalledTimes(2);
143
143
  });
144
144
  });
145
- it('when title and slug are the same field', async ()=>{
145
+ (0, _vitest.it)('when title and slug are the same field', async ()=>{
146
146
  const { field, titleField, sdk } = createMocks();
147
147
  sdk.contentType.displayField = 'entry-id';
148
148
  (0, _react1.render)(/*#__PURE__*/ _react.createElement(_SlugEditor.SlugEditor, {
@@ -151,11 +151,11 @@ describe('SlugEditor', ()=>{
151
151
  isInitiallyDisabled: false
152
152
  }));
153
153
  await (0, _react1.waitFor)(()=>{
154
- expect(titleField.onValueChanged).not.toHaveBeenCalled();
155
- expect(field.setValue).not.toHaveBeenCalled();
154
+ (0, _vitest.expect)(titleField.onValueChanged).not.toHaveBeenCalled();
155
+ (0, _vitest.expect)(field.setValue).not.toHaveBeenCalled();
156
156
  });
157
157
  });
158
- it('when a saved slug is different from a title at the render', async ()=>{
158
+ (0, _vitest.it)('when a saved slug is different from a title at the render', async ()=>{
159
159
  const { field, titleField, sdk } = createMocks({
160
160
  titleField: 'Hello world!',
161
161
  field: 'something-different'
@@ -166,13 +166,13 @@ describe('SlugEditor', ()=>{
166
166
  isInitiallyDisabled: false
167
167
  }));
168
168
  await (0, _react1.waitFor)(()=>{
169
- expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
170
- expect(field.setValue).not.toHaveBeenCalled();
169
+ (0, _vitest.expect)(titleField.onValueChanged).toHaveBeenCalledWith('en-US', _vitest.expect.any(Function));
170
+ (0, _vitest.expect)(field.setValue).not.toHaveBeenCalled();
171
171
  });
172
172
  });
173
173
  });
174
- describe('should check for uniqueness', ()=>{
175
- it('if it is published', async ()=>{
174
+ (0, _vitest.describe)('should check for uniqueness', ()=>{
175
+ (0, _vitest.it)('if it is published', async ()=>{
176
176
  const { field, titleField, sdk } = createMocks({
177
177
  titleField: 'Slug value',
178
178
  field: 'slug-value'
@@ -195,8 +195,8 @@ describe('SlugEditor', ()=>{
195
195
  isInitiallyDisabled: false
196
196
  }));
197
197
  await (0, _react1.waitFor)(()=>{
198
- expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
199
- expect(sdk.cma.entry.getMany).toHaveBeenLastCalledWith({
198
+ (0, _vitest.expect)(titleField.onValueChanged).toHaveBeenCalledWith('en-US', _vitest.expect.any(Function));
199
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenLastCalledWith({
200
200
  query: {
201
201
  content_type: 'content-type-id',
202
202
  'fields.slug-id.en-US': 'slug-value',
@@ -206,12 +206,12 @@ describe('SlugEditor', ()=>{
206
206
  },
207
207
  releaseid: undefined
208
208
  });
209
- expect(sdk.cma.entry.getMany).toHaveBeenCalledTimes(1);
210
- expect(queryByTestId('slug-editor-spinner')).not.toBeInTheDocument();
211
- expect(queryByText('This slug has already been published in another entry')).not.toBeInTheDocument();
209
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenCalledTimes(1);
210
+ (0, _vitest.expect)(queryByTestId('slug-editor-spinner')).not.toBeInTheDocument();
211
+ (0, _vitest.expect)(queryByText('This slug has already been published in another entry')).not.toBeInTheDocument();
212
212
  });
213
213
  });
214
- it('if it is not published', async ()=>{
214
+ (0, _vitest.it)('if it is not published', async ()=>{
215
215
  const { field, titleField, sdk } = createMocks({
216
216
  titleField: 'Slug value',
217
217
  field: 'slug-value'
@@ -234,8 +234,8 @@ describe('SlugEditor', ()=>{
234
234
  isInitiallyDisabled: false
235
235
  }));
236
236
  await (0, _react1.waitFor)(()=>{
237
- expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
238
- expect(sdk.cma.entry.getMany).toHaveBeenLastCalledWith({
237
+ (0, _vitest.expect)(titleField.onValueChanged).toHaveBeenCalledWith('en-US', _vitest.expect.any(Function));
238
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenLastCalledWith({
239
239
  query: {
240
240
  content_type: 'content-type-id',
241
241
  'fields.slug-id.en-US': 'slug-value',
@@ -245,10 +245,10 @@ describe('SlugEditor', ()=>{
245
245
  },
246
246
  releaseid: undefined
247
247
  });
248
- expect(sdk.cma.entry.getMany).toHaveBeenCalledTimes(1);
249
- expect(queryByTestId('slug-editor-spinner')).not.toBeInTheDocument();
250
- expect(queryByText('This slug has already been published in another entry')).toBeInTheDocument();
251
- expect(getByTestId('cf-ui-text-input')).toHaveValue('slug-value');
248
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenCalledTimes(1);
249
+ (0, _vitest.expect)(queryByTestId('slug-editor-spinner')).not.toBeInTheDocument();
250
+ (0, _vitest.expect)(queryByText('This slug has already been published in another entry')).toBeInTheDocument();
251
+ (0, _vitest.expect)(getByTestId('cf-ui-text-input')).toHaveValue('slug-value');
252
252
  });
253
253
  sdk.cma.entry.getMany.mockResolvedValue({
254
254
  total: 0
@@ -259,10 +259,10 @@ describe('SlugEditor', ()=>{
259
259
  }
260
260
  });
261
261
  await (0, _react1.waitFor)(()=>{
262
- expect(field.setValue).toHaveBeenCalledTimes(1);
263
- expect(field.setValue).toHaveBeenCalledWith('123');
264
- expect(sdk.cma.entry.getMany).toHaveBeenCalledTimes(2);
265
- expect(sdk.cma.entry.getMany).toHaveBeenLastCalledWith({
262
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(1);
263
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledWith('123');
264
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenCalledTimes(2);
265
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenLastCalledWith({
266
266
  query: {
267
267
  content_type: 'content-type-id',
268
268
  'fields.slug-id.en-US': '123',
@@ -272,10 +272,10 @@ describe('SlugEditor', ()=>{
272
272
  },
273
273
  releaseid: undefined
274
274
  });
275
- expect(queryByText('This slug has already been published in another entry')).not.toBeInTheDocument();
275
+ (0, _vitest.expect)(queryByText('This slug has already been published in another entry')).not.toBeInTheDocument();
276
276
  });
277
277
  });
278
- it('shows warning instead of error when unique validation is disabled on content model', async ()=>{
278
+ (0, _vitest.it)('shows warning instead of error when unique validation is disabled on content model', async ()=>{
279
279
  const { field, sdk } = createMocks({
280
280
  titleField: 'Slug value',
281
281
  field: 'slug-value'
@@ -299,14 +299,14 @@ describe('SlugEditor', ()=>{
299
299
  isInitiallyDisabled: false
300
300
  }));
301
301
  await (0, _react1.waitFor)(()=>{
302
- expect(sdk.cma.entry.getMany).toHaveBeenCalledTimes(1);
303
- expect(queryByText('This slug has already been published in another entry.')).toBeInTheDocument();
304
- expect(getByTestId('cf-ui-text-input')).not.toHaveAttribute('aria-invalid');
302
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenCalledTimes(1);
303
+ (0, _vitest.expect)(queryByText('This slug has already been published in another entry.')).toBeInTheDocument();
304
+ (0, _vitest.expect)(getByTestId('cf-ui-text-input')).not.toHaveAttribute('aria-invalid');
305
305
  });
306
306
  });
307
- it('hides duplicate warning when publish sets hasError', async ()=>{
308
- const performUniqueCheck = jest.fn().mockResolvedValue(false);
309
- const setValue = jest.fn();
307
+ (0, _vitest.it)('hides duplicate warning when publish sets hasError', async ()=>{
308
+ const performUniqueCheck = _vitest.vi.fn().mockResolvedValue(false);
309
+ const setValue = _vitest.vi.fn();
310
310
  const { queryByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_SlugEditorField.SlugEditorFieldStatic, {
311
311
  hasError: true,
312
312
  isUniqueValidationEnabled: false,
@@ -320,13 +320,13 @@ describe('SlugEditor', ()=>{
320
320
  performUniqueCheck: performUniqueCheck
321
321
  }));
322
322
  await (0, _react1.waitFor)(()=>{
323
- expect(queryByTestId('slug-editor-duplicate-warning')).not.toBeInTheDocument();
324
- expect(queryByTestId('slug-editor-duplicate-error')).not.toBeInTheDocument();
323
+ (0, _vitest.expect)(queryByTestId('slug-editor-duplicate-warning')).not.toBeInTheDocument();
324
+ (0, _vitest.expect)(queryByTestId('slug-editor-duplicate-error')).not.toBeInTheDocument();
325
325
  });
326
326
  });
327
327
  });
328
- describe('should react to title changes', ()=>{
329
- it('when field is disabled', async ()=>{
328
+ (0, _vitest.describe)('should react to title changes', ()=>{
329
+ (0, _vitest.it)('when field is disabled', async ()=>{
330
330
  const { field, titleField, sdk } = createMocks({
331
331
  field: '',
332
332
  titleField: ''
@@ -337,14 +337,14 @@ describe('SlugEditor', ()=>{
337
337
  isInitiallyDisabled: true
338
338
  }));
339
339
  await (0, _react1.waitFor)(()=>{
340
- expect(field.setValue).toHaveBeenCalled();
341
- expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
342
- expect(sdk.cma.entry.getMany).toHaveBeenCalled();
343
- expect(sdk.entry.fields['title-id'].getValue).toHaveBeenCalledTimes(1);
344
- expect(sdk.entry.getSys).toHaveBeenCalledTimes(2);
340
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalled();
341
+ (0, _vitest.expect)(titleField.onValueChanged).toHaveBeenCalledWith('en-US', _vitest.expect.any(Function));
342
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenCalled();
343
+ (0, _vitest.expect)(sdk.entry.fields['title-id'].getValue).toHaveBeenCalledTimes(1);
344
+ (0, _vitest.expect)(sdk.entry.getSys).toHaveBeenCalledTimes(2);
345
345
  });
346
346
  });
347
- it('should generate unique value with date if title is empty', async ()=>{
347
+ (0, _vitest.it)('should generate unique value with date if title is empty', async ()=>{
348
348
  const { field, titleField, sdk } = createMocks({
349
349
  field: '',
350
350
  titleField: ''
@@ -355,24 +355,24 @@ describe('SlugEditor', ()=>{
355
355
  isInitiallyDisabled: false
356
356
  }));
357
357
  await (0, _react1.waitFor)(()=>{
358
- expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
359
- expect(field.setValue).toHaveBeenCalledTimes(1);
360
- expect(field.setValue).toHaveBeenLastCalledWith('untitled-entry-2020-01-24-at-15-33-47');
358
+ (0, _vitest.expect)(titleField.onValueChanged).toHaveBeenCalledWith('en-US', _vitest.expect.any(Function));
359
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(1);
360
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('untitled-entry-2020-01-24-at-15-33-47');
361
361
  });
362
362
  await sdk.entry.fields['title-id'].setValue('Hello world!');
363
363
  await (0, _react1.waitFor)(()=>{
364
- expect(field.setValue).toHaveBeenCalledTimes(2);
365
- expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
366
- expect(sdk.cma.entry.getMany).toHaveBeenCalledTimes(2);
364
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(2);
365
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('hello-world');
366
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenCalledTimes(2);
367
367
  });
368
368
  await sdk.entry.fields['title-id'].setValue('фраза написанная по русски');
369
369
  await (0, _react1.waitFor)(()=>{
370
- expect(field.setValue).toHaveBeenCalledTimes(3);
371
- expect(field.setValue).toHaveBeenLastCalledWith('fraza-napisannaya-po-russki');
372
- expect(sdk.cma.entry.getMany).toHaveBeenCalledTimes(3);
370
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(3);
371
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('fraza-napisannaya-po-russki');
372
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenCalledTimes(3);
373
373
  });
374
374
  });
375
- it('should generate value from title if it is not empty', async ()=>{
375
+ (0, _vitest.it)('should generate value from title if it is not empty', async ()=>{
376
376
  const { field, titleField, sdk } = createMocks({
377
377
  field: '',
378
378
  titleField: 'This is initial title value'
@@ -383,18 +383,18 @@ describe('SlugEditor', ()=>{
383
383
  isInitiallyDisabled: false
384
384
  }));
385
385
  await (0, _react1.waitFor)(()=>{
386
- expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
387
- expect(field.setValue).toHaveBeenCalledTimes(1);
388
- expect(field.setValue).toHaveBeenLastCalledWith('this-is-initial-title-value');
386
+ (0, _vitest.expect)(titleField.onValueChanged).toHaveBeenCalledWith('en-US', _vitest.expect.any(Function));
387
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(1);
388
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('this-is-initial-title-value');
389
389
  });
390
390
  await sdk.entry.fields['title-id'].setValue('Hello world!');
391
391
  await (0, _react1.waitFor)(()=>{
392
- expect(field.setValue).toHaveBeenCalledTimes(2);
393
- expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
394
- expect(sdk.cma.entry.getMany).toHaveBeenCalledTimes(2);
392
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(2);
393
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('hello-world');
394
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenCalledTimes(2);
395
395
  });
396
396
  });
397
- it('should stop tracking value after user intentionally changes slug value', async ()=>{
397
+ (0, _vitest.it)('should stop tracking value after user intentionally changes slug value', async ()=>{
398
398
  const { field, titleField, sdk } = createMocks({
399
399
  field: '',
400
400
  titleField: ''
@@ -408,11 +408,11 @@ describe('SlugEditor', ()=>{
408
408
  await sdk.entry.fields['title-id'].setValue('Hello world!');
409
409
  });
410
410
  await (0, _react1.waitFor)(()=>{
411
- expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
412
- expect(field.setValue).toHaveBeenCalledTimes(2);
413
- expect(field.setValue).toHaveBeenCalledWith('untitled-entry-2020-01-24-at-15-33-47');
414
- expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
415
- expect(sdk.cma.entry.getMany).toHaveBeenCalledTimes(2);
411
+ (0, _vitest.expect)(titleField.onValueChanged).toHaveBeenCalledWith('en-US', _vitest.expect.any(Function));
412
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(2);
413
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledWith('untitled-entry-2020-01-24-at-15-33-47');
414
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('hello-world');
415
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenCalledTimes(2);
416
416
  });
417
417
  _react1.fireEvent.change(getByTestId('cf-ui-text-input'), {
418
418
  target: {
@@ -420,19 +420,19 @@ describe('SlugEditor', ()=>{
420
420
  }
421
421
  });
422
422
  await (0, _react1.waitFor)(()=>{
423
- expect(field.setValue).toHaveBeenCalledTimes(3);
424
- expect(field.setValue).toHaveBeenLastCalledWith('new-custom-slug');
423
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(3);
424
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('new-custom-slug');
425
425
  });
426
426
  await sdk.entry.fields['title-id'].setValue('I decided to update my title');
427
427
  await (0, _react1.waitFor)(()=>{
428
- expect(field.setValue).toHaveBeenCalledTimes(3);
428
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(3);
429
429
  });
430
430
  await sdk.entry.fields['title-id'].setValue('I decided to update my title again');
431
431
  await (0, _react1.waitFor)(()=>{
432
- expect(field.setValue).toHaveBeenCalledTimes(3);
432
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(3);
433
433
  });
434
434
  });
435
- it('should start tracking again after potential slug equals real one', async ()=>{
435
+ (0, _vitest.it)('should start tracking again after potential slug equals real one', async ()=>{
436
436
  const { field, sdk } = createMocks({
437
437
  field: '',
438
438
  titleField: ''
@@ -446,8 +446,8 @@ describe('SlugEditor', ()=>{
446
446
  await sdk.entry.fields['title-id'].setValue('ABC DEF');
447
447
  });
448
448
  await (0, _react1.waitFor)(()=>{
449
- expect(field.setValue).toHaveBeenLastCalledWith('abc-def');
450
- expect(field.setValue).toHaveBeenCalledTimes(2);
449
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('abc-def');
450
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(2);
451
451
  });
452
452
  _react1.fireEvent.change(getByTestId('cf-ui-text-input'), {
453
453
  target: {
@@ -456,21 +456,21 @@ describe('SlugEditor', ()=>{
456
456
  });
457
457
  await sdk.entry.fields['title-id'].setValue('ABC D');
458
458
  await (0, _react1.waitFor)(()=>{
459
- expect(field.setValue).toHaveBeenLastCalledWith('abc');
460
- expect(field.setValue).toHaveBeenCalledTimes(3);
459
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('abc');
460
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(3);
461
461
  });
462
462
  await (0, _react1.waitFor)(async ()=>{
463
463
  await sdk.entry.fields['title-id'].setValue('ABC');
464
464
  await sdk.entry.fields['title-id'].setValue('ABC ABC');
465
465
  });
466
466
  await (0, _react1.waitFor)(()=>{
467
- expect(field.setValue).toHaveBeenLastCalledWith('abc-abc');
468
- expect(field.setValue).toHaveBeenCalledTimes(4);
467
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('abc-abc');
468
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(4);
469
469
  });
470
470
  });
471
471
  });
472
- describe('for non default locales', ()=>{
473
- it('locale is not optional and has no fallback then it should track default locale changes & current locale changes', async ()=>{
472
+ (0, _vitest.describe)('for non default locales', ()=>{
473
+ (0, _vitest.it)('locale is not optional and has no fallback then it should track default locale changes & current locale changes', async ()=>{
474
474
  const { sdk, field, titleField } = createMocks();
475
475
  field.locale = 'ru-RU';
476
476
  field.required = false;
@@ -493,12 +493,12 @@ describe('SlugEditor', ()=>{
493
493
  isInitiallyDisabled: false
494
494
  }));
495
495
  await (0, _react1.waitFor)(()=>{
496
- expect(field.setValue).toHaveBeenCalledWith('untitled-entry-2020-01-24-at-15-33-47');
497
- expect(titleField.onValueChanged).toHaveBeenCalledWith('ru-RU', expect.any(Function));
498
- expect(titleField.onValueChanged).toHaveBeenCalledWith('de-DE', expect.any(Function));
496
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledWith('untitled-entry-2020-01-24-at-15-33-47');
497
+ (0, _vitest.expect)(titleField.onValueChanged).toHaveBeenCalledWith('ru-RU', _vitest.expect.any(Function));
498
+ (0, _vitest.expect)(titleField.onValueChanged).toHaveBeenCalledWith('de-DE', _vitest.expect.any(Function));
499
499
  });
500
500
  });
501
- it('locale is optional and has a fallback then it should track only current locale changes', async ()=>{
501
+ (0, _vitest.it)('locale is optional and has a fallback then it should track only current locale changes', async ()=>{
502
502
  const { sdk, field, titleField } = createMocks();
503
503
  field.locale = 'ru-RU';
504
504
  field.required = false;
@@ -521,13 +521,13 @@ describe('SlugEditor', ()=>{
521
521
  isInitiallyDisabled: false
522
522
  }));
523
523
  await (0, _react1.waitFor)(()=>{
524
- expect(field.setValue).not.toHaveBeenCalled();
525
- expect(titleField.onValueChanged).toHaveBeenCalledWith('ru-RU', expect.any(Function));
526
- expect(titleField.onValueChanged).not.toHaveBeenCalledWith('de-DE', expect.any(Function));
524
+ (0, _vitest.expect)(field.setValue).not.toHaveBeenCalled();
525
+ (0, _vitest.expect)(titleField.onValueChanged).toHaveBeenCalledWith('ru-RU', _vitest.expect.any(Function));
526
+ (0, _vitest.expect)(titleField.onValueChanged).not.toHaveBeenCalledWith('de-DE', _vitest.expect.any(Function));
527
527
  });
528
528
  });
529
529
  });
530
- it('slug suggestion is limited to size validation max', async ()=>{
530
+ (0, _vitest.it)('slug suggestion is limited to size validation max', async ()=>{
531
531
  const { field, sdk } = createMocks({
532
532
  field: '',
533
533
  titleField: ''
@@ -551,10 +551,10 @@ describe('SlugEditor', ()=>{
551
551
  await sdk.entry.fields['title-id'].setValue('the quick brown fox jumps over the lazy dog');
552
552
  });
553
553
  await (0, _react1.waitFor)(()=>{
554
- expect(field.setValue).toHaveBeenLastCalledWith('the-quick-brown-fox');
554
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('the-quick-brown-fox');
555
555
  });
556
556
  });
557
- it('slug suggestion does not contain cut-off words', async ()=>{
557
+ (0, _vitest.it)('slug suggestion does not contain cut-off words', async ()=>{
558
558
  const { field, sdk } = createMocks({
559
559
  field: '',
560
560
  titleField: ''
@@ -579,10 +579,10 @@ describe('SlugEditor', ()=>{
579
579
  });
580
580
  await (0, _react1.waitFor)(()=>{
581
581
  const expectedSlug = 'one-two-three';
582
- expect(field.setValue).toHaveBeenLastCalledWith(expectedSlug);
582
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith(expectedSlug);
583
583
  });
584
584
  });
585
- it('should subscribe for changes in custom field id', async ()=>{
585
+ (0, _vitest.it)('should subscribe for changes in custom field id', async ()=>{
586
586
  const { field, titleField, descriptionField, sdk } = createMocks({
587
587
  field: '',
588
588
  titleField: 'This is initial title value',
@@ -599,16 +599,16 @@ describe('SlugEditor', ()=>{
599
599
  }
600
600
  }));
601
601
  await (0, _react1.waitFor)(()=>{
602
- expect(titleField.onValueChanged).not.toHaveBeenCalled();
603
- expect(descriptionField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
604
- expect(field.setValue).toHaveBeenCalledTimes(1);
605
- expect(field.setValue).toHaveBeenLastCalledWith('this-is-initial-description-value');
602
+ (0, _vitest.expect)(titleField.onValueChanged).not.toHaveBeenCalled();
603
+ (0, _vitest.expect)(descriptionField.onValueChanged).toHaveBeenCalledWith('en-US', _vitest.expect.any(Function));
604
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(1);
605
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('this-is-initial-description-value');
606
606
  });
607
607
  await sdk.entry.fields['description-id'].setValue('Hello world!');
608
608
  await (0, _react1.waitFor)(()=>{
609
- expect(field.setValue).toHaveBeenCalledTimes(2);
610
- expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
611
- expect(sdk.cma.entry.getMany).toHaveBeenCalledTimes(2);
609
+ (0, _vitest.expect)(field.setValue).toHaveBeenCalledTimes(2);
610
+ (0, _vitest.expect)(field.setValue).toHaveBeenLastCalledWith('hello-world');
611
+ (0, _vitest.expect)(sdk.cma.entry.getMany).toHaveBeenCalledTimes(2);
612
612
  });
613
613
  });
614
614
  });
@@ -2,17 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ const _vitest = require("vitest");
5
6
  const _makeSlug = require("./makeSlug");
6
- describe('makeSlug', ()=>{
7
- it('should return untitled slug if title is empty', ()=>{
8
- expect((0, _makeSlug.makeSlug)('', {
7
+ (0, _vitest.describe)('makeSlug', ()=>{
8
+ (0, _vitest.it)('should return untitled slug if title is empty', ()=>{
9
+ (0, _vitest.expect)((0, _makeSlug.makeSlug)('', {
9
10
  locale: 'en',
10
11
  isOptionalLocaleWithFallback: false,
11
12
  createdAt: '2020-01-14T14:45:39.709Z'
12
13
  })).toBe('untitled-entry-2020-01-14-at-14-45-39');
13
14
  });
14
- it('should respect maxLength when provided', ()=>{
15
- expect((0, _makeSlug.makeSlug)('hello world foo bar', {
15
+ (0, _vitest.it)('should respect maxLength when provided', ()=>{
16
+ (0, _vitest.expect)((0, _makeSlug.makeSlug)('hello world foo bar', {
16
17
  locale: 'en',
17
18
  isOptionalLocaleWithFallback: false,
18
19
  createdAt: '2020-01-14T14:45:39.709Z',
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ const _vitest = require("vitest");
5
6
  const _slugify = require("./slugify");
6
- describe('slugify', ()=>{
7
+ (0, _vitest.describe)('slugify', ()=>{
7
8
  const cases = [
8
9
  [
9
10
  'We ♥ $ & €',
@@ -23,11 +24,11 @@ describe('slugify', ()=>{
23
24
  ]
24
25
  ];
25
26
  cases.forEach((input)=>{
26
- it(`converts "${input[0]}" to "${input[1]}"`, ()=>{
27
- expect((0, _slugify.slugify)(input[0])).toBe(input[1]);
27
+ (0, _vitest.it)(`converts "${input[0]}" to "${input[1]}"`, ()=>{
28
+ (0, _vitest.expect)((0, _slugify.slugify)(input[0])).toBe(input[1]);
28
29
  });
29
30
  });
30
- it('truncates to maxLength', ()=>{
31
- expect((0, _slugify.slugify)('hello world', 'en', 5)).toBe('hello');
31
+ (0, _vitest.it)('truncates to maxLength', ()=>{
32
+ (0, _vitest.expect)((0, _slugify.slugify)('hello world', 'en', 5)).toBe('hello');
32
33
  });
33
34
  });
@@ -1,13 +1,13 @@
1
1
  import * as React from 'react';
2
2
  import { createFakeFieldAPI, createFakeLocalesAPI } from '@contentful/field-editor-test-utils';
3
3
  import { cleanup, configure, fireEvent, render, waitFor } from '@testing-library/react';
4
- import '@testing-library/jest-dom/extend-expect';
4
+ import { afterEach, describe, expect, it, vi } from 'vitest';
5
5
  import { SlugEditor } from './SlugEditor';
6
6
  import { SlugEditorFieldStatic } from './SlugEditorField';
7
7
  configure({
8
8
  testIdAttribute: 'data-test-id'
9
9
  });
10
- jest.mock('use-debounce', ()=>({
10
+ vi.mock('use-debounce', ()=>({
11
11
  useDebounce: (text)=>[
12
12
  text
13
13
  ]
@@ -21,34 +21,34 @@ function createMocks(initialValues = {}) {
21
21
  unique: true
22
22
  }
23
23
  ],
24
- onValueChanged: jest.fn().mockImplementation(field.onValueChanged),
25
- setValue: jest.fn().mockImplementation(field.setValue)
24
+ onValueChanged: vi.fn().mockImplementation(field.onValueChanged),
25
+ setValue: vi.fn().mockImplementation(field.setValue)
26
26
  }), initialValues.field || '');
27
27
  const [titleField] = createFakeFieldAPI((field)=>({
28
28
  ...field,
29
29
  id: 'title-id',
30
- setValue: jest.fn().mockImplementation(field.setValue),
31
- getValue: jest.fn().mockImplementation(field.getValue),
32
- onValueChanged: jest.fn().mockImplementation(field.onValueChanged)
30
+ setValue: vi.fn().mockImplementation(field.setValue),
31
+ getValue: vi.fn().mockImplementation(field.getValue),
32
+ onValueChanged: vi.fn().mockImplementation(field.onValueChanged)
33
33
  }), initialValues.titleField || '');
34
34
  const [descriptionField] = createFakeFieldAPI((field)=>({
35
35
  ...field,
36
36
  id: 'description-id',
37
- setValue: jest.fn().mockImplementation(field.setValue),
38
- getValue: jest.fn().mockImplementation(field.getValue),
39
- onValueChanged: jest.fn().mockImplementation(field.onValueChanged)
37
+ setValue: vi.fn().mockImplementation(field.setValue),
38
+ getValue: vi.fn().mockImplementation(field.getValue),
39
+ onValueChanged: vi.fn().mockImplementation(field.onValueChanged)
40
40
  }), initialValues.descriptionField || '');
41
41
  const sdk = {
42
42
  locales: createFakeLocalesAPI(),
43
43
  cma: {
44
44
  entry: {
45
- getMany: jest.fn().mockResolvedValue({
45
+ getMany: vi.fn().mockResolvedValue({
46
46
  total: 0
47
47
  })
48
48
  }
49
49
  },
50
50
  entry: {
51
- getSys: jest.fn().mockReturnValue({
51
+ getSys: vi.fn().mockReturnValue({
52
52
  id: 'entry-id',
53
53
  publishedVersion: undefined,
54
54
  createdAt: '2020-01-24T15:33:47.906Z',
@@ -58,7 +58,7 @@ function createMocks(initialValues = {}) {
58
58
  }
59
59
  }
60
60
  }),
61
- onSysChanged: jest.fn(),
61
+ onSysChanged: vi.fn(),
62
62
  fields: {
63
63
  'title-id': titleField,
64
64
  'entry-id': field,
@@ -260,8 +260,8 @@ describe('SlugEditor', ()=>{
260
260
  });
261
261
  });
262
262
  it('hides duplicate warning when publish sets hasError', async ()=>{
263
- const performUniqueCheck = jest.fn().mockResolvedValue(false);
264
- const setValue = jest.fn();
263
+ const performUniqueCheck = vi.fn().mockResolvedValue(false);
264
+ const setValue = vi.fn();
265
265
  const { queryByTestId } = render(/*#__PURE__*/ React.createElement(SlugEditorFieldStatic, {
266
266
  hasError: true,
267
267
  isUniqueValidationEnabled: false,
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import { makeSlug } from './makeSlug';
2
3
  describe('makeSlug', ()=>{
3
4
  it('should return untitled slug if title is empty', ()=>{
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import { slugify } from './slugify';
2
3
  describe('slugify', ()=>{
3
4
  const cases = [
@@ -1 +1 @@
1
- import '@testing-library/jest-dom/extend-expect';
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-slug",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -31,8 +31,8 @@
31
31
  "build:types": "tsc --outDir dist/types --emitDeclarationOnly",
32
32
  "build:cjs": "swc src --config-file ../../.swcrc -d dist/cjs -C module.type=commonjs",
33
33
  "build:esm": "swc src --config-file ../../.swcrc -d dist/esm",
34
- "test": "jest --watch",
35
- "test:ci": "jest --ci",
34
+ "test": "vitest",
35
+ "test:ci": "vitest run",
36
36
  "tsc": "tsc -p ./ --noEmit"
37
37
  },
38
38
  "dependencies": {
@@ -40,7 +40,7 @@
40
40
  "@contentful/f36-icons": "^6.7.1",
41
41
  "@contentful/f36-note": "^6.7.0",
42
42
  "@contentful/f36-tokens": "^6.1.2",
43
- "@contentful/field-editor-shared": "^4.4.0",
43
+ "@contentful/field-editor-shared": "^4.4.1",
44
44
  "@emotion/css": "^11.13.5",
45
45
  "@types/speakingurl": "^13.0.2",
46
46
  "speakingurl": "^14.0.1",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "@contentful/app-sdk": "^4.45.0",
51
- "@contentful/field-editor-test-utils": "^3.1.0",
51
+ "@contentful/field-editor-test-utils": "^3.1.1",
52
52
  "@lingui/core": "5.3.0"
53
53
  },
54
54
  "peerDependencies": {
@@ -60,5 +60,5 @@
60
60
  "publishConfig": {
61
61
  "registry": "https://npm.pkg.github.com/"
62
62
  },
63
- "gitHead": "b3a1d791df55536d6de78bb138b97224d6c0c70e"
63
+ "gitHead": "5fb6c32d2590e72e56a53cb180a155f84d6505d9"
64
64
  }