-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathpreview.test.ts
715 lines (615 loc) · 20.7 KB
/
preview.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
import './dom-parser.ts'
import { ensureLoaded } from '@logux/client'
import { restoreAll, spyOn } from 'nanospy'
import { keepMount } from 'nanostores'
import { deepStrictEqual, equal, ok } from 'node:assert'
import { afterEach, beforeEach, test } from 'node:test'
import { setTimeout } from 'node:timers/promises'
import {
addFeed,
addPreviewCandidate,
checkAndRemoveRequestMock,
clearPreview,
createPostsList,
currentCandidate,
expectRequest,
getFeeds,
getPosts,
loaders,
mockRequest,
onPreviewUrlType,
previewCandidate,
type PreviewCandidate,
previewCandidateAdded,
previewCandidates,
previewCandidatesLoading,
previewNoResults,
previewPosts,
previewUrl,
previewUrlError,
router,
setBaseTestRoute,
setIsMobile,
setPreviewCandidate,
setPreviewUrl,
testFeed
} from '../index.ts'
import { cleanClientTest, enableClientTest } from './utils.ts'
beforeEach(() => {
enableClientTest()
mockRequest()
setBaseTestRoute({ params: {}, route: 'add' })
})
afterEach(async () => {
await cleanClientTest()
restoreAll()
clearPreview()
checkAndRemoveRequestMock()
})
function equalWithText(a: PreviewCandidate[], b: PreviewCandidate[]): void {
equal(a.length, b.length)
for (let i = 0; i < a.length; i++) {
let aFix = { ...a[i], text: undefined }
let bFix = { ...b[i], text: undefined }
deepStrictEqual(aFix, bFix)
}
}
test('empty from beginning', () => {
keepMount(previewUrlError)
keepMount(previewCandidatesLoading)
keepMount(previewCandidates)
equal(previewUrlError.get(), undefined)
equal(previewCandidatesLoading.get(), false)
deepStrictEqual(previewCandidates.get(), [])
})
test('validates URL', () => {
keepMount(previewUrlError)
setPreviewUrl('mailto:[email protected]')
equal(previewUrlError.get(), 'invalidUrl')
setPreviewUrl('http://a b')
equal(previewUrlError.get(), 'invalidUrl')
setPreviewUrl('not URL')
equal(previewUrlError.get(), 'invalidUrl')
equal(previewNoResults.get(), false)
})
test('uses HTTPS for specific domains', async () => {
keepMount(previewCandidatesLoading)
keepMount(previewCandidates)
spyOn(loaders.rss, 'getMineLinksFromText', () => [])
spyOn(loaders.atom, 'getMineLinksFromText', () => [])
spyOn(loaders.jsonFeed, 'getMineLinksFromText', () => [])
spyOn(loaders.rss, 'getSuggestedLinksFromText', () => [])
spyOn(loaders.atom, 'getSuggestedLinksFromText', () => [])
spyOn(loaders.jsonFeed, 'getSuggestedLinksFromText', () => [])
expectRequest('https://twitter.com/blog').andRespond(200, '')
setPreviewUrl('twitter.com/blog')
await setTimeout(10)
expectRequest('https://twitter.com/blog').andRespond(200, '')
setPreviewUrl('http://twitter.com/blog')
await setTimeout(10)
})
test('cleans state', async () => {
keepMount(previewUrlError)
keepMount(previewCandidates)
keepMount(previewPosts)
keepMount(previewCandidate)
let reply = expectRequest('http://example.com').andWait()
setPreviewUrl('example.com')
await setTimeout(10)
clearPreview()
equal(previewUrlError.get(), undefined)
deepStrictEqual(previewCandidates.get(), [])
equal(reply.aborted, true)
equal(previewPosts.get(), undefined)
equal(previewCandidate.get(), undefined)
setPreviewUrl('not URL')
clearPreview()
equal(previewUrlError.get(), undefined)
deepStrictEqual(previewCandidates.get(), [])
})
test('is ready for network errors', async () => {
keepMount(previewCandidatesLoading)
keepMount(previewUrlError)
let reply = expectRequest('http://example.com').andWait()
setPreviewUrl('example.com')
equal(previewCandidatesLoading.get(), true)
equal(previewUrlError.get(), undefined)
equal(previewNoResults.get(), false)
await reply(404)
equal(previewCandidatesLoading.get(), false)
equal(previewUrlError.get(), 'unloadable')
equal(previewNoResults.get(), false)
setPreviewUrl('')
equal(previewCandidatesLoading.get(), false)
equal(previewUrlError.get(), undefined)
equal(previewNoResults.get(), false)
})
test('aborts all HTTP requests on URL change', async () => {
let reply1 = expectRequest('http://example.com').andWait()
setPreviewUrl('example.com')
setPreviewUrl('')
await setTimeout(10)
equal(reply1.aborted, true)
let reply2 = expectRequest('http://other.com').andWait()
setPreviewUrl('other.com')
clearPreview()
await setTimeout(10)
equal(reply2.aborted, true)
})
test('detects RSS links', async () => {
keepMount(previewCandidatesLoading)
keepMount(previewUrlError)
keepMount(previewCandidates)
let replyHtml = expectRequest('http://example.com').andWait()
setPreviewUrl('example.com')
await setTimeout(10)
equal(previewCandidatesLoading.get(), true)
equal(previewUrlError.get(), undefined)
deepStrictEqual(previewCandidates.get(), [])
equal(previewNoResults.get(), false)
let replyRss = expectRequest('http://example.com/news').andWait()
replyHtml(
200,
'<!DOCTYPE html><html><head>' +
'<link rel="alternate" type="application/rss+xml" href="/news">' +
'</head></html>'
)
await setTimeout(10)
equal(previewCandidatesLoading.get(), true)
equal(previewUrlError.get(), undefined)
deepStrictEqual(previewCandidates.get(), [])
equal(previewNoResults.get(), false)
let rss = '<rss><channel><title> News </title></channel></rss>'
replyRss(200, rss, 'application/rss+xml')
await setTimeout(10)
equal(previewCandidatesLoading.get(), false)
equal(previewUrlError.get(), undefined)
equalWithText(previewCandidates.get(), [
{
loader: 'rss',
title: 'News',
url: 'http://example.com/news'
}
])
equal(previewNoResults.get(), false)
})
test('is ready for empty title', async () => {
keepMount(previewCandidatesLoading)
keepMount(previewUrlError)
keepMount(previewCandidates)
expectRequest('http://example.com').andRespond(
200,
`<html>
<link type="application/atom+xml" href="http://other.com/atom">
</html>`
)
let rss = '<feed><title></title></feed>'
expectRequest('http://other.com/atom').andRespond(200, rss, 'text/xml')
setPreviewUrl('example.com')
await setTimeout(10)
equal(previewCandidatesLoading.get(), false)
equal(previewUrlError.get(), undefined)
equalWithText(previewCandidates.get(), [
{
loader: 'atom',
title: '',
url: 'http://other.com/atom'
}
])
})
test('ignores duplicate links', async () => {
keepMount(previewCandidatesLoading)
keepMount(previewUrlError)
keepMount(previewCandidates)
expectRequest('http://example.com').andRespond(
200,
`<html>
<link type="application/atom+xml" href="http://other.com/atom">
<a href="http://other.com/atom">Feed</a>
</html>`
)
let rss = '<feed><title>Feed</title></feed>'
expectRequest('http://other.com/atom').andRespond(200, rss, 'text/xml')
setPreviewUrl('example.com')
await setTimeout(10)
equal(previewCandidatesLoading.get(), false)
equal(previewUrlError.get(), undefined)
equalWithText(previewCandidates.get(), [
{
loader: 'atom',
title: 'Feed',
url: 'http://other.com/atom'
}
])
})
test('looks for popular RSS, Atom and JsonFeed places', async () => {
keepMount(previewCandidatesLoading)
keepMount(previewUrlError)
keepMount(previewCandidates)
expectRequest('http://example.com').andRespond(200, '<html>Nothing</html>')
let atom = '<feed><title></title></feed>'
expectRequest('http://example.com/feed').andRespond(404)
expectRequest('http://example.com/atom').andRespond(200, atom, 'text/xml')
expectRequest('http://example.com/feed.json').andRespond(404)
expectRequest('http://example.com/rss').andRespond(404)
setPreviewUrl('example.com')
await setTimeout(10)
equal(previewCandidatesLoading.get(), false)
equal(previewUrlError.get(), undefined)
equalWithText(previewCandidates.get(), [
{
loader: 'atom',
title: '',
url: 'http://example.com/atom'
}
])
})
test('shows if unknown URL', async () => {
keepMount(previewCandidatesLoading)
keepMount(previewUrlError)
keepMount(previewCandidates)
expectRequest('http://example.com').andRespond(200, '<html>Nothing</html>')
expectRequest('http://example.com/feed').andRespond(404)
expectRequest('http://example.com/atom').andRespond(404)
expectRequest('http://example.com/feed.json').andRespond(404)
expectRequest('http://example.com/rss').andRespond(404)
setPreviewUrl('example.com')
await setTimeout(10)
equal(previewCandidatesLoading.get(), false)
equal(previewUrlError.get(), undefined)
deepStrictEqual(previewCandidates.get(), [])
equal(previewNoResults.get(), true)
})
test('always keep the same order of candidates', async () => {
keepMount(previewCandidates)
expectRequest('http://example.com').andRespond(200, '<html>Nothing</html>')
expectRequest('http://example.com/feed').andRespond(404)
expectRequest('http://example.com/atom').andRespond(
200,
'<feed><title>Atom</title></feed>',
'application/rss+xml'
)
expectRequest('http://example.com/feed.json').andRespond(
200,
'{ "version": "https://jsonfeed.org/version/1.1", "title": "JsonFeed", "items": [] }',
'application/json'
)
expectRequest('http://example.com/rss').andRespond(
200,
'<rss><channel><title>RSS</title></channel></rss>',
'application/rss+xml'
)
setPreviewUrl('example.com')
await setTimeout(10)
deepStrictEqual(
previewCandidates.get().map(i => i.title),
['Atom', 'JsonFeed', 'RSS']
)
clearPreview()
expectRequest('http://example.com').andRespond(200, '<html>Nothing</html>')
expectRequest('http://example.com/feed').andRespond(404)
let atom = expectRequest('http://example.com/atom').andWait()
let jsonFeed = expectRequest('http://example.com/feed.json').andWait()
expectRequest('http://example.com/rss').andRespond(
200,
'<rss><channel><title>RSS</title></channel></rss>',
'application/rss+xml'
)
setPreviewUrl('example.com')
await setTimeout(10)
atom(200, '<feed><title>Atom</title></feed>', 'application/rss+xml')
jsonFeed(
200,
'{ "version": "https://jsonfeed.org/version/1.1", "title": "JsonFeed", "items": [] }',
'application/json'
)
await setTimeout(10)
deepStrictEqual(
previewCandidates.get().map(i => i.title),
['Atom', 'JsonFeed', 'RSS']
)
})
test('tracks current candidate', async () => {
keepMount(previewCandidatesLoading)
keepMount(previewUrlError)
keepMount(previewCandidates)
keepMount(previewCandidate)
let getAtomPosts = spyOn(loaders.atom, 'getPosts')
let getRssPosts = spyOn(loaders.rss, 'getPosts')
let getJsonFeedPosts = spyOn(loaders.jsonFeed, 'getPosts')
expectRequest('http://example.com').andRespond(200, '<html>Nothing</html>')
expectRequest('http://example.com/feed').andRespond(404)
expectRequest('http://example.com/atom').andRespond(
200,
'<feed><title>Atom</title></feed>',
'application/rss+xml'
)
expectRequest('http://example.com/feed.json').andRespond(
200,
'{ "version": "https://jsonfeed.org/version/1.1", "title": "JsonFeed", "items": [] }',
'application/json'
)
expectRequest('http://example.com/rss').andRespond(
200,
'<rss><channel><title>RSS</title></channel></rss>',
'application/rss+xml'
)
getAtomPosts.nextResult(
createPostsList([{ media: [], originId: '1', url: '1' }], undefined)
)
setPreviewUrl('example.com')
await setTimeout(10)
equal(previewCandidatesLoading.get(), false)
equal(previewUrlError.get(), undefined)
equal(previewCandidates.get().length, 3)
equal(previewCandidate.get(), 'http://example.com/atom')
deepStrictEqual(previewPosts.get()!.get(), {
hasNext: false,
isLoading: false,
list: [{ media: [], originId: '1', url: '1' }]
})
equal(getAtomPosts.calls.length, 1)
equal(getAtomPosts.calls[0]![1], 'http://example.com/atom')
getRssPosts.nextResult(
createPostsList([{ media: [], originId: '2', url: '2' }], undefined)
)
setPreviewCandidate('http://example.com/rss')
await setTimeout(10)
equal(previewCandidate.get(), 'http://example.com/rss')
deepStrictEqual(previewPosts.get()!.get(), {
hasNext: false,
isLoading: false,
list: [{ media: [], originId: '2', url: '2' }]
})
equal(getRssPosts.calls.length, 1)
equal(getRssPosts.calls[0]![1], 'http://example.com/rss')
getJsonFeedPosts.nextResult(
createPostsList([{ media: [], originId: '3', url: '3' }], undefined)
)
setPreviewCandidate('http://example.com/feed.json')
await setTimeout(10)
equal(previewCandidate.get(), 'http://example.com/feed.json')
deepStrictEqual(previewPosts.get()!.get(), {
hasNext: false,
isLoading: false,
list: [{ media: [], originId: '3', url: '3' }]
})
equal(getJsonFeedPosts.calls.length, 1)
equal(getJsonFeedPosts.calls[0]![1], 'http://example.com/feed.json')
setPreviewCandidate('http://example.com/atom')
await setTimeout(10)
equal(previewCandidate.get(), 'http://example.com/atom')
deepStrictEqual(previewPosts.get()!.get(), {
hasNext: false,
isLoading: false,
list: [{ media: [], originId: '1', url: '1' }]
})
equal(getAtomPosts.calls.length, 1)
setPreviewCandidate('http://example.com/rss')
await setTimeout(10)
equal(previewCandidate.get(), 'http://example.com/rss')
deepStrictEqual(previewPosts.get()!.get(), {
hasNext: false,
isLoading: false,
list: [{ media: [], originId: '2', url: '2' }]
})
equal(getRssPosts.calls.length, 1)
setPreviewCandidate('http://example.com/feed.json')
await setTimeout(10)
equal(previewCandidate.get(), 'http://example.com/feed.json')
deepStrictEqual(previewPosts.get()!.get(), {
hasNext: false,
isLoading: false,
list: [{ media: [], originId: '3', url: '3' }]
})
equal(getJsonFeedPosts.calls.length, 1)
})
test('tracks added status of candidate', async () => {
keepMount(previewCandidateAdded)
expectRequest('https://a.com/atom').andRespond(
200,
'<feed><title>Atom</title></feed>',
'text/xml'
)
setPreviewUrl('https://a.com/atom')
equal(previewCandidateAdded.get(), undefined)
await setTimeout(10)
equal(previewCandidateAdded.get(), false)
await addFeed(
testFeed({
loader: 'rss',
title: 'RSS',
url: 'https://a.com/rss'
})
)
equal(previewCandidateAdded.get(), false)
let id = await addFeed(
testFeed({
loader: 'atom',
title: 'Atom',
url: 'https://a.com/atom'
})
)
equal(previewCandidateAdded.get(), id)
expectRequest('https://b.com/atom').andRespond(
200,
'<feed><title>Atom</title></feed>',
'text/xml'
)
setPreviewUrl('https://b.com/atom')
equal(previewCandidateAdded.get(), undefined)
})
test('adds current preview candidate', async () => {
keepMount(previewCandidateAdded)
let $feeds = getFeeds()
keepMount($feeds)
await $feeds.loading
expectRequest('https://a.com/atom').andRespond(
200,
'<feed><title>Atom</title>' +
'<entry><id>2</id><updated>2023-07-01T00:00:00Z</updated></entry>' +
'<entry><id>1</id><updated>2023-06-01T00:00:00Z</updated></entry>' +
'</feed>',
'text/xml'
)
setPreviewUrl('https://a.com/atom')
await setTimeout(10)
equal(ensureLoaded($feeds.get()).list.length, 0)
await addPreviewCandidate()
equal(typeof previewCandidateAdded.get(), 'string')
equal(ensureLoaded($feeds.get()).list.length, 1)
equal(ensureLoaded($feeds.get()).list[0]!.lastOriginId, '2')
equal(ensureLoaded($feeds.get()).list[0]!.lastPublishedAt, 1688169600)
})
test('adds last post for current preview', async () => {
keepMount(previewCandidateAdded)
let $posts = getPosts({})
keepMount($posts)
await $posts.loading
expectRequest('https://a.com/atom').andRespond(
200,
'<feed><title>Atom</title>' +
'<entry><id>2</id><updated>2023-07-01T00:00:00Z</updated></entry>' +
'<entry><id>1</id><updated>2023-06-01T00:00:00Z</updated></entry>' +
'</feed>',
'text/xml'
)
setPreviewUrl('https://a.com/atom')
await setTimeout(10)
equal(ensureLoaded($posts.get()).list.length, 0)
await addPreviewCandidate()
equal(ensureLoaded($posts.get()).list.length, 1)
equal(ensureLoaded($posts.get()).list[0]!.originId, '2')
})
test('adds current preview candidate without posts', async () => {
keepMount(previewCandidateAdded)
let $feeds = getFeeds()
keepMount($feeds)
await $feeds.loading
expectRequest('https://a.com/atom').andRespond(
200,
'<feed><title>Atom</title></feed>',
'text/xml'
)
setPreviewUrl('https://a.com/atom')
await setTimeout(10)
equal(ensureLoaded($feeds.get()).list.length, 0)
await addPreviewCandidate()
equal(typeof previewCandidateAdded.get(), 'string')
equal(ensureLoaded($feeds.get()).list.length, 1)
equal(ensureLoaded($feeds.get()).list[0]!.lastOriginId, undefined)
let lastPublishedAt = ensureLoaded($feeds.get()).list[0]!.lastPublishedAt!
let now = Date.now() / 1000
ok(lastPublishedAt <= now)
ok(lastPublishedAt > now / 1000 - 2000)
})
test('changes URL during typing in the field', async () => {
equal(previewUrl.get(), '')
setPreviewUrl('')
equal(previewUrl.get(), '')
expectRequest('http://example.com').andRespond(200, '<html>Nothing</html>')
expectRequest('http://example.com/feed').andRespond(404)
expectRequest('http://example.com/atom').andRespond(404)
expectRequest('http://example.com/feed.json').andRespond(404)
expectRequest('http://example.com/rss').andRespond(404)
setPreviewUrl('example.com')
equal(previewUrl.get(), 'http://example.com')
await setTimeout(10)
onPreviewUrlType('other')
equal(previewUrl.get(), 'http://example.com')
onPreviewUrlType('other.')
equal(previewUrl.get(), 'http://example.com')
expectRequest('http://other.net').andRespond(200, '<html>Nothing</html>')
expectRequest('http://other.net/feed').andRespond(404)
expectRequest('http://other.net/atom').andRespond(404)
expectRequest('http://other.net/feed.json').andRespond(404)
expectRequest('http://other.net/rss').andRespond(404)
onPreviewUrlType('other.net')
await setTimeout(500)
equal(previewUrl.get(), 'http://other.net')
expectRequest('http://example.com').andRespond(200, '<html>Nothing</html>')
expectRequest('http://example.com/feed').andRespond(404)
expectRequest('http://example.com/atom').andRespond(404)
expectRequest('http://example.com/feed.json').andRespond(404)
expectRequest('http://example.com/rss').andRespond(404)
onPreviewUrlType('other.net/some')
setPreviewUrl('example.com')
await setTimeout(500)
equal(previewUrl.get(), 'http://example.com')
})
test('syncs URL with router', () => {
deepStrictEqual(router.get(), { params: {}, route: 'add' })
expectRequest('http://example.com').andRespond(404)
setPreviewUrl('example.com')
deepStrictEqual(router.get(), {
params: { url: 'http://example.com' },
route: 'add'
})
expectRequest('https://other.com').andRespond(404)
setPreviewUrl('https://other.com')
deepStrictEqual(router.get(), {
params: { url: 'https://other.com' },
route: 'add'
})
expectRequest('http://example.com').andRespond(404)
setBaseTestRoute({ params: { url: 'http://example.com' }, route: 'add' })
deepStrictEqual(previewUrl.get(), 'http://example.com')
setBaseTestRoute({ params: {}, route: 'add' })
deepStrictEqual(previewUrl.get(), '')
expectRequest('https://new.com').andRespond(404)
setPreviewUrl('https://new.com')
setBaseTestRoute({ params: {}, route: 'home' })
deepStrictEqual(previewUrl.get(), '')
})
test('show candidate on wide screen', async () => {
setIsMobile(false)
expectRequest('https://a.com/atom').andRespond(
200,
'<feed><title>Atom</title>' +
'<entry><id>2</id><updated>2023-07-01T00:00:00Z</updated></entry>' +
'<entry><id>1</id><updated>2023-06-01T00:00:00Z</updated></entry>' +
'</feed>',
'text/xml'
)
setPreviewUrl('https://a.com/atom')
await setTimeout(10)
deepStrictEqual(router.get(), {
params: { candidate: 'https://a.com/atom', url: 'https://a.com/atom' },
route: 'add'
})
equal(currentCandidate.get(), undefined)
equal(previewCandidate.get(), 'https://a.com/atom')
})
test('do not show candidate on mobile screen', async () => {
setIsMobile(true)
expectRequest('https://a.com/atom').andRespond(
200,
'<feed><title>Atom</title>' +
'<entry><id>2</id><updated>2023-07-01T00:00:00Z</updated></entry>' +
'<entry><id>1</id><updated>2023-06-01T00:00:00Z</updated></entry>' +
'</feed>',
'text/xml'
)
setPreviewUrl('https://a.com/atom')
await setTimeout(10)
deepStrictEqual(router.get(), {
params: { url: 'https://a.com/atom' },
route: 'add'
})
equal(previewCandidate.get(), undefined)
})
test('redirect to candidates list if no current candidate', async () => {
setBaseTestRoute({
params: {
candidate: 'unknown candidate',
url: 'https://a.com/atom'
},
route: 'add'
})
await setTimeout(10)
equal(previewCandidate.get(), undefined)
deepStrictEqual(router.get(), {
params: { url: 'https://a.com/atom' },
route: 'add'
})
})