Completed
Push — master ( 734acd...e65e46 )
by Pieter Epeüs
13s queued 10s
created

test/multisort.js   A

Complexity

Total Complexity 7
Complexity/F 1

Size

Lines of Code 137
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 100
mnd 0
bc 0
fnc 7
dl 0
loc 137
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
1
import { Arr } from '../src/helpers';
2
3
const exampleArray = new Arr([
4
    {
5
        id: 0,
6
        name: 'John',
7
        age: 93,
8
        city: 'Patmos',
9
    },
10
    {
11
        id: 1,
12
        name: 'Peter',
13
        age: 62,
14
        city: 'Rome',
15
    },
16
    {
17
        id: 2,
18
        name: 'Luke',
19
        age: 84,
20
        city: 'Boeotia',
21
    },
22
    {
23
        id: 2,
24
        name: 'Paul',
25
        age: 62,
26
        city: 'Rome',
27
    },
28
]);
29
30
const expectedResults = {
31
    test1: JSON.stringify([
32
        {
33
            id: 1,
34
            name: 'Peter',
35
            age: 62,
36
            city: 'Rome',
37
        },
38
        {
39
            id: 2,
40
            name: 'Paul',
41
            age: 62,
42
            city: 'Rome',
43
        },
44
        {
45
            id: 2,
46
            name: 'Luke',
47
            age: 84,
48
            city: 'Boeotia',
49
        },
50
        {
51
            id: 0,
52
            name: 'John',
53
            age: 93,
54
            city: 'Patmos',
55
        },
56
    ]),
57
    test2: JSON.stringify([
58
        {
59
            id: 0,
60
            name: 'John',
61
            age: 93,
62
            city: 'Patmos',
63
        },
64
        {
65
            id: 2,
66
            name: 'Luke',
67
            age: 84,
68
            city: 'Boeotia',
69
        },
70
        {
71
            id: 1,
72
            name: 'Peter',
73
            age: 62,
74
            city: 'Rome',
75
        },
76
        {
77
            id: 2,
78
            name: 'Paul',
79
            age: 62,
80
            city: 'Rome',
81
        },
82
    ]),
83
    test3: JSON.stringify([
84
        {
85
            id: 0,
86
            name: 'John',
87
            age: 93,
88
            city: 'Patmos',
89
        },
90
        {
91
            id: 2,
92
            name: 'Luke',
93
            age: 84,
94
            city: 'Boeotia',
95
        },
96
        {
97
            id: 2,
98
            name: 'Paul',
99
            age: 62,
100
            city: 'Rome',
101
        },
102
        {
103
            id: 1,
104
            name: 'Peter',
105
            age: 62,
106
            city: 'Rome',
107
        },
108
    ]),
109
};
110
111
exampleArray.multisort('age', 'desc');
112
113
describe('Multisort', () => {
114
    describe('Test 1 (ASC)', () => {
115
        it('Should return the array, sorted by age asc.', () => {
116
            expect(expectedResults.test1).toEqual(
117
                JSON.stringify(exampleArray.multisort('age', 'asc'))
118
            );
119
        });
120
    });
121
122
    describe('Test 1 (DESC)', () => {
123
        it('Should return the array, sorted by age desc.', () => {
124
            expect(expectedResults.test2).toEqual(
125
                JSON.stringify(exampleArray.multisort('age', 'desc'))
126
            );
127
        });
128
    });
129
130
    describe('Test 3 (sort text ASC)', () => {
131
        it('Should return the array, sorted by age asc.', () => {
132
            expect(expectedResults.test3).toEqual(
133
                JSON.stringify(exampleArray.multisort('name', 'asc'))
134
            );
135
        });
136
    });
137
});
138