Skip to content

Commit 8056cae

Browse files
committed
Update unit tests
Signed-off-by: Olga Bulat <obulat@gmail.com>
1 parent f5a2416 commit 8056cae

12 files changed

+151
-19
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { shallowMount, createLocalVue } from '@vue/test-utils'
22
import HelpSection from '@/components/HelpSection'
33
import Buefy from 'buefy'
4+
import LicenseUtilities from '@/utils/license-utilities'
45

56
describe('HelpSection.vue', () => {
67
let wrapper
@@ -9,6 +10,7 @@ describe('HelpSection.vue', () => {
910
beforeEach(() => {
1011
const localVue = createLocalVue()
1112
localVue.use(Buefy)
13+
localVue.use(LicenseUtilities)
1214

1315
wrapper = shallowMount(HelpSection, {
1416
localVue

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {createLocalVue, mount} from '@vue/test-utils'
1+
import { createLocalVue, mount } from '@vue/test-utils'
22
import SelectedLicenseDropdown from '@/components/SelectedLicenseDropdown'
33
import Buefy from 'buefy'
4+
import LicenseUtilities from '@/utils/license-utilities'
45

56
const value = {
67
shortName: 'CC BY 4.0',
@@ -18,6 +19,7 @@ describe('LicenseDropdown.vue', () => {
1819
beforeEach(() => {
1920
const localVue = createLocalVue()
2021
localVue.use(Buefy)
22+
localVue.use(LicenseUtilities)
2123
wrapper = mount(SelectedLicenseDropdown, {
2224
localVue,
2325
propsData: {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mount, createLocalVue } from '@vue/test-utils'
22
import PersonalizationStep from '@/components/PersonalizationStep'
33
import Buefy from 'buefy'
4+
import LicenseUtilities from '@/utils/license-utilities'
45

56
describe('PersonalizationStep.vue', () => {
67
let wrapper
@@ -9,6 +10,7 @@ describe('PersonalizationStep.vue', () => {
910
beforeEach(() => {
1011
const localVue = createLocalVue()
1112
localVue.use(Buefy)
13+
localVue.use(LicenseUtilities)
1214

1315
wrapper = mount(PersonalizationStep, {
1416
localVue,

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { mount, createLocalVue } from '@vue/test-utils'
22
import SelectedLicenseCode from '@/components/SelectedLicenseCode'
33
import Buefy from 'buefy'
44
import sinon from 'sinon'
5+
import LicenseUtilities from '@/utils/license-utilities'
56

67
const value = {
78
shortName: 'CC BY 4.0',
@@ -28,11 +29,12 @@ function _mockDomMethodsForClipboardJS(value) {
2829
describe('SelectedLicenseCode.vue', () => {
2930
let wrapper
3031
let spy
31-
let clipboard
3232

3333
beforeEach(() => {
3434
const localVue = createLocalVue()
3535
localVue.use(Buefy)
36+
localVue.use(LicenseUtilities)
37+
3638
_mockDomMethodsForClipboardJS()
3739
spy = sinon.stub()
3840
wrapper = mount(SelectedLicenseCode, {
@@ -91,15 +93,17 @@ describe('SelectedLicenseCode.vue', () => {
9193
// Test copying
9294
it('Copies text from active tab', () => {
9395
const copyLink = wrapper.findAll('li').at(2).find('a').find('span').find('a')
96+
9497
expect(wrapper.vm.currentTab).toEqual(0)
95-
expect(wrapper.vm.clipboardTarget).toEqual('#attribution-richtext')
96-
wrapper.findAll('li').at(1).find('a').trigger('click')
97-
expect(wrapper.vm.clipboardTarget).toEqual('#attribution-html')
98+
expect(wrapper.vm.clipboardTarget()).toEqual('#attribution-richtext')
99+
const htmlTab = wrapper.findAll('li').at(1).find('a')
100+
htmlTab.trigger('click')
98101
copyLink.trigger('click')
99-
expect(wrapper.vm.clipboardTarget).toEqual('#attribution-html')
102+
expect(wrapper.vm.clipboardTarget()).toEqual('#attribution-html')
103+
expect(wrapper.vm.currentSelection).toEqual('html')
104+
100105
const emittedEvents = wrapper.emitted()
101106
expect(emittedEvents).toHaveProperty('copyFailed')
102107
expect(emittedEvents.copyFailed.length).toBe(1)
103108
})
104-
105109
})

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { shallowMount, createLocalVue } from '@vue/test-utils'
22
import SelectedLicenseInfo from '@/components/SelectedLicenseInfo'
33
import Buefy from 'buefy'
4+
import LicenseUtilities from '@/utils/license-utilities'
45

56
describe('SelectedLicenseInfo.vue', () => {
67
let wrapper
@@ -9,6 +10,7 @@ describe('SelectedLicenseInfo.vue', () => {
910
beforeEach(() => {
1011
const localVue = createLocalVue()
1112
localVue.use(Buefy)
13+
localVue.use(LicenseUtilities)
1214

1315
wrapper = shallowMount(SelectedLicenseInfo, {
1416
localVue,

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
1-
import { shallowMount, createLocalVue } from '@vue/test-utils'
1+
import { mount, createLocalVue, config } from '@vue/test-utils'
22
import SelectionStep from '@/components/SelectionStep'
33
import Buefy from 'buefy'
4+
import LicenseUtilities from '@/utils/license-utilities'
5+
import VueI18n from 'vue-i18n'
46

57
describe('SelectionStep.vue', () => {
68
let wrapper
79

8-
// Always creates a shallow instance of component
910
beforeEach(() => {
1011
const localVue = createLocalVue()
1112
localVue.use(Buefy)
13+
localVue.use(LicenseUtilities)
14+
localVue.use(VueI18n)
1215

13-
wrapper = shallowMount(SelectionStep, {
16+
const i18n = new VueI18n({
17+
locale: 'en',
18+
fallbackLocale: 'en',
19+
messages: 'src/locales/en.json'
20+
})
21+
22+
config.mocks.i18n = i18n
23+
24+
config.mocks.$t = (key) => {
25+
return i18n.t(key)
26+
}
27+
28+
wrapper = mount(SelectionStep, {
1429
localVue,
1530
propsData: {
16-
value: {
17-
shortName: 'CC BY 4.0',
18-
fullName: 'Attribution 4.0 International'
19-
}
31+
selected: true,
32+
stepId: 'by'
2033
}
2134
})
2235
})

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { shallowMount, createLocalVue } from '@vue/test-utils'
22
import Stepper from '@/components/Stepper'
33
import Buefy from 'buefy'
4+
import LicenseUtilities from '@/utils/license-utilities'
45

56
describe('Stepper.vue', () => {
67
let wrapper
@@ -9,6 +10,7 @@ describe('Stepper.vue', () => {
910
beforeEach(() => {
1011
const localVue = createLocalVue()
1112
localVue.use(Buefy)
13+
localVue.use(LicenseUtilities)
1214

1315
wrapper = shallowMount(Stepper, {
1416
localVue,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`PersonalizationStep.vue has the expected UI 1`] = `
4+
<section class="pers-form">
5+
<div class="field is-floating-in-label"><label class="label">Work Author</label>
6+
<div class="control is-clearfix"><input type="text" autocomplete="on" placeholder="John Silver" class="input">
7+
<!---->
8+
<!---->
9+
<!---->
10+
</div>
11+
<!---->
12+
</div>
13+
<div class="field is-floating-in-label"><label class="label">Title of Work</label>
14+
<div class="control is-clearfix"><input type="text" autocomplete="on" placeholder="This work" class="input">
15+
<!---->
16+
<!---->
17+
<!---->
18+
</div>
19+
<!---->
20+
</div>
21+
<div class="field is-floating-in-label"><label class="label">Work URL</label>
22+
<div class="control is-clearfix"><input type="text" autocomplete="on" placeholder="https://www.example.com/image.jpg" class="input">
23+
<!---->
24+
<!---->
25+
<!---->
26+
</div>
27+
<!---->
28+
</div>
29+
<div class="field is-floating-in-label"><label class="label">URL of the Source Work</label>
30+
<div class="control is-clearfix"><input type="text" autocomplete="on" placeholder="https://www.example.com/source.jpg" class="input">
31+
<!---->
32+
<!---->
33+
<!---->
34+
</div>
35+
<!---->
36+
</div>
37+
</section>
38+
`;

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ exports[`SelectedLicenseCode.vue has the expected UI 1`] = `
1111
<!----> <span>Rich Text</span></a></li>
1212
<li class=""><a>
1313
<!----> <span>HTML</span></a></li>
14-
<li class=""><a><span><a data-clipboard-target="#attribution-richtext" class="copyBtn"><span class="icon" icon-pack="fas"><i class="mdi mdi-copy mdi-24px"></i></span>
15-
Copy
16-
</a></span></a></li>
14+
<li class=""><a><span><a data-clipboard-target="#attribution-richtext" class="copyBtn"><span class="icon" icon-pack="fas"><i class="mdi mdi-copy mdi-24px"></i></span> <span class="button-text">Copy
15+
</span></a></span></a></li>
1716
</ul>
1817
</nav>
1918
<section class="tab-content">
2019
<div class="tab-item" style="">
21-
<div id="attribution-richtext-container">
20+
<div id="generated-richtext-container">
2221
<div id="attribution-richtext" class="photo_usage-attribution">
2322
<!---->
2423
<!---->
@@ -29,7 +28,7 @@ exports[`SelectedLicenseCode.vue has the expected UI 1`] = `
2928
<a href="https://creativecommons.org/licenses/by/4.0/?ref=ccchooser" target="_blank" rel="noopener" class="photo_license">
3029
CC BY 4.0
3130
</a>
32-
<!----> <a href="https://creativecommons.org/licenses/by/4.0/?ref=ccchooser" target="_blank" rel="noopener noreferrer" class="photo-license-icons"><img src="../assets/license-icons/cc_icon.svg" class="photo-license-icon"><img src="[object Object]" class="photo-license-icon"></a>
31+
<!----> <a href="https://creativecommons.org/licenses/by/4.0/?ref=ccchooser" target="_blank" rel="noopener noreferrer" class="attribution-license-icons"><img src="../assets/license-icons/cc_icon.svg" class="attribution-license-icon"> <img src="[object Object]" class="attribution-license-icon"></a>
3332
</div>
3433
</div>
3534
</div>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`SelectedLicenseInfo.vue has the expected UI 1`] = `
4+
<div class="selected-license-info">
5+
<h4><a href="https://creativecommons.org/licenses/by/4.0/?ref=ccchooser">Attribution 4.0 International</a></h4>
6+
<hr class="h4-underline">
7+
<section class="license-visual-info">
8+
<ul class="license-list"><span name="highlight"><li><licenseiconography-stub iconlist="by"></licenseiconography-stub> <span class="readable-string">
9+
The creator must be credited
10+
</span></li></span></ul> <a href="https://creativecommons.org/freeworks">
11+
<div class="license-freeworks-status"><img src="../assets/license-icons/fc_approved_small.png" alt="">
12+
<p>Free Culture License</p>
13+
</div>
14+
</a>
15+
</section>
16+
<licensedescription-stub selectedlicense="CC BY 4.0"></licensedescription-stub>
17+
</div>
18+
`;

0 commit comments

Comments
 (0)