Skip to content

Commit 3397be2

Browse files
committed
Modified getters and names of unit tests
1 parent ce62e52 commit 3397be2

File tree

1 file changed

+54
-61
lines changed

1 file changed

+54
-61
lines changed

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

+54-61
Original file line numberDiff line numberDiff line change
@@ -7,104 +7,97 @@ import Vuex from 'vuex'
77
describe('LicenseDetailsCard.vue', () => {
88
let wrapper
99
let getters
10-
let state
1110
let store
1211
let i18n
1312

1413
// Always creates a shallow instance of component
1514
beforeEach(() => {
16-
const localVue = createLocalVue()
17-
localVue.use(VueI18n)
18-
localVue.use(Vuex)
19-
state = {
20-
attributionDetails: {
21-
creatorName: 'J Doe',
22-
creatorProfileUrl: 'www.author.com',
23-
workTitle: 'My work',
24-
workUrl: 'www.author.com/pic.jpg'
25-
}
15+
const localVue = createLocalVue()
16+
localVue.use(VueI18n)
17+
localVue.use(Vuex)
18+
getters = {
19+
shortName: () => {
20+
return 'CC BY-SA 4.0'
21+
},
22+
fullName: () => {
23+
return 'Attribution-ShareAlike 4.0 International'
24+
},
25+
licenseUrl: () => {
26+
return 'https://creativecommons.org/licenses/by-sa/4.0/?ref=ccchooser'
27+
},
28+
iconsList: () => {
29+
return ['by', 'sa']
2630
}
27-
getters = {
28-
shortName: state => {
29-
return 'foo'
30-
},
31-
fullName: state => {
32-
return 'fooBar'
33-
},
34-
licenseUrl: state => (mode) => {
35-
return 'http://example.com'
36-
},
37-
iconsList: state => {
38-
return ['by', 'sa']
39-
}
40-
}
41-
store = new Vuex.Store({
42-
state,
43-
getters
44-
})
45-
const messages = require('@/locales/en.json')
46-
i18n = new VueI18n({
47-
locale: 'en',
48-
fallbackLocale: 'en',
49-
messages: messages
50-
})
31+
}
32+
store = new Vuex.Store({
33+
getters
34+
})
35+
const messages = require('@/locales/en.json')
36+
i18n = new VueI18n({
37+
locale: 'en',
38+
fallbackLocale: 'en',
39+
messages: messages,
40+
silentTranslationWarn: true
41+
})
5142

52-
config.mocks.i18n = i18n
43+
config.mocks.i18n = i18n
5344

54-
config.mocks.i18n.$t = (key) => {
55-
return i18n.messages[key]
56-
}
57-
wrapper = mount(LicenseDetailsCard, {
58-
localVue,
59-
store,
60-
i18n
61-
})
45+
config.mocks.i18n.$t = (key) => {
46+
return i18n.messages[key]
47+
}
48+
wrapper = mount(LicenseDetailsCard, {
49+
localVue,
50+
store,
51+
i18n
6252
})
63-
// Test for DOM elements which must be present
64-
it('Has the main div tag', () => {
53+
})
54+
55+
it('Check if LicenseDetailsCard.vue component renders without any errors', () => {
56+
expect(wrapper.isVueInstance()).toBeTruthy()
57+
})
58+
59+
// Test for DOM elements which must be present
60+
it('Check if the main div-tag with class selected-license-card is present in the DOM', () => {
6561
expect(wrapper.contains('.selected-license-card')).toBe(true)
6662
})
67-
it('Has the h3 tag', () => {
63+
it('Check if the heading of the license details card is present in the DOM', () => {
6864
expect(wrapper.contains('h3')).toBe(true)
6965
})
70-
it('Has the h4 tag', () => {
66+
it('Check if the heading with full license name is present in the DOM', () => {
7167
expect(wrapper.contains('h4')).toBe(true)
7268
})
73-
it('Has the a tag', () => {
69+
it('Check if the license heading is a link to the license', () => {
7470
expect(wrapper.contains('.license-name')).toBe(true)
7571
})
76-
it('Has the p tag', () => {
72+
it('Check if the license description is present in the DOM', () => {
7773
expect(wrapper.contains('.chooser-selected-description')).toBe(true)
7874
})
79-
it('Has the section tag', () => {
75+
it('Check if the visual-info section is present in the DOM', () => {
8076
expect(wrapper.contains('.license-visual-info')).toBe(true)
8177
})
82-
it('Has the ul tag', () => {
78+
it('Check if the license list is present in the DOM', () => {
8379
expect(wrapper.contains('.license-list')).toBe(true)
8480
})
85-
it('Has the li tag', () => {
81+
it('Check if the license list elements are present in the DOM', () => {
8682
expect(wrapper.contains('li')).toBe(true)
8783
})
88-
it('Has the span tag', () => {
84+
it('Check if the license list elements have description about them', () => {
8985
expect(wrapper.contains('.readable-string')).toBe(true)
9086
})
9187

9288
// Tests for computed props and methods
93-
it('renders without any errors', () => {
94-
expect(wrapper.isVueInstance()).toBeTruthy()
95-
})
9689
it('Check if the slug function returns the correct text', () => {
97-
expect(wrapper.vm.slug).toBe(licenseSlug('foo'))
90+
expect(wrapper.vm.slug).toBe(licenseSlug('CC BY-SA 4.0'))
9891
})
9992
it('Check if the licenseKey function returns the correct text', () => {
100-
expect(wrapper.vm.licenseKey).toBe(`license-details-card.full-description.${licenseSlug('foo')}`)
93+
expect(wrapper.vm.licenseKey).toBe(`license-details-card.full-description.${licenseSlug('CC BY-SA 4.0')}`)
10194
})
10295
it('Check if the licenseDescription function returns the correct text', () => {
103-
expect(wrapper.vm.licenseDescription).toBe(`${licenseSlug('foo')}-description`)
96+
expect(wrapper.vm.licenseDescription).toBe(`${licenseSlug('CC BY-SA 4.0')}-description`)
10497
})
10598

10699
// Snapshot tests
107-
it('has the expected UI', () => {
100+
it('Check if the LicenseDetailsCard.vue component has the expected UI', () => {
108101
expect(wrapper).toMatchSnapshot()
109102
})
110103
})

0 commit comments

Comments
 (0)