Skip to content

Commit 896fb25

Browse files
committed
Modified the unit tests of LicenseCode.vue component
1 parent e371fe3 commit 896fb25

File tree

1 file changed

+43
-49
lines changed

1 file changed

+43
-49
lines changed

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

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,55 @@ import Vuex from 'vuex'
55

66
describe('LicenseCode.vue', () => {
77
let wrapper
8-
let getters
98
let state
109
let store
1110

1211
// Always creates a shallow instance of component
1312
beforeEach(() => {
14-
const localVue = createLocalVue()
15-
localVue.use(VueI18n)
16-
localVue.use(Vuex)
17-
state = {
18-
attributionDetails: {
19-
creatorName: 'J Doe',
20-
creatorProfileUrl: 'www.author.com',
21-
workTitle: 'My work',
22-
workUrl: 'www.author.com/pic.jpg'
23-
}
13+
const localVue = createLocalVue()
14+
localVue.use(VueI18n)
15+
localVue.use(Vuex)
16+
state = {
17+
attributionDetails: {
18+
creatorName: 'J Doe',
19+
creatorProfileUrl: 'www.author.com',
20+
workTitle: 'My work',
21+
workUrl: 'www.author.com/pic.jpg'
2422
}
25-
getters = {
26-
shortName: state => {
27-
return 'foo'
28-
},
29-
licenseUrl: state => (mode) => {
30-
return 'http://example.com'
31-
},
32-
iconsList: state => {
33-
return ['by', 'sa']
34-
}
35-
}
36-
store = new Vuex.Store({
37-
state,
38-
getters
39-
})
40-
const messages = require('@/locales/en.json')
41-
const i18n = new VueI18n({
42-
locale: 'en',
43-
fallbackLocale: 'en',
44-
messages: messages
45-
})
23+
}
24+
store = new Vuex.Store({
25+
state
26+
})
27+
const messages = require('@/locales/en.json')
28+
const i18n = new VueI18n({
29+
locale: 'en',
30+
fallbackLocale: 'en',
31+
messages: messages,
32+
silentTranslationWarn: true
33+
})
4634

47-
config.mocks.i18n = i18n
35+
config.mocks.i18n = i18n
4836

49-
config.mocks.$t = (key) => {
50-
return i18n.messages[key]
51-
}
52-
wrapper = mount(LicenseCode, {
53-
localVue,
54-
store
55-
})
37+
config.mocks.$t = (key) => {
38+
return i18n.messages[key]
39+
}
40+
wrapper = mount(LicenseCode, {
41+
localVue,
42+
store,
43+
i18n
5644
})
57-
// Test for DOM elements which must be present
58-
it('Has the main p tag', () => {
45+
})
46+
47+
// Test for DOM elements which must be present
48+
it('Check if the p-tag with class license-text is present in the DOM', () => {
5949
expect(wrapper.contains('.license-text')).toBe(true)
6050
})
6151

62-
// Tests for computed props and methods
63-
it('renders without any errors', () => {
52+
it('Check if the LicenseCode.vue component renders without any errors', () => {
6453
expect(wrapper.isVueInstance()).toBeTruthy()
6554
})
55+
56+
// Tests for computed props and methods
6657
it('Check if the byString function returns the correct text', () => {
6758
expect(wrapper.vm.byString).toBe('license-use.richtext.by')
6859
})
@@ -81,12 +72,15 @@ describe('LicenseCode.vue', () => {
8172
it('Check if the workUrl function returns the correct text', () => {
8273
expect(wrapper.vm.workUrl).toBe('www.author.com/pic.jpg')
8374
})
84-
it('Check if the isWeb function returns the correct boolean', () => {
75+
it('Check if the isWeb function returns true if attribution type is web', () => {
8576
wrapper.setProps({
86-
attributionType: {
87-
type: String,
88-
default: 'web'
89-
}
77+
attributionType: 'web'
78+
})
79+
expect(wrapper.vm.isWeb).toBe(true)
80+
})
81+
it('Check if the isWeb function returns false if attribution type is print', () => {
82+
wrapper.setProps({
83+
attributionType: 'print'
9084
})
9185
expect(wrapper.vm.isWeb).toBe(false)
9286
})

0 commit comments

Comments
 (0)