Skip to content

Commit 03f702c

Browse files
committed
Merge branch 'master' of github.com:creativecommons/cc-chooser into 38-write-tests-for-license-description-component
2 parents 70bb2a4 + bcc3958 commit 03f702c

File tree

6 files changed

+158
-11
lines changed

6 files changed

+158
-11
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"babel-register": "^6.22.0",
4646
"chalk": "^2.0.1",
4747
"chromedriver": "^2.27.2",
48+
"clipboardy": "^2.1.0",
4849
"copy-webpack-plugin": "^4.0.1",
4950
"cross-spawn": "^5.0.1",
5051
"css-loader": "^0.28.0",

src/App.vue

+39-10
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
<HTMLGenerator :shortLicenseName="selected.shortName"/>
1010
</div>
1111
<Footer>
12-
<p>
13-
<a href="https://github.com/creativecommons/cc-chooser">Icons</a> by The Noun Project and FontAwesome.
14-
</p>
15-
<p>
16-
View this page's source code <a href="https://github.com/creativecommons/cc-chooser">on Github</a>.
17-
</p>
18-
<Locale/>
12+
<div class="panel">
13+
<div>
14+
<span><a href="https://github.com/creativecommons/cc-chooser">Icons</a> by The Noun Project and FontAwesome.</span>
15+
<span>View this page's source code <a href="https://github.com/creativecommons/cc-chooser">on Github</a>.</span>
16+
</div>
17+
<Locale/>
18+
</div>
1919
</Footer>
2020
</div>
2121
</template>
@@ -96,10 +96,39 @@ hr {
9696
margin-right: 3%;
9797
}
9898
}
99+
.vocab-container .vocab-grid .panel {
100+
height: 100%;
101+
display: -webkit-box;
102+
display: -ms-flexbox;
103+
display: flex;
104+
-webkit-box-orient: vertical;
105+
-webkit-box-direction: normal;
106+
-ms-flex-direction: column;
107+
flex-direction: column;
108+
-webkit-box-pack: justify;
109+
-ms-flex-pack: justify;
110+
justify-content: space-between;
111+
}
112+
.vocab.select-field.normal-sized {
113+
font-size: 1rem;
114+
}
115+
.vocab.select-field>.field.has-addons {
116+
padding-left: calc(1em + var(--select-field-addons-space));
117+
margin-bottom: 0;
118+
min-width: 10em;
119+
}
120+
.vocab.select-field>.field>option[disabled] {
121+
opacity: 0.6;
122+
}
99123
</style>
100-
<style scoped>
101-
p {
102-
margin-bottom: .5em;
124+
<style scoped>
125+
p { margin-bottom: .5em; }
126+
#custom .panel > div:first-child {
127+
margin-bottom: 10vh;
128+
}
129+
.vocab.footer {
130+
font-family: Source Sans Pro,Noto Sans,Arial,Helvetica Neue,Helvetica,sans-serif;
131+
line-height: 1.2;
103132
}
104133
</style>
105134

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const clipboardy = require('clipboardy');
2+
3+
module.exports = {
4+
'Copybutton.vue - testing the #copy-richtext-btn flow': function (browser) {
5+
browser
6+
.url(browser.globals.devServerURL)
7+
.waitForElementVisible('#app', 5000)
8+
.assert.elementPresent('#copy-richtext-btn')
9+
.assert.elementPresent('#attribution-richtext')
10+
.click('#copy-richtext-btn')
11+
.assert.containsText('#copy-richtext-btn', "Copied!")
12+
.getText('#attribution-richtext', function (result) {
13+
this.assert.equal(result.value, clipboardy.readSync().trim());
14+
})
15+
.expect.element('#copy-richtext-btn').text.to.equal('Copy Rich Text').after(3000);
16+
},
17+
18+
'Copybutton.vue - testing the #copy-html-btn flow': function (browser) {
19+
browser
20+
.url(browser.globals.devServerURL)
21+
.waitForElementVisible('#app', 5000)
22+
.assert.elementPresent('#copy-html-btn')
23+
.assert.elementPresent('#attribution-html')
24+
.click('#copy-html-btn')
25+
.assert.containsText('#copy-html-btn', "Copied!")
26+
.getValue('#attribution-html', function (result) {
27+
this.assert.equal(result.value, clipboardy.readSync().trim());
28+
})
29+
.expect.element('#copy-html-btn').text.to.equal('Copy HTML').after(3000);
30+
}
31+
}
32+
33+

test/unit/jest.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
transform: {
1414
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
1515
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest',
16-
'^.+\\.svg$': '<rootDir>/test/svgTransform.js'
16+
'^.+\\.svg$': '<rootDir>/test/unit/svgTransform.js'
1717
},
1818
testPathIgnorePatterns: [
1919
'<rootDir>/test/e2e'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import Vue from 'vue'
2+
import { mount } from '@vue/test-utils'
3+
import CopyButton from '@/components/CopyButton.vue'
4+
import { doesNotThrow } from 'assert';
5+
6+
const DOM_SOURCE_ID = 'el-test';
7+
const DOM_SOURCE_VALUE = 'test clipboard value';
8+
9+
const slots = { default: 'Copy button' };
10+
const propsData = { id: 'copy-button', el: `#${DOM_SOURCE_ID}` }
11+
const defaults = {
12+
slots,
13+
propsData,
14+
attachToDocument: true,
15+
}
16+
17+
let wrapper
18+
19+
// mock dom source
20+
function _mockDOMSource(value) {
21+
// creates the span and append to JSDOM
22+
const span = document.createElement('span')
23+
span.setAttribute('id', DOM_SOURCE_ID);
24+
span.textContent = value;
25+
document.body.appendChild(span)
26+
}
27+
28+
// mock dom methods
29+
function _mockDomMethodsForClipboardJS(value) {
30+
window.getSelection = () => ({
31+
addRange: () => {},
32+
removeAllRanges: () => {},
33+
toString: () => value,
34+
});
35+
36+
document.execCommand = () => value;
37+
document.createRange = () => ({ selectNodeContents: () => { } });
38+
}
39+
40+
beforeEach(() => {
41+
_mockDOMSource(DOM_SOURCE_VALUE)
42+
_mockDomMethodsForClipboardJS(DOM_SOURCE_VALUE)
43+
wrapper = mount(CopyButton, defaults)
44+
})
45+
46+
afterEach(() => {
47+
wrapper.destroy()
48+
})
49+
50+
describe('CopyButton.vue', () => {
51+
it('should render the right content text', () => {
52+
expect(wrapper.text()).toBe(slots.default);
53+
})
54+
55+
it('should change the text when clicked to \'Copied!\' and 2 secs later swich back to the original text', done => {
56+
wrapper.trigger('click');
57+
expect(wrapper.text()).toBe('Copied!');
58+
setTimeout(() => {
59+
expect(wrapper.text()).toBe(slots.default);
60+
done();
61+
}, 2000);
62+
})
63+
64+
it('should emit only the \'copied\' event with a valid value', () => {
65+
wrapper.trigger('click');
66+
67+
const emittedEvents = wrapper.emitted()
68+
expect(emittedEvents).toHaveProperty('copied');
69+
expect(emittedEvents.copied).toBeTruthy();
70+
expect(emittedEvents.copied.length).toBe(1);
71+
expect(emittedEvents.copied[0].length).toBe(1);
72+
expect(emittedEvents.copied[0][0].content).toBe(DOM_SOURCE_VALUE);
73+
expect(emittedEvents.copyFailed).toBeFalsy();
74+
})
75+
76+
it('should emit only the \'copyFailed\' event', () => {
77+
document.execCommand = () => false // force error on clipboard.js
78+
wrapper.trigger('click');
79+
80+
const emittedEvents = wrapper.emitted()
81+
expect(emittedEvents).toHaveProperty('copyFailed');
82+
expect(emittedEvents.copied).toBeFalsy();
83+
})
84+
})
File renamed without changes.

0 commit comments

Comments
 (0)