-
Notifications
You must be signed in to change notification settings - Fork 4
/
MentorsSection.spec.js
201 lines (151 loc) · 4.69 KB
/
MentorsSection.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
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
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 MentorsSection from 'admin/dashboard/components/MentorsSection'
import PieChart from 'components/PieChart'
const localVue = createLocalVue()
localVue.use(Vuex)
describe('Admin Dashboard - MentorSection component', () => {
let wrapper
const onboardingMentors = {
totals: {
mentors: '402',
},
labels: [
'Fully onboarded - (75%)',
'Not fully onboarded - (25%)',
],
data: [
1,
0,
],
urls: [
'/fully/onboarded/',
'/not/fully/onboarded/',
],
}
const returningMentors = {
totals: {
mentors: '402',
},
labels: [
'Returning mentors – (25%)',
'New mentors – (75%)',
],
data: [
1,
3,
],
}
beforeEach(() => {
const initialState = Object.assign({}, state, {
chartEndpoints: {
'onboarding_mentors': '/onboarding/mentors',
'returning_mentors': '/returning/mentors',
},
cachedStates: {
'/onboarding/mentors': onboardingMentors,
'/returning/mentors': returningMentors,
},
})
const storeMocks = mockStore.createMocks({
state: initialState,
})
wrapper = shallowMount(
MentorsSection, {
localVue,
store: storeMocks.store,
}
)
wrapper.vm.totals = onboardingMentors.totals
})
it('has a name attribute', () => {
expect(MentorsSection.name).toEqual('mentors-section')
})
it('extends the DashboardSection component', () => {
expect(MentorsSection.extends).toEqual(DashboardSection)
})
describe('computed properties', () => {
describe('onboardingMentorsEndpoint', () => {
it('returns an AJAX endpoint for the onboarding mentors chart', () => {
expect(wrapper.vm.onboardingMentorsEndpoint)
.toEqual('/onboarding/mentors')
})
})
describe('onboardingMentorsChartData', () => {
it('returns the cached chart data for the onboarding mentors chart', () => {
expect(wrapper.vm.onboardingMentorsChartData)
.toEqual(onboardingMentors)
const initialState = Object.assign({}, state, {
cachedStates: {},
})
const storeMocks = mockStore.createMocks({
state: initialState,
})
wrapper = shallowMount(
MentorsSection, {
localVue,
store: storeMocks.store,
}
)
expect(wrapper.vm.onboardingMentorsChartData)
.toEqual({})
})
})
describe('returningMentorsEndpoint', () => {
it('returns an AJAX endpoint for the returning mentors chart', () => {
expect(wrapper.vm.returningMentorsEndpoint)
.toEqual('/returning/mentors')
})
})
describe('returningMentorsChartData', () => {
it('returns the cached chart data for the returning mentors chart', () => {
expect(wrapper.vm.returningMentorsChartData)
.toEqual(returningMentors)
const initialState = Object.assign({}, state, {
cachedStates: {},
})
const storeMocks = mockStore.createMocks({
state: initialState,
})
wrapper = shallowMount(
MentorsSection, {
localVue,
store: storeMocks.store,
}
)
expect(wrapper.vm.returningMentorsChartData)
.toEqual({})
})
})
})
describe('HTML markup', () => {
it('contains the correct markup', () => {
expect(wrapper.element.getAttribute('id')).toEqual('mentors')
expect(wrapper.find('h3 span').text()).toEqual('(402)')
const charts = wrapper.findAll('.tabs__tab-content')
const onboardingChart = charts.at(0)
const returningChart = charts.at(1)
expect(onboardingChart.find('h6').text())
.toEqual('Onboarding')
expect(onboardingChart.find(PieChart).exists()).toBe(true)
expect(returningChart.find('h6').text())
.toEqual('New vs. Returning')
expect(returningChart.find(PieChart).exists()).toBe(true)
})
it('hides the mentors count label if the mentors total is not found', async () => {
wrapper.vm.totals = {}
await wrapper.vm.$nextTick()
expect(wrapper.find('h3 span').exists()).toBe(false)
})
it('hides the mentors 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)
})
})
})