Passed
Push — trunk ( a8cce2...93595c )
by Christian
14:41 queued 12s
created

src/Administration/Resources/app/administration/test/app/component/base/sw-error-summary.spec.ts   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 84
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 65
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 1
mnd 0
bc 0
fnc 1
bpm 0
cpm 1
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A sw-error-summary.spec.ts ➔ createWrapper 0 17 1
1
import { shallowMount } from '@vue/test-utils';
2
import 'src/app/component/base/sw-error-summary/index';
3
import 'src/app/component/base/sw-alert/index';
4
import flushPromises from 'flush-promises';
5
6
function createWrapper(errors = {}, options = {}) {
7
    Shopware.State.registerModule('error', {
8
        namespaced: true,
9
10
        state: {
11
            api: errors,
12
        },
13
    });
14
15
    return shallowMount(Shopware.Component.build('sw-error-summary'), {
16
        stubs: {
17
            'sw-alert': Shopware.Component.build('sw-alert'),
18
            'sw-icon': true,
19
        },
20
        attachTo: document.body,
21
        ...options,
22
    });
23
}
24
25
describe('src/app/component/base/sw-error-summary/index.js', () => {
26
    let wrapper;
27
28
    beforeEach(async () => {
29
        wrapper = createWrapper();
30
        await flushPromises();
31
    });
32
33
    afterEach(() => {
34
        wrapper.destroy();
35
    });
36
37
    it('should be a Vue.js component', () => {
38
        expect(wrapper.vm).toBeTruthy();
39
    });
40
41
    it('should not show alert box without errors', () => {
42
        const alert = wrapper.find('.sw-alert');
43
44
        expect(alert.exists()).toBeFalsy();
45
    });
46
47
    it('should show alert box with errors', async () => {
48
        wrapper = createWrapper({
49
            entity: {
50
                someId: {
51
                    someProperty: {
52
                        _code: 'error-1',
53
                        _detail: 'Error 1',
54
                        selfLink: 'error-1',
55
                    },
56
                    otherProperty: {
57
                        _code: 'error-1',
58
                        _detail: 'Error 1',
59
                        selfLink: 'error-2',
60
                    },
61
                    somethingStrange: null,
62
                },
63
            },
64
        },
65
        {
66
            mocks: {
67
                $te: () => false,
68
            }
69
        });
70
        await flushPromises();
71
72
        const alert = wrapper.find('.sw-alert');
73
        expect(alert.exists()).toBeTruthy();
74
75
        const quantity = wrapper.find('.sw-error-summary__quantity');
76
        expect(quantity.exists()).toBeTruthy();
77
        expect(quantity.text()).toBe('2x');
78
79
        const message = wrapper.find('.sw-alert__message');
80
        expect(message.exists()).toBeTruthy();
81
        expect(message.text()).toBe('2x "Error 1"');
82
    });
83
});
84