Skip to content

Commit 49b2076

Browse files
author
akmadian
committed
Add unit tests for the Step component
1 parent f3236b8 commit 49b2076

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { shallowMount, createLocalVue, config } from '@vue/test-utils'
2+
import Step from '@/components/Step'
3+
import Buefy from 'buefy'
4+
import VueI18n from 'vue-i18n'
5+
import Vuex from 'vuex'
6+
import Vue from 'vue'
7+
import store from '@/store'
8+
9+
describe('Step.vue', () => {
10+
let wrapper
11+
let localVue
12+
13+
// Always creates a shallow instance of component
14+
beforeEach(() => {
15+
localVue = createLocalVue()
16+
localVue.use(Vuex)
17+
localVue.use(Buefy)
18+
Vue.use(VueI18n)
19+
const messages = require('@/locales/en.json')
20+
const i18n = new VueI18n({
21+
locale: 'en',
22+
fallbackLocale: 'en',
23+
messages: messages
24+
})
25+
26+
config.mocks.i18n = i18n
27+
28+
config.mocks.$t = key => {}
29+
wrapper = shallowMount(Step, {
30+
store,
31+
localVue
32+
})
33+
})
34+
35+
it('Check if Step.vue component renders without any errors', () => {
36+
expect(wrapper.isVueInstance()).toBeTruthy()
37+
})
38+
39+
// It's only for one state, but this should be enough to test if the logic works properly
40+
it('Check that all computed i18n props return correct values', () => {
41+
wrapper.setProps({
42+
disabledDue: "",
43+
enabled: true,
44+
reversed: false,
45+
selected: undefined,
46+
status: "current",
47+
stepId: 1,
48+
stepName: "BY"
49+
})
50+
51+
expect(wrapper.vm.cardText).toBe('stepper.BY.not-selected')
52+
expect(wrapper.vm.noSelected).toBe('selected')
53+
expect(wrapper.vm.noText).toBe('stepper.BY.not-selected')
54+
expect(wrapper.vm.question).toBe('stepper.BY.question')
55+
expect(wrapper.vm.tPrefix).toBe('stepper.BY')
56+
expect(wrapper.vm.yesSelected).toBe('not-selected')
57+
expect(wrapper.vm.yesText).toBe('stepper.BY.selected')
58+
})
59+
60+
it('Check that all computed i18n props return correct values after true selected', () => {
61+
wrapper.setProps({
62+
disabledDue: undefined,
63+
enabled: true,
64+
reversed: false,
65+
selected: true,
66+
status: "current",
67+
stepId: 1,
68+
stepName: "BY"
69+
})
70+
71+
expect(wrapper.vm.radio).toBe("yes")
72+
expect(wrapper.vm.cardText).toBe('stepper.BY.selected')
73+
expect(wrapper.vm.noSelected).toBe('not-selected')
74+
expect(wrapper.vm.noText).toBe('stepper.BY.not-selected')
75+
expect(wrapper.vm.question).toBe('stepper.BY.question')
76+
expect(wrapper.vm.tPrefix).toBe('stepper.BY')
77+
expect(wrapper.vm.yesSelected).toBe('selected')
78+
expect(wrapper.vm.yesText).toBe('stepper.BY.selected')
79+
})
80+
81+
it('Check that all computed i18n props return correct values after false selected', () => {
82+
wrapper.setProps({
83+
disabledDue: undefined,
84+
enabled: true,
85+
reversed: false,
86+
selected: false,
87+
status: "current",
88+
stepId: 1,
89+
stepName: "BY"
90+
})
91+
92+
expect(wrapper.vm.radio).toBe("no")
93+
expect(wrapper.vm.cardText).toBe('stepper.BY.not-selected')
94+
expect(wrapper.vm.noSelected).toBe('selected')
95+
expect(wrapper.vm.noText).toBe('stepper.BY.not-selected')
96+
expect(wrapper.vm.question).toBe('stepper.BY.question')
97+
expect(wrapper.vm.tPrefix).toBe('stepper.BY')
98+
expect(wrapper.vm.yesSelected).toBe('not-selected')
99+
expect(wrapper.vm.yesText).toBe('stepper.BY.selected')
100+
})
101+
102+
// Snapshot tests
103+
it('Check if the Step.vue component has the expected UI', () => {
104+
expect(wrapper).toMatchSnapshot()
105+
})
106+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Step.vue Check if the Step.vue component has the expected UI 1`] = `
4+
<div class="step-content">
5+
<!---->
6+
</div>
7+
`;

0 commit comments

Comments
 (0)