Passed
Push — trunk ( 88e2f6...97604d )
by Christian
15:50 queued 12s
created

src/Administration/Resources/app/administration/src/core/service/util.service.spec.js   A

Complexity

Total Complexity 10
Complexity/F 1

Size

Lines of Code 96
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 61
dl 0
loc 96
rs 10
c 0
b 0
f 0
wmc 10
mnd 0
bc 0
fnc 10
bpm 0
cpm 1
noi 1
1
import UtilService from './util.service';
2
3
describe('src/core/service/util.service.spec.js', () => {
4
    describe('moveItem', () => {
5
        let entity = new MutationObserver(() => {});
0 ignored issues
show
Bug introduced by
The variable MutationObserver seems to be never declared. If this is a global, consider adding a /** global: MutationObserver */ 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...
6
7
        beforeEach(() => {
8
            entity = [
9
                { id: 1 },
10
                { id: 2 },
11
                { id: 3 },
12
                { id: 4 },
13
            ];
14
        });
15
16
        it('should move the item correctly', () => {
17
            const oldIndex = 1;
18
            const newIndex = 3;
19
20
            UtilService.moveItem(entity, oldIndex, newIndex);
21
22
            expect(entity).toEqual([
23
                { id: 1 },
24
                { id: 3 },
25
                { id: 4 },
26
                { id: 2 },
27
            ]);
28
        });
29
30
        it('should not move the item if the new index is null', () => {
31
            const oldIndex = 2;
32
            const newIndex = null;
33
34
            UtilService.moveItem(entity, oldIndex, newIndex);
35
36
            expect(entity).toEqual([
37
                { id: 1 },
38
                { id: 2 },
39
                { id: 4 },
40
                { id: 3 },
41
            ]);
42
        });
43
44
        it('should not move the item if the old index is out of bounds', () => {
45
            const oldIndex = -1;
46
            const newIndex = 2;
47
48
            UtilService.moveItem(entity, oldIndex, newIndex);
49
50
            expect(entity).toEqual([
51
                { id: 1 },
52
                { id: 2 },
53
                { id: 3 },
54
                { id: 4 },
55
            ]);
56
        });
57
58
        it('should not move the item if the new index is the same as the old index', () => {
59
            const oldIndex = 2;
60
            const newIndex = 2;
61
62
            UtilService.moveItem(entity, oldIndex, newIndex);
63
64
            expect(entity).toEqual([
65
                { id: 1 },
66
                { id: 2 },
67
                { id: 3 },
68
                { id: 4 },
69
            ]);
70
        });
71
72
        it('should not move the item if it does not exist', () => {
73
            const oldIndex = 10;
74
            const newIndex = 2;
75
76
            UtilService.moveItem(entity, oldIndex, newIndex);
77
78
            expect(entity).toEqual([
79
                { id: 1 },
80
                { id: 2 },
81
                { id: 3 },
82
                { id: 4 },
83
            ]);
84
        });
85
86
        it('should not move the item if entity does not exist', () => {
87
            entity = [null, 1, null];
88
            const oldIndex = 0;
89
            const newIndex = 1;
90
91
            UtilService.moveItem(entity, oldIndex, newIndex);
92
93
            expect(entity).toEqual([null, 1, null]);
94
        });
95
    });
96
});
97
98