|
| 1 | +import { createLocalVue, mount } from '@vue/test-utils' |
| 2 | +import Buefy from 'buefy' |
| 3 | +import Vuex from 'vuex' |
| 4 | +import CopyrightWaiverStep from '@/components/CopyrightWaiverStep' |
| 5 | + |
| 6 | +const localVue = createLocalVue() |
| 7 | + |
| 8 | +localVue.use(Vuex) |
| 9 | +localVue.use(Buefy) |
| 10 | + |
| 11 | +describe('CopyrightWaiver Step: Check conditional rendering of markup', () => { |
| 12 | + let wrapper |
| 13 | + |
| 14 | + beforeEach(() => { |
| 15 | + wrapper = mount(CopyrightWaiverStep, { |
| 16 | + localVue, |
| 17 | + data() { |
| 18 | + return { |
| 19 | + agreed: false, |
| 20 | + confirmed: false |
| 21 | + } |
| 22 | + }, |
| 23 | + mocks: { |
| 24 | + $t: key => key |
| 25 | + } |
| 26 | + }) |
| 27 | + }) |
| 28 | + |
| 29 | + afterEach(() => { |
| 30 | + wrapper.destroy() |
| 31 | + }) |
| 32 | + |
| 33 | + it('Component not mounted if status is inactive', () => { |
| 34 | + wrapper.setProps({ |
| 35 | + selected: undefined, |
| 36 | + status: 'inactive', |
| 37 | + stepId: 6, |
| 38 | + stepName: 'CW' |
| 39 | + }) |
| 40 | + |
| 41 | + expect(wrapper.find('.step-description').exists()).toBeFalsy() |
| 42 | + expect(wrapper.find('.step-actions').exists()).toBeFalsy() |
| 43 | + }) |
| 44 | + |
| 45 | + it('Step Description block mounted if status is previous', () => { |
| 46 | + wrapper.setProps({ status: 'previous' }) |
| 47 | + |
| 48 | + expect(wrapper.find('.step-description').exists()).toBeTruthy() |
| 49 | + expect(wrapper.find('.step-actions').exists()).toBeFalsy() |
| 50 | + }) |
| 51 | + |
| 52 | + it('Step Actions block mounted if status is current', () => { |
| 53 | + wrapper.setProps({ status: 'current' }) |
| 54 | + |
| 55 | + expect(wrapper.find('.step-description').exists()).toBeFalsy() |
| 56 | + expect(wrapper.find('.step-actions').exists()).toBeTruthy() |
| 57 | + expect(wrapper.vm.copyrightWaiverAgreed).toBe(false) |
| 58 | + }) |
| 59 | +}) |
| 60 | + |
| 61 | +describe('Test the functionality of Computed properties', () => { |
| 62 | + let wrapper |
| 63 | + |
| 64 | + beforeEach(() => { |
| 65 | + wrapper = mount(CopyrightWaiverStep, { |
| 66 | + localVue, |
| 67 | + data() { |
| 68 | + return { |
| 69 | + agreed: false, |
| 70 | + confirmed: false |
| 71 | + } |
| 72 | + }, |
| 73 | + propsData: { |
| 74 | + selected: true, |
| 75 | + status: 'current', |
| 76 | + stepId: 6, |
| 77 | + stepName: 'CW' |
| 78 | + }, |
| 79 | + mocks: { |
| 80 | + $t: key => key |
| 81 | + } |
| 82 | + }) |
| 83 | + }) |
| 84 | + |
| 85 | + afterEach(() => { |
| 86 | + wrapper.destroy() |
| 87 | + }) |
| 88 | + |
| 89 | + it('User checks confirmed then checks agreed', () => { |
| 90 | + const checkbox1 = wrapper.findAll('input[type="checkbox"]').at(1) |
| 91 | + checkbox1.setChecked() |
| 92 | + |
| 93 | + const checkbox = wrapper.findAll('input[type="checkbox"]').at(0) |
| 94 | + checkbox.setChecked() |
| 95 | + |
| 96 | + expect(wrapper.emitted().change[0]).toStrictEqual(['CW', 6, true]) |
| 97 | + expect(wrapper.vm.copyrightWaiverAgreed).toBe(true) |
| 98 | + }) |
| 99 | + |
| 100 | + it('User checks agreed and then checks confirmed', () => { |
| 101 | + const checkbox = wrapper.findAll('input[type="checkbox"]').at(0) |
| 102 | + checkbox.setChecked() |
| 103 | + |
| 104 | + const checkbox1 = wrapper.findAll('input[type="checkbox"]').at(1) |
| 105 | + checkbox1.setChecked() |
| 106 | + |
| 107 | + expect(wrapper.emitted().change[0]).toStrictEqual(['CW', 6, true]) |
| 108 | + expect(wrapper.vm.copyrightWaiverConfirmed).toBe(true) |
| 109 | + }) |
| 110 | + |
| 111 | + it('User unchecks agreed', () => { |
| 112 | + const checkbox = wrapper.findAll('input[type="checkbox"]').at(0) |
| 113 | + checkbox.setChecked() |
| 114 | + checkbox.setChecked(false) |
| 115 | + |
| 116 | + expect(wrapper.emitted().change[0]).toStrictEqual(['CW', 6, undefined]) |
| 117 | + expect(wrapper.vm.copyrightWaiverAgreed).toBe(false) |
| 118 | + }) |
| 119 | + |
| 120 | + it('User unchecks confirmed', () => { |
| 121 | + const checkbox = wrapper.findAll('input[type="checkbox"]').at(1) |
| 122 | + |
| 123 | + checkbox.setChecked() |
| 124 | + checkbox.setChecked(false) |
| 125 | + |
| 126 | + expect(wrapper.emitted().change[0]).toStrictEqual(['CW', 6, undefined]) |
| 127 | + expect(wrapper.vm.copyrightWaiverConfirmed).toBe(false) |
| 128 | + }) |
| 129 | +}) |
0 commit comments