Browse Source

Update tests to match new implementations

Arnaud Vergnet 3 years ago
parent
commit
1be913c5aa

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

64
     .mockImplementationOnce(() => {
64
     .mockImplementationOnce(() => {
65
       return Promise.resolve(true);
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
 test('connect good credentials no consent', () => {
70
 test('connect good credentials no consent', () => {
100
       return Promise.reject(false);
100
       return Promise.reject(false);
101
     });
101
     });
102
   return expect(c.connect('email', 'password')).rejects.toBe(
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
     });
125
     });
126
   });
126
   });
127
   return expect(c.connect('email', 'password')).rejects.toBe(
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
   });
188
   });
189
   return expect(
189
   return expect(
190
     c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
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
 test('authenticatedRequest connection error', () => {
194
 test('authenticatedRequest connection error', () => {
213
     });
213
     });
214
   return expect(
214
   return expect(
215
     c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'),
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
 import ScoreManager from '../logic/ScoreManager';
5
 import ScoreManager from '../logic/ScoreManager';
6
 import Piece from '../logic/Piece';
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
 afterAll(() => {
16
 afterAll(() => {
15
   jest.restoreAllMocks();
17
   jest.restoreAllMocks();
16
 });
18
 });
17
 
19
 
18
 test('getEmptyLine', () => {
20
 test('getEmptyLine', () => {
19
-  let g = new GridManager(2, 2, colors);
21
+  let g = new GridManager(2, 2, theme);
20
   expect(g.getEmptyLine(2)).toStrictEqual([
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
   expect(g.getEmptyLine(-1)).toStrictEqual([]);
27
   expect(g.getEmptyLine(-1)).toStrictEqual([]);
26
 });
28
 });
27
 
29
 
28
 test('getEmptyGrid', () => {
30
 test('getEmptyGrid', () => {
29
-  let g = new GridManager(2, 2, colors);
31
+  let g = new GridManager(2, 2, theme);
30
   expect(g.getEmptyGrid(2, 2)).toStrictEqual([
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
 });
45
 });
44
 
46
 
45
 test('getLinesToClear', () => {
47
 test('getLinesToClear', () => {
46
-  let g = new GridManager(2, 2, colors);
48
+  let g = new GridManager(2, 2, theme);
47
   g.getCurrentGrid()[0][0].isEmpty = false;
49
   g.getCurrentGrid()[0][0].isEmpty = false;
48
   g.getCurrentGrid()[0][1].isEmpty = false;
50
   g.getCurrentGrid()[0][1].isEmpty = false;
49
   let coord = [{x: 1, y: 0}];
51
   let coord = [{x: 1, y: 0}];
59
 });
61
 });
60
 
62
 
61
 test('clearLines', () => {
63
 test('clearLines', () => {
62
-  let g = new GridManager(2, 2, colors);
64
+  let g = new GridManager(2, 2, theme);
63
   let grid = [
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
   g.getCurrentGrid()[1][0].color = '0';
75
   g.getCurrentGrid()[1][0].color = '0';
77
   g.clearLines([1], scoreManager);
79
   g.clearLines([1], scoreManager);
78
   grid = [
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
   expect(g.getCurrentGrid()).toStrictEqual(grid);
90
   expect(g.getCurrentGrid()).toStrictEqual(grid);
89
 });
91
 });
90
 
92
 
91
 test('freezeTetromino', () => {
93
 test('freezeTetromino', () => {
92
-  let g = new GridManager(2, 2, colors);
94
+  let g = new GridManager(2, 2, theme);
93
   let spy1 = jest
95
   let spy1 = jest
94
     .spyOn(GridManager.prototype, 'getLinesToClear')
96
     .spyOn(GridManager.prototype, 'getLinesToClear')
95
     .mockImplementation(() => {});
97
     .mockImplementation(() => {});

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

4
 import Piece from '../logic/Piece';
4
 import Piece from '../logic/Piece';
5
 import ShapeI from '../Shapes/ShapeI';
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
 jest.mock('../Shapes/ShapeI');
14
 jest.mock('../Shapes/ShapeI');
37
   ];
39
   ];
38
   let size = 2;
40
   let size = 2;
39
 
41
 
40
-  let p = new Piece(colors);
42
+  let p = new Piece(theme);
41
   expect(p.isPositionValid(grid, size, size)).toBeTrue();
43
   expect(p.isPositionValid(grid, size, size)).toBeTrue();
42
   x = 1;
44
   x = 1;
43
   y = 0;
45
   y = 0;
65
 });
67
 });
66
 
68
 
67
 test('tryMove', () => {
69
 test('tryMove', () => {
68
-  let p = new Piece(colors);
70
+  let p = new Piece(theme);
69
   const callbackMock = jest.fn();
71
   const callbackMock = jest.fn();
70
   let isValid = true;
72
   let isValid = true;
71
   let spy1 = jest
73
   let spy1 = jest
98
 });
100
 });
99
 
101
 
100
 test('tryRotate', () => {
102
 test('tryRotate', () => {
101
-  let p = new Piece(colors);
103
+  let p = new Piece(theme);
102
   let isValid = true;
104
   let isValid = true;
103
   let spy1 = jest
105
   let spy1 = jest
104
     .spyOn(Piece.prototype, 'isPositionValid')
106
     .spyOn(Piece.prototype, 'isPositionValid')
131
       return [{x: x, y: y}];
133
       return [{x: x, y: y}];
132
     });
134
     });
133
   let spy2 = jest.spyOn(ShapeI.prototype, 'getColor').mockImplementation(() => {
135
   let spy2 = jest.spyOn(ShapeI.prototype, 'getColor').mockImplementation(() => {
134
-    return colors.tetrisI;
136
+    return theme.colors.tetrisI;
135
   });
137
   });
136
   let grid = [
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
   let expectedGrid = [
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
   p.toGrid(grid, true);
160
   p.toGrid(grid, true);
147
   expect(grid).toStrictEqual(expectedGrid);
161
   expect(grid).toStrictEqual(expectedGrid);
148
 
162
 
153
 test('removeFromGrid', () => {
167
 test('removeFromGrid', () => {
154
   let gridOld = [
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
   let gridNew = [
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
   let oldCoord = [
182
   let oldCoord = [
175
       return oldCoord;
189
       return oldCoord;
176
     });
190
     });
177
   let spy2 = jest.spyOn(ShapeI.prototype, 'getColor').mockImplementation(() => {
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
   p.removeFromGrid(gridOld);
195
   p.removeFromGrid(gridOld);
182
   expect(gridOld).toStrictEqual(gridNew);
196
   expect(gridOld).toStrictEqual(gridNew);
183
 
197
 

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

4
 import BaseShape from '../Shapes/BaseShape';
4
 import BaseShape from '../Shapes/BaseShape';
5
 import ShapeI from '../Shapes/ShapeI';
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
 test('constructor', () => {
19
 test('constructor', () => {
18
   expect(() => new BaseShape()).toThrow(Error);
20
   expect(() => new BaseShape()).toThrow(Error);
19
 
21
 
20
-  let T = new ShapeI(colors);
22
+  let T = new ShapeI(theme);
21
   expect(T.position.y).toBe(0);
23
   expect(T.position.y).toBe(0);
22
   expect(T.position.x).toBe(3);
24
   expect(T.position.x).toBe(3);
23
   expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[0]);
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
 test('move', () => {
29
 test('move', () => {
28
-  let T = new ShapeI(colors);
30
+  let T = new ShapeI(theme);
29
   T.move(0, 1);
31
   T.move(0, 1);
30
   expect(T.position.x).toBe(3);
32
   expect(T.position.x).toBe(3);
31
   expect(T.position.y).toBe(1);
33
   expect(T.position.y).toBe(1);
44
 });
46
 });
45
 
47
 
46
 test('rotate', () => {
48
 test('rotate', () => {
47
-  let T = new ShapeI(colors);
49
+  let T = new ShapeI(theme);
48
   T.rotate(true);
50
   T.rotate(true);
49
   expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[1]);
51
   expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[1]);
50
   T.rotate(true);
52
   T.rotate(true);
64
 });
66
 });
65
 
67
 
66
 test('getCellsCoordinates', () => {
68
 test('getCellsCoordinates', () => {
67
-  let T = new ShapeI(colors);
69
+  let T = new ShapeI(theme);
68
   expect(T.getCellsCoordinates(false)).toStrictEqual([
70
   expect(T.getCellsCoordinates(false)).toStrictEqual([
69
     {x: 0, y: 1},
71
     {x: 0, y: 1},
70
     {x: 1, y: 1},
72
     {x: 1, y: 1},

Loading…
Cancel
Save