Skip to content

Commit 179da4e

Browse files
authored
Merge pull request #146 from creativecommons/stepper-test
Add tests for Stepper component
2 parents a1875b4 + 788764b commit 179da4e

File tree

8 files changed

+612
-209
lines changed

8 files changed

+612
-209
lines changed

src/components/DropdownStep.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default {
3737
},
3838
methods: {
3939
updateSelected() {
40-
this.$emit('input', 'DD', this.$props.stepId, true)
40+
this.$emit('change', 'DD', this.$props.stepId, true)
4141
}
4242
}
4343
}

src/components/Stepper.vue

+7-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div
44
v-for="(step, idx) in visibleSteps()"
55
:key="idx"
6-
:class="['step-container', step.status, enabledQualifier(step.enabled)]"
6+
:class="['step-container', step.name, step.status, enabledQualifier(step.enabled)]"
77
>
88
<div
99
:class="['step-header']"
@@ -43,7 +43,7 @@
4343
v-else-if="step.status!=='inactive' && step.name==='DD'"
4444
:step-id="step.id"
4545
:status="step.status"
46-
@input="changeStepSelected"
46+
@change="changeStepSelected"
4747
/>
4848
<AttributionDetailsStep
4949
v-else-if="step.status!=='inactive' && step.name==='AD'"
@@ -258,26 +258,18 @@ export default {
258258
this.$set(this.steps, previousStep, { ...this.steps[previousStep], status: 'current' })
259259
this.currentStepId = previousStep
260260
},
261-
handleFinish() {
262-
// TODO: write the method
263-
},
264261
setActiveStep(clickedStepId) {
265262
/**
266263
* Handles a click on Step header
267264
*/
268265
if (!this.steps[clickedStepId].enabled) return
269266
if (this.steps[clickedStepId].status === 'inactive') return
270-
if (clickedStepId > this.currentStepId) {
271-
for (let i = this.currentStepId; i < clickedStepId; i++) {
272-
this.$set(this.steps, i, { ...this.steps[i], status: 'previous' })
273-
}
274-
this.$set(this.steps, clickedStepId, { ...this.steps[clickedStepId], status: 'current' })
275-
} else {
276-
for (let i = this.currentStepId; i > clickedStepId; i--) {
277-
this.$set(this.steps, i, { ...this.steps[i], status: 'inactive' })
278-
}
279-
this.$set(this.steps, clickedStepId, { ...this.steps[clickedStepId], status: 'current' })
267+
// only steps before the current one are clickable
268+
if (clickedStepId >= this.currentStepId) return
269+
for (let i = this.currentStepId; i > clickedStepId; i--) {
270+
this.$set(this.steps, i, { ...this.steps[i], status: 'inactive' })
280271
}
272+
this.$set(this.steps, clickedStepId, { ...this.steps[clickedStepId], status: 'current' })
281273
this.currentStepId = clickedStepId
282274
},
283275
setStepsVisible(stepsToSetVisible) {

tests/e2e/page-objects/chooser.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* Page object for license chooser
3+
*/
4+
5+
const stepperCommands = {
6+
clickYes: function() {
7+
this.click('.step-actions .field:first-of-type .check')
8+
return this
9+
},
10+
clickNo: function() {
11+
this.click('.step-actions .field:last-of-type .check')
12+
return this
13+
},
14+
clickNext: function() {
15+
this.click('.pagination-next')
16+
return this
17+
},
18+
clickPrevious: function() {
19+
this.click('.pagination-previous')
20+
return this
21+
},
22+
chooseNo: function() {
23+
this.clickNo()
24+
.clickNext()
25+
return this
26+
},
27+
chooseYes: function() {
28+
this.clickYes()
29+
.clickNext()
30+
return this
31+
},
32+
clickWaiver: function() {
33+
this.click('.checkbox:first-of-type input[type=checkbox]')
34+
.click('.checkbox:last-of-type input[type=checkbox]')
35+
.click('.pagination-next')
36+
return this
37+
},
38+
selectFromDropdown: function(licenseName) {
39+
this
40+
.waitForElementVisible('.license-dropdown')
41+
.click('.license-dropdown')
42+
.click(`.license-dropdown option[value="${licenseName}"]`)
43+
.click('.pagination-next')
44+
return this
45+
},
46+
assertStepName: function(stepName) {
47+
this.expect.element('@currentStep').to.have.property('classList').contain(stepName)
48+
return this
49+
}
50+
}
51+
const chooserCommands = {
52+
assertSelectedLicenseDisplayed: function(licenseName) {
53+
this
54+
.assert.containsText('.license-name', licenseName)
55+
.assert.containsText('p.license-text a', licenseName)
56+
return this
57+
}
58+
}
59+
module.exports = {
60+
url: '/',
61+
commands: [chooserCommands],
62+
63+
elements: {
64+
appContainer: '#app',
65+
stepper: '.stepper-container',
66+
selectedLicenseCard: '.selected-license-card',
67+
licenseUseCard: '.license-use-card'
68+
},
69+
70+
sections: {
71+
stepper: {
72+
selector: '.stepper-container',
73+
elements: {
74+
currentStep: {
75+
selector: '.step-container.current'
76+
}
77+
},
78+
commands: [stepperCommands]
79+
},
80+
selectedLicenseCard: {
81+
selector: '.selected-license-card'
82+
},
83+
licenseUseCard: {
84+
selector: '.license-use-card'
85+
}
86+
}
87+
88+
}

tests/e2e/page-objects/homepage.js

-52
This file was deleted.

tests/e2e/specs/HelpSection.js

-141
This file was deleted.

0 commit comments

Comments
 (0)