Browse Source

Disable lint for test files

Arnaud Vergnet 4 years ago
parent
commit
4cc9c61d72

+ 178
- 171
__tests__/managers/ConnectionManager.test.js View File

@@ -1,210 +1,217 @@
1
-jest.mock('react-native-keychain');
1
+/* eslint-disable */
2 2
 
3 3
 import React from 'react';
4
-import ConnectionManager from "../../src/managers/ConnectionManager";
5
-import {ERROR_TYPE} from "../../src/utils/WebData";
4
+import ConnectionManager from '../../src/managers/ConnectionManager';
5
+import {ERROR_TYPE} from '../../src/utils/WebData';
6
+
7
+jest.mock('react-native-keychain');
6 8
 
7
-let fetch = require('isomorphic-fetch'); // fetch is not implemented in nodeJS but in react-native
9
+const fetch = require('isomorphic-fetch'); // fetch is not implemented in nodeJS but in react-native
8 10
 
9 11
 const c = ConnectionManager.getInstance();
10 12
 
11 13
 afterEach(() => {
12
-    jest.restoreAllMocks();
14
+  jest.restoreAllMocks();
13 15
 });
14 16
 
15 17
 test('isLoggedIn yes', () => {
16
-    jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
17
-        return 'token';
18
+  jest
19
+    .spyOn(ConnectionManager.prototype, 'getToken')
20
+    .mockImplementationOnce(() => {
21
+      return 'token';
18 22
     });
19
-    return expect(c.isLoggedIn()).toBe(true);
23
+  return expect(c.isLoggedIn()).toBe(true);
20 24
 });
21 25
 
22 26
 test('isLoggedIn no', () => {
23
-    jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
24
-        return null;
27
+  jest
28
+    .spyOn(ConnectionManager.prototype, 'getToken')
29
+    .mockImplementationOnce(() => {
30
+      return null;
25 31
     });
26
-    return expect(c.isLoggedIn()).toBe(false);
32
+  return expect(c.isLoggedIn()).toBe(false);
27 33
 });
28 34
 
29
-test("isConnectionResponseValid", () => {
30
-    let json = {
31
-        error: 0,
32
-        data: {token: 'token'}
33
-    };
34
-    expect(c.isConnectionResponseValid(json)).toBeTrue();
35
-    json = {
36
-        error: 2,
37
-        data: {}
38
-    };
39
-    expect(c.isConnectionResponseValid(json)).toBeTrue();
40
-    json = {
41
-        error: 0,
42
-        data: {token: ''}
43
-    };
44
-    expect(c.isConnectionResponseValid(json)).toBeFalse();
45
-    json = {
46
-        error: 'prout',
47
-        data: {token: ''}
48
-    };
49
-    expect(c.isConnectionResponseValid(json)).toBeFalse();
35
+test('connect bad credentials', () => {
36
+  jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
37
+    return Promise.resolve({
38
+      json: () => {
39
+        return {
40
+          error: ERROR_TYPE.BAD_CREDENTIALS,
41
+          data: {},
42
+        };
43
+      },
44
+    });
45
+  });
46
+  return expect(c.connect('email', 'password')).rejects.toBe(
47
+    ERROR_TYPE.BAD_CREDENTIALS,
48
+  );
50 49
 });
51 50
 
52
-test("connect bad credentials", () => {
53
-    jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
54
-        return Promise.resolve({
55
-            json: () => {
56
-                return {
57
-                    error: ERROR_TYPE.BAD_CREDENTIALS,
58
-                    data: {}
59
-                };
60
-            },
61
-        })
62
-    });
63
-    return expect(c.connect('email', 'password'))
64
-        .rejects.toBe(ERROR_TYPE.BAD_CREDENTIALS);
51
+test('connect good credentials', () => {
52
+  jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
53
+    return Promise.resolve({
54
+      json: () => {
55
+        return {
56
+          error: ERROR_TYPE.SUCCESS,
57
+          data: {token: 'token'},
58
+        };
59
+      },
60
+    });
61
+  });
62
+  jest
63
+    .spyOn(ConnectionManager.prototype, 'saveLogin')
64
+    .mockImplementationOnce(() => {
65
+      return Promise.resolve(true);
66
+    });
67
+  return expect(c.connect('email', 'password')).resolves.toBeTruthy();
65 68
 });
66 69
 
67
-test("connect good credentials", () => {
68
-    jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
69
-        return Promise.resolve({
70
-            json: () => {
71
-                return {
72
-                    error: ERROR_TYPE.SUCCESS,
73
-                    data: {token: 'token'}
74
-                };
75
-            },
76
-        })
77
-    });
78
-    jest.spyOn(ConnectionManager.prototype, 'saveLogin').mockImplementationOnce(() => {
79
-        return Promise.resolve(true);
80
-    });
81
-    return expect(c.connect('email', 'password')).resolves.toBeTruthy();
70
+test('connect good credentials no consent', () => {
71
+  jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
72
+    return Promise.resolve({
73
+      json: () => {
74
+        return {
75
+          error: ERROR_TYPE.NO_CONSENT,
76
+          data: {},
77
+        };
78
+      },
79
+    });
80
+  });
81
+  return expect(c.connect('email', 'password')).rejects.toBe(
82
+    ERROR_TYPE.NO_CONSENT,
83
+  );
82 84
 });
83 85
 
84
-test("connect good credentials no consent", () => {
85
-    jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
86
-        return Promise.resolve({
87
-            json: () => {
88
-                return {
89
-                    error: ERROR_TYPE.NO_CONSENT,
90
-                    data: {}
91
-                };
92
-            },
93
-        })
94
-    });
95
-    return expect(c.connect('email', 'password'))
96
-        .rejects.toBe(ERROR_TYPE.NO_CONSENT);
86
+test('connect good credentials, fail save token', () => {
87
+  jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
88
+    return Promise.resolve({
89
+      json: () => {
90
+        return {
91
+          error: ERROR_TYPE.SUCCESS,
92
+          data: {token: 'token'},
93
+        };
94
+      },
95
+    });
96
+  });
97
+  jest
98
+    .spyOn(ConnectionManager.prototype, 'saveLogin')
99
+    .mockImplementationOnce(() => {
100
+      return Promise.reject(false);
101
+    });
102
+  return expect(c.connect('email', 'password')).rejects.toBe(
103
+    ERROR_TYPE.UNKNOWN,
104
+  );
97 105
 });
98 106
 
99
-test("connect good credentials, fail save token", () => {
100
-    jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
101
-        return Promise.resolve({
102
-            json: () => {
103
-                return {
104
-                    error: ERROR_TYPE.SUCCESS,
105
-                    data: {token: 'token'}
106
-                };
107
-            },
108
-        })
109
-    });
110
-    jest.spyOn(ConnectionManager.prototype, 'saveLogin').mockImplementationOnce(() => {
111
-        return Promise.reject(false);
112
-    });
113
-    return expect(c.connect('email', 'password')).rejects.toBe(ERROR_TYPE.UNKNOWN);
107
+test('connect connection error', () => {
108
+  jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
109
+    return Promise.reject();
110
+  });
111
+  return expect(c.connect('email', 'password')).rejects.toBe(
112
+    ERROR_TYPE.CONNECTION_ERROR,
113
+  );
114 114
 });
115 115
 
116
-test("connect connection error", () => {
117
-    jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
118
-        return Promise.reject();
119
-    });
120
-    return expect(c.connect('email', 'password'))
121
-        .rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
116
+test('connect bogus response 1', () => {
117
+  jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
118
+    return Promise.resolve({
119
+      json: () => {
120
+        return {
121
+          thing: true,
122
+          wrong: '',
123
+        };
124
+      },
125
+    });
126
+  });
127
+  return expect(c.connect('email', 'password')).rejects.toBe(
128
+    ERROR_TYPE.CONNECTION_ERROR,
129
+  );
122 130
 });
123 131
 
124
-test("connect bogus response 1", () => {
125
-    jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
126
-        return Promise.resolve({
127
-            json: () => {
128
-                return {
129
-                    thing: true,
130
-                    wrong: '',
131
-                }
132
-            },
133
-        })
134
-    });
135
-    return expect(c.connect('email', 'password'))
136
-        .rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
132
+test('authenticatedRequest success', () => {
133
+  jest
134
+    .spyOn(ConnectionManager.prototype, 'getToken')
135
+    .mockImplementationOnce(() => {
136
+      return 'token';
137
+    });
138
+  jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
139
+    return Promise.resolve({
140
+      json: () => {
141
+        return {
142
+          error: ERROR_TYPE.SUCCESS,
143
+          data: {coucou: 'toi'},
144
+        };
145
+      },
146
+    });
147
+  });
148
+  return expect(
149
+    c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
150
+  ).resolves.toStrictEqual({coucou: 'toi'});
137 151
 });
138 152
 
139
-
140
-test("authenticatedRequest success", () => {
141
-    jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
142
-        return 'token';
143
-    });
144
-    jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
145
-        return Promise.resolve({
146
-            json: () => {
147
-                return {
148
-                    error: ERROR_TYPE.SUCCESS,
149
-                    data: {coucou: 'toi'}
150
-                };
151
-            },
152
-        })
153
-    });
154
-    return expect(c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'))
155
-        .resolves.toStrictEqual({coucou: 'toi'});
156
-});
157
-
158
-test("authenticatedRequest error wrong token", () => {
159
-    jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
160
-        return 'token';
161
-    });
162
-    jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
163
-        return Promise.resolve({
164
-            json: () => {
165
-                return {
166
-                    error: ERROR_TYPE.BAD_TOKEN,
167
-                    data: {}
168
-                };
169
-            },
170
-        })
171
-    });
172
-    return expect(c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'))
173
-        .rejects.toBe(ERROR_TYPE.BAD_TOKEN);
153
+test('authenticatedRequest error wrong token', () => {
154
+  jest
155
+    .spyOn(ConnectionManager.prototype, 'getToken')
156
+    .mockImplementationOnce(() => {
157
+      return 'token';
158
+    });
159
+  jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
160
+    return Promise.resolve({
161
+      json: () => {
162
+        return {
163
+          error: ERROR_TYPE.BAD_TOKEN,
164
+          data: {},
165
+        };
166
+      },
167
+    });
168
+  });
169
+  return expect(
170
+    c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
171
+  ).rejects.toBe(ERROR_TYPE.BAD_TOKEN);
174 172
 });
175 173
 
176
-test("authenticatedRequest error bogus response", () => {
177
-    jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
178
-        return 'token';
179
-    });
180
-    jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
181
-        return Promise.resolve({
182
-            json: () => {
183
-                return {
184
-                    error: ERROR_TYPE.SUCCESS,
185
-                };
186
-            },
187
-        })
188
-    });
189
-    return expect(c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'))
190
-        .rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
174
+test('authenticatedRequest error bogus response', () => {
175
+  jest
176
+    .spyOn(ConnectionManager.prototype, 'getToken')
177
+    .mockImplementationOnce(() => {
178
+      return 'token';
179
+    });
180
+  jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
181
+    return Promise.resolve({
182
+      json: () => {
183
+        return {
184
+          error: ERROR_TYPE.SUCCESS,
185
+        };
186
+      },
187
+    });
188
+  });
189
+  return expect(
190
+    c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
191
+  ).rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
191 192
 });
192 193
 
193
-test("authenticatedRequest connection error", () => {
194
-    jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
195
-        return 'token';
196
-    });
197
-    jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
198
-        return Promise.reject()
199
-    });
200
-    return expect(c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'))
201
-        .rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
194
+test('authenticatedRequest connection error', () => {
195
+  jest
196
+    .spyOn(ConnectionManager.prototype, 'getToken')
197
+    .mockImplementationOnce(() => {
198
+      return 'token';
199
+    });
200
+  jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
201
+    return Promise.reject();
202
+  });
203
+  return expect(
204
+    c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
205
+  ).rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
202 206
 });
203 207
 
204
-test("authenticatedRequest error no token", () => {
205
-    jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
206
-        return null;
208
+test('authenticatedRequest error no token', () => {
209
+  jest
210
+    .spyOn(ConnectionManager.prototype, 'getToken')
211
+    .mockImplementationOnce(() => {
212
+      return null;
207 213
     });
208
-    return expect(c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'))
209
-        .rejects.toBe(ERROR_TYPE.UNKNOWN);
214
+  return expect(
215
+    c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
216
+  ).rejects.toBe(ERROR_TYPE.UNKNOWN);
210 217
 });

+ 312
- 286
__tests__/utils/EquipmentBooking.test.js View File

@@ -1,319 +1,345 @@
1
+/* eslint-disable */
2
+
1 3
 import React from 'react';
2
-import * as EquipmentBooking from "../../src/utils/EquipmentBooking";
3
-import i18n from "i18n-js";
4
+import * as EquipmentBooking from '../../src/utils/EquipmentBooking';
5
+import i18n from 'i18n-js';
4 6
 
5 7
 test('getISODate', () => {
6
-    let date = new Date("2020-03-05 12:00");
7
-    expect(EquipmentBooking.getISODate(date)).toBe("2020-03-05");
8
-    date = new Date("2020-03-05");
9
-    expect(EquipmentBooking.getISODate(date)).toBe("2020-03-05");
10
-    date = new Date("2020-03-05 00:00"); // Treated as local time
11
-    expect(EquipmentBooking.getISODate(date)).toBe("2020-03-04"); // Treated as UTC
8
+  let date = new Date('2020-03-05 12:00');
9
+  expect(EquipmentBooking.getISODate(date)).toBe('2020-03-05');
10
+  date = new Date('2020-03-05');
11
+  expect(EquipmentBooking.getISODate(date)).toBe('2020-03-05');
12
+  date = new Date('2020-03-05 00:00'); // Treated as local time
13
+  expect(EquipmentBooking.getISODate(date)).toBe('2020-03-04'); // Treated as UTC
12 14
 });
13 15
 
14 16
 test('getCurrentDay', () => {
15
-    jest.spyOn(Date, 'now')
16
-        .mockImplementation(() =>
17
-            new Date('2020-01-14 14:50:35').getTime()
18
-        );
19
-    expect(EquipmentBooking.getCurrentDay().getTime()).toBe(new Date("2020-01-14").getTime());
17
+  jest
18
+    .spyOn(Date, 'now')
19
+    .mockImplementation(() => new Date('2020-01-14 14:50:35').getTime());
20
+  expect(EquipmentBooking.getCurrentDay().getTime()).toBe(
21
+    new Date('2020-01-14').getTime(),
22
+  );
20 23
 });
21 24
 
22 25
 test('isEquipmentAvailable', () => {
23
-    jest.spyOn(Date, 'now')
24
-        .mockImplementation(() =>
25
-            new Date('2020-07-09').getTime()
26
-        );
27
-    let testDevice = {
28
-        id: 1,
29
-        name: "Petit barbecue",
30
-        caution: 100,
31
-        booked_at: [{begin: "2020-07-07", end: "2020-07-10"}]
32
-    };
33
-    expect(EquipmentBooking.isEquipmentAvailable(testDevice)).toBeFalse();
26
+  jest
27
+    .spyOn(Date, 'now')
28
+    .mockImplementation(() => new Date('2020-07-09').getTime());
29
+  let testDevice = {
30
+    id: 1,
31
+    name: 'Petit barbecue',
32
+    caution: 100,
33
+    booked_at: [{begin: '2020-07-07', end: '2020-07-10'}],
34
+  };
35
+  expect(EquipmentBooking.isEquipmentAvailable(testDevice)).toBeFalse();
34 36
 
35
-    testDevice.booked_at = [{begin: "2020-07-07", end: "2020-07-09"}];
36
-    expect(EquipmentBooking.isEquipmentAvailable(testDevice)).toBeFalse();
37
+  testDevice.booked_at = [{begin: '2020-07-07', end: '2020-07-09'}];
38
+  expect(EquipmentBooking.isEquipmentAvailable(testDevice)).toBeFalse();
37 39
 
38
-    testDevice.booked_at = [{begin: "2020-07-09", end: "2020-07-10"}];
39
-    expect(EquipmentBooking.isEquipmentAvailable(testDevice)).toBeFalse();
40
+  testDevice.booked_at = [{begin: '2020-07-09', end: '2020-07-10'}];
41
+  expect(EquipmentBooking.isEquipmentAvailable(testDevice)).toBeFalse();
40 42
 
41
-    testDevice.booked_at = [
42
-        {begin: "2020-07-07", end: "2020-07-8"},
43
-        {begin: "2020-07-10", end: "2020-07-12"},
44
-    ];
45
-    expect(EquipmentBooking.isEquipmentAvailable(testDevice)).toBeTrue();
43
+  testDevice.booked_at = [
44
+    {begin: '2020-07-07', end: '2020-07-8'},
45
+    {begin: '2020-07-10', end: '2020-07-12'},
46
+  ];
47
+  expect(EquipmentBooking.isEquipmentAvailable(testDevice)).toBeTrue();
46 48
 });
47 49
 
48 50
 test('getFirstEquipmentAvailability', () => {
49
-    jest.spyOn(Date, 'now')
50
-        .mockImplementation(() =>
51
-            new Date('2020-07-09').getTime()
52
-        );
53
-    let testDevice = {
54
-        id: 1,
55
-        name: "Petit barbecue",
56
-        caution: 100,
57
-        booked_at: [{begin: "2020-07-07", end: "2020-07-10"}]
58
-    };
59
-    expect(EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime()).toBe(new Date("2020-07-11").getTime());
60
-    testDevice.booked_at = [{begin: "2020-07-07", end: "2020-07-09"}];
61
-    expect(EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime()).toBe(new Date("2020-07-10").getTime());
62
-    testDevice.booked_at = [
63
-        {begin: "2020-07-07", end: "2020-07-09"},
64
-        {begin: "2020-07-10", end: "2020-07-16"},
65
-    ];
66
-    expect(EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime()).toBe(new Date("2020-07-17").getTime());
67
-    testDevice.booked_at = [
68
-        {begin: "2020-07-07", end: "2020-07-09"},
69
-        {begin: "2020-07-10", end: "2020-07-12"},
70
-        {begin: "2020-07-14", end: "2020-07-16"},
71
-    ];
72
-    expect(EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime()).toBe(new Date("2020-07-13").getTime());
51
+  jest
52
+    .spyOn(Date, 'now')
53
+    .mockImplementation(() => new Date('2020-07-09').getTime());
54
+  let testDevice = {
55
+    id: 1,
56
+    name: 'Petit barbecue',
57
+    caution: 100,
58
+    booked_at: [{begin: '2020-07-07', end: '2020-07-10'}],
59
+  };
60
+  expect(
61
+    EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime(),
62
+  ).toBe(new Date('2020-07-11').getTime());
63
+  testDevice.booked_at = [{begin: '2020-07-07', end: '2020-07-09'}];
64
+  expect(
65
+    EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime(),
66
+  ).toBe(new Date('2020-07-10').getTime());
67
+  testDevice.booked_at = [
68
+    {begin: '2020-07-07', end: '2020-07-09'},
69
+    {begin: '2020-07-10', end: '2020-07-16'},
70
+  ];
71
+  expect(
72
+    EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime(),
73
+  ).toBe(new Date('2020-07-17').getTime());
74
+  testDevice.booked_at = [
75
+    {begin: '2020-07-07', end: '2020-07-09'},
76
+    {begin: '2020-07-10', end: '2020-07-12'},
77
+    {begin: '2020-07-14', end: '2020-07-16'},
78
+  ];
79
+  expect(
80
+    EquipmentBooking.getFirstEquipmentAvailability(testDevice).getTime(),
81
+  ).toBe(new Date('2020-07-13').getTime());
73 82
 });
74 83
 
75 84
 test('getRelativeDateString', () => {
76
-    jest.spyOn(Date, 'now')
77
-        .mockImplementation(() =>
78
-            new Date('2020-07-09').getTime()
79
-        );
80
-    jest.spyOn(i18n, 't')
81
-        .mockImplementation((translationString: string) => {
82
-                const prefix = "screens.equipment.";
83
-                if (translationString === prefix + "otherYear")
84
-                    return "0";
85
-                else if (translationString === prefix + "otherMonth")
86
-                    return "1";
87
-                else if (translationString === prefix + "thisMonth")
88
-                    return "2";
89
-                else if (translationString === prefix + "tomorrow")
90
-                    return "3";
91
-                else if (translationString === prefix + "today")
92
-                    return "4";
93
-                else
94
-                    return null;
95
-            }
96
-        );
97
-    expect(EquipmentBooking.getRelativeDateString(new Date("2020-07-09"))).toBe("4");
98
-    expect(EquipmentBooking.getRelativeDateString(new Date("2020-07-10"))).toBe("3");
99
-    expect(EquipmentBooking.getRelativeDateString(new Date("2020-07-11"))).toBe("2");
100
-    expect(EquipmentBooking.getRelativeDateString(new Date("2020-07-30"))).toBe("2");
101
-    expect(EquipmentBooking.getRelativeDateString(new Date("2020-08-30"))).toBe("1");
102
-    expect(EquipmentBooking.getRelativeDateString(new Date("2020-11-10"))).toBe("1");
103
-    expect(EquipmentBooking.getRelativeDateString(new Date("2021-11-10"))).toBe("0");
85
+  jest
86
+    .spyOn(Date, 'now')
87
+    .mockImplementation(() => new Date('2020-07-09').getTime());
88
+  jest.spyOn(i18n, 't').mockImplementation((translationString: string) => {
89
+    const prefix = 'screens.equipment.';
90
+    if (translationString === prefix + 'otherYear') return '0';
91
+    else if (translationString === prefix + 'otherMonth') return '1';
92
+    else if (translationString === prefix + 'thisMonth') return '2';
93
+    else if (translationString === prefix + 'tomorrow') return '3';
94
+    else if (translationString === prefix + 'today') return '4';
95
+    else return null;
96
+  });
97
+  expect(EquipmentBooking.getRelativeDateString(new Date('2020-07-09'))).toBe(
98
+    '4',
99
+  );
100
+  expect(EquipmentBooking.getRelativeDateString(new Date('2020-07-10'))).toBe(
101
+    '3',
102
+  );
103
+  expect(EquipmentBooking.getRelativeDateString(new Date('2020-07-11'))).toBe(
104
+    '2',
105
+  );
106
+  expect(EquipmentBooking.getRelativeDateString(new Date('2020-07-30'))).toBe(
107
+    '2',
108
+  );
109
+  expect(EquipmentBooking.getRelativeDateString(new Date('2020-08-30'))).toBe(
110
+    '1',
111
+  );
112
+  expect(EquipmentBooking.getRelativeDateString(new Date('2020-11-10'))).toBe(
113
+    '1',
114
+  );
115
+  expect(EquipmentBooking.getRelativeDateString(new Date('2021-11-10'))).toBe(
116
+    '0',
117
+  );
104 118
 });
105 119
 
106 120
 test('getValidRange', () => {
107
-    let testDevice = {
108
-        id: 1,
109
-        name: "Petit barbecue",
110
-        caution: 100,
111
-        booked_at: [{begin: "2020-07-07", end: "2020-07-10"}]
112
-    };
113
-    let start = new Date("2020-07-11");
114
-    let end = new Date("2020-07-15");
115
-    let result = [
116
-        "2020-07-11",
117
-        "2020-07-12",
118
-        "2020-07-13",
119
-        "2020-07-14",
120
-        "2020-07-15",
121
-    ];
122
-    expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(result);
123
-    testDevice.booked_at = [
124
-        {begin: "2020-07-07", end: "2020-07-10"},
125
-        {begin: "2020-07-13", end: "2020-07-15"},
126
-    ];
127
-    result = [
128
-        "2020-07-11",
129
-        "2020-07-12",
130
-    ];
131
-    expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(result);
121
+  let testDevice = {
122
+    id: 1,
123
+    name: 'Petit barbecue',
124
+    caution: 100,
125
+    booked_at: [{begin: '2020-07-07', end: '2020-07-10'}],
126
+  };
127
+  let start = new Date('2020-07-11');
128
+  let end = new Date('2020-07-15');
129
+  let result = [
130
+    '2020-07-11',
131
+    '2020-07-12',
132
+    '2020-07-13',
133
+    '2020-07-14',
134
+    '2020-07-15',
135
+  ];
136
+  expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(
137
+    result,
138
+  );
139
+  testDevice.booked_at = [
140
+    {begin: '2020-07-07', end: '2020-07-10'},
141
+    {begin: '2020-07-13', end: '2020-07-15'},
142
+  ];
143
+  result = ['2020-07-11', '2020-07-12'];
144
+  expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(
145
+    result,
146
+  );
132 147
 
133
-    testDevice.booked_at = [{begin: "2020-07-12", end: "2020-07-13"}];
134
-    result = ["2020-07-11"];
135
-    expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(result);
136
-    testDevice.booked_at = [{begin: "2020-07-07", end: "2020-07-12"},];
137
-    result = [
138
-        "2020-07-13",
139
-        "2020-07-14",
140
-        "2020-07-15",
141
-    ];
142
-    expect(EquipmentBooking.getValidRange(end, start, testDevice)).toStrictEqual(result);
143
-    start = new Date("2020-07-14");
144
-    end = new Date("2020-07-14");
145
-    result = [
146
-        "2020-07-14",
147
-    ];
148
-    expect(EquipmentBooking.getValidRange(start, start, testDevice)).toStrictEqual(result);
149
-    expect(EquipmentBooking.getValidRange(end, start, testDevice)).toStrictEqual(result);
150
-    expect(EquipmentBooking.getValidRange(start, end, null)).toStrictEqual(result);
148
+  testDevice.booked_at = [{begin: '2020-07-12', end: '2020-07-13'}];
149
+  result = ['2020-07-11'];
150
+  expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(
151
+    result,
152
+  );
153
+  testDevice.booked_at = [{begin: '2020-07-07', end: '2020-07-12'}];
154
+  result = ['2020-07-13', '2020-07-14', '2020-07-15'];
155
+  expect(EquipmentBooking.getValidRange(end, start, testDevice)).toStrictEqual(
156
+    result,
157
+  );
158
+  start = new Date('2020-07-14');
159
+  end = new Date('2020-07-14');
160
+  result = ['2020-07-14'];
161
+  expect(
162
+    EquipmentBooking.getValidRange(start, start, testDevice),
163
+  ).toStrictEqual(result);
164
+  expect(EquipmentBooking.getValidRange(end, start, testDevice)).toStrictEqual(
165
+    result,
166
+  );
167
+  expect(EquipmentBooking.getValidRange(start, end, null)).toStrictEqual(
168
+    result,
169
+  );
151 170
 
152
-    start = new Date("2020-07-14");
153
-    end = new Date("2020-07-17");
154
-    result = [
155
-        "2020-07-14",
156
-        "2020-07-15",
157
-        "2020-07-16",
158
-        "2020-07-17",
159
-    ];
160
-    expect(EquipmentBooking.getValidRange(start, end, null)).toStrictEqual(result);
171
+  start = new Date('2020-07-14');
172
+  end = new Date('2020-07-17');
173
+  result = ['2020-07-14', '2020-07-15', '2020-07-16', '2020-07-17'];
174
+  expect(EquipmentBooking.getValidRange(start, end, null)).toStrictEqual(
175
+    result,
176
+  );
161 177
 
162
-    testDevice.booked_at = [{begin: "2020-07-17", end: "2020-07-17"}];
163
-    result = [
164
-        "2020-07-14",
165
-        "2020-07-15",
166
-        "2020-07-16",
167
-    ];
168
-    expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(result);
178
+  testDevice.booked_at = [{begin: '2020-07-17', end: '2020-07-17'}];
179
+  result = ['2020-07-14', '2020-07-15', '2020-07-16'];
180
+  expect(EquipmentBooking.getValidRange(start, end, testDevice)).toStrictEqual(
181
+    result,
182
+  );
169 183
 
170
-    testDevice.booked_at = [
171
-        {begin: "2020-07-12", end: "2020-07-13"},
172
-        {begin: "2020-07-15", end: "2020-07-20"},
173
-    ];
174
-    start = new Date("2020-07-11");
175
-    end = new Date("2020-07-23");
176
-    result = [
177
-        "2020-07-21",
178
-        "2020-07-22",
179
-        "2020-07-23",
180
-    ];
181
-    expect(EquipmentBooking.getValidRange(end, start, testDevice)).toStrictEqual(result);
184
+  testDevice.booked_at = [
185
+    {begin: '2020-07-12', end: '2020-07-13'},
186
+    {begin: '2020-07-15', end: '2020-07-20'},
187
+  ];
188
+  start = new Date('2020-07-11');
189
+  end = new Date('2020-07-23');
190
+  result = ['2020-07-21', '2020-07-22', '2020-07-23'];
191
+  expect(EquipmentBooking.getValidRange(end, start, testDevice)).toStrictEqual(
192
+    result,
193
+  );
182 194
 });
183 195
 
184 196
 test('generateMarkedDates', () => {
185
-    let theme = {
186
-        colors: {
187
-            primary: "primary",
188
-            danger: "primary",
189
-            textDisabled: "primary",
190
-        }
191
-    }
192
-    let testDevice = {
193
-        id: 1,
194
-        name: "Petit barbecue",
195
-        caution: 100,
196
-        booked_at: [{begin: "2020-07-07", end: "2020-07-10"}]
197
-    };
198
-    let start = new Date("2020-07-11");
199
-    let end = new Date("2020-07-13");
200
-    let range = EquipmentBooking.getValidRange(start, end, testDevice);
201
-    let result = {
202
-        "2020-07-11": {
203
-            startingDay: true,
204
-            endingDay: false,
205
-            color: theme.colors.primary
206
-        },
207
-        "2020-07-12": {
208
-            startingDay: false,
209
-            endingDay: false,
210
-            color: theme.colors.danger
211
-        },
212
-        "2020-07-13": {
213
-            startingDay: false,
214
-            endingDay: true,
215
-            color: theme.colors.primary
216
-        },
217
-    };
218
-    expect(EquipmentBooking.generateMarkedDates(true, theme, range)).toStrictEqual(result);
219
-    result = {
220
-        "2020-07-11": {
221
-            startingDay: true,
222
-            endingDay: false,
223
-            color: theme.colors.textDisabled
224
-        },
225
-        "2020-07-12": {
226
-            startingDay: false,
227
-            endingDay: false,
228
-            color: theme.colors.textDisabled
229
-        },
230
-        "2020-07-13": {
231
-            startingDay: false,
232
-            endingDay: true,
233
-            color: theme.colors.textDisabled
234
-        },
235
-    };
236
-    expect(EquipmentBooking.generateMarkedDates(false, theme, range)).toStrictEqual(result);
237
-    result = {
238
-        "2020-07-11": {
239
-            startingDay: true,
240
-            endingDay: false,
241
-            color: theme.colors.textDisabled
242
-        },
243
-        "2020-07-12": {
244
-            startingDay: false,
245
-            endingDay: false,
246
-            color: theme.colors.textDisabled
247
-        },
248
-        "2020-07-13": {
249
-            startingDay: false,
250
-            endingDay: true,
251
-            color: theme.colors.textDisabled
252
-        },
253
-    };
254
-    range = EquipmentBooking.getValidRange(end, start, testDevice);
255
-    expect(EquipmentBooking.generateMarkedDates(false, theme, range)).toStrictEqual(result);
197
+  let theme = {
198
+    colors: {
199
+      primary: 'primary',
200
+      danger: 'primary',
201
+      textDisabled: 'primary',
202
+    },
203
+  };
204
+  let testDevice = {
205
+    id: 1,
206
+    name: 'Petit barbecue',
207
+    caution: 100,
208
+    booked_at: [{begin: '2020-07-07', end: '2020-07-10'}],
209
+  };
210
+  let start = new Date('2020-07-11');
211
+  let end = new Date('2020-07-13');
212
+  let range = EquipmentBooking.getValidRange(start, end, testDevice);
213
+  let result = {
214
+    '2020-07-11': {
215
+      startingDay: true,
216
+      endingDay: false,
217
+      color: theme.colors.primary,
218
+    },
219
+    '2020-07-12': {
220
+      startingDay: false,
221
+      endingDay: false,
222
+      color: theme.colors.danger,
223
+    },
224
+    '2020-07-13': {
225
+      startingDay: false,
226
+      endingDay: true,
227
+      color: theme.colors.primary,
228
+    },
229
+  };
230
+  expect(
231
+    EquipmentBooking.generateMarkedDates(true, theme, range),
232
+  ).toStrictEqual(result);
233
+  result = {
234
+    '2020-07-11': {
235
+      startingDay: true,
236
+      endingDay: false,
237
+      color: theme.colors.textDisabled,
238
+    },
239
+    '2020-07-12': {
240
+      startingDay: false,
241
+      endingDay: false,
242
+      color: theme.colors.textDisabled,
243
+    },
244
+    '2020-07-13': {
245
+      startingDay: false,
246
+      endingDay: true,
247
+      color: theme.colors.textDisabled,
248
+    },
249
+  };
250
+  expect(
251
+    EquipmentBooking.generateMarkedDates(false, theme, range),
252
+  ).toStrictEqual(result);
253
+  result = {
254
+    '2020-07-11': {
255
+      startingDay: true,
256
+      endingDay: false,
257
+      color: theme.colors.textDisabled,
258
+    },
259
+    '2020-07-12': {
260
+      startingDay: false,
261
+      endingDay: false,
262
+      color: theme.colors.textDisabled,
263
+    },
264
+    '2020-07-13': {
265
+      startingDay: false,
266
+      endingDay: true,
267
+      color: theme.colors.textDisabled,
268
+    },
269
+  };
270
+  range = EquipmentBooking.getValidRange(end, start, testDevice);
271
+  expect(
272
+    EquipmentBooking.generateMarkedDates(false, theme, range),
273
+  ).toStrictEqual(result);
256 274
 
257
-    testDevice.booked_at = [{begin: "2020-07-13", end: "2020-07-15"},];
258
-    result = {
259
-        "2020-07-11": {
260
-            startingDay: true,
261
-            endingDay: false,
262
-            color: theme.colors.primary
263
-        },
264
-        "2020-07-12": {
265
-            startingDay: false,
266
-            endingDay: true,
267
-            color: theme.colors.primary
268
-        },
269
-    };
270
-    range = EquipmentBooking.getValidRange(start, end, testDevice);
271
-    expect(EquipmentBooking.generateMarkedDates(true, theme, range)).toStrictEqual(result);
275
+  testDevice.booked_at = [{begin: '2020-07-13', end: '2020-07-15'}];
276
+  result = {
277
+    '2020-07-11': {
278
+      startingDay: true,
279
+      endingDay: false,
280
+      color: theme.colors.primary,
281
+    },
282
+    '2020-07-12': {
283
+      startingDay: false,
284
+      endingDay: true,
285
+      color: theme.colors.primary,
286
+    },
287
+  };
288
+  range = EquipmentBooking.getValidRange(start, end, testDevice);
289
+  expect(
290
+    EquipmentBooking.generateMarkedDates(true, theme, range),
291
+  ).toStrictEqual(result);
272 292
 
273
-    testDevice.booked_at = [{begin: "2020-07-12", end: "2020-07-13"},];
274
-    result = {
275
-        "2020-07-11": {
276
-            startingDay: true,
277
-            endingDay: true,
278
-            color: theme.colors.primary
279
-        },
280
-    };
281
-    range = EquipmentBooking.getValidRange(start, end, testDevice);
282
-    expect(EquipmentBooking.generateMarkedDates(true, theme, range)).toStrictEqual(result);
293
+  testDevice.booked_at = [{begin: '2020-07-12', end: '2020-07-13'}];
294
+  result = {
295
+    '2020-07-11': {
296
+      startingDay: true,
297
+      endingDay: true,
298
+      color: theme.colors.primary,
299
+    },
300
+  };
301
+  range = EquipmentBooking.getValidRange(start, end, testDevice);
302
+  expect(
303
+    EquipmentBooking.generateMarkedDates(true, theme, range),
304
+  ).toStrictEqual(result);
283 305
 
284
-    testDevice.booked_at = [
285
-        {begin: "2020-07-12", end: "2020-07-13"},
286
-        {begin: "2020-07-15", end: "2020-07-20"},
287
-    ];
288
-    start = new Date("2020-07-11");
289
-    end = new Date("2020-07-23");
290
-    result = {
291
-        "2020-07-11": {
292
-            startingDay: true,
293
-            endingDay: true,
294
-            color: theme.colors.primary
295
-        },
296
-    };
297
-    range = EquipmentBooking.getValidRange(start, end, testDevice);
298
-    expect(EquipmentBooking.generateMarkedDates(true, theme, range)).toStrictEqual(result);
306
+  testDevice.booked_at = [
307
+    {begin: '2020-07-12', end: '2020-07-13'},
308
+    {begin: '2020-07-15', end: '2020-07-20'},
309
+  ];
310
+  start = new Date('2020-07-11');
311
+  end = new Date('2020-07-23');
312
+  result = {
313
+    '2020-07-11': {
314
+      startingDay: true,
315
+      endingDay: true,
316
+      color: theme.colors.primary,
317
+    },
318
+  };
319
+  range = EquipmentBooking.getValidRange(start, end, testDevice);
320
+  expect(
321
+    EquipmentBooking.generateMarkedDates(true, theme, range),
322
+  ).toStrictEqual(result);
299 323
 
300
-    result = {
301
-        "2020-07-21": {
302
-            startingDay: true,
303
-            endingDay: false,
304
-            color: theme.colors.primary
305
-        },
306
-        "2020-07-22": {
307
-            startingDay: false,
308
-            endingDay: false,
309
-            color: theme.colors.danger
310
-        },
311
-        "2020-07-23": {
312
-            startingDay: false,
313
-            endingDay: true,
314
-            color: theme.colors.primary
315
-        },
316
-    };
317
-    range = EquipmentBooking.getValidRange(end, start, testDevice);
318
-    expect(EquipmentBooking.generateMarkedDates(true, theme, range)).toStrictEqual(result);
324
+  result = {
325
+    '2020-07-21': {
326
+      startingDay: true,
327
+      endingDay: false,
328
+      color: theme.colors.primary,
329
+    },
330
+    '2020-07-22': {
331
+      startingDay: false,
332
+      endingDay: false,
333
+      color: theme.colors.danger,
334
+    },
335
+    '2020-07-23': {
336
+      startingDay: false,
337
+      endingDay: true,
338
+      color: theme.colors.primary,
339
+    },
340
+  };
341
+  range = EquipmentBooking.getValidRange(end, start, testDevice);
342
+  expect(
343
+    EquipmentBooking.generateMarkedDates(true, theme, range),
344
+  ).toStrictEqual(result);
319 345
 });

+ 188
- 176
__tests__/utils/PlanningEventManager.test.js View File

@@ -1,210 +1,222 @@
1
+/* eslint-disable */
2
+
1 3
 import React from 'react';
2
-import * as Planning from "../../src/utils/Planning";
4
+import * as Planning from '../../src/utils/Planning';
3 5
 
4 6
 test('isDescriptionEmpty', () => {
5
-    expect(Planning.isDescriptionEmpty("")).toBeTrue();
6
-    expect(Planning.isDescriptionEmpty("   ")).toBeTrue();
7
-    // noinspection CheckTagEmptyBody
8
-    expect(Planning.isDescriptionEmpty("<p></p>")).toBeTrue();
9
-    expect(Planning.isDescriptionEmpty("<p>   </p>")).toBeTrue();
10
-    expect(Planning.isDescriptionEmpty("<p><br></p>")).toBeTrue();
11
-    expect(Planning.isDescriptionEmpty("<p><br></p><p><br></p>")).toBeTrue();
12
-    expect(Planning.isDescriptionEmpty("<p><br><br><br></p>")).toBeTrue();
13
-    expect(Planning.isDescriptionEmpty("<p><br>")).toBeTrue();
14
-    expect(Planning.isDescriptionEmpty(null)).toBeTrue();
15
-    expect(Planning.isDescriptionEmpty(undefined)).toBeTrue();
16
-    expect(Planning.isDescriptionEmpty("coucou")).toBeFalse();
17
-    expect(Planning.isDescriptionEmpty("<p>coucou</p>")).toBeFalse();
7
+  expect(Planning.isDescriptionEmpty('')).toBeTrue();
8
+  expect(Planning.isDescriptionEmpty('   ')).toBeTrue();
9
+  // noinspection CheckTagEmptyBody
10
+  expect(Planning.isDescriptionEmpty('<p></p>')).toBeTrue();
11
+  expect(Planning.isDescriptionEmpty('<p>   </p>')).toBeTrue();
12
+  expect(Planning.isDescriptionEmpty('<p><br></p>')).toBeTrue();
13
+  expect(Planning.isDescriptionEmpty('<p><br></p><p><br></p>')).toBeTrue();
14
+  expect(Planning.isDescriptionEmpty('<p><br><br><br></p>')).toBeTrue();
15
+  expect(Planning.isDescriptionEmpty('<p><br>')).toBeTrue();
16
+  expect(Planning.isDescriptionEmpty(null)).toBeTrue();
17
+  expect(Planning.isDescriptionEmpty(undefined)).toBeTrue();
18
+  expect(Planning.isDescriptionEmpty('coucou')).toBeFalse();
19
+  expect(Planning.isDescriptionEmpty('<p>coucou</p>')).toBeFalse();
18 20
 });
19 21
 
20 22
 test('isEventDateStringFormatValid', () => {
21
-    expect(Planning.isEventDateStringFormatValid("2020-03-21 09:00")).toBeTrue();
22
-    expect(Planning.isEventDateStringFormatValid("3214-64-12 01:16")).toBeTrue();
23
-
24
-    expect(Planning.isEventDateStringFormatValid("3214-64-12 01:16:00")).toBeFalse();
25
-    expect(Planning.isEventDateStringFormatValid("3214-64-12 1:16")).toBeFalse();
26
-    expect(Planning.isEventDateStringFormatValid("3214-f4-12 01:16")).toBeFalse();
27
-    expect(Planning.isEventDateStringFormatValid("sqdd 09:00")).toBeFalse();
28
-    expect(Planning.isEventDateStringFormatValid("2020-03-21")).toBeFalse();
29
-    expect(Planning.isEventDateStringFormatValid("2020-03-21 truc")).toBeFalse();
30
-    expect(Planning.isEventDateStringFormatValid("3214-64-12 1:16:65")).toBeFalse();
31
-    expect(Planning.isEventDateStringFormatValid("garbage")).toBeFalse();
32
-    expect(Planning.isEventDateStringFormatValid("")).toBeFalse();
33
-    expect(Planning.isEventDateStringFormatValid(undefined)).toBeFalse();
34
-    expect(Planning.isEventDateStringFormatValid(null)).toBeFalse();
23
+  expect(Planning.isEventDateStringFormatValid('2020-03-21 09:00')).toBeTrue();
24
+  expect(Planning.isEventDateStringFormatValid('3214-64-12 01:16')).toBeTrue();
25
+
26
+  expect(
27
+    Planning.isEventDateStringFormatValid('3214-64-12 01:16:00'),
28
+  ).toBeFalse();
29
+  expect(Planning.isEventDateStringFormatValid('3214-64-12 1:16')).toBeFalse();
30
+  expect(Planning.isEventDateStringFormatValid('3214-f4-12 01:16')).toBeFalse();
31
+  expect(Planning.isEventDateStringFormatValid('sqdd 09:00')).toBeFalse();
32
+  expect(Planning.isEventDateStringFormatValid('2020-03-21')).toBeFalse();
33
+  expect(Planning.isEventDateStringFormatValid('2020-03-21 truc')).toBeFalse();
34
+  expect(
35
+    Planning.isEventDateStringFormatValid('3214-64-12 1:16:65'),
36
+  ).toBeFalse();
37
+  expect(Planning.isEventDateStringFormatValid('garbage')).toBeFalse();
38
+  expect(Planning.isEventDateStringFormatValid('')).toBeFalse();
39
+  expect(Planning.isEventDateStringFormatValid(undefined)).toBeFalse();
40
+  expect(Planning.isEventDateStringFormatValid(null)).toBeFalse();
35 41
 });
36 42
 
37 43
 test('stringToDate', () => {
38
-    let testDate = new Date();
39
-    expect(Planning.stringToDate(undefined)).toBeNull();
40
-    expect(Planning.stringToDate("")).toBeNull();
41
-    expect(Planning.stringToDate("garbage")).toBeNull();
42
-    expect(Planning.stringToDate("2020-03-21")).toBeNull();
43
-    expect(Planning.stringToDate("09:00:00")).toBeNull();
44
-    expect(Planning.stringToDate("2020-03-21 09:g0")).toBeNull();
45
-    expect(Planning.stringToDate("2020-03-21 09:g0:")).toBeNull();
46
-    testDate.setFullYear(2020, 2, 21);
47
-    testDate.setHours(9, 0, 0, 0);
48
-    expect(Planning.stringToDate("2020-03-21 09:00")).toEqual(testDate);
49
-    testDate.setFullYear(2020, 0, 31);
50
-    testDate.setHours(18, 30, 0, 0);
51
-    expect(Planning.stringToDate("2020-01-31 18:30")).toEqual(testDate);
52
-    testDate.setFullYear(2020, 50, 50);
53
-    testDate.setHours(65, 65, 0, 0);
54
-    expect(Planning.stringToDate("2020-51-50 65:65")).toEqual(testDate);
44
+  let testDate = new Date();
45
+  expect(Planning.stringToDate(undefined)).toBeNull();
46
+  expect(Planning.stringToDate('')).toBeNull();
47
+  expect(Planning.stringToDate('garbage')).toBeNull();
48
+  expect(Planning.stringToDate('2020-03-21')).toBeNull();
49
+  expect(Planning.stringToDate('09:00:00')).toBeNull();
50
+  expect(Planning.stringToDate('2020-03-21 09:g0')).toBeNull();
51
+  expect(Planning.stringToDate('2020-03-21 09:g0:')).toBeNull();
52
+  testDate.setFullYear(2020, 2, 21);
53
+  testDate.setHours(9, 0, 0, 0);
54
+  expect(Planning.stringToDate('2020-03-21 09:00')).toEqual(testDate);
55
+  testDate.setFullYear(2020, 0, 31);
56
+  testDate.setHours(18, 30, 0, 0);
57
+  expect(Planning.stringToDate('2020-01-31 18:30')).toEqual(testDate);
58
+  testDate.setFullYear(2020, 50, 50);
59
+  testDate.setHours(65, 65, 0, 0);
60
+  expect(Planning.stringToDate('2020-51-50 65:65')).toEqual(testDate);
55 61
 });
56 62
 
57 63
 test('getFormattedEventTime', () => {
58
-    expect(Planning.getFormattedEventTime(null, null))
59
-        .toBe('/ - /');
60
-    expect(Planning.getFormattedEventTime(undefined, undefined))
61
-        .toBe('/ - /');
62
-    expect(Planning.getFormattedEventTime("20:30", "23:00"))
63
-        .toBe('/ - /');
64
-    expect(Planning.getFormattedEventTime("2020-03-30", "2020-03-31"))
65
-        .toBe('/ - /');
66
-
67
-
68
-    expect(Planning.getFormattedEventTime("2020-03-21 09:00", "2020-03-21 09:00"))
69
-        .toBe('09:00');
70
-    expect(Planning.getFormattedEventTime("2020-03-21 09:00", "2020-03-22 17:00"))
71
-        .toBe('09:00 - 23:59');
72
-    expect(Planning.getFormattedEventTime("2020-03-30 20:30", "2020-03-30 23:00"))
73
-        .toBe('20:30 - 23:00');
64
+  expect(Planning.getFormattedEventTime(null, null)).toBe('/ - /');
65
+  expect(Planning.getFormattedEventTime(undefined, undefined)).toBe('/ - /');
66
+  expect(Planning.getFormattedEventTime('20:30', '23:00')).toBe('/ - /');
67
+  expect(Planning.getFormattedEventTime('2020-03-30', '2020-03-31')).toBe(
68
+    '/ - /',
69
+  );
70
+
71
+  expect(
72
+    Planning.getFormattedEventTime('2020-03-21 09:00', '2020-03-21 09:00'),
73
+  ).toBe('09:00');
74
+  expect(
75
+    Planning.getFormattedEventTime('2020-03-21 09:00', '2020-03-22 17:00'),
76
+  ).toBe('09:00 - 23:59');
77
+  expect(
78
+    Planning.getFormattedEventTime('2020-03-30 20:30', '2020-03-30 23:00'),
79
+  ).toBe('20:30 - 23:00');
74 80
 });
75 81
 
76 82
 test('getDateOnlyString', () => {
77
-    expect(Planning.getDateOnlyString("2020-03-21 09:00")).toBe("2020-03-21");
78
-    expect(Planning.getDateOnlyString("2021-12-15 09:00")).toBe("2021-12-15");
79
-    expect(Planning.getDateOnlyString("2021-12-o5 09:00")).toBeNull();
80
-    expect(Planning.getDateOnlyString("2021-12-15 09:")).toBeNull();
81
-    expect(Planning.getDateOnlyString("2021-12-15")).toBeNull();
82
-    expect(Planning.getDateOnlyString("garbage")).toBeNull();
83
+  expect(Planning.getDateOnlyString('2020-03-21 09:00')).toBe('2020-03-21');
84
+  expect(Planning.getDateOnlyString('2021-12-15 09:00')).toBe('2021-12-15');
85
+  expect(Planning.getDateOnlyString('2021-12-o5 09:00')).toBeNull();
86
+  expect(Planning.getDateOnlyString('2021-12-15 09:')).toBeNull();
87
+  expect(Planning.getDateOnlyString('2021-12-15')).toBeNull();
88
+  expect(Planning.getDateOnlyString('garbage')).toBeNull();
83 89
 });
84 90
 
85 91
 test('isEventBefore', () => {
86
-    expect(Planning.isEventBefore(
87
-        "2020-03-21 09:00", "2020-03-21 10:00")).toBeTrue();
88
-    expect(Planning.isEventBefore(
89
-        "2020-03-21 10:00", "2020-03-21 10:15")).toBeTrue();
90
-    expect(Planning.isEventBefore(
91
-        "2020-03-21 10:15", "2021-03-21 10:15")).toBeTrue();
92
-    expect(Planning.isEventBefore(
93
-        "2020-03-21 10:15", "2020-05-21 10:15")).toBeTrue();
94
-    expect(Planning.isEventBefore(
95
-        "2020-03-21 10:15", "2020-03-30 10:15")).toBeTrue();
96
-
97
-    expect(Planning.isEventBefore(
98
-        "2020-03-21 10:00", "2020-03-21 10:00")).toBeFalse();
99
-    expect(Planning.isEventBefore(
100
-        "2020-03-21 10:00", "2020-03-21 09:00")).toBeFalse();
101
-    expect(Planning.isEventBefore(
102
-        "2020-03-21 10:15", "2020-03-21 10:00")).toBeFalse();
103
-    expect(Planning.isEventBefore(
104
-        "2021-03-21 10:15", "2020-03-21 10:15")).toBeFalse();
105
-    expect(Planning.isEventBefore(
106
-        "2020-05-21 10:15", "2020-03-21 10:15")).toBeFalse();
107
-    expect(Planning.isEventBefore(
108
-        "2020-03-30 10:15", "2020-03-21 10:15")).toBeFalse();
109
-
110
-    expect(Planning.isEventBefore(
111
-        "garbage", "2020-03-21 10:15")).toBeFalse();
112
-    expect(Planning.isEventBefore(
113
-        undefined, undefined)).toBeFalse();
92
+  expect(
93
+    Planning.isEventBefore('2020-03-21 09:00', '2020-03-21 10:00'),
94
+  ).toBeTrue();
95
+  expect(
96
+    Planning.isEventBefore('2020-03-21 10:00', '2020-03-21 10:15'),
97
+  ).toBeTrue();
98
+  expect(
99
+    Planning.isEventBefore('2020-03-21 10:15', '2021-03-21 10:15'),
100
+  ).toBeTrue();
101
+  expect(
102
+    Planning.isEventBefore('2020-03-21 10:15', '2020-05-21 10:15'),
103
+  ).toBeTrue();
104
+  expect(
105
+    Planning.isEventBefore('2020-03-21 10:15', '2020-03-30 10:15'),
106
+  ).toBeTrue();
107
+
108
+  expect(
109
+    Planning.isEventBefore('2020-03-21 10:00', '2020-03-21 10:00'),
110
+  ).toBeFalse();
111
+  expect(
112
+    Planning.isEventBefore('2020-03-21 10:00', '2020-03-21 09:00'),
113
+  ).toBeFalse();
114
+  expect(
115
+    Planning.isEventBefore('2020-03-21 10:15', '2020-03-21 10:00'),
116
+  ).toBeFalse();
117
+  expect(
118
+    Planning.isEventBefore('2021-03-21 10:15', '2020-03-21 10:15'),
119
+  ).toBeFalse();
120
+  expect(
121
+    Planning.isEventBefore('2020-05-21 10:15', '2020-03-21 10:15'),
122
+  ).toBeFalse();
123
+  expect(
124
+    Planning.isEventBefore('2020-03-30 10:15', '2020-03-21 10:15'),
125
+  ).toBeFalse();
126
+
127
+  expect(Planning.isEventBefore('garbage', '2020-03-21 10:15')).toBeFalse();
128
+  expect(Planning.isEventBefore(undefined, undefined)).toBeFalse();
114 129
 });
115 130
 
116 131
 test('dateToString', () => {
117
-    let testDate = new Date();
118
-    testDate.setFullYear(2020, 2, 21);
119
-    testDate.setHours(9, 0, 0, 0);
120
-    expect(Planning.dateToString(testDate)).toBe("2020-03-21 09:00");
121
-    testDate.setFullYear(2021, 0, 12);
122
-    testDate.setHours(9, 10, 0, 0);
123
-    expect(Planning.dateToString(testDate)).toBe("2021-01-12 09:10");
124
-    testDate.setFullYear(2022, 11, 31);
125
-    testDate.setHours(9, 10, 15, 0);
126
-    expect(Planning.dateToString(testDate)).toBe("2022-12-31 09:10");
132
+  let testDate = new Date();
133
+  testDate.setFullYear(2020, 2, 21);
134
+  testDate.setHours(9, 0, 0, 0);
135
+  expect(Planning.dateToString(testDate)).toBe('2020-03-21 09:00');
136
+  testDate.setFullYear(2021, 0, 12);
137
+  testDate.setHours(9, 10, 0, 0);
138
+  expect(Planning.dateToString(testDate)).toBe('2021-01-12 09:10');
139
+  testDate.setFullYear(2022, 11, 31);
140
+  testDate.setHours(9, 10, 15, 0);
141
+  expect(Planning.dateToString(testDate)).toBe('2022-12-31 09:10');
127 142
 });
128 143
 
129 144
 test('generateEmptyCalendar', () => {
130
-    jest.spyOn(Date, 'now')
131
-        .mockImplementation(() =>
132
-            new Date('2020-01-14T00:00:00.000Z').getTime()
133
-        );
134
-    let calendar = Planning.generateEmptyCalendar(1);
135
-    expect(calendar).toHaveProperty("2020-01-14");
136
-    expect(calendar).toHaveProperty("2020-01-20");
137
-    expect(calendar).toHaveProperty("2020-02-10");
138
-    expect(Object.keys(calendar).length).toBe(32);
139
-    calendar = Planning.generateEmptyCalendar(3);
140
-    expect(calendar).toHaveProperty("2020-01-14");
141
-    expect(calendar).toHaveProperty("2020-01-20");
142
-    expect(calendar).toHaveProperty("2020-02-10");
143
-    expect(calendar).toHaveProperty("2020-02-14");
144
-    expect(calendar).toHaveProperty("2020-03-20");
145
-    expect(calendar).toHaveProperty("2020-04-12");
146
-    expect(Object.keys(calendar).length).toBe(92);
145
+  jest
146
+    .spyOn(Date, 'now')
147
+    .mockImplementation(() => new Date('2020-01-14T00:00:00.000Z').getTime());
148
+  let calendar = Planning.generateEmptyCalendar(1);
149
+  expect(calendar).toHaveProperty('2020-01-14');
150
+  expect(calendar).toHaveProperty('2020-01-20');
151
+  expect(calendar).toHaveProperty('2020-02-10');
152
+  expect(Object.keys(calendar).length).toBe(32);
153
+  calendar = Planning.generateEmptyCalendar(3);
154
+  expect(calendar).toHaveProperty('2020-01-14');
155
+  expect(calendar).toHaveProperty('2020-01-20');
156
+  expect(calendar).toHaveProperty('2020-02-10');
157
+  expect(calendar).toHaveProperty('2020-02-14');
158
+  expect(calendar).toHaveProperty('2020-03-20');
159
+  expect(calendar).toHaveProperty('2020-04-12');
160
+  expect(Object.keys(calendar).length).toBe(92);
147 161
 });
148 162
 
149 163
 test('pushEventInOrder', () => {
150
-    let eventArray = [];
151
-    let event1 = {date_begin: "2020-01-14 09:15"};
152
-    Planning.pushEventInOrder(eventArray, event1);
153
-    expect(eventArray.length).toBe(1);
154
-    expect(eventArray[0]).toBe(event1);
155
-
156
-    let event2 = {date_begin: "2020-01-14 10:15"};
157
-    Planning.pushEventInOrder(eventArray, event2);
158
-    expect(eventArray.length).toBe(2);
159
-    expect(eventArray[0]).toBe(event1);
160
-    expect(eventArray[1]).toBe(event2);
161
-
162
-    let event3 = {date_begin: "2020-01-14 10:15", title: "garbage"};
163
-    Planning.pushEventInOrder(eventArray, event3);
164
-    expect(eventArray.length).toBe(3);
165
-    expect(eventArray[0]).toBe(event1);
166
-    expect(eventArray[1]).toBe(event2);
167
-    expect(eventArray[2]).toBe(event3);
168
-
169
-    let event4 = {date_begin: "2020-01-13 09:00"};
170
-    Planning.pushEventInOrder(eventArray, event4);
171
-    expect(eventArray.length).toBe(4);
172
-    expect(eventArray[0]).toBe(event4);
173
-    expect(eventArray[1]).toBe(event1);
174
-    expect(eventArray[2]).toBe(event2);
175
-    expect(eventArray[3]).toBe(event3);
164
+  let eventArray = [];
165
+  let event1 = {date_begin: '2020-01-14 09:15'};
166
+  Planning.pushEventInOrder(eventArray, event1);
167
+  expect(eventArray.length).toBe(1);
168
+  expect(eventArray[0]).toBe(event1);
169
+
170
+  let event2 = {date_begin: '2020-01-14 10:15'};
171
+  Planning.pushEventInOrder(eventArray, event2);
172
+  expect(eventArray.length).toBe(2);
173
+  expect(eventArray[0]).toBe(event1);
174
+  expect(eventArray[1]).toBe(event2);
175
+
176
+  let event3 = {date_begin: '2020-01-14 10:15', title: 'garbage'};
177
+  Planning.pushEventInOrder(eventArray, event3);
178
+  expect(eventArray.length).toBe(3);
179
+  expect(eventArray[0]).toBe(event1);
180
+  expect(eventArray[1]).toBe(event2);
181
+  expect(eventArray[2]).toBe(event3);
182
+
183
+  let event4 = {date_begin: '2020-01-13 09:00'};
184
+  Planning.pushEventInOrder(eventArray, event4);
185
+  expect(eventArray.length).toBe(4);
186
+  expect(eventArray[0]).toBe(event4);
187
+  expect(eventArray[1]).toBe(event1);
188
+  expect(eventArray[2]).toBe(event2);
189
+  expect(eventArray[3]).toBe(event3);
176 190
 });
177 191
 
178 192
 test('generateEventAgenda', () => {
179
-    jest.spyOn(Date, 'now')
180
-        .mockImplementation(() =>
181
-            new Date('2020-01-14T00:00:00.000Z').getTime()
182
-        );
183
-    let eventList = [
184
-        {date_begin: "2020-01-14 09:15"},
185
-        {date_begin: "2020-02-01 09:15"},
186
-        {date_begin: "2020-01-15 09:15"},
187
-        {date_begin: "2020-02-01 09:30"},
188
-        {date_begin: "2020-02-01 08:30"},
189
-    ];
190
-    const calendar = Planning.generateEventAgenda(eventList, 2);
191
-    expect(calendar["2020-01-14"].length).toBe(1);
192
-    expect(calendar["2020-01-14"][0]).toBe(eventList[0]);
193
-    expect(calendar["2020-01-15"].length).toBe(1);
194
-    expect(calendar["2020-01-15"][0]).toBe(eventList[2]);
195
-    expect(calendar["2020-02-01"].length).toBe(3);
196
-    expect(calendar["2020-02-01"][0]).toBe(eventList[4]);
197
-    expect(calendar["2020-02-01"][1]).toBe(eventList[1]);
198
-    expect(calendar["2020-02-01"][2]).toBe(eventList[3]);
193
+  jest
194
+    .spyOn(Date, 'now')
195
+    .mockImplementation(() => new Date('2020-01-14T00:00:00.000Z').getTime());
196
+  let eventList = [
197
+    {date_begin: '2020-01-14 09:15'},
198
+    {date_begin: '2020-02-01 09:15'},
199
+    {date_begin: '2020-01-15 09:15'},
200
+    {date_begin: '2020-02-01 09:30'},
201
+    {date_begin: '2020-02-01 08:30'},
202
+  ];
203
+  const calendar = Planning.generateEventAgenda(eventList, 2);
204
+  expect(calendar['2020-01-14'].length).toBe(1);
205
+  expect(calendar['2020-01-14'][0]).toBe(eventList[0]);
206
+  expect(calendar['2020-01-15'].length).toBe(1);
207
+  expect(calendar['2020-01-15'][0]).toBe(eventList[2]);
208
+  expect(calendar['2020-02-01'].length).toBe(3);
209
+  expect(calendar['2020-02-01'][0]).toBe(eventList[4]);
210
+  expect(calendar['2020-02-01'][1]).toBe(eventList[1]);
211
+  expect(calendar['2020-02-01'][2]).toBe(eventList[3]);
199 212
 });
200 213
 
201 214
 test('getCurrentDateString', () => {
202
-    jest.spyOn(Date, 'now')
203
-        .mockImplementation(() => {
204
-            let date = new Date();
205
-            date.setFullYear(2020, 0, 14);
206
-            date.setHours(15, 30, 54, 65);
207
-            return date.getTime();
208
-        });
209
-    expect(Planning.getCurrentDateString()).toBe('2020-01-14 15:30');
215
+  jest.spyOn(Date, 'now').mockImplementation(() => {
216
+    let date = new Date();
217
+    date.setFullYear(2020, 0, 14);
218
+    date.setHours(15, 30, 54, 65);
219
+    return date.getTime();
220
+  });
221
+  expect(Planning.getCurrentDateString()).toBe('2020-01-14 15:30');
210 222
 });

+ 149
- 124
__tests__/utils/Proxiwash.test.js View File

@@ -1,142 +1,167 @@
1
+/* eslint-disable */
2
+
1 3
 import React from 'react';
2
-import {getCleanedMachineWatched, getMachineEndDate, getMachineOfId, isMachineWatched} from "../../src/utils/Proxiwash";
4
+import {
5
+  getCleanedMachineWatched,
6
+  getMachineEndDate,
7
+  getMachineOfId,
8
+  isMachineWatched,
9
+} from '../../src/utils/Proxiwash';
3 10
 
4 11
 test('getMachineEndDate', () => {
5
-    jest.spyOn(Date, 'now')
6
-        .mockImplementation(() =>
7
-            new Date('2020-01-14T15:00:00.000Z').getTime()
8
-        );
9
-    let expectDate = new Date('2020-01-14T15:00:00.000Z');
10
-    expectDate.setHours(23);
11
-    expectDate.setMinutes(10);
12
-    expect(getMachineEndDate({endTime: "23:10"}).getTime()).toBe(expectDate.getTime());
12
+  jest
13
+    .spyOn(Date, 'now')
14
+    .mockImplementation(() => new Date('2020-01-14T15:00:00.000Z').getTime());
15
+  let expectDate = new Date('2020-01-14T15:00:00.000Z');
16
+  expectDate.setHours(23);
17
+  expectDate.setMinutes(10);
18
+  expect(getMachineEndDate({endTime: '23:10'}).getTime()).toBe(
19
+    expectDate.getTime(),
20
+  );
13 21
 
14
-    expectDate.setHours(16);
15
-    expectDate.setMinutes(30);
16
-    expect(getMachineEndDate({endTime: "16:30"}).getTime()).toBe(expectDate.getTime());
22
+  expectDate.setHours(16);
23
+  expectDate.setMinutes(30);
24
+  expect(getMachineEndDate({endTime: '16:30'}).getTime()).toBe(
25
+    expectDate.getTime(),
26
+  );
17 27
 
18
-    expect(getMachineEndDate({endTime: "15:30"})).toBeNull();
28
+  expect(getMachineEndDate({endTime: '15:30'})).toBeNull();
19 29
 
20
-    expect(getMachineEndDate({endTime: "13:10"})).toBeNull();
30
+  expect(getMachineEndDate({endTime: '13:10'})).toBeNull();
21 31
 
22
-    jest.spyOn(Date, 'now')
23
-        .mockImplementation(() =>
24
-            new Date('2020-01-14T23:00:00.000Z').getTime()
25
-        );
26
-    expectDate = new Date('2020-01-14T23:00:00.000Z');
27
-    expectDate.setHours(0);
28
-    expectDate.setMinutes(30);
29
-    expect(getMachineEndDate({endTime: "00:30"}).getTime()).toBe(expectDate.getTime());
32
+  jest
33
+    .spyOn(Date, 'now')
34
+    .mockImplementation(() => new Date('2020-01-14T23:00:00.000Z').getTime());
35
+  expectDate = new Date('2020-01-14T23:00:00.000Z');
36
+  expectDate.setHours(0);
37
+  expectDate.setMinutes(30);
38
+  expect(getMachineEndDate({endTime: '00:30'}).getTime()).toBe(
39
+    expectDate.getTime(),
40
+  );
30 41
 });
31 42
 
32 43
 test('isMachineWatched', () => {
33
-    let machineList = [
34
-        {
35
-            number: "0",
36
-            endTime: "23:30",
37
-        },
38
-        {
39
-            number: "1",
40
-            endTime: "20:30",
41
-        },
42
-    ];
43
-    expect(isMachineWatched({number: "0", endTime: "23:30"}, machineList)).toBeTrue();
44
-    expect(isMachineWatched({number: "1", endTime: "20:30"}, machineList)).toBeTrue();
45
-    expect(isMachineWatched({number: "3", endTime: "20:30"}, machineList)).toBeFalse();
46
-    expect(isMachineWatched({number: "1", endTime: "23:30"}, machineList)).toBeFalse();
44
+  let machineList = [
45
+    {
46
+      number: '0',
47
+      endTime: '23:30',
48
+    },
49
+    {
50
+      number: '1',
51
+      endTime: '20:30',
52
+    },
53
+  ];
54
+  expect(
55
+    isMachineWatched({number: '0', endTime: '23:30'}, machineList),
56
+  ).toBeTrue();
57
+  expect(
58
+    isMachineWatched({number: '1', endTime: '20:30'}, machineList),
59
+  ).toBeTrue();
60
+  expect(
61
+    isMachineWatched({number: '3', endTime: '20:30'}, machineList),
62
+  ).toBeFalse();
63
+  expect(
64
+    isMachineWatched({number: '1', endTime: '23:30'}, machineList),
65
+  ).toBeFalse();
47 66
 });
48 67
 
49 68
 test('getMachineOfId', () => {
50
-    let machineList = [
51
-        {
52
-            number: "0",
53
-        },
54
-        {
55
-            number: "1",
56
-        },
57
-    ];
58
-    expect(getMachineOfId("0", machineList)).toStrictEqual({number: "0"});
59
-    expect(getMachineOfId("1", machineList)).toStrictEqual({number: "1"});
60
-    expect(getMachineOfId("3", machineList)).toBeNull();
69
+  let machineList = [
70
+    {
71
+      number: '0',
72
+    },
73
+    {
74
+      number: '1',
75
+    },
76
+  ];
77
+  expect(getMachineOfId('0', machineList)).toStrictEqual({number: '0'});
78
+  expect(getMachineOfId('1', machineList)).toStrictEqual({number: '1'});
79
+  expect(getMachineOfId('3', machineList)).toBeNull();
61 80
 });
62 81
 
63 82
 test('getCleanedMachineWatched', () => {
64
-    let machineList = [
65
-        {
66
-            number: "0",
67
-            endTime: "23:30",
68
-        },
69
-        {
70
-            number: "1",
71
-            endTime: "20:30",
72
-        },
73
-        {
74
-            number: "2",
75
-            endTime: "",
76
-        },
77
-    ];
78
-    let watchList = [
79
-        {
80
-            number: "0",
81
-            endTime: "23:30",
82
-        },
83
-        {
84
-            number: "1",
85
-            endTime: "20:30",
86
-        },
87
-        {
88
-            number: "2",
89
-            endTime: "",
90
-        },
91
-    ];
92
-    let cleanedList = watchList;
93
-    expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(cleanedList);
83
+  let machineList = [
84
+    {
85
+      number: '0',
86
+      endTime: '23:30',
87
+    },
88
+    {
89
+      number: '1',
90
+      endTime: '20:30',
91
+    },
92
+    {
93
+      number: '2',
94
+      endTime: '',
95
+    },
96
+  ];
97
+  let watchList = [
98
+    {
99
+      number: '0',
100
+      endTime: '23:30',
101
+    },
102
+    {
103
+      number: '1',
104
+      endTime: '20:30',
105
+    },
106
+    {
107
+      number: '2',
108
+      endTime: '',
109
+    },
110
+  ];
111
+  let cleanedList = watchList;
112
+  expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(
113
+    cleanedList,
114
+  );
94 115
 
95
-    watchList = [
96
-        {
97
-            number: "0",
98
-            endTime: "23:30",
99
-        },
100
-        {
101
-            number: "1",
102
-            endTime: "20:30",
103
-        },
104
-        {
105
-            number: "2",
106
-            endTime: "15:30",
107
-        },
108
-    ];
109
-    cleanedList = [
110
-        {
111
-            number: "0",
112
-            endTime: "23:30",
113
-        },
114
-        {
115
-            number: "1",
116
-            endTime: "20:30",
117
-        },
118
-    ];
119
-    expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(cleanedList);
116
+  watchList = [
117
+    {
118
+      number: '0',
119
+      endTime: '23:30',
120
+    },
121
+    {
122
+      number: '1',
123
+      endTime: '20:30',
124
+    },
125
+    {
126
+      number: '2',
127
+      endTime: '15:30',
128
+    },
129
+  ];
130
+  cleanedList = [
131
+    {
132
+      number: '0',
133
+      endTime: '23:30',
134
+    },
135
+    {
136
+      number: '1',
137
+      endTime: '20:30',
138
+    },
139
+  ];
140
+  expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(
141
+    cleanedList,
142
+  );
120 143
 
121
-    watchList = [
122
-        {
123
-            number: "0",
124
-            endTime: "23:30",
125
-        },
126
-        {
127
-            number: "1",
128
-            endTime: "20:31",
129
-        },
130
-        {
131
-            number: "3",
132
-            endTime: "15:30",
133
-        },
134
-    ];
135
-    cleanedList = [
136
-        {
137
-            number: "0",
138
-            endTime: "23:30",
139
-        },
140
-    ];
141
-    expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(cleanedList);
142
-});
144
+  watchList = [
145
+    {
146
+      number: '0',
147
+      endTime: '23:30',
148
+    },
149
+    {
150
+      number: '1',
151
+      endTime: '20:31',
152
+    },
153
+    {
154
+      number: '3',
155
+      endTime: '15:30',
156
+    },
157
+  ];
158
+  cleanedList = [
159
+    {
160
+      number: '0',
161
+      endTime: '23:30',
162
+    },
163
+  ];
164
+  expect(getCleanedMachineWatched(watchList, machineList)).toStrictEqual(
165
+    cleanedList,
166
+  );
167
+});

+ 42
- 40
__tests__/utils/WebData.js View File

@@ -1,45 +1,47 @@
1
+/* eslint-disable */
2
+
1 3
 import React from 'react';
2
-import {isResponseValid} from "../../src/utils/WebData";
4
+import {isApiResponseValid} from '../../src/utils/WebData';
3 5
 
4
-let fetch = require('isomorphic-fetch'); // fetch is not implemented in nodeJS but in react-native
6
+const fetch = require('isomorphic-fetch'); // fetch is not implemented in nodeJS but in react-native
5 7
 
6 8
 test('isRequestResponseValid', () => {
7
-    let json = {
8
-        error: 0,
9
-        data: {}
10
-    };
11
-    expect(isResponseValid(json)).toBeTrue();
12
-    json = {
13
-        error: 1,
14
-        data: {}
15
-    };
16
-    expect(isResponseValid(json)).toBeTrue();
17
-    json = {
18
-        error: 50,
19
-        data: {}
20
-    };
21
-    expect(isResponseValid(json)).toBeTrue();
22
-    json = {
23
-        error: 50,
24
-        data: {truc: 'machin'}
25
-    };
26
-    expect(isResponseValid(json)).toBeTrue();
27
-    json = {
28
-        message: 'coucou'
29
-    };
30
-    expect(isResponseValid(json)).toBeFalse();
31
-    json = {
32
-        error: 'coucou',
33
-        data: {truc: 'machin'}
34
-    };
35
-    expect(isResponseValid(json)).toBeFalse();
36
-    json = {
37
-        error: 0,
38
-        data: 'coucou'
39
-    };
40
-    expect(isResponseValid(json)).toBeFalse();
41
-    json = {
42
-        error: 0,
43
-    };
44
-    expect(isResponseValid(json)).toBeFalse();
9
+  let json = {
10
+    error: 0,
11
+    data: {},
12
+  };
13
+  expect(isApiResponseValid(json)).toBeTrue();
14
+  json = {
15
+    error: 1,
16
+    data: {},
17
+  };
18
+  expect(isApiResponseValid(json)).toBeTrue();
19
+  json = {
20
+    error: 50,
21
+    data: {},
22
+  };
23
+  expect(isApiResponseValid(json)).toBeTrue();
24
+  json = {
25
+    error: 50,
26
+    data: {truc: 'machin'},
27
+  };
28
+  expect(isApiResponseValid(json)).toBeTrue();
29
+  json = {
30
+    message: 'coucou',
31
+  };
32
+  expect(isApiResponseValid(json)).toBeFalse();
33
+  json = {
34
+    error: 'coucou',
35
+    data: {truc: 'machin'},
36
+  };
37
+  expect(isApiResponseValid(json)).toBeFalse();
38
+  json = {
39
+    error: 0,
40
+    data: 'coucou',
41
+  };
42
+  expect(isApiResponseValid(json)).toBeFalse();
43
+  json = {
44
+    error: 0,
45
+  };
46
+  expect(isApiResponseValid(json)).toBeFalse();
45 47
 });

+ 78
- 75
src/screens/Game/__tests__/GridManager.test.js View File

@@ -1,103 +1,106 @@
1
+/* eslint-disable */
2
+
1 3
 import React from 'react';
2
-import GridManager from "../logic/GridManager";
3
-import ScoreManager from "../logic/ScoreManager";
4
-import Piece from "../logic/Piece";
4
+import GridManager from '../logic/GridManager';
5
+import ScoreManager from '../logic/ScoreManager';
6
+import Piece from '../logic/Piece';
5 7
 
6 8
 let colors = {
7
-    tetrisBackground: "#000002"
9
+  tetrisBackground: '#000002',
8 10
 };
9 11
 
10
-jest.mock("../ScoreManager");
12
+jest.mock('../ScoreManager');
11 13
 
12 14
 afterAll(() => {
13
-    jest.restoreAllMocks();
15
+  jest.restoreAllMocks();
14 16
 });
15 17
 
16
-
17 18
 test('getEmptyLine', () => {
18
-    let g = new GridManager(2, 2, colors);
19
-    expect(g.getEmptyLine(2)).toStrictEqual([
20
-        {color: colors.tetrisBackground, isEmpty: true},
21
-        {color: colors.tetrisBackground, isEmpty: true},
22
-    ]);
19
+  let g = new GridManager(2, 2, colors);
20
+  expect(g.getEmptyLine(2)).toStrictEqual([
21
+    {color: colors.tetrisBackground, isEmpty: true},
22
+    {color: colors.tetrisBackground, isEmpty: true},
23
+  ]);
23 24
 
24
-    expect(g.getEmptyLine(-1)).toStrictEqual([]);
25
+  expect(g.getEmptyLine(-1)).toStrictEqual([]);
25 26
 });
26 27
 
27 28
 test('getEmptyGrid', () => {
28
-    let g = new GridManager(2, 2, colors);
29
-    expect(g.getEmptyGrid(2, 2)).toStrictEqual([
30
-        [
31
-            {color: colors.tetrisBackground, isEmpty: true},
32
-            {color: colors.tetrisBackground, isEmpty: true},
33
-        ],
34
-        [
35
-            {color: colors.tetrisBackground, isEmpty: true},
36
-            {color: colors.tetrisBackground, isEmpty: true},
37
-        ],
38
-    ]);
29
+  let g = new GridManager(2, 2, colors);
30
+  expect(g.getEmptyGrid(2, 2)).toStrictEqual([
31
+    [
32
+      {color: colors.tetrisBackground, isEmpty: true},
33
+      {color: colors.tetrisBackground, isEmpty: true},
34
+    ],
35
+    [
36
+      {color: colors.tetrisBackground, isEmpty: true},
37
+      {color: colors.tetrisBackground, isEmpty: true},
38
+    ],
39
+  ]);
39 40
 
40
-    expect(g.getEmptyGrid(-1, 2)).toStrictEqual([]);
41
-    expect(g.getEmptyGrid(2, -1)).toStrictEqual([[], []]);
41
+  expect(g.getEmptyGrid(-1, 2)).toStrictEqual([]);
42
+  expect(g.getEmptyGrid(2, -1)).toStrictEqual([[], []]);
42 43
 });
43 44
 
44 45
 test('getLinesToClear', () => {
45
-    let g = new GridManager(2, 2, colors);
46
-    g.getCurrentGrid()[0][0].isEmpty = false;
47
-    g.getCurrentGrid()[0][1].isEmpty = false;
48
-    let coord = [{x: 1, y: 0}];
49
-    expect(g.getLinesToClear(coord)).toStrictEqual([0]);
46
+  let g = new GridManager(2, 2, colors);
47
+  g.getCurrentGrid()[0][0].isEmpty = false;
48
+  g.getCurrentGrid()[0][1].isEmpty = false;
49
+  let coord = [{x: 1, y: 0}];
50
+  expect(g.getLinesToClear(coord)).toStrictEqual([0]);
50 51
 
51
-    g.getCurrentGrid()[0][0].isEmpty = true;
52
-    g.getCurrentGrid()[0][1].isEmpty = true;
53
-    g.getCurrentGrid()[1][0].isEmpty = false;
54
-    g.getCurrentGrid()[1][1].isEmpty = false;
55
-    expect(g.getLinesToClear(coord)).toStrictEqual([]);
56
-    coord = [{x: 1, y: 1}];
57
-    expect(g.getLinesToClear(coord)).toStrictEqual([1]);
52
+  g.getCurrentGrid()[0][0].isEmpty = true;
53
+  g.getCurrentGrid()[0][1].isEmpty = true;
54
+  g.getCurrentGrid()[1][0].isEmpty = false;
55
+  g.getCurrentGrid()[1][1].isEmpty = false;
56
+  expect(g.getLinesToClear(coord)).toStrictEqual([]);
57
+  coord = [{x: 1, y: 1}];
58
+  expect(g.getLinesToClear(coord)).toStrictEqual([1]);
58 59
 });
59 60
 
60 61
 test('clearLines', () => {
61
-    let g = new GridManager(2, 2, colors);
62
-    let grid = [
63
-        [
64
-            {color: colors.tetrisBackground, isEmpty: true},
65
-            {color: colors.tetrisBackground, isEmpty: true},
66
-        ],
67
-        [
68
-            {color: '0', isEmpty: true},
69
-            {color: '0', isEmpty: true},
70
-        ],
71
-    ];
72
-    g.getCurrentGrid()[1][0].color = '0';
73
-    g.getCurrentGrid()[1][1].color = '0';
74
-    expect(g.getCurrentGrid()).toStrictEqual(grid);
75
-    let scoreManager = new ScoreManager();
76
-    g.clearLines([1], scoreManager);
77
-    grid = [
78
-        [
79
-            {color: colors.tetrisBackground, isEmpty: true},
80
-            {color: colors.tetrisBackground, isEmpty: true},
81
-        ],
82
-        [
83
-            {color: colors.tetrisBackground, isEmpty: true},
84
-            {color: colors.tetrisBackground, isEmpty: true},
85
-        ],
86
-    ];
87
-    expect(g.getCurrentGrid()).toStrictEqual(grid);
62
+  let g = new GridManager(2, 2, colors);
63
+  let grid = [
64
+    [
65
+      {color: colors.tetrisBackground, isEmpty: true},
66
+      {color: colors.tetrisBackground, isEmpty: true},
67
+    ],
68
+    [
69
+      {color: '0', isEmpty: true},
70
+      {color: '0', isEmpty: true},
71
+    ],
72
+  ];
73
+  g.getCurrentGrid()[1][0].color = '0';
74
+  g.getCurrentGrid()[1][1].color = '0';
75
+  expect(g.getCurrentGrid()).toStrictEqual(grid);
76
+  let scoreManager = new ScoreManager();
77
+  g.clearLines([1], scoreManager);
78
+  grid = [
79
+    [
80
+      {color: colors.tetrisBackground, isEmpty: true},
81
+      {color: colors.tetrisBackground, isEmpty: true},
82
+    ],
83
+    [
84
+      {color: colors.tetrisBackground, isEmpty: true},
85
+      {color: colors.tetrisBackground, isEmpty: true},
86
+    ],
87
+  ];
88
+  expect(g.getCurrentGrid()).toStrictEqual(grid);
88 89
 });
89 90
 
90 91
 test('freezeTetromino', () => {
91
-    let g = new GridManager(2, 2, colors);
92
-    let spy1 = jest.spyOn(GridManager.prototype, 'getLinesToClear')
93
-        .mockImplementation(() => {});
94
-    let spy2 = jest.spyOn(GridManager.prototype, 'clearLines')
95
-        .mockImplementation(() => {});
96
-    g.freezeTetromino(new Piece({}), null);
92
+  let g = new GridManager(2, 2, colors);
93
+  let spy1 = jest
94
+    .spyOn(GridManager.prototype, 'getLinesToClear')
95
+    .mockImplementation(() => {});
96
+  let spy2 = jest
97
+    .spyOn(GridManager.prototype, 'clearLines')
98
+    .mockImplementation(() => {});
99
+  g.freezeTetromino(new Piece({}), null);
97 100
 
98
-    expect(spy1).toHaveBeenCalled();
99
-    expect(spy2).toHaveBeenCalled();
101
+  expect(spy1).toHaveBeenCalled();
102
+  expect(spy2).toHaveBeenCalled();
100 103
 
101
-    spy1.mockRestore();
102
-    spy2.mockRestore();
104
+  spy1.mockRestore();
105
+  spy2.mockRestore();
103 106
 });

+ 160
- 129
src/screens/Game/__tests__/Piece.test.js View File

@@ -1,155 +1,186 @@
1
+/* eslint-disable */
2
+
1 3
 import React from 'react';
2
-import Piece from "../logic/Piece";
3
-import ShapeI from "../Shapes/ShapeI";
4
+import Piece from '../logic/Piece';
5
+import ShapeI from '../Shapes/ShapeI';
4 6
 
5 7
 let colors = {
6
-    tetrisI: "#000001",
7
-    tetrisBackground: "#000002"
8
+  tetrisI: '#000001',
9
+  tetrisBackground: '#000002',
8 10
 };
9 11
 
10
-jest.mock("../Shapes/ShapeI");
12
+jest.mock('../Shapes/ShapeI');
11 13
 
12 14
 beforeAll(() => {
13
-    jest.spyOn(Piece.prototype, 'getRandomShape')
14
-        .mockImplementation((colors: Object) => {return new ShapeI(colors);});
15
+  jest
16
+    .spyOn(Piece.prototype, 'getRandomShape')
17
+    .mockImplementation((colors: Object) => {
18
+      return new ShapeI(colors);
19
+    });
15 20
 });
16 21
 
17 22
 afterAll(() => {
18
-    jest.restoreAllMocks();
23
+  jest.restoreAllMocks();
19 24
 });
20 25
 
21 26
 test('isPositionValid', () => {
22
-    let x = 0;
23
-    let y = 0;
24
-    let spy = jest.spyOn(ShapeI.prototype, 'getCellsCoordinates')
25
-        .mockImplementation(() => {return [{x: x, y: y}];});
26
-    let grid = [
27
-        [{isEmpty: true}, {isEmpty: true}],
28
-        [{isEmpty: true}, {isEmpty: false}],
29
-    ];
30
-    let size = 2;
31
-
32
-    let p = new Piece(colors);
33
-    expect(p.isPositionValid(grid, size, size)).toBeTrue();
34
-    x = 1; y = 0;
35
-    expect(p.isPositionValid(grid, size, size)).toBeTrue();
36
-    x = 0; y = 1;
37
-    expect(p.isPositionValid(grid, size, size)).toBeTrue();
38
-    x = 1; y = 1;
39
-    expect(p.isPositionValid(grid, size, size)).toBeFalse();
40
-    x = 2; y = 0;
41
-    expect(p.isPositionValid(grid, size, size)).toBeFalse();
42
-    x = -1; y = 0;
43
-    expect(p.isPositionValid(grid, size, size)).toBeFalse();
44
-    x = 0; y = 2;
45
-    expect(p.isPositionValid(grid, size, size)).toBeFalse();
46
-    x = 0; y = -1;
47
-    expect(p.isPositionValid(grid, size, size)).toBeFalse();
48
-
49
-    spy.mockRestore();
27
+  let x = 0;
28
+  let y = 0;
29
+  let spy = jest
30
+    .spyOn(ShapeI.prototype, 'getCellsCoordinates')
31
+    .mockImplementation(() => {
32
+      return [{x: x, y: y}];
33
+    });
34
+  let grid = [
35
+    [{isEmpty: true}, {isEmpty: true}],
36
+    [{isEmpty: true}, {isEmpty: false}],
37
+  ];
38
+  let size = 2;
39
+
40
+  let p = new Piece(colors);
41
+  expect(p.isPositionValid(grid, size, size)).toBeTrue();
42
+  x = 1;
43
+  y = 0;
44
+  expect(p.isPositionValid(grid, size, size)).toBeTrue();
45
+  x = 0;
46
+  y = 1;
47
+  expect(p.isPositionValid(grid, size, size)).toBeTrue();
48
+  x = 1;
49
+  y = 1;
50
+  expect(p.isPositionValid(grid, size, size)).toBeFalse();
51
+  x = 2;
52
+  y = 0;
53
+  expect(p.isPositionValid(grid, size, size)).toBeFalse();
54
+  x = -1;
55
+  y = 0;
56
+  expect(p.isPositionValid(grid, size, size)).toBeFalse();
57
+  x = 0;
58
+  y = 2;
59
+  expect(p.isPositionValid(grid, size, size)).toBeFalse();
60
+  x = 0;
61
+  y = -1;
62
+  expect(p.isPositionValid(grid, size, size)).toBeFalse();
63
+
64
+  spy.mockRestore();
50 65
 });
51 66
 
52 67
 test('tryMove', () => {
53
-    let p = new Piece(colors);
54
-    const callbackMock = jest.fn();
55
-    let isValid = true;
56
-    let spy1 = jest.spyOn(Piece.prototype, 'isPositionValid')
57
-        .mockImplementation(() => {return isValid;});
58
-    let spy2 = jest.spyOn(Piece.prototype, 'removeFromGrid')
59
-        .mockImplementation(() => {});
60
-    let spy3 = jest.spyOn(Piece.prototype, 'toGrid')
61
-        .mockImplementation(() => {});
62
-
63
-    expect(p.tryMove(-1, 0, null, null, null, callbackMock)).toBeTrue();
64
-    isValid = false;
65
-    expect(p.tryMove(-1, 0, null, null, null, callbackMock)).toBeFalse();
66
-    isValid = true;
67
-    expect(p.tryMove(0, 1, null, null, null, callbackMock)).toBeTrue();
68
-    expect(callbackMock).toBeCalledTimes(0);
69
-
70
-    isValid = false;
71
-    expect(p.tryMove(0, 1, null, null, null, callbackMock)).toBeFalse();
72
-    expect(callbackMock).toBeCalledTimes(1);
73
-
74
-    expect(spy2).toBeCalledTimes(4);
75
-    expect(spy3).toBeCalledTimes(4);
76
-
77
-    spy1.mockRestore();
78
-    spy2.mockRestore();
79
-    spy3.mockRestore();
68
+  let p = new Piece(colors);
69
+  const callbackMock = jest.fn();
70
+  let isValid = true;
71
+  let spy1 = jest
72
+    .spyOn(Piece.prototype, 'isPositionValid')
73
+    .mockImplementation(() => {
74
+      return isValid;
75
+    });
76
+  let spy2 = jest
77
+    .spyOn(Piece.prototype, 'removeFromGrid')
78
+    .mockImplementation(() => {});
79
+  let spy3 = jest.spyOn(Piece.prototype, 'toGrid').mockImplementation(() => {});
80
+
81
+  expect(p.tryMove(-1, 0, null, null, null, callbackMock)).toBeTrue();
82
+  isValid = false;
83
+  expect(p.tryMove(-1, 0, null, null, null, callbackMock)).toBeFalse();
84
+  isValid = true;
85
+  expect(p.tryMove(0, 1, null, null, null, callbackMock)).toBeTrue();
86
+  expect(callbackMock).toBeCalledTimes(0);
87
+
88
+  isValid = false;
89
+  expect(p.tryMove(0, 1, null, null, null, callbackMock)).toBeFalse();
90
+  expect(callbackMock).toBeCalledTimes(1);
91
+
92
+  expect(spy2).toBeCalledTimes(4);
93
+  expect(spy3).toBeCalledTimes(4);
94
+
95
+  spy1.mockRestore();
96
+  spy2.mockRestore();
97
+  spy3.mockRestore();
80 98
 });
81 99
 
82 100
 test('tryRotate', () => {
83
-    let p = new Piece(colors);
84
-    let isValid = true;
85
-    let spy1 = jest.spyOn(Piece.prototype, 'isPositionValid')
86
-        .mockImplementation(() => {return isValid;});
87
-    let spy2 = jest.spyOn(Piece.prototype, 'removeFromGrid')
88
-        .mockImplementation(() => {});
89
-    let spy3 = jest.spyOn(Piece.prototype, 'toGrid')
90
-        .mockImplementation(() => {});
91
-
92
-    expect(p.tryRotate( null, null, null)).toBeTrue();
93
-    isValid = false;
94
-    expect(p.tryRotate( null, null, null)).toBeFalse();
95
-
96
-    expect(spy2).toBeCalledTimes(2);
97
-    expect(spy3).toBeCalledTimes(2);
98
-
99
-    spy1.mockRestore();
100
-    spy2.mockRestore();
101
-    spy3.mockRestore();
101
+  let p = new Piece(colors);
102
+  let isValid = true;
103
+  let spy1 = jest
104
+    .spyOn(Piece.prototype, 'isPositionValid')
105
+    .mockImplementation(() => {
106
+      return isValid;
107
+    });
108
+  let spy2 = jest
109
+    .spyOn(Piece.prototype, 'removeFromGrid')
110
+    .mockImplementation(() => {});
111
+  let spy3 = jest.spyOn(Piece.prototype, 'toGrid').mockImplementation(() => {});
112
+
113
+  expect(p.tryRotate(null, null, null)).toBeTrue();
114
+  isValid = false;
115
+  expect(p.tryRotate(null, null, null)).toBeFalse();
116
+
117
+  expect(spy2).toBeCalledTimes(2);
118
+  expect(spy3).toBeCalledTimes(2);
119
+
120
+  spy1.mockRestore();
121
+  spy2.mockRestore();
122
+  spy3.mockRestore();
102 123
 });
103 124
 
104
-
105 125
 test('toGrid', () => {
106
-    let x = 0;
107
-    let y = 0;
108
-    let spy1 = jest.spyOn(ShapeI.prototype, 'getCellsCoordinates')
109
-        .mockImplementation(() => {return [{x: x, y: y}];});
110
-    let spy2 = jest.spyOn(ShapeI.prototype, 'getColor')
111
-        .mockImplementation(() => {return colors.tetrisI;});
112
-    let grid = [
113
-        [{isEmpty: true}, {isEmpty: true}],
114
-        [{isEmpty: true}, {isEmpty: true}],
115
-    ];
116
-    let expectedGrid = [
117
-        [{color: colors.tetrisI, isEmpty: false}, {isEmpty: true}],
118
-        [{isEmpty: true}, {isEmpty: true}],
119
-    ];
120
-
121
-    let p = new Piece(colors);
122
-    p.toGrid(grid, true);
123
-    expect(grid).toStrictEqual(expectedGrid);
124
-
125
-    spy1.mockRestore();
126
-    spy2.mockRestore();
126
+  let x = 0;
127
+  let y = 0;
128
+  let spy1 = jest
129
+    .spyOn(ShapeI.prototype, 'getCellsCoordinates')
130
+    .mockImplementation(() => {
131
+      return [{x: x, y: y}];
132
+    });
133
+  let spy2 = jest.spyOn(ShapeI.prototype, 'getColor').mockImplementation(() => {
134
+    return colors.tetrisI;
135
+  });
136
+  let grid = [
137
+    [{isEmpty: true}, {isEmpty: true}],
138
+    [{isEmpty: true}, {isEmpty: true}],
139
+  ];
140
+  let expectedGrid = [
141
+    [{color: colors.tetrisI, isEmpty: false}, {isEmpty: true}],
142
+    [{isEmpty: true}, {isEmpty: true}],
143
+  ];
144
+
145
+  let p = new Piece(colors);
146
+  p.toGrid(grid, true);
147
+  expect(grid).toStrictEqual(expectedGrid);
148
+
149
+  spy1.mockRestore();
150
+  spy2.mockRestore();
127 151
 });
128 152
 
129 153
 test('removeFromGrid', () => {
130
-    let gridOld = [
131
-        [
132
-            {color: colors.tetrisI, isEmpty: false},
133
-            {color: colors.tetrisI, isEmpty: false},
134
-            {color: colors.tetrisBackground, isEmpty: true},
135
-        ],
136
-    ];
137
-    let gridNew = [
138
-        [
139
-            {color: colors.tetrisBackground, isEmpty: true},
140
-            {color: colors.tetrisBackground, isEmpty: true},
141
-            {color: colors.tetrisBackground, isEmpty: true},
142
-        ],
143
-    ];
144
-    let oldCoord = [{x: 0, y: 0}, {x: 1, y: 0}];
145
-    let spy1 = jest.spyOn(ShapeI.prototype, 'getCellsCoordinates')
146
-        .mockImplementation(() => {return oldCoord;});
147
-    let spy2 = jest.spyOn(ShapeI.prototype, 'getColor')
148
-        .mockImplementation(() => {return colors.tetrisI;});
149
-    let p = new Piece(colors);
150
-    p.removeFromGrid(gridOld);
151
-    expect(gridOld).toStrictEqual(gridNew);
152
-
153
-    spy1.mockRestore();
154
-    spy2.mockRestore();
154
+  let gridOld = [
155
+    [
156
+      {color: colors.tetrisI, isEmpty: false},
157
+      {color: colors.tetrisI, isEmpty: false},
158
+      {color: colors.tetrisBackground, isEmpty: true},
159
+    ],
160
+  ];
161
+  let gridNew = [
162
+    [
163
+      {color: colors.tetrisBackground, isEmpty: true},
164
+      {color: colors.tetrisBackground, isEmpty: true},
165
+      {color: colors.tetrisBackground, isEmpty: true},
166
+    ],
167
+  ];
168
+  let oldCoord = [
169
+    {x: 0, y: 0},
170
+    {x: 1, y: 0},
171
+  ];
172
+  let spy1 = jest
173
+    .spyOn(ShapeI.prototype, 'getCellsCoordinates')
174
+    .mockImplementation(() => {
175
+      return oldCoord;
176
+    });
177
+  let spy2 = jest.spyOn(ShapeI.prototype, 'getColor').mockImplementation(() => {
178
+    return colors.tetrisI;
179
+  });
180
+  let p = new Piece(colors);
181
+  p.removeFromGrid(gridOld);
182
+  expect(gridOld).toStrictEqual(gridNew);
183
+
184
+  spy1.mockRestore();
185
+  spy2.mockRestore();
155 186
 });

+ 52
- 51
src/screens/Game/__tests__/ScoreManager.test.js View File

@@ -1,71 +1,72 @@
1
-import React from 'react';
2
-import ScoreManager from "../logic/ScoreManager";
1
+/* eslint-disable */
3 2
 
3
+import React from 'react';
4
+import ScoreManager from '../logic/ScoreManager';
4 5
 
5 6
 test('incrementScore', () => {
6
-    let scoreManager = new ScoreManager();
7
-    expect(scoreManager.getScore()).toBe(0);
8
-    scoreManager.incrementScore();
9
-    expect(scoreManager.getScore()).toBe(1);
7
+  let scoreManager = new ScoreManager();
8
+  expect(scoreManager.getScore()).toBe(0);
9
+  scoreManager.incrementScore();
10
+  expect(scoreManager.getScore()).toBe(1);
10 11
 });
11 12
 
12 13
 test('addLinesRemovedPoints', () => {
13
-    let scoreManager = new ScoreManager();
14
-    scoreManager.addLinesRemovedPoints(0);
15
-    scoreManager.addLinesRemovedPoints(5);
16
-    expect(scoreManager.getScore()).toBe(0);
17
-    expect(scoreManager.getLevelProgression()).toBe(0);
14
+  let scoreManager = new ScoreManager();
15
+  scoreManager.addLinesRemovedPoints(0);
16
+  scoreManager.addLinesRemovedPoints(5);
17
+  expect(scoreManager.getScore()).toBe(0);
18
+  expect(scoreManager.getLevelProgression()).toBe(0);
18 19
 
19
-    scoreManager.addLinesRemovedPoints(1);
20
-    expect(scoreManager.getScore()).toBe(40);
21
-    expect(scoreManager.getLevelProgression()).toBe(1);
20
+  scoreManager.addLinesRemovedPoints(1);
21
+  expect(scoreManager.getScore()).toBe(40);
22
+  expect(scoreManager.getLevelProgression()).toBe(1);
22 23
 
23
-    scoreManager.addLinesRemovedPoints(2);
24
-    expect(scoreManager.getScore()).toBe(140);
25
-    expect(scoreManager.getLevelProgression()).toBe(4);
24
+  scoreManager.addLinesRemovedPoints(2);
25
+  expect(scoreManager.getScore()).toBe(140);
26
+  expect(scoreManager.getLevelProgression()).toBe(4);
26 27
 
27
-    scoreManager.addLinesRemovedPoints(3);
28
-    expect(scoreManager.getScore()).toBe(440);
29
-    expect(scoreManager.getLevelProgression()).toBe(9);
28
+  scoreManager.addLinesRemovedPoints(3);
29
+  expect(scoreManager.getScore()).toBe(440);
30
+  expect(scoreManager.getLevelProgression()).toBe(9);
30 31
 
31
-    scoreManager.addLinesRemovedPoints(4);
32
-    expect(scoreManager.getScore()).toBe(1640);
33
-    expect(scoreManager.getLevelProgression()).toBe(17);
32
+  scoreManager.addLinesRemovedPoints(4);
33
+  expect(scoreManager.getScore()).toBe(1640);
34
+  expect(scoreManager.getLevelProgression()).toBe(17);
34 35
 });
35 36
 
36 37
 test('canLevelUp', () => {
37
-    let scoreManager = new ScoreManager();
38
-    expect(scoreManager.canLevelUp()).toBeFalse();
39
-    expect(scoreManager.getLevel()).toBe(0);
40
-    expect(scoreManager.getLevelProgression()).toBe(0);
38
+  let scoreManager = new ScoreManager();
39
+  expect(scoreManager.canLevelUp()).toBeFalse();
40
+  expect(scoreManager.getLevel()).toBe(0);
41
+  expect(scoreManager.getLevelProgression()).toBe(0);
41 42
 
42
-    scoreManager.addLinesRemovedPoints(1);
43
-    expect(scoreManager.canLevelUp()).toBeTrue();
44
-    expect(scoreManager.getLevel()).toBe(1);
45
-    expect(scoreManager.getLevelProgression()).toBe(1);
43
+  scoreManager.addLinesRemovedPoints(1);
44
+  expect(scoreManager.canLevelUp()).toBeTrue();
45
+  expect(scoreManager.getLevel()).toBe(1);
46
+  expect(scoreManager.getLevelProgression()).toBe(1);
46 47
 
47
-    scoreManager.addLinesRemovedPoints(1);
48
-    expect(scoreManager.canLevelUp()).toBeFalse();
49
-    expect(scoreManager.getLevel()).toBe(1);
50
-    expect(scoreManager.getLevelProgression()).toBe(2);
48
+  scoreManager.addLinesRemovedPoints(1);
49
+  expect(scoreManager.canLevelUp()).toBeFalse();
50
+  expect(scoreManager.getLevel()).toBe(1);
51
+  expect(scoreManager.getLevelProgression()).toBe(2);
51 52
 
52
-    scoreManager.addLinesRemovedPoints(2);
53
-    expect(scoreManager.canLevelUp()).toBeFalse();
54
-    expect(scoreManager.getLevel()).toBe(1);
55
-    expect(scoreManager.getLevelProgression()).toBe(5);
53
+  scoreManager.addLinesRemovedPoints(2);
54
+  expect(scoreManager.canLevelUp()).toBeFalse();
55
+  expect(scoreManager.getLevel()).toBe(1);
56
+  expect(scoreManager.getLevelProgression()).toBe(5);
56 57
 
57
-    scoreManager.addLinesRemovedPoints(1);
58
-    expect(scoreManager.canLevelUp()).toBeTrue();
59
-    expect(scoreManager.getLevel()).toBe(2);
60
-    expect(scoreManager.getLevelProgression()).toBe(1);
58
+  scoreManager.addLinesRemovedPoints(1);
59
+  expect(scoreManager.canLevelUp()).toBeTrue();
60
+  expect(scoreManager.getLevel()).toBe(2);
61
+  expect(scoreManager.getLevelProgression()).toBe(1);
61 62
 
62
-    scoreManager.addLinesRemovedPoints(4);
63
-    expect(scoreManager.canLevelUp()).toBeFalse();
64
-    expect(scoreManager.getLevel()).toBe(2);
65
-    expect(scoreManager.getLevelProgression()).toBe(9);
63
+  scoreManager.addLinesRemovedPoints(4);
64
+  expect(scoreManager.canLevelUp()).toBeFalse();
65
+  expect(scoreManager.getLevel()).toBe(2);
66
+  expect(scoreManager.getLevelProgression()).toBe(9);
66 67
 
67
-    scoreManager.addLinesRemovedPoints(2);
68
-    expect(scoreManager.canLevelUp()).toBeTrue();
69
-    expect(scoreManager.getLevel()).toBe(3);
70
-    expect(scoreManager.getLevelProgression()).toBe(2);
68
+  scoreManager.addLinesRemovedPoints(2);
69
+  expect(scoreManager.canLevelUp()).toBeTrue();
70
+  expect(scoreManager.getLevel()).toBe(3);
71
+  expect(scoreManager.getLevelProgression()).toBe(2);
71 72
 });

+ 90
- 88
src/screens/Game/__tests__/Shape.test.js View File

@@ -1,104 +1,106 @@
1
+/* eslint-disable */
2
+
1 3
 import React from 'react';
2
-import BaseShape from "../Shapes/BaseShape";
3
-import ShapeI from "../Shapes/ShapeI";
4
+import BaseShape from '../Shapes/BaseShape';
5
+import ShapeI from '../Shapes/ShapeI';
4 6
 
5 7
 const colors = {
6
-    tetrisI: '#000001',
7
-    tetrisO: '#000002',
8
-    tetrisT: '#000003',
9
-    tetrisS: '#000004',
10
-    tetrisZ: '#000005',
11
-    tetrisJ: '#000006',
12
-    tetrisL: '#000007',
8
+  tetrisI: '#000001',
9
+  tetrisO: '#000002',
10
+  tetrisT: '#000003',
11
+  tetrisS: '#000004',
12
+  tetrisZ: '#000005',
13
+  tetrisJ: '#000006',
14
+  tetrisL: '#000007',
13 15
 };
14 16
 
15 17
 test('constructor', () => {
16
-    expect(() => new BaseShape()).toThrow(Error);
18
+  expect(() => new BaseShape()).toThrow(Error);
17 19
 
18
-    let T = new ShapeI(colors);
19
-    expect(T.position.y).toBe(0);
20
-    expect(T.position.x).toBe(3);
21
-    expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[0]);
22
-    expect(T.getColor()).toBe(colors.tetrisI);
20
+  let T = new ShapeI(colors);
21
+  expect(T.position.y).toBe(0);
22
+  expect(T.position.x).toBe(3);
23
+  expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[0]);
24
+  expect(T.getColor()).toBe(colors.tetrisI);
23 25
 });
24 26
 
25
-test("move", () => {
26
-    let T = new ShapeI(colors);
27
-    T.move(0, 1);
28
-    expect(T.position.x).toBe(3);
29
-    expect(T.position.y).toBe(1);
30
-    T.move(1, 0);
31
-    expect(T.position.x).toBe(4);
32
-    expect(T.position.y).toBe(1);
33
-    T.move(1, 1);
34
-    expect(T.position.x).toBe(5);
35
-    expect(T.position.y).toBe(2);
36
-    T.move(2, 2);
37
-    expect(T.position.x).toBe(7);
38
-    expect(T.position.y).toBe(4);
39
-    T.move(-1, -1);
40
-    expect(T.position.x).toBe(6);
41
-    expect(T.position.y).toBe(3);
27
+test('move', () => {
28
+  let T = new ShapeI(colors);
29
+  T.move(0, 1);
30
+  expect(T.position.x).toBe(3);
31
+  expect(T.position.y).toBe(1);
32
+  T.move(1, 0);
33
+  expect(T.position.x).toBe(4);
34
+  expect(T.position.y).toBe(1);
35
+  T.move(1, 1);
36
+  expect(T.position.x).toBe(5);
37
+  expect(T.position.y).toBe(2);
38
+  T.move(2, 2);
39
+  expect(T.position.x).toBe(7);
40
+  expect(T.position.y).toBe(4);
41
+  T.move(-1, -1);
42
+  expect(T.position.x).toBe(6);
43
+  expect(T.position.y).toBe(3);
42 44
 });
43 45
 
44 46
 test('rotate', () => {
45
-    let T = new ShapeI(colors);
46
-    T.rotate(true);
47
-    expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[1]);
48
-    T.rotate(true);
49
-    expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[2]);
50
-    T.rotate(true);
51
-    expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[3]);
52
-    T.rotate(true);
53
-    expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[0]);
54
-    T.rotate(false);
55
-    expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[3]);
56
-    T.rotate(false);
57
-    expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[2]);
58
-    T.rotate(false);
59
-    expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[1]);
60
-    T.rotate(false);
61
-    expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[0]);
47
+  let T = new ShapeI(colors);
48
+  T.rotate(true);
49
+  expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[1]);
50
+  T.rotate(true);
51
+  expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[2]);
52
+  T.rotate(true);
53
+  expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[3]);
54
+  T.rotate(true);
55
+  expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[0]);
56
+  T.rotate(false);
57
+  expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[3]);
58
+  T.rotate(false);
59
+  expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[2]);
60
+  T.rotate(false);
61
+  expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[1]);
62
+  T.rotate(false);
63
+  expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[0]);
62 64
 });
63 65