forked from vergnet/application-amicale
Added grid tests
This commit is contained in:
parent
3d45bc62b8
commit
931d7b0fe6
1 changed files with 69 additions and 0 deletions
|
@ -1,10 +1,19 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import GridManager from "../GridManager";
|
import GridManager from "../GridManager";
|
||||||
|
import ScoreManager from "../ScoreManager";
|
||||||
|
import Piece from "../Piece";
|
||||||
|
|
||||||
let colors = {
|
let colors = {
|
||||||
tetrisBackground: "#000002"
|
tetrisBackground: "#000002"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
jest.mock("../ScoreManager");
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
jest.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
test('getEmptyLine', () => {
|
test('getEmptyLine', () => {
|
||||||
let g = new GridManager(2, 2, colors);
|
let g = new GridManager(2, 2, colors);
|
||||||
expect(g.getEmptyLine(2)).toStrictEqual([
|
expect(g.getEmptyLine(2)).toStrictEqual([
|
||||||
|
@ -32,3 +41,63 @@ test('getEmptyGrid', () => {
|
||||||
expect(g.getEmptyGrid(2, -1)).toStrictEqual([[], []]);
|
expect(g.getEmptyGrid(2, -1)).toStrictEqual([[], []]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getLinesToClear', () => {
|
||||||
|
let g = new GridManager(2, 2, colors);
|
||||||
|
g.getCurrentGrid()[0][0].isEmpty = false;
|
||||||
|
g.getCurrentGrid()[0][1].isEmpty = false;
|
||||||
|
let coord = [{x: 1, y: 0}];
|
||||||
|
expect(g.getLinesToClear(coord)).toStrictEqual([0]);
|
||||||
|
|
||||||
|
g.getCurrentGrid()[0][0].isEmpty = true;
|
||||||
|
g.getCurrentGrid()[0][1].isEmpty = true;
|
||||||
|
g.getCurrentGrid()[1][0].isEmpty = false;
|
||||||
|
g.getCurrentGrid()[1][1].isEmpty = false;
|
||||||
|
expect(g.getLinesToClear(coord)).toStrictEqual([]);
|
||||||
|
coord = [{x: 1, y: 1}];
|
||||||
|
expect(g.getLinesToClear(coord)).toStrictEqual([1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('clearLines', () => {
|
||||||
|
let g = new GridManager(2, 2, colors);
|
||||||
|
let grid = [
|
||||||
|
[
|
||||||
|
{color: colors.tetrisBackground, isEmpty: true},
|
||||||
|
{color: colors.tetrisBackground, isEmpty: true},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{color: '0', isEmpty: true},
|
||||||
|
{color: '0', isEmpty: true},
|
||||||
|
],
|
||||||
|
];
|
||||||
|
g.getCurrentGrid()[1][0].color = '0';
|
||||||
|
g.getCurrentGrid()[1][1].color = '0';
|
||||||
|
expect(g.getCurrentGrid()).toStrictEqual(grid);
|
||||||
|
let scoreManager = new ScoreManager();
|
||||||
|
g.clearLines([1], scoreManager);
|
||||||
|
grid = [
|
||||||
|
[
|
||||||
|
{color: colors.tetrisBackground, isEmpty: true},
|
||||||
|
{color: colors.tetrisBackground, isEmpty: true},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{color: colors.tetrisBackground, isEmpty: true},
|
||||||
|
{color: colors.tetrisBackground, isEmpty: true},
|
||||||
|
],
|
||||||
|
];
|
||||||
|
expect(g.getCurrentGrid()).toStrictEqual(grid);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('freezeTetromino', () => {
|
||||||
|
let g = new GridManager(2, 2, colors);
|
||||||
|
let spy1 = jest.spyOn(GridManager.prototype, 'getLinesToClear')
|
||||||
|
.mockImplementation(() => {});
|
||||||
|
let spy2 = jest.spyOn(GridManager.prototype, 'clearLines')
|
||||||
|
.mockImplementation(() => {});
|
||||||
|
g.freezeTetromino(new Piece({}), null);
|
||||||
|
|
||||||
|
expect(spy1).toHaveBeenCalled();
|
||||||
|
expect(spy2).toHaveBeenCalled();
|
||||||
|
|
||||||
|
spy1.mockRestore();
|
||||||
|
spy2.mockRestore();
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue