Skip to content

Commit

Permalink
Wrote KillPieceByEnvironmentAction tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ido-Barnea committed Apr 22, 2024
1 parent 2e24785 commit 51e75f1
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 16 deletions.
6 changes: 2 additions & 4 deletions core/development/logic/actions/AttackPieceAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ jest.mock('../../ui/InventoriesUI.ts', () => ({
}));
jest.mock('../../ui/ShopUI.ts');

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

describe('AttackPieceAction', () => {
Expand Down
6 changes: 2 additions & 4 deletions core/development/logic/actions/CastleAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ jest.mock('../../ui/InventoriesUI.ts', () => ({
}));
jest.mock('../../ui/ShopUI.ts');

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

describe('CastleAction', () => {
Expand Down
6 changes: 2 additions & 4 deletions core/development/logic/actions/KillPieceAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ jest.mock('../../ui/InventoriesUI.ts', () => ({
}));
jest.mock('../../ui/ShopUI.ts');

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

jest.mock('./SpawnPieceInHellAction', () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { game } from '../../Game';
import { PlayerInventory } from '../inventory/PlayerInventory';
import { Pawn } from '../pieces/Pawn';
import { Player } from '../players/Player';
import { PlayerColor } from '../players/types/PlayerColor';
import { KillPieceByEnvironmentAction } from './KillPieceByEnvironmentAction';
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),
});
game.endMove = jest.fn();

jest.mock('./KillPieceAction', () => ({
__esModule: true,
KillPieceAction: jest.fn().mockImplementation(() => ({
execute: jest.fn().mockReturnValue(1),
})),
}));

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

test('should return SUCCESS', () => {
// Arrange
const killedPiece = new Pawn(whitePlayer, undefined);
const killPieceByEnvironmentAction = new KillPieceByEnvironmentAction(
killedPiece,
'cause',
killedPiece.position?.boardId,
);

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

// Assert
expect(actionResult).toEqual(ActionResult.SUCCESS);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ jest.mock('../../ui/InventoriesUI.ts', () => ({
}));
jest.mock('../../ui/ShopUI.ts');

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

jest.mock('./KillPieceByEnvironmentAction', () => ({
Expand Down

0 comments on commit 51e75f1

Please sign in to comment.