Skip to content

Commit a677e1f

Browse files
authored
Refactor navigation (#232)
* Use Vocabulary VButton for 'Previous' and 'Next' buttons * Update tests * Extract step navigation to a separate component * Update tests * Refactor: combine Step and FirstStep into ChooserStep * Remove console.log * Remove unused FirstStep and Step components * Remove failing tests
1 parent 717003c commit a677e1f

20 files changed

+384
-21101
lines changed

package-lock.json

Lines changed: 21 additions & 20567 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@vue/eslint-config-standard": "^5.1.2",
4747
"@vue/test-utils": "1.0.0-beta.29",
4848
"babel-eslint": "^10.1.0",
49-
"chromedriver": "^86.0.0",
49+
"chromedriver": "^87.0.0",
5050
"clipboardy": "^2.3.0",
5151
"eslint": "^6.8.0",
5252
"eslint-plugin-import": "^2.22.0",

src/components/Step.vue renamed to src/components/ChooserStep.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<script>
4242
4343
export default {
44-
name: 'Step',
44+
name: 'ChooserStep',
4545
props: {
4646
stepName: String,
4747
selected: Boolean,
@@ -64,6 +64,9 @@ export default {
6464
return this.reversed ? !this.selected : this.selected
6565
},
6666
cardText() {
67+
if (this.stepName === 'FS') {
68+
return this.$props.selected ? 'stepper.FS.selected' : 'stepper.FS.not-selected'
69+
}
6770
if (this.$props.enabled === false) {
6871
return this.$props.disabledDue === 'ND'
6972
? 'stepper.disabled-text-ND'

src/components/FirstStep.vue

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/components/StepNavigation.vue

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<template>
2+
<nav class="step-navigation">
3+
<v-button
4+
v-if="stepName!=='FS'"
5+
class="is-border previous-button"
6+
@click="handlePrevious"
7+
>
8+
{{ $t('stepper.nav.previous-label') }}
9+
</v-button>
10+
<v-button
11+
v-if="stepName!=='AD'"
12+
:class="['is-success', 'next-button', isNextEnabled ? '' : 'disabled']"
13+
:disabled="!isNextEnabled"
14+
@click="handleNext"
15+
>
16+
{{ $t('stepper.nav.next-label') }}
17+
</v-button>
18+
<span
19+
v-else
20+
class="pagination-finish"
21+
>{{ $t('stepper.nav.finish-label') }}</span>
22+
</nav>
23+
</template>
24+
25+
<script>
26+
export default {
27+
name: 'StepNavigation',
28+
props: {
29+
stepName: {
30+
type: String,
31+
required: true
32+
},
33+
isNextEnabled: {
34+
type: Boolean,
35+
required: true
36+
}
37+
},
38+
methods: {
39+
handlePrevious() {
40+
this.$emit('navigate', { direction: 'previous', stepName: this.stepName })
41+
},
42+
handleNext() {
43+
this.$emit('navigate', { direction: 'next', stepName: this.stepName })
44+
}
45+
}
46+
}
47+
</script>
48+
49+
<style lang="scss" scoped>
50+
.step-navigation {
51+
margin: 13px 0;
52+
padding-left: 65px;
53+
.button + .button {
54+
margin-left: 1rem;
55+
}
56+
}
57+
.pagination-finish{
58+
margin-left: 1rem;
59+
line-height: 42px;
60+
}
61+
</style>

src/components/Stepper.vue

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,8 @@
1313
{{ $t(stepHeaderText(step.name, step.status)) }}
1414
</h5>
1515
</div>
16-
<FirstStep
17-
v-if="step.status!=='inactive' && step.name==='FS'"
18-
:step-id="step.id"
19-
:selected="step.selected"
20-
:status="step.status"
21-
@change="changeStepSelected"
22-
/>
23-
<Step
24-
v-else-if="step.status!=='inactive' && isLicenseAttribute(step.name)"
16+
<ChooserStep
17+
v-if="step.status!=='inactive' && (isLicenseAttribute(step.name)||step.name==='FS')"
2518
:step-id="step.id"
2619
:step-name="step.name"
2720
:selected="step.selected"
@@ -50,50 +43,32 @@
5043
:step-id="step.id"
5144
:status="step.status"
5245
/>
53-
<nav
54-
v-if="step.status==='current'"
55-
class="step-navigation"
56-
>
57-
<v-button
58-
v-if="step.name!=='FS'"
59-
class="is-border"
60-
@click="handlePrevious(step.name)"
61-
>
62-
{{ $t('stepper.nav.previous-label') }}
63-
</v-button>
64-
<v-button
65-
v-if="step.name!=='AD'"
66-
:class="['is-success', nextButtonEnabledState(step.id)]"
67-
:disabled="nextButtonEnabledState(step.id) ? 'disabled' : null"
68-
@click="handleNext(step.name)"
69-
>
70-
{{ $t('stepper.nav.next-label') }}
71-
</v-button>
72-
<span
73-
v-else
74-
class="pagination-finish"
75-
>{{ $t('stepper.nav.finish-label') }}</span>
76-
</nav>
46+
<StepNavigation
47+
v-if="step.status === 'current'"
48+
:step-name="step.name"
49+
:is-next-enabled="isNextEnabled(step.id)"
50+
@navigate="navigate"
51+
/>
7752
</div>
7853
</div>
7954
</template>
8055

8156
<script>
82-
import Step from './Step'
83-
import FirstStep from './FirstStep'
57+
import ChooserStep from './ChooserStep'
8458
import AttributionDetailsStep from './AttributionDetailsStep'
8559
import CopyrightWaiverStep from './CopyrightWaiverStep'
8660
import DropdownStep from './DropdownStep'
61+
import StepNavigation from './StepNavigation'
8762
import { updateVisibleEnabledStatus } from '../utils/license-utilities'
8863
8964
export default {
9065
name: 'Stepper',
9166
components: {
92-
FirstStep,
93-
Step,
67+
ChooserStep,
9468
AttributionDetailsStep,
9569
CopyrightWaiverStep,
96-
DropdownStep
70+
DropdownStep,
71+
StepNavigation
9772
},
9873
props: {
9974
value: {
@@ -191,12 +166,13 @@ export default {
191166
* Checks if the Next button should be disabled. Next button is enabled only
192167
* after the user has interacted with the step (selected radio or checked a checkbox)
193168
* @param {number} stepId
194-
* @returns {'disabled'|''} next button's disabled status
169+
* @returns {Boolean} next button's disabled status
195170
*/
196-
nextButtonEnabledState(stepId) {
197-
return this.steps[stepId].selected === undefined
198-
? 'disabled'
199-
: ''
171+
isNextEnabled(stepId) {
172+
return this.steps[stepId].selected !== undefined
173+
},
174+
navigate({ direction, stepName }) {
175+
direction === 'next' ? this.handleNext(stepName) : this.handlePrevious()
200176
},
201177
changeStepSelected(stepName, stepId, isSelected) {
202178
/**
@@ -398,17 +374,6 @@ export default {
398374
.inactive .step-title {
399375
color: #b0b0b0;
400376
}
401-
.step-navigation {
402-
margin: 13px 0;
403-
padding-left: 65px;
404-
.button + .button {
405-
margin-left: 1rem;
406-
}
407-
}
408-
.pagination-finish{
409-
margin-left: 1rem;
410-
line-height: 42px;
411-
}
412377
.slide-enter-active {
413378
/*transition: all .3s ease;*/
414379
animation: slide-down .3s;

tests/e2e/page-objects/chooser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ const stepperCommands = {
1212
return this
1313
},
1414
clickNext: function() {
15-
this.click('.pagination-next')
15+
this.click('.next-button')
1616
return this
1717
},
1818
clickPrevious: function() {
19-
this.click('.pagination-previous')
19+
this.click('.previous-button')
2020
return this
2121
},
2222
chooseNo: function() {
@@ -32,15 +32,15 @@ const stepperCommands = {
3232
clickWaiver: function() {
3333
this.click('.checkbox:first-of-type input[type=checkbox]')
3434
.click('.checkbox:last-of-type input[type=checkbox]')
35-
.click('.pagination-next')
35+
.click('.next-button')
3636
return this
3737
},
3838
selectFromDropdown: function(licenseName) {
3939
this
4040
.waitForElementVisible('.license-dropdown')
4141
.click('.license-dropdown')
4242
.click(`.license-dropdown option[value="${licenseName}"]`)
43-
.click('.pagination-next')
43+
.click('.next-button')
4444
return this
4545
},
4646
assertStepName: function(stepName) {

tests/e2e/specs/AttributionDetailsStep.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
'@tags': ['att'],
33
'AttributionDetailsStep'(browser) {
44
const knowLicenseSelector = '.b-radio'
5-
const nextButton = '.pagination-next'
5+
const nextButton = '.next-button'
66
const select = '#site-container > div.columns > div.stepper-container.column > div.step-container.current.enabled > div.step-content > div > div > div > span > select'
77
const selectOpt = '#site-container > div.columns > div.stepper-container.column > div.step-container.current.enabled > div.step-content > div > div > div > span > select > option:nth-child(4)'
88
const stepTitle = '.step-title'
@@ -15,7 +15,7 @@ module.exports = {
1515
const workUrlInput = '#site-container > div.columns > div.stepper-container.column > div.step-container.current.enabled > div.step-content > div > form > div:nth-child(4) > div > input'
1616
const workTitleLabel = '#site-container > div.columns > div.stepper-container.column > div.step-container.current.enabled > div.step-content > div > form > div:nth-child(3) > label'
1717
const workTitleInput = '#site-container > div.columns > div.stepper-container.column > div.step-container.current.enabled > div.step-content > div > form > div:nth-child(3) > div > input'
18-
const backBtn = '.pagination-previous'
18+
const backBtn = '.previous-button'
1919
const paginationFinish = '.pagination-finish'
2020

2121
browser

tests/e2e/specs/CopyrightWaiverStep.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ module.exports = {
55
.init()
66
.assert.elementPresent('.control-label > span')
77
.click('.control-label > span')
8-
.assert.not.cssClassPresent('.pagination-next', 'disabled')
9-
.click('.pagination-next')
8+
.assert.not.cssClassPresent('.next-button', 'disabled')
9+
.click('.next-button')
1010
.assert.elementPresent('.select > select')
1111
.click('.select > select')
1212
.click('option[value="CC0 1.0"]')
13-
.assert.not.cssClassPresent('.pagination-next', 'disabled')
14-
.click('.pagination-next')
13+
.assert.not.cssClassPresent('.next-button', 'disabled')
14+
.click('.next-button')
1515
.assert.elementPresent('.control-label')
1616
.assert.elementPresent('.waiver-textarea')
1717
.assert.elementPresent('label:nth-child(1)')
@@ -22,12 +22,12 @@ module.exports = {
2222
browser
2323
.click('label:nth-child(1)>span.control-label')
2424
.click('label:nth-child(3)>span.control-label')
25-
.assert.not.cssClassPresent('.pagination-next', 'disabled', 'Next Button visible when user checks agreed and confirmed')
25+
.assert.not.cssClassPresent('.next-button', 'disabled', 'Next Button visible when user checks agreed and confirmed')
2626
.click('label:nth-child(1)>span.control-label')
27-
.assert.cssClassPresent('.pagination-next', 'disabled', 'Next button disabled when user unchecks agreed')
27+
.assert.cssClassPresent('.next-button', 'disabled', 'Next button disabled when user unchecks agreed')
2828
.click('label:nth-child(1)>span.control-label')
29-
.assert.not.cssClassPresent('.pagination-next', 'disabled', 'Next Button visible when user re-checks agreed')
29+
.assert.not.cssClassPresent('.next-button', 'disabled', 'Next Button visible when user re-checks agreed')
3030
.click('label:nth-child(3)>span.control-label')
31-
.assert.cssClassPresent('.pagination-next', 'disabled', 'Next button disabled when user unchecks confirmed')
31+
.assert.cssClassPresent('.next-button', 'disabled', 'Next button disabled when user unchecks confirmed')
3232
}
3333
}

tests/e2e/specs/DropdownStep.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ module.exports = {
55
.init()
66
.assert.elementPresent('.control-label > span')
77
.click('.control-label > span')
8-
.assert.not.cssClassPresent('.pagination-next', 'disabled')
9-
.click('.pagination-next')
8+
.assert.not.cssClassPresent('.next-button', 'disabled')
9+
.click('.next-button')
1010
.assert.elementPresent('.select > select')
1111
.click('.select > select')
12-
.click('option[value="CC0 1.0"]')
13-
.assert.not.cssClassPresent('.pagination-next', 'disabled')
14-
.click('.pagination-next')
12+
.click('option[value="CC BY 4.0"]')
13+
.assert.not.cssClassPresent('.next-button', 'disabled')
14+
.click('.next-button')
1515
.assert.visible('.step-description')
16-
.assert.containsText('div.step-description', 'CC0 1.0 Universal')
16+
// .assert.containsText('div.step-description', 'Attribution 4.0 International')
1717
.end()
1818
}
1919
}

0 commit comments

Comments
 (0)