generated from bcgov/bcrs-template-ui
-
Notifications
You must be signed in to change notification settings - Fork 51
/
EntityInfo.spec.ts
467 lines (391 loc) · 14.8 KB
/
EntityInfo.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
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
import Vue from 'vue'
import Vuetify from 'vuetify'
import VueRouter from 'vue-router'
import { mount, shallowMount } from '@vue/test-utils'
import { getVuexStore } from '@/store'
import EntityInfo from '@/components/EntityInfo.vue'
import { StaffComments } from '@bcrs-shared-components/staff-comments'
import mockRouter from './mockRouter'
import { min } from 'lodash'
Vue.use(Vuetify)
Vue.use(VueRouter)
const vuetify = new Vuetify({})
const store = getVuexStore() as any // remove typings for unit tests
describe('EntityInfo - data', () => {
const router = mockRouter.mock()
it('displays Business entity info properly', async () => {
// session storage must be set before mounting component
sessionStorage.clear()
sessionStorage.setItem('BUSINESS_ID', 'CP0001191')
// set store properties
store.state.entityName = 'My Business'
store.state.goodStanding = true
store.state.entityType = 'CP'
store.state.businessNumber = '123456789'
store.state.identifier = 'CP0001191'
store.state.businessEmail = 'business@mail.zzz'
store.state.businessPhone = '(111)222-3333'
store.state.businessPhoneExtension = '444'
// mount the component and wait for everything to stabilize
const wrapper = shallowMount(EntityInfo, { store, vuetify, router })
await Vue.nextTick()
// verify displayed text
expect(wrapper.find('#entity-legal-name').text()).toBe('My Business')
expect(wrapper.find('#entity-business-number').text()).toBe('123456789')
expect(wrapper.find('#entity-incorporation-number').text()).toBe('CP0001191')
expect(wrapper.find('#entity-business-email span').text()).toBe('business@mail.zzz')
expect(wrapper.find('#entity-business-phone span').text()).toBe('(111)222-3333 x444')
expect(wrapper.find('#ia-reg-subtitle').exists()).toBeFalsy()
expect(wrapper.find('#nr-number').exists()).toBeFalsy()
})
it('displays Draft Incorp App entity info properly - Named Company', async () => {
sessionStorage.clear()
sessionStorage.setItem('TEMP_REG_NUMBER', 'T123456789')
store.state.entityName = 'My Named Company'
store.state.entityStatus = 'DRAFT_APP'
store.state.entityType = 'BEN'
store.state.nameRequest = { nrNumber: 'NR 1234567' }
const wrapper = shallowMount(EntityInfo, { store, vuetify, router })
await Vue.nextTick()
expect(wrapper.find('#incorp-app-title').text()).toBe('My Named Company')
expect(wrapper.find('#entity-status').exists()).toBeFalsy()
expect(wrapper.find('#entity-business-number').exists()).toBeFalsy()
expect(wrapper.find('#entity-incorporation-number').exists()).toBeFalsy()
expect(wrapper.find('#entity-business-email').exists()).toBeFalsy()
expect(wrapper.find('#entity-business-phone').exists()).toBeFalsy()
expect(wrapper.find('#ia-reg-subtitle').text()).toBe('BC Benefit Company Incorporation Application')
expect(wrapper.find('#nr-number').text()).toBe('NR 1234567')
})
it('displays Draft Incorp App entity info properly - Numbered Company', async () => {
sessionStorage.clear()
sessionStorage.setItem('TEMP_REG_NUMBER', 'T123456789')
store.state.entityName = null
store.state.entityStatus = 'DRAFT_APP'
store.state.entityType = 'BEN'
store.state.nameRequest = null
const wrapper = shallowMount(EntityInfo, { store, vuetify, router })
await Vue.nextTick()
expect(wrapper.find('#incorp-app-title').text()).toBe('Numbered Benefit Company')
expect(wrapper.find('#entity-status').exists()).toBeFalsy()
expect(wrapper.find('#entity-business-number').exists()).toBeFalsy()
expect(wrapper.find('#entity-incorporation-number').exists()).toBeFalsy()
expect(wrapper.find('#entity-business-email').exists()).toBeFalsy()
expect(wrapper.find('#entity-business-phone').exists()).toBeFalsy()
expect(wrapper.find('#ia-reg-subtitle').text()).toBe('BC Benefit Company Incorporation Application')
expect(wrapper.find('#nr-number').exists()).toBeFalsy()
})
it('displays Paid (Named) Incorp App entity info properly', async () => {
sessionStorage.clear()
sessionStorage.setItem('TEMP_REG_NUMBER', 'T123456789')
store.state.entityName = 'My Future Company'
store.state.entityStatus = 'FILED_APP'
store.state.entityType = 'BEN'
store.state.nameRequest = { nrNumber: 'NR 1234567' }
const wrapper = shallowMount(EntityInfo, { store, vuetify, router })
await Vue.nextTick()
expect(wrapper.find('#incorp-app-title').text()).toBe('My Future Company')
expect(wrapper.find('#entity-status').exists()).toBeFalsy()
expect(wrapper.find('#entity-business-number').exists()).toBeFalsy()
expect(wrapper.find('#entity-incorporation-number').exists()).toBeFalsy()
expect(wrapper.find('#entity-business-email').exists()).toBeFalsy()
expect(wrapper.find('#entity-business-phone').exists()).toBeFalsy()
expect(wrapper.find('#ia-reg-subtitle').text()).toBe('BC Benefit Company Incorporation Application')
expect(wrapper.find('#nr-number').text()).toBe('NR 1234567')
})
it('handles empty data', async () => {
sessionStorage.clear()
store.state.entityName = null
store.state.entityType = null
store.state.entityStatus = null
store.state.businessNumber = null
store.state.identifier = null
store.state.businessEmail = null
store.state.businessPhone = null
store.state.businessPhoneExtension = null
store.state.nameRequest = null
const wrapper = shallowMount(EntityInfo, { store, vuetify, router })
await Vue.nextTick()
expect(wrapper.find('#entity-legal-name').exists()).toBeFalsy()
expect(wrapper.find('#entity-status').exists()).toBeFalsy()
expect(wrapper.find('#entity-business-number').exists()).toBeFalsy()
expect(wrapper.find('#entity-incorporation-number').exists()).toBeFalsy()
expect(wrapper.find('#entity-business-email').exists()).toBeFalsy()
expect(wrapper.find('#entity-business-phone').exists()).toBeFalsy()
expect(wrapper.find('#ia-reg-subtitle').exists()).toBeFalsy()
expect(wrapper.find('#nr-number').exists()).toBeFalsy()
})
})
describe('EntityInfo - Staff Comments', () => {
const router = mockRouter.mock()
it('does not display Staff Comments component when there is no business id', async () => {
// init session storage + store
sessionStorage.clear()
sessionStorage.setItem('BUSINESS_ID', null)
store.state.keycloakRoles = []
const wrapper = mount(EntityInfo, { vuetify, store, router })
await Vue.nextTick()
expect(wrapper.find(StaffComments).exists()).toBe(false)
wrapper.destroy()
})
it('does not display Staff Comments component when not allowed', async () => {
// init session storage + store
sessionStorage.clear()
sessionStorage.setItem('BUSINESS_ID', 'BC1234567')
store.state.keycloakRoles = []
const wrapper = mount(EntityInfo, { vuetify, store, router })
await Vue.nextTick()
expect(wrapper.find(StaffComments).exists()).toBe(false)
wrapper.destroy()
})
it('displays Staff Comments component when conditions are met', async () => {
// init session storage + store
sessionStorage.clear()
sessionStorage.setItem('BUSINESS_ID', 'BC1234567')
store.state.keycloakRoles = ['staff']
const wrapper = mount(EntityInfo, { vuetify, store, router })
await Vue.nextTick()
expect(wrapper.find(StaffComments).exists()).toBe(true)
store.state.keycloakRoles = []
wrapper.destroy()
})
})
describe('EntityInfo - company info button and tooltip', () => {
const router = mockRouter.mock()
const variations = [
{ // 0
businessId: 'CP1234567',
entityType: 'CP',
goodStanding: true,
buttonExists: false,
tooltip: null
},
{ // 1
businessId: 'BC1234567',
entityType: 'BEN',
goodStanding: true,
buttonExists: true,
tooltip: null
},
{ // 2
businessId: 'BC1234567',
entityType: 'BC',
goodStanding: true,
buttonExists: true,
tooltip: null
},
{ // 3
businessId: 'BC1234567',
entityType: 'ULC',
goodStanding: true,
buttonExists: true,
tooltip: null
},
{ // 4
businessId: 'BC1234567',
entityType: 'BEN',
warnings: [{ warningType: 'COMPLIANCE' }, { warningType: 'COMPLIANCE' }],
buttonExists: true,
tooltip: 'not in compliance'
},
{ // 5
tempRegNumber: 'T123456789',
entityType: 'BEN',
entityStatus: 'DRAFT_APP',
buttonExists: false
},
{ // 6
tempRegNumber: 'T123456789',
entityType: 'BEN',
entityStatus: 'FILED_APP',
buttonExists: false
},
{ // 7
businessId: null,
tempRegNumber: null,
entityType: null,
goodStanding: false,
warnings: null,
entityStatus: null,
buttonExists: false,
tooltip: null
}
]
variations.forEach((_, index) => {
it(`displays company info button and tooltips properly - variation #${index}`, async () => {
sessionStorage.clear()
if (_.businessId) sessionStorage.setItem('BUSINESS_ID', _.businessId)
if (_.tempRegNumber) sessionStorage.setItem('TEMP_REG_NUMBER', _.tempRegNumber)
store.state.entityType = _.entityType
store.state.goodStanding = _.goodStanding || false
store.state.businessWarnings = _.warnings || []
store.state.entityStatus = _.entityStatus || null
const wrapper = shallowMount(EntityInfo, { store, vuetify, router })
await Vue.nextTick()
// verify button
const companyInformationButton = wrapper.find('#company-information-button')
expect(companyInformationButton.exists()).toBe(_.buttonExists)
// verify tooltip
// expect index = 4 to display compliance warning
const vTooltipStub = wrapper.find('v-tooltip-stub')
expect(vTooltipStub.exists()).toBe(index === 4 ? !!_.tooltip : false)
if (_.tooltip) expect(vTooltipStub.text()).toContain(_.tooltip)
})
})
})
describe('EntityInfo - Historical badge', () => {
const router = mockRouter.mock()
const variations = [
{ // 0
state: 'ACTIVE',
exists: false
},
{ // 1
state: 'LIQUIDATION',
exists: false
},
{ // 2
state: 'HISTORICAL',
exists: true,
text: null
},
{ // 3
state: 'HISTORICAL',
exists: true,
text: 'Some Reason Text'
}
]
variations.forEach((_, index) => {
it(`conditionally displays historical badge - variation #${index}`, async () => {
// init store
store.state.entityState = _.state
store.state.reasonText = _.text
const wrapper = mount(EntityInfo, { vuetify, store, router })
await Vue.nextTick()
expect(wrapper.find('.v-chip').exists()).toBe(_.exists)
if (_.exists) {
expect(wrapper.find('.v-chip__content').text()).toBe('HISTORICAL')
expect(wrapper.find('.v-chip + span').text()).toBe(_.text || 'Unknown Reason')
}
// cleanup
store.state.entityState = null
store.state.reasonText = null
wrapper.destroy()
})
})
})
describe('EntityInfo - Click Tests - Alterations', () => {
const router = mockRouter.mock()
const { assign } = window.location
beforeAll(() => {
// mock the window.location.assign function
delete window.location
window.location = { assign: jest.fn() } as any
})
afterAll(() => {
window.location.assign = assign
})
it('redirects to Edit URL to view/alter business info', async () => {
// init session storage + store
sessionStorage.clear()
sessionStorage.setItem('EDIT_URL', 'https://edit.url/')
sessionStorage.setItem('BUSINESS_ID', 'BC1234567')
sessionStorage.setItem('CURRENT_ACCOUNT', '{ "id": "2288" }')
store.state.identifier = 'BC1234567'
store.state.goodStanding = true
store.state.entityType = 'BEN'
// store.state.entityType = 'LTD' // FUTURE: uncomment this
const wrapper = mount(EntityInfo, { vuetify, store, router })
await Vue.nextTick()
wrapper.find('#company-information-button').trigger('click')
await Vue.nextTick()
// verify redirection
const accountId = JSON.parse(sessionStorage.getItem('CURRENT_ACCOUNT'))?.id
const editUrl = 'https://edit.url/BC1234567/alteration'
expect(window.location.assign).toHaveBeenCalledWith(editUrl + '?accountid=' + accountId)
wrapper.destroy()
})
})
describe('EntityInfo - Click Tests - Dissolutions', () => {
const router = mockRouter.mock()
// mock the mixin to always return True
const AllowableActionsMixin: any = {
methods: {
isAllowed: () => true
}
}
it('displays the Dissolve this Company button', async () => {
// mount the component and wait for everything to stabilize
const wrapper = mount(EntityInfo, {
store,
vuetify,
router,
mixins: [AllowableActionsMixin]
})
await Vue.nextTick()
expect(wrapper.find('#dissolution-button').exists()).toBe(true)
})
it('prompts the Confirm Dissolution dialog if in good standing', async () => {
store.state.goodStanding = true
// mount the component and wait for everything to stabilize
const wrapper: any = mount(EntityInfo, {
store,
vuetify,
router,
mixins: [AllowableActionsMixin]
})
await Vue.nextTick()
wrapper.find('#dissolution-button').trigger('click')
await Vue.nextTick()
// verify emit event
expect(wrapper.emitted().confirmDissolution).toEqual([[]])
})
it('prompts the Not In Good Standing dialog', async () => {
store.state.goodStanding = false
// mount the component and wait for everything to stabilize
const wrapper: any = mount(EntityInfo, {
store,
vuetify,
router,
mixins: [AllowableActionsMixin]
})
await Vue.nextTick()
wrapper.find('#dissolution-button').trigger('click')
await Vue.nextTick()
// verify emit event
expect(wrapper.emitted().notInGoodStanding).toEqual([['dissolve']])
})
})
describe('EntityInfo - Click Tests - Business Summary', () => {
const router = mockRouter.mock()
// mock the mixin to always return True
const AllowableActionsMixin: any = {
methods: {
isAllowed: () => true
}
}
it('displays the Business Summary button', async () => {
// mount the component and wait for everything to stabilize
const wrapper = mount(EntityInfo, {
store,
vuetify,
router,
mixins: [AllowableActionsMixin]
})
await Vue.nextTick()
expect(wrapper.find('#download-summary-button').exists()).toBe(true)
})
it('emits the download business summary event', async () => {
// mount the component and wait for everything to stabilize
const wrapper: any = mount(EntityInfo, {
store,
vuetify,
router,
mixins: [AllowableActionsMixin]
})
await Vue.nextTick()
wrapper.find('#download-summary-button').trigger('click')
await Vue.nextTick()
// verify emit event
expect(wrapper.emitted().downloadBusinessSummary).toEqual([[]])
})
})