Skip to content

Commit cbf54c8

Browse files
author
Ari Madian
authored
Issue 35 - Write Unit Tests and e2e for HelpSection component (#43)
Issue 35 - Write Unit Tests and e2e for HelpSection component
2 parents 35d117d + c66a99e commit cbf54c8

File tree

4 files changed

+225
-14
lines changed

4 files changed

+225
-14
lines changed

src/components/HelpSection.vue

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,39 @@
66
<p align="center" class="desktop-hide mobile-show">You can tap the buttons below to get answers to the questions on them!</p>
77
<div class="columns" id="modal-buttons">
88
<div class="column top-bottom-paddingless">
9-
<button class="button is-light is-large is-fullwidth"
9+
<button id="cc_license_btn" class="button is-light is-large is-fullwidth"
1010
@click="isModal1Active = true">
1111
<p>
1212
What Are Creative Commons Licenses?
1313
</p>
1414
</button>
15-
<button class="button is-light is-large is-fullwidth"
15+
<button id="license_work_btn" class="button is-light is-large is-fullwidth"
1616
@click="isModal2Active = true">
1717
<p>
1818
How do the Licenses Work?
1919
</p>
2020
</button>
21-
<button class="button is-light is-large is-fullwidth"
21+
<button id="public_domain_btn" class="button is-light is-large is-fullwidth"
2222
@click="isModal3Active = true">
2323
<p>
2424
Want Public Domain Instead?
2525
</p>
2626
</button>
2727
</div>
2828
<div class="column top-bottom-paddingless">
29-
<button class="button is-light is-large is-fullwidth"
29+
<button id="consideration_btn" class="button is-light is-large is-fullwidth"
3030
@click="isModal4Active = true">
3131
<p>
3232
Considerations Before Licensing
3333
</p>
3434
</button>
35-
<button class="button is-light is-large is-fullwidth"
35+
<button id="formal_license_btn" class="button is-light is-large is-fullwidth"
3636
@click="isModal5Active = true">
3737
<p>
3838
How do I Formally License my Work?
3939
</p>
4040
</button>
41-
<button class="button is-light is-large is-fullwidth"
41+
<button id="license_description_btn" class="button is-light is-large is-fullwidth"
4242
@click="isModal6Active = true">
4343
<p>
4444
The Six CC Licenses
@@ -170,7 +170,7 @@
170170
<footer class="modal-card-foot">
171171
<p>
172172
For more information, please see
173-
<a href="https://creativecommons.org/licenses/">About the Licenses</a>
173+
<a id="license_link" href="https://creativecommons.org/licenses/">About the Licenses</a>
174174
</p>
175175
</footer>
176176
</section>
@@ -211,15 +211,15 @@
211211
software, we provide a "Machine Readable" version of the license. <br><br>
212212

213213
We developed a standardized way to describe licenses that software can
214-
understand called <a href="https://wiki.creativecommons.org/Ccrel">CC Rights Expression language</a>
214+
understand called <a id="cc_rights_link" href="https://wiki.creativecommons.org/Ccrel">CC Rights Expression language</a>
215215
(CC REL) to accomplish this.
216216
</p>
217217
</li> <br>
218218
</ul>
219219
<footer class="modal-card-foot">
220220
<p>
221221
For more information, please see
222-
<a href="https://creativecommons.org/licenses/">About the Licenses</a>
222+
<a id="license_link_2" href="https://creativecommons.org/licenses/">About the Licenses</a>
223223
</p>
224224
</footer>
225225
</section>
@@ -238,7 +238,7 @@
238238
<footer class="modal-card-foot">
239239
<p>
240240
For more information on CC's public domain tools, please see
241-
<a href="https://creativecommons.org/publicdomain/">Our Public Domain Tools</a>
241+
<a id="domain_link" href="https://creativecommons.org/publicdomain/">Our Public Domain Tools</a>
242242
</p>
243243
</footer>
244244
</section>
@@ -253,17 +253,17 @@
253253
a Creative Commons license to your work, or before using Creative
254254
Commons-licened material. <br><br>
255255

256-
<a href="https://wiki.creativecommons.org/wiki/Considerations_for_licensors_and_licensees#Considerations_for_licensors">
256+
<a id="licensors_link" href="https://wiki.creativecommons.org/wiki/Considerations_for_licensors_and_licensees#Considerations_for_licensors">
257257
Considerations for Licensors
258258
</a> - If you are licensing your own work <br>
259-
<a href="https://wiki.creativecommons.org/wiki/Considerations_for_licensors_and_licensees#Considerations_for_licensees">
259+
<a id="licensees_link" href="https://wiki.creativecommons.org/wiki/Considerations_for_licensors_and_licensees#Considerations_for_licensees">
260260
Considerations for Licensees
261261
</a> - If you are using someone else's licensed work
262262
</p> <br>
263263
<footer class="modal-card-foot">
264264
<p>
265265
For more information, please see
266-
<a href="https://wiki.creativecommons.org/wiki/Before_Licensing">
266+
<a id="wiki_link" href="https://wiki.creativecommons.org/wiki/Before_Licensing">
267267
the CC wiki's page on Considerations for Licensors and Licensees.
268268
</a>
269269
</p>
@@ -339,7 +339,7 @@
339339
<footer class="modal-card-foot">
340340
<p>
341341
For more information, please see
342-
<a href="https://creativecommons.org/share-your-work/licensing-types-examples/">
342+
<a id="licensing_examples_link" href="https://creativecommons.org/share-your-work/licensing-types-examples/">
343343
this page on Creative Commons licenses.
344344
</a>
345345
</p>

test/TEST.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Testing
2+
3+
This file will be used to document some useful commands and tips for tests. Also, some common errors found that may prevent you from running them.
4+
5+
## Unit Testing
6+
7+
### Useful Commands and Tips
8+
If you want to run only unit tests, use:
9+
10+
``` bash
11+
$ npm run unit
12+
```
13+
14+
If you want to run only e2e tests, use:
15+
``` bash
16+
$ npm run e2e
17+
```
18+
19+
### About Snapshots Test
20+
When updating some components, snapshots test may fail if the UI's changed. To prevent that from happening, press u while in watch mode to update your snapshots.
21+
22+
### Common Errors
23+
When running your unit tests for the first time, you may encounter this error:
24+
25+
``` bash
26+
$ ENOSPC: System limit for number of file watchers reached
27+
```
28+
29+
This means that your system's preventing you from running the command, since the numbers of files it can watch has been exceeded. To fix it you'll have to manually expand it's file limits. On Ubuntu distributions, it looks like this:
30+
31+
``` bash
32+
$ sudo vim /etc/sysctl.conf
33+
```
34+
35+
Then add the following line:
36+
37+
``` bash
38+
$ fs.inotify.max_user_watches=524288
39+
```
40+
41+
After running it you should be good to go!
42+
43+
44+
45+
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
module.exports = {
2+
3+
beforeEach: function(browser) {
4+
const devServer = browser.globals.devServerURL
5+
6+
browser
7+
.url(devServer)
8+
.waitForElementVisible('#app', 1000)
9+
},
10+
11+
'Common license pop up redirects to https://creativecommons.org/licenses/': function (browser) {
12+
browser
13+
.assert.elementPresent('#cc_license_btn')
14+
.click('#cc_license_btn')
15+
.assert.elementPresent('#license_link')
16+
.click('#license_link')
17+
.assert.urlEquals('https://creativecommons.org/licenses/')
18+
},
19+
20+
'How do licenses work pop up redirects to https://creativecommons.org/licenses/': function (browser) {
21+
browser
22+
.assert.elementPresent('#license_work_btn')
23+
.click('#license_work_btn')
24+
.assert.elementPresent('#license_link_2')
25+
.click('#license_link_2')
26+
.assert.urlEquals('https://creativecommons.org/licenses/')
27+
},
28+
29+
'How do licenses work pop up redirects to https://wiki.creativecommons.org/wiki/CC_REL': function (browser) {
30+
browser
31+
.assert.elementPresent('#license_work_btn')
32+
.click('#license_work_btn')
33+
.assert.elementPresent('#cc_rights_link')
34+
.click('#cc_rights_link')
35+
.assert.urlEquals('https://wiki.creativecommons.org/wiki/CC_REL')
36+
},
37+
38+
'Public domain pop up redirects to https://creativecommons.org/publicdomain/': function (browser) {
39+
browser
40+
.assert.elementPresent('#public_domain_btn')
41+
.click('#public_domain_btn')
42+
.assert.elementPresent('#domain_link')
43+
.click('#domain_link')
44+
.assert.urlEquals('https://creativecommons.org/publicdomain/')
45+
},
46+
47+
'License consideration pop up redirects to https://wiki.creativecommons.org/wiki/Considerations_for_licensors_and_licensees#Considerations_for_licensors': function (browser) {
48+
browser
49+
.assert.elementPresent('#consideration_btn')
50+
.click('#consideration_btn')
51+
.assert.elementPresent('#licensors_link')
52+
.click('#licensors_link')
53+
.assert.urlEquals('https://wiki.creativecommons.org/wiki/Considerations_for_licensors_and_licensees#Considerations_for_licensors')
54+
},
55+
56+
'License consideration pop up redirects to https://wiki.creativecommons.org/wiki/Considerations_for_licensors_and_licensees#Considerations_for_licensees': function (browser) {
57+
browser
58+
.assert.elementPresent('#consideration_btn')
59+
.click('#consideration_btn')
60+
.assert.elementPresent('#licensees_link')
61+
.click('#licensees_link')
62+
.assert.urlEquals('https://wiki.creativecommons.org/wiki/Considerations_for_licensors_and_licensees#Considerations_for_licensees')
63+
},
64+
65+
'License consideration pop up redirects to https://wiki.creativecommons.org/wiki/Considerations_for_licensors_and_licensees': function (browser) {
66+
browser
67+
.assert.elementPresent('#consideration_btn')
68+
.click('#consideration_btn')
69+
.assert.elementPresent('#wiki_link')
70+
.click('#wiki_link')
71+
.assert.urlEquals('https://wiki.creativecommons.org/wiki/Considerations_for_licensors_and_licensees')
72+
},
73+
74+
'License types pop up redirects to https://creativecommons.org/share-your-work/licensing-types-examples/': function (browser) {
75+
browser
76+
.assert.elementPresent('#license_description_btn')
77+
.click('#license_description_btn')
78+
.assert.elementPresent('#licensing_examples_link')
79+
.click('#licensing_examples_link')
80+
.assert.urlEquals('https://creativecommons.org/share-your-work/licensing-types-examples/')
81+
},
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { shallowMount, createLocalVue } from '@vue/test-utils'
2+
import HelpSection from '@/components/HelpSection';
3+
import Buefy from 'buefy';
4+
5+
describe('HelpSection.vue', () => {
6+
let wrapper;
7+
8+
// Always creates a shallow instance of component
9+
beforeEach(() => {
10+
const localVue = createLocalVue();
11+
localVue.use(Buefy);
12+
13+
wrapper = shallowMount(HelpSection, {
14+
localVue
15+
});
16+
});
17+
18+
// Snapshot tests
19+
it("has the expected UI", () => {
20+
expect(wrapper).toMatchSnapshot();
21+
});
22+
23+
// Variables tests
24+
it("equals isModal1Active to false", () => {
25+
expect(wrapper.vm.isModal1Active).toEqual(false);
26+
});
27+
28+
it("expects isModal1Active to be true after clicking it", () => {
29+
const button = wrapper.find('#cc_license_btn');
30+
button.trigger('click');
31+
expect(wrapper.vm.isModal1Active).toEqual(true);
32+
});
33+
34+
it("equals isModal2Active to false", () => {
35+
expect(wrapper.vm.isModal2Active).toEqual(false);
36+
});
37+
38+
it("expects isModal2Active to be true after clicking it", () => {
39+
const button = wrapper.find('#license_work_btn');
40+
button.trigger('click');
41+
expect(wrapper.vm.isModal2Active).toEqual(true);
42+
});
43+
44+
it("equals isModal3Active to false", () => {
45+
expect(wrapper.vm.isModal3Active).toEqual(false);
46+
});
47+
48+
it("expects isModal3Active to be true after clicking it", () => {
49+
const button = wrapper.find('#public_domain_btn');
50+
button.trigger('click');
51+
expect(wrapper.vm.isModal3Active).toEqual(true);
52+
});
53+
54+
it("equals isModal4Active to false", () => {
55+
expect(wrapper.vm.isModal4Active).toEqual(false);
56+
});
57+
58+
it("expects isModal4Active to be true after clicking it", () => {
59+
const button = wrapper.find('#consideration_btn');
60+
button.trigger('click');
61+
expect(wrapper.vm.isModal4Active).toEqual(true);
62+
});
63+
64+
it("equals isModal5Active to false", () => {
65+
expect(wrapper.vm.isModal5Active).toEqual(false);
66+
});
67+
68+
it("expects isModal5Active to be true after clicking it", () => {
69+
const button = wrapper.find('#formal_license_btn');
70+
button.trigger('click');
71+
expect(wrapper.vm.isModal5Active).toEqual(true);
72+
});
73+
74+
it("equals isModal6Active to false", () => {
75+
expect(wrapper.vm.isModal6Active).toEqual(false);
76+
});
77+
78+
it("expects isModal6Active to be true after clicking it", () => {
79+
const button = wrapper.find('#license_description_btn');
80+
button.trigger('click');
81+
expect(wrapper.vm.isModal6Active).toEqual(true);
82+
});
83+
84+
})

0 commit comments

Comments
 (0)