Browse Source

Update tests to match new implementations

Arnaud Vergnet 1 year ago
parent
commit
1be913c5aa

+ 5
- 5
__tests__/managers/ConnectionManager.test.js View File

@@ -64,7 +64,7 @@ test('connect good credentials', () => {
64 64
     .mockImplementationOnce(() => {
65 65
       return Promise.resolve(true);
66 66
     });
67
-  return expect(c.connect('email', 'password')).resolves.toBeTruthy();
67
+  return expect(c.connect('email', 'password')).resolves.toBe(undefined);
68 68
 });
69 69
 
70 70
 test('connect good credentials no consent', () => {
@@ -100,7 +100,7 @@ test('connect good credentials, fail save token', () => {
100 100
       return Promise.reject(false);
101 101
     });
102 102
   return expect(c.connect('email', 'password')).rejects.toBe(
103
-    ERROR_TYPE.UNKNOWN,
103
+    ERROR_TYPE.TOKEN_SAVE,
104 104
   );
105 105
 });
106 106
 
@@ -125,7 +125,7 @@ test('connect bogus response 1', () => {
125 125
     });
126 126
   });
127 127
   return expect(c.connect('email', 'password')).rejects.toBe(
128
-    ERROR_TYPE.CONNECTION_ERROR,
128
+    ERROR_TYPE.SERVER_ERROR,
129 129
   );
130 130
 });
131 131
 
@@ -188,7 +188,7 @@ test('authenticatedRequest error bogus response', () => {
188 188
   });
189 189
   return expect(
190 190
     c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
191
-  ).rejects.toBe(ERROR_TYPE.CONNECTION_ERROR);
191
+  ).rejects.toBe(ERROR_TYPE.SERVER_ERROR);
192 192
 });
193 193
 
194 194
 test('authenticatedRequest connection error', () => {
@@ -213,5 +213,5 @@ test('authenticatedRequest error no token', () => {
213 213
     });
214 214
   return expect(
215 215
     c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
216
-  ).rejects.toBe(ERROR_TYPE.UNKNOWN);
216
+  ).rejects.toBe(ERROR_TYPE.TOKEN_RETRIEVE);
217 217
 });

+ 24
- 22
src/screens/Game/__tests__/GridManager.test.js View File

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

+ 34
- 20
src/screens/Game/__tests__/Piece.test.js View File

@@ -4,9 +4,11 @@ import React from 'react';
4 4
 import Piece from '../logic/Piece';
5 5
 import ShapeI from '../Shapes/ShapeI';
6 6
 
7
-let colors = {
8
-  tetrisI: '#000001',
9
-  tetrisBackground: '#000002',
7
+let theme = {
8
+  colors: {
9
+    tetrisI: '#000001',
10
+    tetrisBackground: '#000002',
11
+  },
10 12
 };
11 13
 
12 14
 jest.mock('../Shapes/ShapeI');
@@ -37,7 +39,7 @@ test('isPositionValid', () => {
37 39
   ];
38 40
   let size = 2;
39 41
 
40
-  let p = new Piece(colors);
42
+  let p = new Piece(theme);
41 43
   expect(p.isPositionValid(grid, size, size)).toBeTrue();
42 44
   x = 1;
43 45
   y = 0;
@@ -65,7 +67,7 @@ test('isPositionValid', () => {
65 67
 });
66 68
 
67 69
 test('tryMove', () => {
68
-  let p = new Piece(colors);
70
+  let p = new Piece(theme);
69 71
   const callbackMock = jest.fn();
70 72
   let isValid = true;
71 73
   let spy1 = jest
@@ -98,7 +100,7 @@ test('tryMove', () => {
98 100
 });
99 101
 
100 102
 test('tryRotate', () => {
101
-  let p = new Piece(colors);
103
+  let p = new Piece(theme);
102 104
   let isValid = true;
103 105
   let spy1 = jest
104 106
     .spyOn(Piece.prototype, 'isPositionValid')
@@ -131,18 +133,30 @@ test('toGrid', () => {
131 133
       return [{x: x, y: y}];
132 134
     });
133 135
   let spy2 = jest.spyOn(ShapeI.prototype, 'getColor').mockImplementation(() => {
134
-    return colors.tetrisI;
136
+    return theme.colors.tetrisI;
135 137
   });
136 138
   let grid = [
137
-    [{isEmpty: true}, {isEmpty: true}],
138
-    [{isEmpty: true}, {isEmpty: true}],
139
+    [
140
+      {isEmpty: true, key: '0'},
141
+      {isEmpty: true, key: '1'},
142
+    ],
143
+    [
144
+      {isEmpty: true, key: '0'},
145
+      {isEmpty: true, key: '1'},
146
+    ],
139 147
   ];
140 148
   let expectedGrid = [
141
-    [{color: colors.tetrisI, isEmpty: false}, {isEmpty: true}],
142
-    [{isEmpty: true}, {isEmpty: true}],
149
+    [
150
+      {color: theme.colors.tetrisI, isEmpty: false, key: '0'},
151
+      {isEmpty: true, key: '1'},
152
+    ],
153
+    [
154
+      {isEmpty: true, key: '0'},
155
+      {isEmpty: true, key: '1'},
156
+    ],
143 157
   ];
144 158
 
145
-  let p = new Piece(colors);
159
+  let p = new Piece(theme);
146 160
   p.toGrid(grid, true);
147 161
   expect(grid).toStrictEqual(expectedGrid);
148 162
 
@@ -153,16 +167,16 @@ test('toGrid', () => {
153 167
 test('removeFromGrid', () => {
154 168
   let gridOld = [
155 169
     [
156
-      {color: colors.tetrisI, isEmpty: false},
157
-      {color: colors.tetrisI, isEmpty: false},
158
-      {color: colors.tetrisBackground, isEmpty: true},
170
+      {color: theme.colors.tetrisI, isEmpty: false, key: '0'},
171
+      {color: theme.colors.tetrisI, isEmpty: false, key: '1'},
172
+      {color: theme.colors.tetrisBackground, isEmpty: true, key: '2'},
159 173
     ],
160 174
   ];
161 175
   let gridNew = [
162 176
     [
163
-      {color: colors.tetrisBackground, isEmpty: true},
164
-      {color: colors.tetrisBackground, isEmpty: true},
165
-      {color: colors.tetrisBackground, isEmpty: true},
177
+      {color: theme.colors.tetrisBackground, isEmpty: true, key: '0'},
178
+      {color: theme.colors.tetrisBackground, isEmpty: true, key: '1'},
179
+      {color: theme.colors.tetrisBackground, isEmpty: true, key: '2'},
166 180
     ],
167 181
   ];
168 182
   let oldCoord = [
@@ -175,9 +189,9 @@ test('removeFromGrid', () => {
175 189
       return oldCoord;
176 190
     });
177 191
   let spy2 = jest.spyOn(ShapeI.prototype, 'getColor').mockImplementation(() => {
178
-    return colors.tetrisI;
192
+    return theme.colors.tetrisI;
179 193
   });
180
-  let p = new Piece(colors);
194
+  let p = new Piece(theme);
181 195
   p.removeFromGrid(gridOld);
182 196
   expect(gridOld).toStrictEqual(gridNew);
183 197
 

+ 15
- 13
src/screens/Game/__tests__/Shape.test.js View File

@@ -4,28 +4,30 @@ import React from 'react';
4 4
 import BaseShape from '../Shapes/BaseShape';
5 5
 import ShapeI from '../Shapes/ShapeI';
6 6
 
7
-const colors = {
8
-  tetrisI: '#000001',
9
-  tetrisO: '#000002',
10
-  tetrisT: '#000003',
11
-  tetrisS: '#000004',
12
-  tetrisZ: '#000005',
13
-  tetrisJ: '#000006',
14
-  tetrisL: '#000007',
7
+const theme = {
8
+  colors: {
9
+    tetrisI: '#000001',
10
+    tetrisO: '#000002',
11
+    tetrisT: '#000003',
12
+    tetrisS: '#000004',
13
+    tetrisZ: '#000005',
14
+    tetrisJ: '#000006',
15
+    tetrisL: '#000007',
16
+  },
15 17
 };
16 18
 
17 19
 test('constructor', () => {
18 20
   expect(() => new BaseShape()).toThrow(Error);
19 21
 
20
-  let T = new ShapeI(colors);
22
+  let T = new ShapeI(theme);
21 23
   expect(T.position.y).toBe(0);
22 24
   expect(T.position.x).toBe(3);
23 25
   expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[0]);
24
-  expect(T.getColor()).toBe(colors.tetrisI);
26
+  expect(T.getColor()).toBe(theme.colors.tetrisI);
25 27
 });
26 28
 
27 29
 test('move', () => {
28
-  let T = new ShapeI(colors);
30
+  let T = new ShapeI(theme);
29 31
   T.move(0, 1);
30 32
   expect(T.position.x).toBe(3);
31 33
   expect(T.position.y).toBe(1);
@@ -44,7 +46,7 @@ test('move', () => {
44 46
 });
45 47
 
46 48
 test('rotate', () => {
47
-  let T = new ShapeI(colors);
49
+  let T = new ShapeI(theme);
48 50
   T.rotate(true);
49 51
   expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[1]);
50 52
   T.rotate(true);
@@ -64,7 +66,7 @@ test('rotate', () => {
64 66
 });
65 67
 
66 68
 test('getCellsCoordinates', () => {
67
-  let T = new ShapeI(colors);
69
+  let T = new ShapeI(theme);
68 70
   expect(T.getCellsCoordinates(false)).toStrictEqual([
69 71
     {x: 0, y: 1},
70 72
     {x: 1, y: 1},

Loading…
Cancel
Save