Skip to content

Commit 1a27a7a

Browse files
Ari Madianobulat
Ari Madian
andauthored
Add unit tests for App component (#186)
* Add unit tests, fix e2e tests on two components * Fix linting errors Co-authored-by: Olga Bulat <obulat@gmail.com>
1 parent 8056d3f commit 1a27a7a

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

tests/e2e/specs/LicenseCode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
})
3232
.getAttribute('p > span > a:nth-child(4)', 'href', function(result) {
3333
const urlString = result.value.split('/').slice(3).join('/')
34-
this.assert.equal(urlString, 'licenses/by-sa/4.0/?ref=ccchooser')
34+
this.assert.equal(urlString, 'licenses/by-sa/4.0/?ref=chooser-v1')
3535
})
3636
},
3737
'Check if the text is displayed under the print attribution': function(browser) {

tests/e2e/specs/LicenseDetailsCard.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
browser
1717
.assert.elementPresent('a[class="license-name"]')
1818
.getAttribute('a[class="license-name"]', 'href', function(result) {
19-
this.assert.equal(result.value, 'https://creativecommons.org/licenses/by-sa/4.0/?ref=ccchooser')
19+
this.assert.equal(result.value, 'https://creativecommons.org/licenses/by-sa/4.0/?ref=chooser-v1')
2020
})
2121
}
2222
}
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { shallowMount, createLocalVue, config } from '@vue/test-utils'
2+
import App from '@/App'
3+
import Buefy from 'buefy'
4+
import VueI18n from 'vue-i18n'
5+
import Vuex from 'vuex'
6+
import Vue from 'vue'
7+
import store from '@/store'
8+
9+
describe('App.vue', () => {
10+
let wrapper
11+
let localVue
12+
13+
// Always creates a shallow instance of component
14+
beforeEach(() => {
15+
localVue = createLocalVue()
16+
localVue.use(Vuex)
17+
localVue.use(Buefy)
18+
Vue.use(VueI18n)
19+
const messages = require('@/locales/en.json')
20+
const i18n = new VueI18n({
21+
locale: 'en',
22+
fallbackLocale: 'en',
23+
messages: messages
24+
})
25+
26+
config.mocks.i18n = i18n
27+
28+
config.mocks.$t = key => {
29+
// key is a string (eg. 'stepper.ND.question')
30+
// this line converts it into an object reference
31+
// eg. messages['stepper.ND.question'] -> messages.stepper.ND.question
32+
return key.split('.').reduce((messages, k) => messages[k], i18n.messages)
33+
}
34+
wrapper = shallowMount(App, {
35+
store,
36+
localVue
37+
})
38+
wrapper.vm.$on('input', (newVal) => {
39+
wrapper.setProps({ value: newVal })
40+
})
41+
})
42+
43+
it('Check if App.vue component renders without any errors', () => {
44+
expect(wrapper.isVueInstance()).toBeTruthy()
45+
})
46+
47+
// Snapshot tests
48+
it('Check if the App.vue component has the expected UI', () => {
49+
expect(wrapper).toMatchSnapshot()
50+
})
51+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`App.vue Check if the App.vue component has the expected UI 1`] = `
4+
<div id="app">
5+
<header-section-stub></header-section-stub>
6+
<div id="site-container" class="container">
7+
<div class="page-head">
8+
<div class="select-license-column">
9+
<h2 class="vocab">
10+
SELECT YOUR LICENSE
11+
</h2>
12+
<p class="stepper-instructions vocab-body body-bigger">
13+
Follow the steps to select the appropriate license for your work.
14+
</p>
15+
</div>
16+
<localechooser-stub class="locale-chooser"></localechooser-stub>
17+
</div>
18+
<div class="columns">
19+
<stepper-stub value="0"></stepper-stub>
20+
<div class="column">
21+
<div class="fixed-right-column">
22+
<!---->
23+
<!---->
24+
<helpsection-stub></helpsection-stub>
25+
</div>
26+
</div>
27+
</div>
28+
</div>
29+
<footer-section-stub></footer-section-stub>
30+
</div>
31+
`;

0 commit comments

Comments
 (0)