Skip to content

Commit

Permalink
Wrote RevertPieceMovementAction tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ido-Barnea committed Apr 22, 2024
1 parent 22a8776 commit 0a1286d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ game.setPieces = jest.fn();
game.increaseDeathCounter = jest.fn();
game.end = jest.fn();

describe('KillPieceByPieceAction', () => {
describe('PermanentlyKillPieceAction', () => {
afterEach(() => {
jest.clearAllMocks();
});
Expand Down
71 changes: 71 additions & 0 deletions core/development/logic/actions/RevertPieceMovementAction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { OVERWORLD_BOARD_ID } from '../../Constants';
import { game } from '../../Game';
import { PlayerInventory } from '../inventory/PlayerInventory';
import { Pawn } from '../pieces/Pawn';
import { Position } from '../pieces/types/Position';
import { Player } from '../players/Player';
import { PlayerColor } from '../players/types/PlayerColor';
import { RevertPieceMovementAction } from './RevertPieceMovementAction';
import { ActionResult } from './types/ActionResult';

const whitePlayer = new Player(PlayerColor.WHITE, new PlayerInventory());

jest.mock('../../ui/BoardManager.ts', () => ({
destroyElementOnBoard: jest.fn(),
moveElementOnBoard: jest.fn(),
getSquareElementById: jest.fn(),
spawnPieceElementOnBoard: jest.fn(),
getAllSquareElements: jest.fn(),
highlightLastMove: jest.fn(),
}));
jest.mock('../../ui/Screen.ts', () => ({
renderGameInformation: jest.fn(),
hideUnicornAttackButton: jest.fn(),
}));
jest.mock('../../ui/logs/Logger.ts');
jest.mock('../../ui/Events.ts', () => ({}));
jest.mock('../../ui/InventoriesUI.ts', () => ({
initializeInventoryUI: jest.fn(),
switchShownInventory: jest.fn(),
showItemOnInventory: jest.fn(),
}));
jest.mock('../../ui/ShopUI.ts');

game.getPlayersTurnSwitcher = jest.fn().mockReturnValue({
getCurrentPlayer: jest.fn().mockReturnValue(whitePlayer),
getTurnsCount: jest.fn().mockReturnValue(1),
});

describe('RevertPieceMovementAction', () => {
afterEach(() => {
jest.clearAllMocks();
});

test('should return FAILURE if piece.position is undefined', () => {
// Arrange
const piece = new Pawn(whitePlayer, undefined);
const revertPieceMovementAction = new RevertPieceMovementAction(piece);

// Act
const actionResult = revertPieceMovementAction.execute();

// Assert
expect(actionResult).toEqual(ActionResult.FAILURE);
});

test('should return SUCCESS if piece.position is defined', () => {
// Arrange
const initialPosition: Position = {
coordinates: [4, 0],
boardId: OVERWORLD_BOARD_ID,
};
const piece = new Pawn(whitePlayer, initialPosition);
const revertPieceMovementAction = new RevertPieceMovementAction(piece);

// Act
const actionResult = revertPieceMovementAction.execute();

// Assert
expect(actionResult).toEqual(ActionResult.SUCCESS);
});
});

0 comments on commit 0a1286d

Please sign in to comment.