Skip to content

Commit 717003c

Browse files
authored
Use Vocabulary VButton in the Stepper (#231)
* Use Vocabulary VButton for 'Previous' and 'Next' buttons * Update tests
1 parent 587cf23 commit 717003c

File tree

3 files changed

+53
-108
lines changed

3 files changed

+53
-108
lines changed

src/components/Stepper.vue

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,21 @@
5454
v-if="step.status==='current'"
5555
class="step-navigation"
5656
>
57-
<a
57+
<v-button
5858
v-if="step.name!=='FS'"
59-
role="button"
60-
class="pagination-previous"
59+
class="is-border"
6160
@click="handlePrevious(step.name)"
62-
>{{ $t('stepper.nav.previous-label') }}</a>
63-
<a
61+
>
62+
{{ $t('stepper.nav.previous-label') }}
63+
</v-button>
64+
<v-button
6465
v-if="step.name!=='AD'"
65-
role="button"
66-
:class="['pagination-next', nextButtonEnabledState(step.id)]"
66+
:class="['is-success', nextButtonEnabledState(step.id)]"
67+
:disabled="nextButtonEnabledState(step.id) ? 'disabled' : null"
6768
@click="handleNext(step.name)"
68-
>{{ $t('stepper.nav.next-label') }}</a>
69+
>
70+
{{ $t('stepper.nav.next-label') }}
71+
</v-button>
6972
<span
7073
v-else
7174
class="pagination-finish"
@@ -184,10 +187,13 @@ export default {
184187
*/
185188
return ['NC', 'ND', 'SA'].indexOf(stepName) > -1
186189
},
190+
/**
191+
* Checks if the Next button should be disabled. Next button is enabled only
192+
* after the user has interacted with the step (selected radio or checked a checkbox)
193+
* @param {number} stepId
194+
* @returns {'disabled'|''} next button's disabled status
195+
*/
187196
nextButtonEnabledState(stepId) {
188-
/**
189-
* Disables the 'Next' button before the user interacts with the step
190-
*/
191197
return this.steps[stepId].selected === undefined
192198
? 'disabled'
193199
: ''
@@ -395,39 +401,9 @@ export default {
395401
.step-navigation {
396402
margin: 13px 0;
397403
padding-left: 65px;
398-
}
399-
.step-navigation .pagination-next,
400-
.step-navigation .pagination-previous {
401-
font-family: Roboto Condensed,sans-serif;
402-
font-style: normal;
403-
font-size: 18px;
404-
line-height: 24px;
405-
}
406-
.step-navigation,
407-
.step-navigation {
408-
font-weight: 500;
409-
}
410-
.pagination-next,
411-
.pagination-previous {
412-
font-weight: bold;
413-
}
414-
.step-navigation .pagination-previous {
415-
border: 2px solid #787878;
416-
color: #787878;
417-
}
418-
.step-navigation .pagination-next {
419-
background-color: #04a635;
420-
color: #fff!important;
421-
border: 2px solid transparent;
422-
}
423-
.pagination-next.disabled {
424-
background-color: #D8D8D8;
425-
color: #787878 !important;
426-
}
427-
.pagination-next.disabled:hover,
428-
.pagination-next.disabled:active {
429-
box-shadow: none;
430-
border: 1px solid transparent;
404+
.button + .button {
405+
margin-left: 1rem;
406+
}
431407
}
432408
.pagination-finish{
433409
margin-left: 1rem;

tests/unit/specs/components/Stepper.spec.js

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import Vuex from 'vuex'
22
import { shallowMount, createLocalVue, config } from '@vue/test-utils'
33
import Stepper from '@/components/Stepper'
44
import Buefy from 'buefy'
5+
import VueVocabulary from '@creativecommons/vue-vocabulary/vue-vocabulary.common'
56
import VueI18n from 'vue-i18n'
67
import Vue from 'vue'
78
import store from '@/store'
89

910
function getNextButton(wrapper) {
10-
return wrapper.find('.pagination-next')
11+
return wrapper.findAll('v-button-stub').at(1)
1112
}
1213
function clickNext(wrapper) {
13-
getNextButton(wrapper).trigger('click')
14+
getNextButton(wrapper).vm.$emit('click')
1415
}
1516
function getStepId(wrapper, stepName) {
1617
return wrapper.vm.steps.filter((step) => { return step.name === stepName })[0].id
@@ -40,6 +41,7 @@ function setUp() {
4041
localVue = createLocalVue()
4142
localVue.use(Vuex)
4243
localVue.use(Buefy)
44+
localVue.use(VueVocabulary)
4345
Vue.use(VueI18n)
4446
const messages = require('@/locales/en.json')
4547
const i18n = new VueI18n({
@@ -115,46 +117,20 @@ describe('Stepper.vue', () => {
115117
})
116118
describe('Next button', () => {
117119
it('becomes clickable only after selection is made', () => {
118-
const nextButton = wrapper.find('.pagination-next')
119-
expect(nextButton.classes('disabled')).toBe(true)
120+
const nextButtonStub = wrapper.find('v-button-stub')
121+
expect(nextButtonStub.classes('disabled')).toBe(true)
120122
setStepSelected(wrapper, 'FS', false)
121-
expect(nextButton.classes('disabled')).toBe(false)
123+
expect(nextButtonStub.classes('disabled')).toBe(false)
122124
})
123125
it('clicking on Next button advances the step', () => {
124126
setStepSelected(wrapper, 'FS', true)
125-
clickNext(wrapper)
127+
wrapper.find('v-button-stub').vm.$emit('click')
126128
const steps = wrapper.findAll('.step-container')
127129
expect(steps.at(0).classes('previous')).toBe(true)
128130
expect(steps.at(1).classes('current')).toBe(true)
129131
})
130132
})
131-
describe('Previous button', () => {
132-
it('AttributionDetails Step opens correct step when Previous button is clicked', () => {
133-
// For BY- licenses, it should open SA step
134-
advanceStep(wrapper, [
135-
{ stepName: 'FS', isSelected: false },
136-
{ stepName: 'BY', isSelected: true },
137-
{ stepName: 'NC', isSelected: false },
138-
{ stepName: 'ND', isSelected: false },
139-
{ stepName: 'SA', isSelected: false }])
140-
wrapper.find('.pagination-previous').trigger('click')
141-
expect(wrapper.find('.current').classes()).toContain('SA')
142-
// for CC0 license, it should open CW step
143-
wrapper.findAll('.step-header').at(1).trigger('click')
144-
setStepSelected(wrapper, 'BY', false)
145-
clickNext(wrapper)
146-
setStepSelected(wrapper, 'CW', true)
147-
clickNext(wrapper)
148-
wrapper.find('.pagination-previous').trigger('click')
149-
expect(wrapper.find('.current').classes()).toContain('CW')
150-
// if using dropdown with a BY- license, it should open DD step
151-
wrapper.findAll('.step-header').at(0).trigger('click')
152-
advanceStep(wrapper, [{ stepName: 'FS', isSelected: true }])
153-
advanceStep(wrapper, [{ stepName: 'DD', isSelected: true, license: 'CC BY-NC-ND 4.0' }])
154-
wrapper.find('.pagination-previous').trigger('click')
155-
expect(wrapper.find('.current').classes()).toContain('DD')
156-
})
157-
})
133+
158134
describe('FirstStep interactions', () => {
159135
it('choosing Yes sets 3 steps visible: FS, Dropdown and AttributionDetails, opens DD', () => {
160136
advanceStep(wrapper, [
@@ -166,40 +142,15 @@ describe('Stepper.vue', () => {
166142
})
167143
it('choosing No sets 6 steps visible: FS, BY, NC, ND, SA and AttributionDetails, opens BY', () => {
168144
setStepSelected(wrapper, 'FS', false)
169-
clickNext(wrapper)
145+
const nextButton = wrapper.find('v-button-stub')
146+
nextButton.vm.$emit('click')
170147
const steps = wrapper.findAll('.step-container')
171148
expect(steps.length).toEqual(6)
172149
expect(wrapper.vm.currentStepId).toEqual(1)
173150
expect(stepHeadingText(steps, 1)).toEqual(wrapper.vm.$t('stepper.BY.question'))
174151
})
175152
})
176-
describe('Step interactions', () => {
177-
it('BY: selecting No updates enabled steps; disables NC, ND and SA; opens CopyrightWaiverStep', () => {
178-
advanceStep(wrapper, [{ stepName: 'FS', isSelected: false }])
179-
setStepSelected(wrapper, 'BY', false)
180-
const nextButton = getNextButton(wrapper)
181-
expect(nextButton.classes('disabled')).toBe(false)
182-
const steps = wrapper.findAll('.step-container')
183-
const disabledSteps = wrapper.findAll('.disabled')
184-
expect(disabledSteps.length).toEqual(3)
185-
expect(steps.length).toEqual(7)
186-
clickNext(wrapper)
187-
expect(wrapper.find('.current').classes()).toContain('CW')
188-
})
189-
it('ND: selecting ND license updates enabled steps; disables SA step; opens AttributionDetailsStep', () => {
190-
advanceStep(wrapper, [
191-
{ stepName: 'FS', isSelected: false },
192-
{ stepName: 'BY', isSelected: true },
193-
{ stepName: 'NC', isSelected: false }])
194-
setStepSelected(wrapper, 'ND', true)
195-
const steps = wrapper.findAll('.step-container')
196-
const disabledSteps = wrapper.findAll('.disabled')
197-
expect(disabledSteps.length).toEqual(1)
198-
expect(steps.length).toEqual(6)
199-
clickNext(wrapper)
200-
expect(wrapper.find('.current').classes()).toContain('AD')
201-
})
202-
})
153+
203154
describe('DropdownStep interactions', () => {
204155
beforeEach(() => {
205156
// setUp()

tests/unit/specs/components/__snapshots__/Stepper.spec.js.snap

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ exports[`Stepper.vue renders correctly has expected UI initially 1`] = `
1010
</div>
1111
<firststep-stub stepid="0" status="current"></firststep-stub>
1212
<nav class="step-navigation">
13-
<!----> <a role="button" class="pagination-next disabled">NEXT STEP</a></nav>
13+
<!---->
14+
<v-button-stub size="normal" disabled="disabled" class="is-success disabled">
15+
NEXT STEP
16+
</v-button-stub>
17+
</nav>
1418
</div>
1519
<div class="step-container BY inactive enabled">
1620
<div class="step-header">
@@ -87,7 +91,14 @@ exports[`Stepper.vue renders correctly has expected UI on CW step after DD 1`] =
8791
</h5>
8892
</div>
8993
<copyrightwaiverstep-stub stepid="6" stepname="CW" status="current"></copyrightwaiverstep-stub>
90-
<nav class="step-navigation"><a role="button" class="pagination-previous">BACK</a> <a role="button" class="pagination-next disabled">NEXT STEP</a></nav>
94+
<nav class="step-navigation">
95+
<v-button-stub size="normal" class="is-border">
96+
BACK
97+
</v-button-stub>
98+
<v-button-stub size="normal" disabled="disabled" class="is-success disabled">
99+
NEXT STEP
100+
</v-button-stub>
101+
</nav>
91102
</div>
92103
<div class="step-container AD inactive enabled">
93104
<div class="step-header">
@@ -137,7 +148,14 @@ exports[`Stepper.vue renders correctly has expected UI on ND step 1`] = `
137148
</h5>
138149
</div>
139150
<step-stub stepname="ND" stepid="3" status="current" reversed="true" enabled="true"></step-stub>
140-
<nav class="step-navigation"><a role="button" class="pagination-previous">BACK</a> <a role="button" class="pagination-next disabled">NEXT STEP</a></nav>
151+
<nav class="step-navigation">
152+
<v-button-stub size="normal" class="is-border">
153+
BACK
154+
</v-button-stub>
155+
<v-button-stub size="normal" disabled="disabled" class="is-success disabled">
156+
NEXT STEP
157+
</v-button-stub>
158+
</nav>
141159
</div>
142160
<div class="step-container SA inactive enabled">
143161
<div class="step-header">

0 commit comments

Comments
 (0)