Passed
Push — master ( 30cae4...e4ea65 )
by Christian
23:42 queued 08:19
created

sw-text-field.spec.js ➔ createWrapper   A

Complexity

Conditions 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 17
rs 9.8
c 0
b 0
f 0
cc 1
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;
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

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.

Loading history...
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