@contentful/field-editor-slug 1.3.0 → 1.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.
- package/dist/cjs/SlugEditor.test.js +161 -131
- package/dist/esm/SlugEditor.test.js +162 -132
- package/package.json +2 -2
|
@@ -135,12 +135,13 @@ describe('SlugEditor', ()=>{
|
|
|
135
135
|
baseSdk: sdk,
|
|
136
136
|
isInitiallyDisabled: false
|
|
137
137
|
}));
|
|
138
|
-
await (0, _react1.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
138
|
+
await (0, _react1.waitFor)(()=>{
|
|
139
|
+
expect(field.setValue).not.toHaveBeenCalled();
|
|
140
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
141
|
+
expect(sdk.space.getEntries).not.toHaveBeenCalled();
|
|
142
|
+
expect(sdk.entry.fields['title-id'].getValue).toHaveBeenCalledTimes(1);
|
|
143
|
+
expect(sdk.entry.getSys).toHaveBeenCalledTimes(2);
|
|
144
|
+
});
|
|
144
145
|
});
|
|
145
146
|
it('when title and slug are the same field', async ()=>{
|
|
146
147
|
const { field , titleField , sdk } = createMocks();
|
|
@@ -150,9 +151,10 @@ describe('SlugEditor', ()=>{
|
|
|
150
151
|
baseSdk: sdk,
|
|
151
152
|
isInitiallyDisabled: false
|
|
152
153
|
}));
|
|
153
|
-
await (0, _react1.
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
await (0, _react1.waitFor)(()=>{
|
|
155
|
+
expect(titleField.onValueChanged).not.toHaveBeenCalled();
|
|
156
|
+
expect(field.setValue).not.toHaveBeenCalled();
|
|
157
|
+
});
|
|
156
158
|
});
|
|
157
159
|
it('when a saved slug is different from a title at the render', async ()=>{
|
|
158
160
|
const { field , titleField , sdk } = createMocks({
|
|
@@ -164,9 +166,10 @@ describe('SlugEditor', ()=>{
|
|
|
164
166
|
baseSdk: sdk,
|
|
165
167
|
isInitiallyDisabled: false
|
|
166
168
|
}));
|
|
167
|
-
await (0, _react1.
|
|
168
|
-
|
|
169
|
-
|
|
169
|
+
await (0, _react1.waitFor)(()=>{
|
|
170
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
171
|
+
expect(field.setValue).not.toHaveBeenCalled();
|
|
172
|
+
});
|
|
170
173
|
});
|
|
171
174
|
});
|
|
172
175
|
describe('should check for uniqueness', ()=>{
|
|
@@ -192,18 +195,19 @@ describe('SlugEditor', ()=>{
|
|
|
192
195
|
baseSdk: sdk,
|
|
193
196
|
isInitiallyDisabled: false
|
|
194
197
|
}));
|
|
195
|
-
await (0, _react1.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
198
|
+
await (0, _react1.waitFor)(()=>{
|
|
199
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
200
|
+
expect(sdk.space.getEntries).toHaveBeenLastCalledWith({
|
|
201
|
+
content_type: 'content-type-id',
|
|
202
|
+
'fields.slug-id.en-US': 'slug-value',
|
|
203
|
+
limit: 0,
|
|
204
|
+
'sys.id[ne]': 'entry-id',
|
|
205
|
+
'sys.publishedAt[exists]': true
|
|
206
|
+
});
|
|
207
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(1);
|
|
208
|
+
expect(queryByTestId('slug-editor-spinner')).not.toBeInTheDocument();
|
|
209
|
+
expect(queryByText('This slug has already been published in another entry')).not.toBeInTheDocument();
|
|
210
|
+
});
|
|
207
211
|
});
|
|
208
212
|
it('if it is not published', async ()=>{
|
|
209
213
|
const { field , titleField , sdk } = createMocks({
|
|
@@ -227,19 +231,20 @@ describe('SlugEditor', ()=>{
|
|
|
227
231
|
baseSdk: sdk,
|
|
228
232
|
isInitiallyDisabled: false
|
|
229
233
|
}));
|
|
230
|
-
await (0, _react1.
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
234
|
+
await (0, _react1.waitFor)(()=>{
|
|
235
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
236
|
+
expect(sdk.space.getEntries).toHaveBeenLastCalledWith({
|
|
237
|
+
content_type: 'content-type-id',
|
|
238
|
+
'fields.slug-id.en-US': 'slug-value',
|
|
239
|
+
limit: 0,
|
|
240
|
+
'sys.id[ne]': 'entry-id',
|
|
241
|
+
'sys.publishedAt[exists]': true
|
|
242
|
+
});
|
|
243
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(1);
|
|
244
|
+
expect(queryByTestId('slug-editor-spinner')).not.toBeInTheDocument();
|
|
245
|
+
expect(queryByText('This slug has already been published in another entry')).toBeInTheDocument();
|
|
246
|
+
expect(getByTestId('cf-ui-text-input')).toHaveValue('slug-value');
|
|
247
|
+
});
|
|
243
248
|
sdk.space.getEntries.mockResolvedValue({
|
|
244
249
|
total: 0
|
|
245
250
|
});
|
|
@@ -248,18 +253,19 @@ describe('SlugEditor', ()=>{
|
|
|
248
253
|
value: '123'
|
|
249
254
|
}
|
|
250
255
|
});
|
|
251
|
-
await (0, _react1.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
256
|
+
await (0, _react1.waitFor)(()=>{
|
|
257
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
258
|
+
expect(field.setValue).toHaveBeenCalledWith('123');
|
|
259
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(2);
|
|
260
|
+
expect(sdk.space.getEntries).toHaveBeenLastCalledWith({
|
|
261
|
+
content_type: 'content-type-id',
|
|
262
|
+
'fields.slug-id.en-US': '123',
|
|
263
|
+
limit: 0,
|
|
264
|
+
'sys.id[ne]': 'entry-id',
|
|
265
|
+
'sys.publishedAt[exists]': true
|
|
266
|
+
});
|
|
267
|
+
expect(queryByText('This slug has already been published in another entry')).not.toBeInTheDocument();
|
|
268
|
+
});
|
|
263
269
|
});
|
|
264
270
|
});
|
|
265
271
|
describe('should react to title changes', ()=>{
|
|
@@ -273,12 +279,13 @@ describe('SlugEditor', ()=>{
|
|
|
273
279
|
baseSdk: sdk,
|
|
274
280
|
isInitiallyDisabled: true
|
|
275
281
|
}));
|
|
276
|
-
await (0, _react1.
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
+
await (0, _react1.waitFor)(()=>{
|
|
283
|
+
expect(field.setValue).toHaveBeenCalled();
|
|
284
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
285
|
+
expect(sdk.space.getEntries).toHaveBeenCalled();
|
|
286
|
+
expect(sdk.entry.fields['title-id'].getValue).toHaveBeenCalledTimes(1);
|
|
287
|
+
expect(sdk.entry.getSys).toHaveBeenCalledTimes(2);
|
|
288
|
+
});
|
|
282
289
|
});
|
|
283
290
|
it('should generate unique value with date if title is empty', async ()=>{
|
|
284
291
|
const { field , titleField , sdk } = createMocks({
|
|
@@ -290,20 +297,23 @@ describe('SlugEditor', ()=>{
|
|
|
290
297
|
baseSdk: sdk,
|
|
291
298
|
isInitiallyDisabled: false
|
|
292
299
|
}));
|
|
293
|
-
await (0, _react1.
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
300
|
+
await (0, _react1.waitFor)(()=>{
|
|
301
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
302
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
303
|
+
expect(field.setValue).toHaveBeenLastCalledWith('untitled-entry-2020-01-24-at-15-33-47');
|
|
304
|
+
});
|
|
297
305
|
await sdk.entry.fields['title-id'].setValue('Hello world!');
|
|
298
|
-
await (0, _react1.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
306
|
+
await (0, _react1.waitFor)(()=>{
|
|
307
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
308
|
+
expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
|
|
309
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(2);
|
|
310
|
+
});
|
|
302
311
|
await sdk.entry.fields['title-id'].setValue('фраза написанная по русски');
|
|
303
|
-
await (0, _react1.
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
312
|
+
await (0, _react1.waitFor)(()=>{
|
|
313
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
314
|
+
expect(field.setValue).toHaveBeenLastCalledWith('fraza-napisannaya-po-russki');
|
|
315
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(3);
|
|
316
|
+
});
|
|
307
317
|
});
|
|
308
318
|
it('should generate value from title if it is not empty', async ()=>{
|
|
309
319
|
const { field , titleField , sdk } = createMocks({
|
|
@@ -315,15 +325,17 @@ describe('SlugEditor', ()=>{
|
|
|
315
325
|
baseSdk: sdk,
|
|
316
326
|
isInitiallyDisabled: false
|
|
317
327
|
}));
|
|
318
|
-
await (0, _react1.
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
328
|
+
await (0, _react1.waitFor)(()=>{
|
|
329
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
330
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
331
|
+
expect(field.setValue).toHaveBeenLastCalledWith('this-is-initial-title-value');
|
|
332
|
+
});
|
|
322
333
|
await sdk.entry.fields['title-id'].setValue('Hello world!');
|
|
323
|
-
await (0, _react1.
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
334
|
+
await (0, _react1.waitFor)(()=>{
|
|
335
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
336
|
+
expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
|
|
337
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(2);
|
|
338
|
+
});
|
|
327
339
|
});
|
|
328
340
|
it('should stop tracking value after user intentionally changes slug value', async ()=>{
|
|
329
341
|
const { field , titleField , sdk } = createMocks({
|
|
@@ -335,28 +347,33 @@ describe('SlugEditor', ()=>{
|
|
|
335
347
|
baseSdk: sdk,
|
|
336
348
|
isInitiallyDisabled: false
|
|
337
349
|
}));
|
|
338
|
-
await (0, _react1.
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
350
|
+
await (0, _react1.waitFor)(async ()=>{
|
|
351
|
+
await sdk.entry.fields['title-id'].setValue('Hello world!');
|
|
352
|
+
});
|
|
353
|
+
await (0, _react1.waitFor)(()=>{
|
|
354
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
355
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
356
|
+
expect(field.setValue).toHaveBeenCalledWith('untitled-entry-2020-01-24-at-15-33-47');
|
|
357
|
+
expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
|
|
358
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(2);
|
|
359
|
+
});
|
|
346
360
|
_react1.fireEvent.change(getByTestId('cf-ui-text-input'), {
|
|
347
361
|
target: {
|
|
348
362
|
value: 'new-custom-slug'
|
|
349
363
|
}
|
|
350
364
|
});
|
|
351
|
-
await (0, _react1.
|
|
352
|
-
|
|
353
|
-
|
|
365
|
+
await (0, _react1.waitFor)(()=>{
|
|
366
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
367
|
+
expect(field.setValue).toHaveBeenLastCalledWith('new-custom-slug');
|
|
368
|
+
});
|
|
354
369
|
await sdk.entry.fields['title-id'].setValue('I decided to update my title');
|
|
355
|
-
await (0, _react1.
|
|
356
|
-
|
|
370
|
+
await (0, _react1.waitFor)(()=>{
|
|
371
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
372
|
+
});
|
|
357
373
|
await sdk.entry.fields['title-id'].setValue('I decided to update my title again');
|
|
358
|
-
await (0, _react1.
|
|
359
|
-
|
|
374
|
+
await (0, _react1.waitFor)(()=>{
|
|
375
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
376
|
+
});
|
|
360
377
|
});
|
|
361
378
|
it('should start tracking again after potential slug equals real one', async ()=>{
|
|
362
379
|
const { field , sdk } = createMocks({
|
|
@@ -368,26 +385,31 @@ describe('SlugEditor', ()=>{
|
|
|
368
385
|
baseSdk: sdk,
|
|
369
386
|
isInitiallyDisabled: false
|
|
370
387
|
}));
|
|
371
|
-
await (0, _react1.
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
388
|
+
await (0, _react1.waitFor)(async ()=>{
|
|
389
|
+
await sdk.entry.fields['title-id'].setValue('ABC DEF');
|
|
390
|
+
});
|
|
391
|
+
await (0, _react1.waitFor)(()=>{
|
|
392
|
+
expect(field.setValue).toHaveBeenLastCalledWith('abc-def');
|
|
393
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
394
|
+
});
|
|
376
395
|
_react1.fireEvent.change(getByTestId('cf-ui-text-input'), {
|
|
377
396
|
target: {
|
|
378
397
|
value: 'abc'
|
|
379
398
|
}
|
|
380
399
|
});
|
|
381
400
|
await sdk.entry.fields['title-id'].setValue('ABC D');
|
|
382
|
-
await (0, _react1.
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
await
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
await (0, _react1.
|
|
401
|
+
await (0, _react1.waitFor)(()=>{
|
|
402
|
+
expect(field.setValue).toHaveBeenLastCalledWith('abc');
|
|
403
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
404
|
+
});
|
|
405
|
+
await (0, _react1.waitFor)(async ()=>{
|
|
406
|
+
await sdk.entry.fields['title-id'].setValue('ABC');
|
|
407
|
+
await sdk.entry.fields['title-id'].setValue('ABC ABC');
|
|
408
|
+
});
|
|
409
|
+
await (0, _react1.waitFor)(()=>{
|
|
410
|
+
expect(field.setValue).toHaveBeenLastCalledWith('abc-abc');
|
|
411
|
+
expect(field.setValue).toHaveBeenCalledTimes(4);
|
|
412
|
+
});
|
|
391
413
|
});
|
|
392
414
|
});
|
|
393
415
|
describe('for non default locales', ()=>{
|
|
@@ -413,10 +435,11 @@ describe('SlugEditor', ()=>{
|
|
|
413
435
|
baseSdk: sdk,
|
|
414
436
|
isInitiallyDisabled: false
|
|
415
437
|
}));
|
|
416
|
-
await (0, _react1.
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
438
|
+
await (0, _react1.waitFor)(()=>{
|
|
439
|
+
expect(field.setValue).toHaveBeenCalledWith('untitled-entry-2020-01-24-at-15-33-47');
|
|
440
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('ru-RU', expect.any(Function));
|
|
441
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('de-DE', expect.any(Function));
|
|
442
|
+
});
|
|
420
443
|
});
|
|
421
444
|
it('locale is optional and has a fallback then it should track only current locale changes', async ()=>{
|
|
422
445
|
const { sdk , field , titleField } = createMocks();
|
|
@@ -440,10 +463,11 @@ describe('SlugEditor', ()=>{
|
|
|
440
463
|
baseSdk: sdk,
|
|
441
464
|
isInitiallyDisabled: false
|
|
442
465
|
}));
|
|
443
|
-
await (0, _react1.
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
466
|
+
await (0, _react1.waitFor)(()=>{
|
|
467
|
+
expect(field.setValue).not.toHaveBeenCalled();
|
|
468
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('ru-RU', expect.any(Function));
|
|
469
|
+
expect(titleField.onValueChanged).not.toHaveBeenCalledWith('de-DE', expect.any(Function));
|
|
470
|
+
});
|
|
447
471
|
});
|
|
448
472
|
});
|
|
449
473
|
it('slug suggestion is limited to 75 symbols', async ()=>{
|
|
@@ -456,11 +480,13 @@ describe('SlugEditor', ()=>{
|
|
|
456
480
|
baseSdk: sdk,
|
|
457
481
|
isInitiallyDisabled: false
|
|
458
482
|
}));
|
|
459
|
-
await (0, _react1.
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
483
|
+
await (0, _react1.waitFor)(async ()=>{
|
|
484
|
+
await sdk.entry.fields['title-id'].setValue('a'.repeat(80));
|
|
485
|
+
});
|
|
486
|
+
await (0, _react1.waitFor)(()=>{
|
|
487
|
+
const expectedSlug = 'a'.repeat(75);
|
|
488
|
+
expect(field.setValue).toHaveBeenLastCalledWith(expectedSlug);
|
|
489
|
+
});
|
|
464
490
|
});
|
|
465
491
|
it('slug suggestion does not contain cut-off words', async ()=>{
|
|
466
492
|
const { field , sdk } = createMocks({
|
|
@@ -472,11 +498,13 @@ describe('SlugEditor', ()=>{
|
|
|
472
498
|
baseSdk: sdk,
|
|
473
499
|
isInitiallyDisabled: false
|
|
474
500
|
}));
|
|
475
|
-
await (0, _react1.
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
501
|
+
await (0, _react1.waitFor)(async ()=>{
|
|
502
|
+
await sdk.entry.fields['title-id'].setValue(`one two three ${'a'.repeat(80)}`);
|
|
503
|
+
});
|
|
504
|
+
await (0, _react1.waitFor)(()=>{
|
|
505
|
+
const expectedSlug = 'one-two-three';
|
|
506
|
+
expect(field.setValue).toHaveBeenLastCalledWith(expectedSlug);
|
|
507
|
+
});
|
|
480
508
|
});
|
|
481
509
|
it('should subscribe for changes in custom field id', async ()=>{
|
|
482
510
|
const { field , titleField , descriptionField , sdk } = createMocks({
|
|
@@ -494,15 +522,17 @@ describe('SlugEditor', ()=>{
|
|
|
494
522
|
}
|
|
495
523
|
}
|
|
496
524
|
}));
|
|
497
|
-
await (0, _react1.
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
525
|
+
await (0, _react1.waitFor)(()=>{
|
|
526
|
+
expect(titleField.onValueChanged).not.toHaveBeenCalled();
|
|
527
|
+
expect(descriptionField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
528
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
529
|
+
expect(field.setValue).toHaveBeenLastCalledWith('this-is-initial-description-value');
|
|
530
|
+
});
|
|
502
531
|
await sdk.entry.fields['description-id'].setValue('Hello world!');
|
|
503
|
-
await (0, _react1.
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
532
|
+
await (0, _react1.waitFor)(()=>{
|
|
533
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
534
|
+
expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
|
|
535
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(2);
|
|
536
|
+
});
|
|
507
537
|
});
|
|
508
538
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { createFakeFieldAPI, createFakeLocalesAPI } from '@contentful/field-editor-test-utils';
|
|
3
|
-
import {
|
|
3
|
+
import { cleanup, configure, fireEvent, render, waitFor } from '@testing-library/react';
|
|
4
4
|
import identity from 'lodash/identity';
|
|
5
5
|
import '@testing-library/jest-dom/extend-expect';
|
|
6
6
|
import { SlugEditor } from './SlugEditor';
|
|
@@ -87,12 +87,13 @@ describe('SlugEditor', ()=>{
|
|
|
87
87
|
baseSdk: sdk,
|
|
88
88
|
isInitiallyDisabled: false
|
|
89
89
|
}));
|
|
90
|
-
await
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
await waitFor(()=>{
|
|
91
|
+
expect(field.setValue).not.toHaveBeenCalled();
|
|
92
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
93
|
+
expect(sdk.space.getEntries).not.toHaveBeenCalled();
|
|
94
|
+
expect(sdk.entry.fields['title-id'].getValue).toHaveBeenCalledTimes(1);
|
|
95
|
+
expect(sdk.entry.getSys).toHaveBeenCalledTimes(2);
|
|
96
|
+
});
|
|
96
97
|
});
|
|
97
98
|
it('when title and slug are the same field', async ()=>{
|
|
98
99
|
const { field , titleField , sdk } = createMocks();
|
|
@@ -102,9 +103,10 @@ describe('SlugEditor', ()=>{
|
|
|
102
103
|
baseSdk: sdk,
|
|
103
104
|
isInitiallyDisabled: false
|
|
104
105
|
}));
|
|
105
|
-
await
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
await waitFor(()=>{
|
|
107
|
+
expect(titleField.onValueChanged).not.toHaveBeenCalled();
|
|
108
|
+
expect(field.setValue).not.toHaveBeenCalled();
|
|
109
|
+
});
|
|
108
110
|
});
|
|
109
111
|
it('when a saved slug is different from a title at the render', async ()=>{
|
|
110
112
|
const { field , titleField , sdk } = createMocks({
|
|
@@ -116,9 +118,10 @@ describe('SlugEditor', ()=>{
|
|
|
116
118
|
baseSdk: sdk,
|
|
117
119
|
isInitiallyDisabled: false
|
|
118
120
|
}));
|
|
119
|
-
await
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
await waitFor(()=>{
|
|
122
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
123
|
+
expect(field.setValue).not.toHaveBeenCalled();
|
|
124
|
+
});
|
|
122
125
|
});
|
|
123
126
|
});
|
|
124
127
|
describe('should check for uniqueness', ()=>{
|
|
@@ -144,18 +147,19 @@ describe('SlugEditor', ()=>{
|
|
|
144
147
|
baseSdk: sdk,
|
|
145
148
|
isInitiallyDisabled: false
|
|
146
149
|
}));
|
|
147
|
-
await
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
await waitFor(()=>{
|
|
151
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
152
|
+
expect(sdk.space.getEntries).toHaveBeenLastCalledWith({
|
|
153
|
+
content_type: 'content-type-id',
|
|
154
|
+
'fields.slug-id.en-US': 'slug-value',
|
|
155
|
+
limit: 0,
|
|
156
|
+
'sys.id[ne]': 'entry-id',
|
|
157
|
+
'sys.publishedAt[exists]': true
|
|
158
|
+
});
|
|
159
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(1);
|
|
160
|
+
expect(queryByTestId('slug-editor-spinner')).not.toBeInTheDocument();
|
|
161
|
+
expect(queryByText('This slug has already been published in another entry')).not.toBeInTheDocument();
|
|
162
|
+
});
|
|
159
163
|
});
|
|
160
164
|
it('if it is not published', async ()=>{
|
|
161
165
|
const { field , titleField , sdk } = createMocks({
|
|
@@ -179,19 +183,20 @@ describe('SlugEditor', ()=>{
|
|
|
179
183
|
baseSdk: sdk,
|
|
180
184
|
isInitiallyDisabled: false
|
|
181
185
|
}));
|
|
182
|
-
await
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
186
|
+
await waitFor(()=>{
|
|
187
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
188
|
+
expect(sdk.space.getEntries).toHaveBeenLastCalledWith({
|
|
189
|
+
content_type: 'content-type-id',
|
|
190
|
+
'fields.slug-id.en-US': 'slug-value',
|
|
191
|
+
limit: 0,
|
|
192
|
+
'sys.id[ne]': 'entry-id',
|
|
193
|
+
'sys.publishedAt[exists]': true
|
|
194
|
+
});
|
|
195
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(1);
|
|
196
|
+
expect(queryByTestId('slug-editor-spinner')).not.toBeInTheDocument();
|
|
197
|
+
expect(queryByText('This slug has already been published in another entry')).toBeInTheDocument();
|
|
198
|
+
expect(getByTestId('cf-ui-text-input')).toHaveValue('slug-value');
|
|
199
|
+
});
|
|
195
200
|
sdk.space.getEntries.mockResolvedValue({
|
|
196
201
|
total: 0
|
|
197
202
|
});
|
|
@@ -200,18 +205,19 @@ describe('SlugEditor', ()=>{
|
|
|
200
205
|
value: '123'
|
|
201
206
|
}
|
|
202
207
|
});
|
|
203
|
-
await
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
208
|
+
await waitFor(()=>{
|
|
209
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
210
|
+
expect(field.setValue).toHaveBeenCalledWith('123');
|
|
211
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(2);
|
|
212
|
+
expect(sdk.space.getEntries).toHaveBeenLastCalledWith({
|
|
213
|
+
content_type: 'content-type-id',
|
|
214
|
+
'fields.slug-id.en-US': '123',
|
|
215
|
+
limit: 0,
|
|
216
|
+
'sys.id[ne]': 'entry-id',
|
|
217
|
+
'sys.publishedAt[exists]': true
|
|
218
|
+
});
|
|
219
|
+
expect(queryByText('This slug has already been published in another entry')).not.toBeInTheDocument();
|
|
220
|
+
});
|
|
215
221
|
});
|
|
216
222
|
});
|
|
217
223
|
describe('should react to title changes', ()=>{
|
|
@@ -225,12 +231,13 @@ describe('SlugEditor', ()=>{
|
|
|
225
231
|
baseSdk: sdk,
|
|
226
232
|
isInitiallyDisabled: true
|
|
227
233
|
}));
|
|
228
|
-
await
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
+
await waitFor(()=>{
|
|
235
|
+
expect(field.setValue).toHaveBeenCalled();
|
|
236
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
237
|
+
expect(sdk.space.getEntries).toHaveBeenCalled();
|
|
238
|
+
expect(sdk.entry.fields['title-id'].getValue).toHaveBeenCalledTimes(1);
|
|
239
|
+
expect(sdk.entry.getSys).toHaveBeenCalledTimes(2);
|
|
240
|
+
});
|
|
234
241
|
});
|
|
235
242
|
it('should generate unique value with date if title is empty', async ()=>{
|
|
236
243
|
const { field , titleField , sdk } = createMocks({
|
|
@@ -242,20 +249,23 @@ describe('SlugEditor', ()=>{
|
|
|
242
249
|
baseSdk: sdk,
|
|
243
250
|
isInitiallyDisabled: false
|
|
244
251
|
}));
|
|
245
|
-
await
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
252
|
+
await waitFor(()=>{
|
|
253
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
254
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
255
|
+
expect(field.setValue).toHaveBeenLastCalledWith('untitled-entry-2020-01-24-at-15-33-47');
|
|
256
|
+
});
|
|
249
257
|
await sdk.entry.fields['title-id'].setValue('Hello world!');
|
|
250
|
-
await
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
258
|
+
await waitFor(()=>{
|
|
259
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
260
|
+
expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
|
|
261
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(2);
|
|
262
|
+
});
|
|
254
263
|
await sdk.entry.fields['title-id'].setValue('фраза написанная по русски');
|
|
255
|
-
await
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
264
|
+
await waitFor(()=>{
|
|
265
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
266
|
+
expect(field.setValue).toHaveBeenLastCalledWith('fraza-napisannaya-po-russki');
|
|
267
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(3);
|
|
268
|
+
});
|
|
259
269
|
});
|
|
260
270
|
it('should generate value from title if it is not empty', async ()=>{
|
|
261
271
|
const { field , titleField , sdk } = createMocks({
|
|
@@ -267,15 +277,17 @@ describe('SlugEditor', ()=>{
|
|
|
267
277
|
baseSdk: sdk,
|
|
268
278
|
isInitiallyDisabled: false
|
|
269
279
|
}));
|
|
270
|
-
await
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
280
|
+
await waitFor(()=>{
|
|
281
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
282
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
283
|
+
expect(field.setValue).toHaveBeenLastCalledWith('this-is-initial-title-value');
|
|
284
|
+
});
|
|
274
285
|
await sdk.entry.fields['title-id'].setValue('Hello world!');
|
|
275
|
-
await
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
286
|
+
await waitFor(()=>{
|
|
287
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
288
|
+
expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
|
|
289
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(2);
|
|
290
|
+
});
|
|
279
291
|
});
|
|
280
292
|
it('should stop tracking value after user intentionally changes slug value', async ()=>{
|
|
281
293
|
const { field , titleField , sdk } = createMocks({
|
|
@@ -287,28 +299,33 @@ describe('SlugEditor', ()=>{
|
|
|
287
299
|
baseSdk: sdk,
|
|
288
300
|
isInitiallyDisabled: false
|
|
289
301
|
}));
|
|
290
|
-
await
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
302
|
+
await waitFor(async ()=>{
|
|
303
|
+
await sdk.entry.fields['title-id'].setValue('Hello world!');
|
|
304
|
+
});
|
|
305
|
+
await waitFor(()=>{
|
|
306
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
307
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
308
|
+
expect(field.setValue).toHaveBeenCalledWith('untitled-entry-2020-01-24-at-15-33-47');
|
|
309
|
+
expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
|
|
310
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(2);
|
|
311
|
+
});
|
|
298
312
|
fireEvent.change(getByTestId('cf-ui-text-input'), {
|
|
299
313
|
target: {
|
|
300
314
|
value: 'new-custom-slug'
|
|
301
315
|
}
|
|
302
316
|
});
|
|
303
|
-
await
|
|
304
|
-
|
|
305
|
-
|
|
317
|
+
await waitFor(()=>{
|
|
318
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
319
|
+
expect(field.setValue).toHaveBeenLastCalledWith('new-custom-slug');
|
|
320
|
+
});
|
|
306
321
|
await sdk.entry.fields['title-id'].setValue('I decided to update my title');
|
|
307
|
-
await
|
|
308
|
-
|
|
322
|
+
await waitFor(()=>{
|
|
323
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
324
|
+
});
|
|
309
325
|
await sdk.entry.fields['title-id'].setValue('I decided to update my title again');
|
|
310
|
-
await
|
|
311
|
-
|
|
326
|
+
await waitFor(()=>{
|
|
327
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
328
|
+
});
|
|
312
329
|
});
|
|
313
330
|
it('should start tracking again after potential slug equals real one', async ()=>{
|
|
314
331
|
const { field , sdk } = createMocks({
|
|
@@ -320,26 +337,31 @@ describe('SlugEditor', ()=>{
|
|
|
320
337
|
baseSdk: sdk,
|
|
321
338
|
isInitiallyDisabled: false
|
|
322
339
|
}));
|
|
323
|
-
await
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
340
|
+
await waitFor(async ()=>{
|
|
341
|
+
await sdk.entry.fields['title-id'].setValue('ABC DEF');
|
|
342
|
+
});
|
|
343
|
+
await waitFor(()=>{
|
|
344
|
+
expect(field.setValue).toHaveBeenLastCalledWith('abc-def');
|
|
345
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
346
|
+
});
|
|
328
347
|
fireEvent.change(getByTestId('cf-ui-text-input'), {
|
|
329
348
|
target: {
|
|
330
349
|
value: 'abc'
|
|
331
350
|
}
|
|
332
351
|
});
|
|
333
352
|
await sdk.entry.fields['title-id'].setValue('ABC D');
|
|
334
|
-
await
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
await
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
await
|
|
353
|
+
await waitFor(()=>{
|
|
354
|
+
expect(field.setValue).toHaveBeenLastCalledWith('abc');
|
|
355
|
+
expect(field.setValue).toHaveBeenCalledTimes(3);
|
|
356
|
+
});
|
|
357
|
+
await waitFor(async ()=>{
|
|
358
|
+
await sdk.entry.fields['title-id'].setValue('ABC');
|
|
359
|
+
await sdk.entry.fields['title-id'].setValue('ABC ABC');
|
|
360
|
+
});
|
|
361
|
+
await waitFor(()=>{
|
|
362
|
+
expect(field.setValue).toHaveBeenLastCalledWith('abc-abc');
|
|
363
|
+
expect(field.setValue).toHaveBeenCalledTimes(4);
|
|
364
|
+
});
|
|
343
365
|
});
|
|
344
366
|
});
|
|
345
367
|
describe('for non default locales', ()=>{
|
|
@@ -365,10 +387,11 @@ describe('SlugEditor', ()=>{
|
|
|
365
387
|
baseSdk: sdk,
|
|
366
388
|
isInitiallyDisabled: false
|
|
367
389
|
}));
|
|
368
|
-
await
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
390
|
+
await waitFor(()=>{
|
|
391
|
+
expect(field.setValue).toHaveBeenCalledWith('untitled-entry-2020-01-24-at-15-33-47');
|
|
392
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('ru-RU', expect.any(Function));
|
|
393
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('de-DE', expect.any(Function));
|
|
394
|
+
});
|
|
372
395
|
});
|
|
373
396
|
it('locale is optional and has a fallback then it should track only current locale changes', async ()=>{
|
|
374
397
|
const { sdk , field , titleField } = createMocks();
|
|
@@ -392,10 +415,11 @@ describe('SlugEditor', ()=>{
|
|
|
392
415
|
baseSdk: sdk,
|
|
393
416
|
isInitiallyDisabled: false
|
|
394
417
|
}));
|
|
395
|
-
await
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
418
|
+
await waitFor(()=>{
|
|
419
|
+
expect(field.setValue).not.toHaveBeenCalled();
|
|
420
|
+
expect(titleField.onValueChanged).toHaveBeenCalledWith('ru-RU', expect.any(Function));
|
|
421
|
+
expect(titleField.onValueChanged).not.toHaveBeenCalledWith('de-DE', expect.any(Function));
|
|
422
|
+
});
|
|
399
423
|
});
|
|
400
424
|
});
|
|
401
425
|
it('slug suggestion is limited to 75 symbols', async ()=>{
|
|
@@ -408,11 +432,13 @@ describe('SlugEditor', ()=>{
|
|
|
408
432
|
baseSdk: sdk,
|
|
409
433
|
isInitiallyDisabled: false
|
|
410
434
|
}));
|
|
411
|
-
await
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
435
|
+
await waitFor(async ()=>{
|
|
436
|
+
await sdk.entry.fields['title-id'].setValue('a'.repeat(80));
|
|
437
|
+
});
|
|
438
|
+
await waitFor(()=>{
|
|
439
|
+
const expectedSlug = 'a'.repeat(75);
|
|
440
|
+
expect(field.setValue).toHaveBeenLastCalledWith(expectedSlug);
|
|
441
|
+
});
|
|
416
442
|
});
|
|
417
443
|
it('slug suggestion does not contain cut-off words', async ()=>{
|
|
418
444
|
const { field , sdk } = createMocks({
|
|
@@ -424,11 +450,13 @@ describe('SlugEditor', ()=>{
|
|
|
424
450
|
baseSdk: sdk,
|
|
425
451
|
isInitiallyDisabled: false
|
|
426
452
|
}));
|
|
427
|
-
await
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
453
|
+
await waitFor(async ()=>{
|
|
454
|
+
await sdk.entry.fields['title-id'].setValue(`one two three ${'a'.repeat(80)}`);
|
|
455
|
+
});
|
|
456
|
+
await waitFor(()=>{
|
|
457
|
+
const expectedSlug = 'one-two-three';
|
|
458
|
+
expect(field.setValue).toHaveBeenLastCalledWith(expectedSlug);
|
|
459
|
+
});
|
|
432
460
|
});
|
|
433
461
|
it('should subscribe for changes in custom field id', async ()=>{
|
|
434
462
|
const { field , titleField , descriptionField , sdk } = createMocks({
|
|
@@ -446,15 +474,17 @@ describe('SlugEditor', ()=>{
|
|
|
446
474
|
}
|
|
447
475
|
}
|
|
448
476
|
}));
|
|
449
|
-
await
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
477
|
+
await waitFor(()=>{
|
|
478
|
+
expect(titleField.onValueChanged).not.toHaveBeenCalled();
|
|
479
|
+
expect(descriptionField.onValueChanged).toHaveBeenCalledWith('en-US', expect.any(Function));
|
|
480
|
+
expect(field.setValue).toHaveBeenCalledTimes(1);
|
|
481
|
+
expect(field.setValue).toHaveBeenLastCalledWith('this-is-initial-description-value');
|
|
482
|
+
});
|
|
454
483
|
await sdk.entry.fields['description-id'].setValue('Hello world!');
|
|
455
|
-
await
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
484
|
+
await waitFor(()=>{
|
|
485
|
+
expect(field.setValue).toHaveBeenCalledTimes(2);
|
|
486
|
+
expect(field.setValue).toHaveBeenLastCalledWith('hello-world');
|
|
487
|
+
expect(sdk.space.getEntries).toHaveBeenCalledTimes(2);
|
|
488
|
+
});
|
|
459
489
|
});
|
|
460
490
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-slug",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"@contentful/app-sdk": "^4.2.0",
|
|
55
55
|
"react": ">=16.8.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "83b651f1638ad6bab53565479e76b8d29b86af3a"
|
|
58
58
|
}
|