Skip to content

Rewrites unit tests for FirstStep.vue #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions tests/e2e/specs/FirstStep.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
module.exports = {
'@tags': ['first'],
'FirstStep'(browser){
const yesRadioSelector = '#site-container > div.columns > div.stepper-container.column > div.step-container.current.enabled > div.step-content > div > div.field.not-selected > label > span.check'
const noRadioSelector = '#site-container > div.columns > div.stepper-container.column > div.step-container.current.enabled > div.step-content > div > div.field.not-selected > label > span.check'
const attributionHeader = '#site-container > div.columns > div.stepper-container.column > div:nth-child(2) > div > h5'
const ccLicenseHeader = '#site-container > div.columns > div.stepper-container.column > div:nth-child(2) > div'
'FirstStep'(browser) {
const radioSelector = 'div.field.not-selected > label > span.control-label > span'
const radioSelected = 'div.field.selected > label > span.control-label > span'
const nextBtn = '.pagination-next'

const stepTitle = 'div.step-header > h5'

browser
.init()
.click(yesRadioSelector)
.assert.visible(ccLicenseHeader, 'Click yes:Creative Commons License header is visible in the step below FirstStep')
.assert.visible(nextBtn, 'Next button is visible')
.click(noRadioSelector)
.assert.visible(attributionHeader, 'Click no:Attribution header is visible in the step below FirstStep')
}
}
.assert.containsText(stepTitle, 'Do you know which license you need?')
.assert.containsText(radioSelector, 'Yes. I know which license I need')
.assert.containsText(radioSelected, 'No. I need help selecting a license')
.click(radioSelector)
.assert.not.cssClassPresent(nextBtn, 'disabled')
.assert.containsText(radioSelector, 'No. I need help selecting a license')
.end()
}
}
42 changes: 20 additions & 22 deletions tests/unit/specs/components/FirstStep.spec.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import { createLocalVue, mount } from "@vue/test-utils";
import { createLocalVue, mount } from '@vue/test-utils'
import Buefy from 'buefy'
import FirstStep from "@/components/FirstStep.vue";
import FirstStep from '@/components/FirstStep.vue'

const localVue = createLocalVue()

localVue.use(Buefy)

describe('FirstStep Component', ()=> {
let wrapper
describe('FirstStep Component', () => {
let wrapper

beforeEach(()=> {
beforeEach(() => {
wrapper = mount(FirstStep, {
localVue,
mocks: {
$t: key => key
}
})
})

afterEach(()=> {
wrapper.destroy()
})
})

afterEach(() => {
wrapper.destroy()
})

it('Mark up is correctly rendered', () => {
wrapper.setProps({
selected: undefined,
stepId: 0,
status: "current"
status: 'current'
})

expect(wrapper.element).toMatchSnapshot()
Expand All @@ -37,11 +36,11 @@ describe('FirstStep Component', ()=> {
wrapper.setProps({
selected: undefined,
stepId: 0,
status: "current"
status: 'current'
})

const radio = wrapper.findAll('input[type="radio"]').at(0)
radio.trigger('change');
radio.trigger('change')

expect(wrapper.emitted().change[0]).toEqual(['FS', 0, true])
})
Expand All @@ -50,35 +49,34 @@ describe('FirstStep Component', ()=> {
wrapper.setProps({
selected: undefined,
stepId: 0,
status: "current"
status: 'current'
})

const radio = wrapper.findAll('input[type="radio"]').at(1)
radio.trigger('change');
radio.trigger('change')

expect(wrapper.emitted().change[0]).toEqual(['FS', 0, false])
})

it('props:selected false', () =>{
it('props:selected false', () => {
wrapper.setProps({
selected: false,
stepId: 0,
status: "current"
status: 'current'
})

expect(wrapper.vm.radio).toBe('no')
expect(wrapper.vm.cardText).toBe('stepper.FS.not-selected')
})

it('props:selected true', () =>{
it('props:selected true', () => {
wrapper.setProps({
selected: true,
stepId: 0,
status: "current"
status: 'current'
})

expect(wrapper.vm.radio).toBe('yes')
expect(wrapper.vm.cardText).toBe('stepper.FS.selected')
})

})
})