Skip to content

Commit f094cf0

Browse files
author
Ari Madian
authored
Merge pull request #130 from hemanth-hk/master
Added unit and e2e tests for the LicenseCode.vue component
2 parents 2722c37 + e718e80 commit f094cf0

File tree

3 files changed

+171
-0
lines changed

3 files changed

+171
-0
lines changed

tests/e2e/specs/LicenseCode.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module.exports = {
2+
3+
'Check if the p-tag with the class license-text is present': function(browser) {
4+
browser
5+
.init()
6+
.assert.elementPresent('.control-label > span')
7+
.click('.control-label > span')
8+
.assert.elementPresent('.pagination-next')
9+
.click('.pagination-next')
10+
.assert.elementPresent('.select > select')
11+
.click('.select > select')
12+
.click('option[value="CC BY-SA 4.0"]')
13+
.assert.elementPresent('.pagination-next')
14+
.click('.pagination-next')
15+
.assert.elementPresent('p[class="license-text"]')
16+
},
17+
'Check if the links in the license code redirects properly': function(browser) {
18+
browser
19+
.setValue('input[placeholder="Jane Doe"]', 'Jane Doe')
20+
.setValue('input[placeholder="www.author.com"]', 'www.author.com')
21+
.setValue('input[placeholder="This work"]', 'This work')
22+
.setValue('input[placeholder="www.author.com/work.jpg"]', 'www.author.com/work.jpg')
23+
.assert.elementPresent('p[class="license-text"] a')
24+
.getAttribute('p > span > a:nth-child(1)', 'href', function(result) {
25+
this.assert.equal(result.value, 'http://localhost:8080/www.author.com/work.jpg')
26+
})
27+
.getAttribute('p > span > a:nth-child(2)', 'href', function(result) {
28+
this.assert.equal(result.value, 'http://localhost:8080/www.author.com')
29+
})
30+
.getAttribute('p > span > a:nth-child(4)', 'href', function(result) {
31+
this.assert.equal(result.value, 'https://creativecommons.org/licenses/by-sa/4.0/?ref=ccchooser')
32+
})
33+
},
34+
'Check if the text is displayed under the print attribution': function(browser) {
35+
browser
36+
.click('nav > ul > li:nth-child(2) > a')
37+
.assert.elementPresent('p[class="license-text"]')
38+
.assert.elementPresent('#attribution-text > p > span:nth-child(1)')
39+
.assert.elementPresent('#attribution-text > p > span:nth-child(2)')
40+
},
41+
42+
// Tests for the text under the "Plain Text"
43+
44+
'Check if the work in plain text is displayed': function(browser) {
45+
browser
46+
.click('nav > ul > li:nth-child(2) > a')
47+
.expect.element('#attribution-text > p > span:nth-child(1) > span:nth-child(1)').text.to.equal('This work')
48+
},
49+
'Check if the license in plain text is displayed': function(browser) {
50+
browser
51+
.expect.element('#attribution-text > p > span:nth-child(1) > span:nth-child(4)').text.to.equal('CC BY-SA 4.0')
52+
},
53+
'Check if the author-name in plain text is displayed': function(browser) {
54+
browser
55+
.expect.element('#attribution-text > p > span:nth-child(1) > span:nth-child(2) > span').text.to.equal('Jane Doe')
56+
},
57+
'Check if the license-details in plain text are displayed': function(browser) {
58+
browser
59+
.click('nav > ul > li:nth-child(2) > a')
60+
.assert.elementPresent('#attribution-text > p > span:nth-child(2)')
61+
.expect.element('#attribution-text > p > span:nth-child(2)').text.to.equal('. To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0')
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { mount, createLocalVue, config } from '@vue/test-utils'
2+
import LicenseCode from '@/components/LicenseCode.vue'
3+
import VueI18n from 'vue-i18n'
4+
import Vuex from 'vuex'
5+
6+
describe('LicenseCode.vue', () => {
7+
let wrapper
8+
let state
9+
let store
10+
11+
// Always creates a shallow instance of component
12+
beforeEach(() => {
13+
const localVue = createLocalVue()
14+
localVue.use(VueI18n)
15+
localVue.use(Vuex)
16+
state = {
17+
attributionDetails: {
18+
creatorName: '',
19+
creatorProfileUrl: 'www.author.com',
20+
workTitle: 'My work',
21+
workUrl: 'www.author.com/pic.jpg'
22+
}
23+
}
24+
store = new Vuex.Store({
25+
state
26+
})
27+
const messages = require('@/locales/en.json')
28+
const i18n = new VueI18n({
29+
locale: 'en',
30+
fallbackLocale: 'en',
31+
messages: messages,
32+
silentTranslationWarn: true
33+
})
34+
35+
config.mocks.i18n = i18n
36+
37+
config.mocks.$t = (key) => {
38+
return i18n.messages[key]
39+
}
40+
wrapper = mount(LicenseCode, {
41+
localVue,
42+
store,
43+
i18n
44+
})
45+
})
46+
47+
// Test for DOM elements which must be present
48+
it('Check if the p-tag with class license-text is present in the DOM', () => {
49+
expect(wrapper.contains('.license-text')).toBe(true)
50+
})
51+
52+
it('Check if the LicenseCode.vue component renders without any errors', () => {
53+
expect(wrapper.isVueInstance()).toBeTruthy()
54+
})
55+
56+
// Tests for computed props and methods
57+
it('Check the creatorSpan function returns else text correctly', () => {
58+
expect(wrapper.vm.creatorSpan).toBe('')
59+
})
60+
it('Check if the byString function returns else text correctly', () => {
61+
expect(wrapper.vm.byString).toBe('')
62+
})
63+
it('Check if the byString function returns the correct text', () => {
64+
state.attributionDetails.creatorName = 'J Doe'
65+
expect(wrapper.vm.byString).toBe('license-use.richtext.by')
66+
})
67+
it('Check if the creatorSpan function returns the correct text', () => {
68+
state.attributionDetails.creatorName = 'J Doe'
69+
expect(wrapper.vm.creatorSpan).toBe('<span rel="cc:attributionName">J Doe</span>')
70+
})
71+
it('Check if the creatorName function returns the correct text', () => {
72+
state.attributionDetails.creatorName = 'J Doe'
73+
expect(wrapper.vm.creatorName).toBe('J Doe')
74+
})
75+
it('Check if the creatorProfileUrl function returns the correct text', () => {
76+
expect(wrapper.vm.creatorProfileUrl).toBe('www.author.com')
77+
})
78+
it('Check if the workTitle function returns the correct text', () => {
79+
expect(wrapper.vm.workTitle).toBe('My work')
80+
})
81+
it('Check if the workUrl function returns the correct text', () => {
82+
expect(wrapper.vm.workUrl).toBe('www.author.com/pic.jpg')
83+
})
84+
it('Check if the isWeb function returns true if attribution type is web', () => {
85+
wrapper.setProps({
86+
attributionType: 'web'
87+
})
88+
expect(wrapper.vm.isWeb).toBe(true)
89+
})
90+
it('Check if the isWeb function returns false if attribution type is print', () => {
91+
wrapper.setProps({
92+
attributionType: 'print'
93+
})
94+
expect(wrapper.vm.isWeb).toBe(false)
95+
})
96+
97+
// Snapshot tests
98+
it('has the expected UI', () => {
99+
expect(wrapper).toMatchSnapshot()
100+
})
101+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`LicenseCode.vue has the expected UI 1`] = `
4+
<p xmlns:dct="http://purl.org/dc/terms/" xmlns:cc="http://creativecommons.org/ns#" class="license-text"><span>license-use.richtext.full-text</span>
5+
<!---->
6+
</p>
7+
`;

0 commit comments

Comments
 (0)