@@ -7,104 +7,97 @@ import Vuex from 'vuex'
7
7
describe ( 'LicenseDetailsCard.vue' , ( ) => {
8
8
let wrapper
9
9
let getters
10
- let state
11
10
let store
12
11
let i18n
13
12
14
13
// Always creates a shallow instance of component
15
14
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' ]
26
30
}
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
+ } )
51
42
52
- config . mocks . i18n = i18n
43
+ config . mocks . i18n = i18n
53
44
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
62
52
} )
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' , ( ) => {
65
61
expect ( wrapper . contains ( '.selected-license-card' ) ) . toBe ( true )
66
62
} )
67
- it ( 'Has the h3 tag ' , ( ) => {
63
+ it ( 'Check if the heading of the license details card is present in the DOM ' , ( ) => {
68
64
expect ( wrapper . contains ( 'h3' ) ) . toBe ( true )
69
65
} )
70
- it ( 'Has the h4 tag ' , ( ) => {
66
+ it ( 'Check if the heading with full license name is present in the DOM ' , ( ) => {
71
67
expect ( wrapper . contains ( 'h4' ) ) . toBe ( true )
72
68
} )
73
- it ( 'Has the a tag ' , ( ) => {
69
+ it ( 'Check if the license heading is a link to the license ' , ( ) => {
74
70
expect ( wrapper . contains ( '.license-name' ) ) . toBe ( true )
75
71
} )
76
- it ( 'Has the p tag ' , ( ) => {
72
+ it ( 'Check if the license description is present in the DOM ' , ( ) => {
77
73
expect ( wrapper . contains ( '.chooser-selected-description' ) ) . toBe ( true )
78
74
} )
79
- it ( 'Has the section tag ' , ( ) => {
75
+ it ( 'Check if the visual-info section is present in the DOM ' , ( ) => {
80
76
expect ( wrapper . contains ( '.license-visual-info' ) ) . toBe ( true )
81
77
} )
82
- it ( 'Has the ul tag ' , ( ) => {
78
+ it ( 'Check if the license list is present in the DOM ' , ( ) => {
83
79
expect ( wrapper . contains ( '.license-list' ) ) . toBe ( true )
84
80
} )
85
- it ( 'Has the li tag ' , ( ) => {
81
+ it ( 'Check if the license list elements are present in the DOM ' , ( ) => {
86
82
expect ( wrapper . contains ( 'li' ) ) . toBe ( true )
87
83
} )
88
- it ( 'Has the span tag ' , ( ) => {
84
+ it ( 'Check if the license list elements have description about them ' , ( ) => {
89
85
expect ( wrapper . contains ( '.readable-string' ) ) . toBe ( true )
90
86
} )
91
87
92
88
// Tests for computed props and methods
93
- it ( 'renders without any errors' , ( ) => {
94
- expect ( wrapper . isVueInstance ( ) ) . toBeTruthy ( )
95
- } )
96
89
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 ' ) )
98
91
} )
99
92
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 ' ) } ` )
101
94
} )
102
95
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` )
104
97
} )
105
98
106
99
// Snapshot tests
107
- it ( 'has the expected UI' , ( ) => {
100
+ it ( 'Check if the LicenseDetailsCard.vue component has the expected UI' , ( ) => {
108
101
expect ( wrapper ) . toMatchSnapshot ( )
109
102
} )
110
103
} )
0 commit comments