-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTimeline.spec.ts
83 lines (71 loc) · 2.01 KB
/
Timeline.spec.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
import { Store } from '../../src/store'
import { mount, flushPromises, RouterLinkStub } from '@vue/test-utils'
import Timeline from '../../src/components/Timeline.vue'
import { today, thisWeek, thisMonth } from '../../src/mocks'
jest.mock('axios', () => ({
get: (url: string) => {
return Promise.resolve({
data: [today, thisWeek, thisMonth]
})
}
}))
function mountTimeline() {
const store = new Store({
posts: {
ids: [],
all: new Map(),
loaded: false
},
authors: {
ids: [],
all: new Map(),
loaded: false,
currentUserId: undefined
}
})
const testComp = {
components: { Timeline },
template: `
<suspense>
<template #default>
<timeline />
</template>
<template #fallback>
Loading...
</template>
</suspense>
`
}
return mount(testComp, {
global: {
components: {
RouterLink: RouterLinkStub
},
plugins: [store]
}
})
}
describe('Timeline', () => {
it('renders today post default', async () => {
const wrapper = mountTimeline()
// nextTick -> Vue internal promises
// axios -> flushPromises
await flushPromises()
expect(wrapper.html()).toContain(today.created.format('Do MMM'))
})
it('update when the period is click', async () => {
const wrapper = mountTimeline()
await flushPromises()
await wrapper.get('[data-test="This Week"]').trigger('click') // nextTick
expect(wrapper.html()).toContain(today.created.format('Do MMM'))
expect(wrapper.html()).toContain(thisWeek.created.format('Do MMM'))
})
it('update when the period is click', async () => {
const wrapper = mountTimeline()
await flushPromises()
await wrapper.get('[data-test="This Month"]').trigger('click') // nextTick
expect(wrapper.html()).toContain(today.created.format('Do MMM'))
expect(wrapper.html()).toContain(thisWeek.created.format('Do MMM'))
expect(wrapper.html()).toContain(thisMonth.created.format('Do MMM'))
})
})