Skip to content

Commit 4128112

Browse files
committed
Help Section Overhaul and edit tests
Signed-off-by: Olga Bulat <obulat@gmail.com>
1 parent 4c5f46d commit 4128112

File tree

10 files changed

+379
-422
lines changed

10 files changed

+379
-422
lines changed

src/components/HelpSection.vue

Lines changed: 157 additions & 155 deletions
Large diffs are not rendered by default.

src/utils/attributionHtml.js

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function workTitle(form) {
1919
}
2020

2121
function workAuthor(form) {
22-
console.log('Getting work author: ', form.creatorName)
2322
if (form.creatorName) {
2423
const creatorNameNoLink = `<span rel="cc:attributionName">${form.creatorName}</span>`
2524
return form.creatorProfileUrl ? `by <a rel="cc:attributionURL" href="${form.creatorProfileUrl}">${creatorNameNoLink}</a>` : `by ${creatorNameNoLink}`
@@ -28,46 +27,17 @@ function workAuthor(form) {
2827

2928
function workLicense(ccLicenseURL, shortLicenseName) {
3029
const baseAssetsPath = 'https://search.creativecommons.org/static/img'
31-
const licenseLink = `<a rel="license" href="${ccLicenseURL}" style="margin-right: 5px;">${shortLicenseName.toUpperCase()}</a>`
32-
let licenseIcons = `<img style="height: inherit;margin-right: 3px;display: inline-block;" src="${baseAssetsPath}/cc_icon.svg" />`
33-
console.log('Icons: ', licenseIcons)
30+
const licenseLink = `<a rel="license" href="${ccLicenseURL}" target="_blank" rel="noopener noreferrer" style="display: inline-block;">${shortLicenseName.toUpperCase()}`
31+
let licenseIcons = `<img style="height: 22px!important;margin-left: 3px;vertical-align:text-bottom;" src="${baseAssetsPath}/cc_icon.svg" />`
3432
if (shortLicenseName) {
3533
if (shortLicenseName.includes('CC0')) {
3634
shortLicenseName = 'CC CC0 1.0'
3735
}
3836
licenseIcons += shortLicenseName.slice(3, shortLicenseName.length - 4).split('-').map(license =>
39-
`<img style="height: inherit;margin-right: 3px;display: inline-block;" src="${baseAssetsPath}/cc-${license.toLowerCase()}_icon.svg" />`
37+
`<img style="margin-top: 2px;height: 22px!important;margin-left: 3px;vertical-align:text-bottom;" src="${baseAssetsPath}/cc-${license.toLowerCase()}_icon.svg" />`
4038
).join('')
41-
const licenseImgLink = `<a href="${ccLicenseURL}" target="_blank" rel="noopener noreferrer" style="display: inline-block;opacity: .7;margin-top: 2px;margin-left: 3px;height: 22px !important;vertical-align:text-bottom">${licenseIcons}</a>`
39+
const licenseImgLink = `<span class="license-icons" style="opacity:.7">${licenseIcons}</span></a>`
4240
return `${licenseLink}${licenseImgLink}`
4341
}
4442
}
45-
46-
// function attributionHtml(form, ccLicenseURL, shortLicenseName) {
47-
// The default string in English is:
48-
// This work is licensed under CC BY 4.0
49-
// String if each form field is filled in
50-
// 'My work" by Author is licensed under CC BY 4.0
51-
// const baseAssetsPath = 'https://search.creativecommons.org/static/img'
52-
// const workTitle = form.workTitle ? `${form.workTitle}` : 'This work'
53-
// const workLink = form.workUrl ? `<a href="${form.workUrl}">${workTitle}</a>` : workTitle
54-
// const creatorNameNoLink = `<span>${form.authorName}</span>`
55-
// const creatorNameLink = form.creatorProfileUrl ? `<a href="${form.creatorProfileUrl}">${creatorNameNoLink}</a>` : creatorNameNoLink
56-
// const creator = `<span> by ${creatorNameLink}</span>`
57-
// const licenseLink = ` is licensed under <a rel="license" href="${ccLicenseURL}" style="margin-right: 5px;">${shortLicenseName.toUpperCase()}</a>`
58-
59-
// let licenseIcons = `<img style="height: inherit;margin-right: 3px;display: inline-block;" src="${baseAssetsPath}/cc_icon.svg" />` // eslint-disable-line global-require, import/no-dynamic-require
60-
// if (shortLicenseName) {
61-
// licenseIcons += shortLicenseName.slice(3, shortLicenseName.length - 4).split('-').map(license =>
62-
// `<img style="height: inherit;margin-right: 3px;display: inline-block;"
63-
// src="${baseAssetsPath}/cc-${license.toLowerCase()}_icon.svg" />` // eslint-disable-line global-require, import/no-dynamic-require
64-
// ).join('')
65-
// }
66-
67-
// const licenseImgLink = `<a href="${ccLicenseURL}" target="_blank" rel="noopener noreferrer" style="display: inline-block;opacity: .7;margin-top: 2px;margin-left: 3px;height: 22px !important;">${licenseIcons}</a>`
68-
// return `<p style="font-size: 0.9rem;">${workLink}${creator}${licenseLink}${licenseImgLink}</p>`
69-
// return { title: workTitle(form), author: workAuthor(form) }
70-
// }
71-
72-
// export default attributionHtml
7343
export { workAuthor, workTitle, workLicense }

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { createLocalVue, mount } from '@vue/test-utils'
1+
import {config, createLocalVue, mount} from '@vue/test-utils'
22
import SelectedLicenseDropdown from '@/components/SelectedLicenseDropdown'
33
import Buefy from 'buefy'
44
import LicenseUtilities from '@/utils/license-utilities'
5+
import Vue from 'vue'
6+
import VueI18n from 'vue-i18n'
57

68
const value = {
79
shortName: 'CC BY 4.0',
@@ -20,6 +22,19 @@ describe('LicenseDropdown.vue', () => {
2022
const localVue = createLocalVue()
2123
localVue.use(Buefy)
2224
localVue.use(LicenseUtilities)
25+
Vue.use(VueI18n)
26+
const messages = require('@/locales/en.json')
27+
const i18n = new VueI18n({
28+
locale: 'en',
29+
fallbackLocale: 'en',
30+
messages: messages
31+
})
32+
33+
config.mocks.i18n = i18n
34+
35+
config.mocks.$t = (key) => {
36+
return i18n.messages[key]
37+
}
2338
wrapper = mount(SelectedLicenseDropdown, {
2439
localVue,
2540
propsData: {
@@ -28,9 +43,6 @@ describe('LicenseDropdown.vue', () => {
2843
})
2944
})
3045
describe('correctly displays initial information and options when mounted', () => {
31-
it('renders the label', () => {
32-
expect(wrapper.html()).toContain('Current selection')
33-
})
3446

3547
it('initializes with base license names', () => {
3648
expect(wrapper.vm.$props.value.shortName).toEqual('CC BY 4.0')

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

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import { mount, createLocalVue } from '@vue/test-utils'
2-
import SelectedLicenseCode from '@/components/SelectedLicenseCode'
1+
import { mount, createLocalVue, config } from '@vue/test-utils'
32
import Buefy from 'buefy'
4-
import sinon from 'sinon'
3+
import SelectedLicenseCode from '@/components/SelectedLicenseCode'
54
import LicenseUtilities from '@/utils/license-utilities'
5+
import Vue from 'vue'
6+
import VueI18n from 'vue-i18n'
67

78
const value = {
89
shortName: 'CC BY 4.0',
910
fullName: 'Attribution 4.0 International',
10-
personalDetails: {
11-
authorName: '',
11+
attributionDetails: {
12+
creatorName: '',
13+
creatorProfileUrl: '',
1214
workTitle: '',
13-
workUrl: '',
14-
sourceWorkUrl: ''
15+
workUrl: ''
1516
}
1617
}
18+
1719
// mock dom methods
1820
function _mockDomMethodsForClipboardJS(value) {
1921
window.getSelection = () => ({
@@ -28,24 +30,32 @@ function _mockDomMethodsForClipboardJS(value) {
2830

2931
describe('SelectedLicenseCode.vue', () => {
3032
let wrapper
31-
let spy
3233

3334
beforeEach(() => {
3435
const localVue = createLocalVue()
3536
localVue.use(Buefy)
3637
localVue.use(LicenseUtilities)
38+
Vue.use(VueI18n)
39+
const messages = require('@/locales/en.json')
40+
const i18n = new VueI18n({
41+
locale: 'en',
42+
fallbackLocale: 'en',
43+
messages: messages
44+
})
45+
46+
config.mocks.i18n = i18n
47+
48+
config.mocks.$t = (key) => {
49+
return i18n.messages[key]
50+
}
3751

3852
_mockDomMethodsForClipboardJS()
39-
spy = sinon.stub()
4053
wrapper = mount(SelectedLicenseCode, {
4154
localVue,
4255
propsData: {
4356
value: value
4457
},
45-
attachToDocument: true,
46-
destroyed() {
47-
spy()
48-
}
58+
attachToDocument: true
4959
})
5060
})
5161
// Snapshot tests
@@ -106,4 +116,20 @@ describe('SelectedLicenseCode.vue', () => {
106116
expect(emittedEvents).toHaveProperty('copyFailed')
107117
expect(emittedEvents.copyFailed.length).toBe(1)
108118
})
119+
120+
// Test generated HTML
121+
it('Generates correct license HTML', () => {
122+
const generatedHtml = wrapper.find('#license-code')
123+
expect(generatedHtml.text()).toContain('is licensed under CC BY 4.0')
124+
// check that icon links are correct
125+
// There are two icons - CC & BY
126+
expect(generatedHtml.findAll('img')).toHaveLength(2)
127+
// There are three links: two icons and license name
128+
expect(generatedHtml.findAll('a')).toHaveLength(1)
129+
console.log(generatedHtml.find('a').attributes('href'))
130+
expect(generatedHtml.find('a').attributes('href')).toEqual('https://creativecommons.org/licenses/by/4.0/?ref=ccchooser')
131+
// check that the text is correct
132+
console.log(wrapper.vm.authorElement)
133+
// check that changing fields generate correct texts
134+
})
109135
})

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { shallowMount, createLocalVue } from '@vue/test-utils'
1+
import {shallowMount, createLocalVue, config} from '@vue/test-utils'
22
import SelectedLicenseInfo from '@/components/SelectedLicenseInfo'
33
import Buefy from 'buefy'
44
import LicenseUtilities from '@/utils/license-utilities'
5+
import Vue from 'vue'
6+
import VueI18n from 'vue-i18n'
57

68
describe('SelectedLicenseInfo.vue', () => {
79
let wrapper
@@ -11,6 +13,19 @@ describe('SelectedLicenseInfo.vue', () => {
1113
const localVue = createLocalVue()
1214
localVue.use(Buefy)
1315
localVue.use(LicenseUtilities)
16+
Vue.use(VueI18n)
17+
const messages = require('@/locales/en.json')
18+
const i18n = new VueI18n({
19+
locale: 'en',
20+
fallbackLocale: 'en',
21+
messages: messages
22+
})
23+
24+
config.mocks.i18n = i18n
25+
26+
config.mocks.$t = (key) => {
27+
return i18n.messages[key]
28+
}
1429

1530
wrapper = shallowMount(SelectedLicenseInfo, {
1631
localVue,

0 commit comments

Comments
 (0)