forked from hplush/slowreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.test.ts
74 lines (60 loc) · 1.77 KB
/
menu.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
import { cleanStores } from 'nanostores'
import { equal } from 'node:assert'
import { afterEach, beforeEach, test } from 'node:test'
import { setTimeout } from 'node:timers/promises'
import {
addCategory,
addFeed,
addPost,
closeMenu,
fastCategories,
isMenuOpened,
openMenu,
setBaseTestRoute,
testFeed,
testPost
} from '../index.ts'
import { cleanClientTest, enableClientTest } from './utils.ts'
beforeEach(() => {
enableClientTest()
})
afterEach(async () => {
cleanStores(fastCategories, isMenuOpened)
await setTimeout(10)
await cleanClientTest()
})
test('do not open menu if fast has 1 category', async () => {
setBaseTestRoute({ params: {}, route: 'add' })
let idA = await addCategory({ title: 'A' })
await addFeed(testFeed({ categoryId: idA, reading: 'fast' }))
await addFeed(testFeed({ categoryId: idA, reading: 'fast' }))
let idB = await addCategory({ title: 'B' })
let feedB = await addFeed(testFeed({ categoryId: idB, reading: 'slow' }))
await addPost(testPost({ feedId: feedB, reading: 'slow' }))
openMenu()
setBaseTestRoute({ params: {}, route: 'fast' })
await setTimeout(10)
equal(isMenuOpened.get(), false)
closeMenu()
await setTimeout(10)
equal(isMenuOpened.get(), false)
openMenu()
setBaseTestRoute({ params: {}, route: 'slow' })
await setTimeout(10)
equal(isMenuOpened.get(), true)
closeMenu()
equal(isMenuOpened.get(), false)
openMenu()
setBaseTestRoute({ params: {}, route: 'add' })
await setTimeout(10)
equal(isMenuOpened.get(), true)
closeMenu()
equal(isMenuOpened.get(), false)
await addFeed(testFeed({ categoryId: idB, reading: 'fast' }))
await setTimeout(10)
openMenu()
setBaseTestRoute({ params: {}, route: 'fast' })
await setTimeout(10)
equal(isMenuOpened.get(), true)
closeMenu()
})