Skip to content

Commit 29b8e9f

Browse files
committed
Merge branch 'master' of https://github.com/creativecommons/chooser into UnitTestFS
2 parents d54618b + 3533fbe commit 29b8e9f

9 files changed

+1287
-12
lines changed

package-lock.json

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/license-utilities.js

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function attrToShort(attr) {
2828
}
2929

3030
function attrToFull(attr) {
31+
if (attr.BY === undefined) { return undefined }
3132
if (!attr.BY) { return 'CC0 1.0 Universal' }
3233
let base = 'Attribution'
3334
if (attr.NC) { base += '-NonCommercial' }

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+
}

tests/e2e/specs/LicenseDetailsCard.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
3+
'Check if the main div tag with the class selected-license-card 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('.selected-license-card')
14+
},
15+
'Check if the a tag with class license-name redirects correctly': function(browser) {
16+
browser
17+
.assert.elementPresent('a[class="license-name"]')
18+
.getAttribute('a[class="license-name"]', 'href', function(result) {
19+
this.assert.equal(result.value, 'https://creativecommons.org/licenses/by-sa/4.0/?ref=ccchooser')
20+
})
21+
}
22+
}
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,102 @@
1+
import { mount, createLocalVue, config } from '@vue/test-utils'
2+
import LicenseDetailsCard from '@/components/LicenseDetailsCard.vue'
3+
import { licenseSlug } from '@/utils/license-utilities'
4+
import VueI18n from 'vue-i18n'
5+
import Vuex from 'vuex'
6+
7+
describe('LicenseDetailsCard.vue', () => {
8+
let wrapper
9+
let getters
10+
let store
11+
12+
// Always creates a shallow instance of component
13+
beforeEach(() => {
14+
const localVue = createLocalVue()
15+
localVue.use(VueI18n)
16+
localVue.use(Vuex)
17+
getters = {
18+
shortName: () => {
19+
return 'CC BY-SA 4.0'
20+
},
21+
fullName: () => {
22+
return 'Attribution-ShareAlike 4.0 International'
23+
},
24+
licenseUrl: () => (mode) => {
25+
return 'https://creativecommons.org/licenses/by-sa/4.0/?ref=ccchooser'
26+
},
27+
iconsList: () => {
28+
return ['by', 'sa']
29+
}
30+
}
31+
store = new Vuex.Store({
32+
getters
33+
})
34+
const messages = require('@/locales/en.json')
35+
const i18n = new VueI18n({
36+
locale: 'en',
37+
fallbackLocale: 'en',
38+
messages: messages,
39+
silentTranslationWarn: true
40+
})
41+
42+
config.mocks.i18n = i18n
43+
44+
config.mocks.i18n.$t = (key) => {
45+
return i18n.messages[key]
46+
}
47+
wrapper = mount(LicenseDetailsCard, {
48+
localVue,
49+
store,
50+
i18n
51+
})
52+
})
53+
54+
it('Check if LicenseDetailsCard.vue component renders without any errors', () => {
55+
expect(wrapper.isVueInstance()).toBeTruthy()
56+
})
57+
58+
// Test for DOM elements which must be present
59+
it('Check if the main div-tag with class selected-license-card is present in the DOM', () => {
60+
expect(wrapper.contains('.selected-license-card')).toBe(true)
61+
})
62+
it('Check if the heading of the license details card is present in the DOM', () => {
63+
expect(wrapper.contains('h3')).toBe(true)
64+
})
65+
it('Check if the heading with full license name is present in the DOM', () => {
66+
expect(wrapper.contains('h4')).toBe(true)
67+
})
68+
it('Check if the license heading is a link to the license', () => {
69+
expect(wrapper.contains('.license-name')).toBe(true)
70+
})
71+
it('Check if the license description is present in the DOM', () => {
72+
expect(wrapper.contains('.chooser-selected-description')).toBe(true)
73+
})
74+
it('Check if the visual-info section is present in the DOM', () => {
75+
expect(wrapper.contains('.license-visual-info')).toBe(true)
76+
})
77+
it('Check if the license list is present in the DOM', () => {
78+
expect(wrapper.contains('.license-list')).toBe(true)
79+
})
80+
it('Check if the license list elements are present in the DOM', () => {
81+
expect(wrapper.contains('li')).toBe(true)
82+
})
83+
it('Check if the license list elements have description about them', () => {
84+
expect(wrapper.contains('.readable-string')).toBe(true)
85+
})
86+
87+
// Tests for computed props and methods
88+
it('Check if the slug function returns the correct text', () => {
89+
expect(wrapper.vm.slug).toBe(licenseSlug('CC BY-SA 4.0'))
90+
})
91+
it('Check if the licenseKey function returns the correct text', () => {
92+
expect(wrapper.vm.licenseKey).toBe(`license-details-card.full-description.${licenseSlug('CC BY-SA 4.0')}`)
93+
})
94+
it('Check if the licenseDescription function returns the correct text', () => {
95+
expect(wrapper.vm.licenseDescription).toBe(`${licenseSlug('CC BY-SA 4.0')}-description`)
96+
})
97+
98+
// Snapshot tests
99+
it('Check if the LicenseDetailsCard.vue component has the expected UI', () => {
100+
expect(wrapper).toMatchSnapshot()
101+
})
102+
})
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+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`LicenseDetailsCard.vue Check if the LicenseDetailsCard.vue component has the expected UI 1`] = `
4+
<div class="selected-license-card">
5+
<h3 class="vocab ha h3a">
6+
license-details-card.heading
7+
</h3>
8+
<h4 class="vocab h4b hb"><a href="https://creativecommons.org/licenses/by-sa/4.0/?ref=ccchooser" class="license-name">
9+
Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
10+
<a href="https://creativecommons.org/licenses/by-sa/4.0/?ref=ccchooser" target="_blank" rel="noopener noreferrer" class="photo-license-icons"><img alt="CC icon" title="CC icon" src="../assets/license-icons/cc_icon.svg" class="photo-license-icon"> <img alt="by icon" title="by icon" src="[object Object]" class="photo-license-icon"><img alt="sa icon" title="sa icon" src="[object Object]" class="photo-license-icon"></a></a></h4>
11+
<p class="chooser-selected-description"><b>CC-BY-SA</b>
12+
license-details-card.full-description.cc-by-sa
13+
</p>
14+
<section class="license-visual-info">
15+
<ul class="license-list"><span name="highlight"><li class="license-list-item by"><span class="readable-string"><b>BY:</b>
16+
license-details-card.item-description.by
17+
</span></li>
18+
<li class="license-list-item sa"><span class="readable-string"><b>SA:</b>
19+
license-details-card.item-description.sa
20+
</span></li>
21+
</span></ul>
22+
</section>
23+
</div>
24+
`;

0 commit comments

Comments
 (0)