Skip to content

Commit ff31a45

Browse files
authored
Merge pull request #149 from JackieBinya/bg-first-step-unit
Rewrites unit tests for FirstStep.vue
2 parents 179da4e + 63e1894 commit ff31a45

File tree

3 files changed

+146
-47
lines changed

3 files changed

+146
-47
lines changed

tests/e2e/specs/FirstStep.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
'@tags': ['first'],
3+
'FirstStep'(browser) {
4+
const radioSelector = 'div.field.not-selected > label > span.control-label > span'
5+
const nextBtn = 'a.pagination-next'
6+
const stepBelowCurrentHeader = 'div:nth-child(2) > div > h5'
7+
const stepDescription = '.step-description'
8+
const backBtn = 'a.pagination-previous'
9+
10+
browser
11+
.init()
12+
.waitForElementVisible('body')
13+
.assert.not.elementPresent(stepDescription)
14+
.click(radioSelector)
15+
.assert.containsText(stepBelowCurrentHeader, 'Creative Commons License')
16+
.click(nextBtn)
17+
.assert.elementPresent(stepDescription)
18+
.assert.visible(stepDescription)
19+
.assert.containsText(stepDescription, 'I know which license I need.')
20+
.click(backBtn)
21+
.click(radioSelector)
22+
.assert.containsText(stepBelowCurrentHeader, 'Attribution')
23+
.click(nextBtn)
24+
.assert.containsText(stepDescription, 'I need help selecting a license.')
25+
.end()
26+
}
27+
}
+50-47
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,82 @@
1-
import { mount } from '@vue/test-utils'
1+
import { createLocalVue, mount } from '@vue/test-utils'
2+
import Buefy from 'buefy'
23
import FirstStep from '@/components/FirstStep.vue'
34

4-
describe('FirstStep.vue', () => {
5-
const wrapper = mount(FirstStep)
6-
it('Has the main div tag', () => {
7-
expect(wrapper.contains('.step-content')).toBe(true)
5+
const localVue = createLocalVue()
6+
7+
localVue.use(Buefy)
8+
9+
describe('FirstStep Component', () => {
10+
let wrapper
11+
12+
beforeEach(() => {
13+
wrapper = mount(FirstStep, {
14+
localVue,
15+
mocks: {
16+
$t: key => key
17+
}
18+
})
819
})
920

10-
it('renders without any errors', () => {
11-
expect(wrapper.isVueInstance()).toBeTruthy()
21+
afterEach(() => {
22+
wrapper.destroy()
1223
})
1324

14-
it('Checks if the cardtext function return the correct answer when selected is true', () => {
25+
it('Mark up is correctly rendered', () => {
1526
wrapper.setProps({
16-
selected: true
27+
selected: undefined,
28+
stepId: 0,
29+
status: 'current'
1730
})
1831

19-
expect(wrapper.vm.cardText).toBe('stepper.FS.selected')
32+
expect(wrapper.element).toMatchSnapshot()
2033
})
2134

22-
it('Checks if the cardtext function return the correct answer when selected is false', () => {
35+
it('Radio Input value is YES', () => {
2336
wrapper.setProps({
24-
selected: false
37+
selected: undefined,
38+
stepId: 0,
39+
status: 'current'
2540
})
2641

27-
expect(wrapper.vm.cardText).toBe('stepper.FS.not-selected')
28-
})
29-
30-
it('Checks if the yesText function returns correct answer ', () => {
31-
expect(wrapper.vm.yesText).toBe('stepper.FS.selected')
32-
})
42+
const radio = wrapper.findAll('input[type="radio"]').at(0)
43+
radio.setChecked()
3344

34-
it('Checks if the noText function returns correct answer', () => {
35-
expect(wrapper.vm.noText).toBe('stepper.FS.not-selected')
45+
expect(wrapper.emitted().change[0]).toEqual(['FS', 0, true])
3646
})
3747

38-
it('Checks if the yesSelected function returns the correct boolean when selected is true', () => {
48+
it('Radio Input value is NO', () => {
3949
wrapper.setProps({
40-
selected: true
50+
selected: undefined,
51+
stepId: 0,
52+
status: 'current'
4153
})
42-
expect(wrapper.vm.yesSelected).toBe('selected')
43-
})
4454

45-
it('Checks if the yesSelected function returns the correct boolean when selected is false', () => {
46-
wrapper.setProps({
47-
selected: false
48-
})
49-
expect(wrapper.vm.yesSelected).toBe('not-selected')
55+
const radio = wrapper.findAll('input[type="radio"]').at(1)
56+
radio.setChecked()
57+
58+
expect(wrapper.emitted().change[0]).toEqual(['FS', 0, false])
5059
})
5160

52-
it('Checks if the get function in radio returns the correct value when selected is undefined', () => {
61+
it('props:selected false', () => {
5362
wrapper.setProps({
54-
selected: undefined
63+
selected: false,
64+
stepId: 0,
65+
status: 'current'
5566
})
56-
expect(wrapper.vm.radio).toBe(undefined)
57-
})
5867

59-
it('Checks if the get function in radio returns the correct value when selected is yes', () => {
60-
wrapper.setData({
61-
selected: 'yes'
62-
})
63-
expect(wrapper.vm.radio).toBe('yes')
68+
expect(wrapper.vm.radio).toBe('no')
69+
expect(wrapper.vm.cardText).toBe('stepper.FS.not-selected')
6470
})
6571

66-
it('Checks if the noSelected function returns the correct boolean when selected is true', () => {
72+
it('props:selected true', () => {
6773
wrapper.setProps({
68-
selected: true
74+
selected: true,
75+
stepId: 0,
76+
status: 'current'
6977
})
70-
expect(wrapper.vm.noSelected).toBe('not-selected')
71-
})
7278

73-
it('Checks if the noSelected function returns the correct boolean when selected is false', () => {
74-
wrapper.setProps({
75-
selected: false
76-
})
77-
expect(wrapper.vm.noSelected).toBe('selected')
79+
expect(wrapper.vm.radio).toBe('yes')
80+
expect(wrapper.vm.cardText).toBe('stepper.FS.selected')
7881
})
7982
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`FirstStep Component Mark up is correctly rendered 1`] = `
4+
<div
5+
class="step-content"
6+
>
7+
<div
8+
class="step-actions"
9+
>
10+
<div
11+
class="field not-selected"
12+
>
13+
<label
14+
class="b-radio radio"
15+
>
16+
<input
17+
type="radio"
18+
value="yes"
19+
/>
20+
21+
<span
22+
class="check"
23+
/>
24+
25+
<span
26+
class="control-label"
27+
>
28+
<span
29+
class="vocab-body body-normal"
30+
>
31+
32+
stepper.yesstepper.FS.selected
33+
34+
</span>
35+
</span>
36+
</label>
37+
</div>
38+
39+
<div
40+
class="field selected"
41+
>
42+
<label
43+
class="b-radio radio"
44+
>
45+
<input
46+
type="radio"
47+
value="no"
48+
/>
49+
50+
<span
51+
class="check"
52+
/>
53+
54+
<span
55+
class="control-label"
56+
>
57+
<span
58+
class="vocab-body body-normal"
59+
>
60+
61+
stepper.nostepper.FS.not-selected
62+
63+
</span>
64+
</span>
65+
</label>
66+
</div>
67+
</div>
68+
</div>
69+
`;

0 commit comments

Comments
 (0)