Skip to content

Commit 3d9cd4f

Browse files
author
Ari Madian
authored
Merge pull request #132 from hemanth-hk/Tests_for_LicenseDetailsCard
Added unit and e2e tests for the LicenseDetailsCard.vue component
2 parents f094cf0 + 79aebbd commit 3d9cd4f

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

tests/e2e/specs/LicenseDetailsCard.js

Lines changed: 22 additions & 0 deletions
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+
}
Lines changed: 102 additions & 0 deletions
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+
})
Lines changed: 24 additions & 0 deletions
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)