-
Notifications
You must be signed in to change notification settings - Fork 4
/
TopCountriesSection.spec.js
142 lines (105 loc) · 3.33 KB
/
TopCountriesSection.spec.js
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
import Vuex from 'vuex'
import { shallowMount, createLocalVue } from '@vue/test-utils'
import state from 'admin/dashboard/store/state'
import mockStore from 'admin/dashboard/store/__mocks__'
import DashboardSection from 'admin/dashboard/components/DashboardSection'
import TopCountriesSection from 'admin/dashboard/components/TopCountriesSection'
import BarChart from 'components/BarChart'
const localVue = createLocalVue()
localVue.use(Vuex)
describe('Admin Dashboard - TopCountriesSection component', () => {
let wrapper
const topCountries = {
totals: {
top_countries: '19,765',
},
labels: [ 'US', 'Spain', 'Mexico', 'Ethiopia', 'Germany', 'India' ],
datasets: [
{
label: 'Students',
data: [ 400, 500, 600, 900, 300, 100 ],
},
{
label: 'Mentors',
data: [ 100, 200, 300, 500, 100, 64 ],
},
{
label: 'Judges',
data: [ 20, 40, 60, 80, 10, 3 ],
}
]
}
beforeEach(() => {
const initialState = Object.assign({}, state, {
chartEndpoints: {
'top_countries': '/top_countries/endpoint',
},
cachedStates: {
'/top_countries/endpoint': topCountries,
},
})
const storeMocks = mockStore.createMocks({
state: initialState,
})
wrapper = shallowMount(
TopCountriesSection, {
localVue,
store: storeMocks.store,
}
)
wrapper.vm.totals = topCountries.totals
})
it('has a name attribute', () => {
expect(TopCountriesSection.name).toEqual('top-countries-section')
})
it('extends the DashboardSection component', () => {
expect(TopCountriesSection.extends).toEqual(DashboardSection)
})
describe('computed properties', () => {
describe('topCountriesEndpoint', () => {
it('returns an AJAX endpoint for the top countries chart', () => {
expect(wrapper.vm.topCountriesEndpoint)
.toEqual('/top_countries/endpoint')
})
})
describe('topCountriesChartData', () => {
it('returns the cached chart data for the top countries chart', () => {
expect(wrapper.vm.topCountriesChartData)
.toEqual(topCountries)
const initialState = Object.assign({}, state, {
cachedStates: {},
})
const storeMocks = mockStore.createMocks({
state: initialState,
})
wrapper = shallowMount(
TopCountriesSection, {
localVue,
store: storeMocks.store,
}
)
expect(wrapper.vm.topCountriesChartData)
.toEqual({})
})
})
})
describe('HTML markup', () => {
it('contains the correct markup', () => {
expect(wrapper.element.getAttribute('id')).toEqual('top-countries')
expect(wrapper.find('h3 span').text()).toEqual('(19,765)')
expect(wrapper.find(BarChart).exists()).toBe(true)
})
it('hides the top countries count label if the top countries total is not found', async () => {
wrapper.vm.totals = {}
await wrapper.vm.$nextTick()
expect(wrapper.find('h3 span').exists()).toBe(false)
})
it('hides the top countries count label if the hideTotal prop is true', async () => {
wrapper.setProps({
hideTotal: true,
})
await wrapper.vm.$nextTick()
expect(wrapper.find('h3 span').exists()).toBe(false)
})
})
})