1
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils'; |
2
|
|
|
import 'src/app/component/form/sw-text-field'; |
3
|
|
|
import 'src/app/component/form/sw-field'; |
4
|
|
|
import 'src/app/component/form/field-base/sw-base-field'; |
5
|
|
|
import 'src/app/component/form/field-base/sw-block-field'; |
6
|
|
|
import 'src/app/component/form/field-base/sw-contextual-field'; |
7
|
|
|
|
8
|
|
|
const { Component } = Shopware; |
|
|
|
|
9
|
|
|
|
10
|
|
|
function createWrapper() { |
11
|
|
|
const localVue = createLocalVue(); |
12
|
|
|
|
13
|
|
|
return shallowMount(Component.build('sw-text-field'), { |
14
|
|
|
localVue, |
15
|
|
|
stubs: { |
16
|
|
|
'sw-field': Component.build('sw-field'), |
17
|
|
|
'sw-base-field': Component.build('sw-base-field'), |
18
|
|
|
'sw-contextual-field': Component.build('sw-contextual-field'), |
19
|
|
|
'sw-block-field': Component.build('sw-block-field'), |
20
|
|
|
'sw-field-error': true |
21
|
|
|
}, |
22
|
|
|
provide: { |
23
|
|
|
validationService: {} |
24
|
|
|
} |
25
|
|
|
}); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
describe('src/app/component/form/sw-text-field', () => { |
29
|
|
|
const localVue = createLocalVue(); |
30
|
|
|
|
31
|
|
|
Component.register('sw-text-field-mock', { |
32
|
|
|
template: |
33
|
|
|
'<div>' + |
34
|
|
|
'<sw-text-field v-model="mockVar" class="no-suffix"></sw-text-field>' + |
35
|
|
|
'<sw-text-field v-model="mockVar" class="with-suffix" idSuffix="iShallBeSuffix"></sw-text-field>' + |
36
|
|
|
'</div>', |
37
|
|
|
|
38
|
|
|
data() { |
39
|
|
|
return { |
40
|
|
|
mockVar: 'content' |
41
|
|
|
}; |
42
|
|
|
} |
43
|
|
|
}); |
44
|
|
|
|
45
|
|
|
const usageWrapper = shallowMount(Component.build('sw-text-field-mock'), { |
46
|
|
|
localVue, |
47
|
|
|
stubs: { |
48
|
|
|
'sw-text-field': Component.build('sw-text-field'), |
49
|
|
|
'sw-base-field': Component.build('sw-base-field'), |
50
|
|
|
'sw-contextual-field': Component.build('sw-contextual-field'), |
51
|
|
|
'sw-block-field': Component.build('sw-block-field'), |
52
|
|
|
'sw-field-error': true |
53
|
|
|
}, |
54
|
|
|
provide: { |
55
|
|
|
validationService: {} |
56
|
|
|
} |
57
|
|
|
}); |
58
|
|
|
|
59
|
|
|
it('should be a Vue.js component', () => { |
60
|
|
|
const wrapper = createWrapper(); |
61
|
|
|
|
62
|
|
|
expect(wrapper.vm).toBeTruthy(); |
63
|
|
|
}); |
64
|
|
|
|
65
|
|
|
it('should render without idSuffix corretly', () => { |
66
|
|
|
const noSuffix = usageWrapper.find('.no-suffix'); |
67
|
|
|
|
68
|
|
|
expect(noSuffix.exists()).toBeTruthy(); |
69
|
|
|
expect(noSuffix.find('#sw-field--mockVar').exists()).toBeTruthy(); |
70
|
|
|
}); |
71
|
|
|
|
72
|
|
|
it('should render with idSuffix corretly and generated a correct HTML-ID', () => { |
73
|
|
|
const withSuffix = usageWrapper.find('.with-suffix'); |
74
|
|
|
|
75
|
|
|
expect(withSuffix.exists()).toBeTruthy(); |
76
|
|
|
expect(withSuffix.find('#sw-field--mockVar-iShallBeSuffix').exists()).toBeTruthy(); |
77
|
|
|
}); |
78
|
|
|
}); |
79
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.