Passed
Push — master ( a884a9...d575cb )
by Christian
11:18 queued 10s
created

src/Administration/Resources/app/administration/test/module/sw-mail-template/page/sw-mail-template-index.spec.js   A

Complexity

Total Complexity 8
Complexity/F 1.14

Size

Lines of Code 81
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 46
mnd 1
bc 1
fnc 7
dl 0
loc 81
rs 10
bpm 0.1428
cpm 1.1428
noi 1
c 0
b 0
f 0
1
import { shallowMount, createLocalVue } from '@vue/test-utils';
2
import 'src/module/sw-mail-template/page/sw-mail-template-index';
3
4
const createWrapper = (privileges = []) => {
5
    const localVue = createLocalVue();
6
    localVue.directive('tooltip', {});
7
8
    return shallowMount(Shopware.Component.build('sw-mail-template-index'), {
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
        localVue,
10
        provide: {
11
            acl: {
12
                can: (identifier) => {
13
                    if (!identifier) { return true; }
14
15
                    return privileges.includes(identifier);
16
                }
17
            }
18
        },
19
        mocks: {
20
            $tc: (translationPath) => translationPath,
21
            $route: {
22
                query: {
23
                    page: 1,
24
                    limit: 25
25
                }
26
            },
27
            $router: {
28
                replace: () => {}
29
            }
30
        },
31
        stubs: {
32
            'sw-page': {
33
                template: `
34
                    <div class="sw-page">
35
                        <slot name="smart-bar-actions"></slot>
36
                        <slot></slot>
37
                    </div>`
38
            },
39
            'sw-card-view': {
40
                template: '<div><slot></slot></div>'
41
            },
42
            'sw-container': {
43
                template: '<div><slot></slot></div>'
44
            },
45
            'sw-button': true,
46
            'sw-context-button': {
47
                template: `
48
                    <div class="sw-context-button">
49
                        <slot name="button"></slot>
50
                        <slot></slot>
51
                     </div>`
52
            },
53
            'sw-context-menu-item': true,
54
            'sw-icon': true
55
        }
56
    });
57
};
58
59
describe('modules/sw-mail-template/page/sw-mail-template-index', () => {
60
    it('should not allow to create', () => {
61
        const wrapper = createWrapper();
62
63
        const createButton = wrapper.find('.sw-context-button');
64
        const innerButton = createButton.find('sw-button-stub');
65
66
        expect(createButton.attributes().disabled).toBeTruthy();
67
        expect(innerButton.attributes().disabled).toBeTruthy();
68
    });
69
70
    it('should allow to create', () => {
71
        const wrapper = createWrapper([
72
            'mail_templates.creator'
73
        ]);
74
75
        const createButton = wrapper.find('.sw-context-button');
76
        const innerButton = createButton.find('sw-button-stub');
77
78
        expect(createButton.attributes().disabled).toBeFalsy();
79
        expect(innerButton.attributes().disabled).toBeFalsy();
80
    });
81
});
82