fix expectations, remove outdated specs

This commit is contained in:
AlecM33
2023-08-03 18:42:00 -04:00
parent 19f12ca1a8
commit 7c61b3a724
10 changed files with 57 additions and 90 deletions

View File

@@ -67,7 +67,7 @@ describe('Create page', function () {
.toEqual('Test name');
});
it('should successfully update custom role information after creating it', () => {
it('should successstartabley update custom role information after creating it', () => {
document.getElementById('role-category-custom').click();
document.getElementById('custom-role-btn').click();
document.getElementById('role-name').value = 'Test name';

View File

@@ -69,18 +69,6 @@ describe('game page', () => {
expect(document.getElementById('current-info-message').innerText).toEqual('Jane joined!');
});
it('should activate the start button for the moderator when the game is full', () => {
expect(document.getElementById('start-game-button').classList.contains('disabled')).toBeTrue();
mockSocket.eventHandlers[globals.EVENT_IDS.PLAYER_JOINED]({
name: 'Jack',
id: '456',
userType: globals.USER_TYPES.PLAYER,
out: false,
revealed: false
}, true);
expect(document.getElementById('start-game-button').classList.contains('disabled')).toBeFalse();
});
afterAll(() => {
document.body.innerHTML = '';
});

View File

@@ -46,7 +46,7 @@ export const mockGames = {
paused: true,
timeRemaining: 600000
},
isFull: false
isStartable: false
},
inProgressGame: {
accessCode: 'TVV6',
@@ -163,7 +163,7 @@ export const mockGames = {
paused: true,
timeRemaining: 600000
},
isFull: true
isStartable: true
},
moderatorGame:
{
@@ -306,6 +306,6 @@ export const mockGames = {
paused: true,
timeRemaining: 600000
},
isFull: true
isStartable: true
}
};

View File

@@ -34,10 +34,10 @@ describe('Events', () => {
STATUS.LOBBY,
[
{ id: 'a', assigned: true, out: true, killed: false, userType: USER_TYPES.MODERATOR },
{ id: 'b', gameRole: 'Villager', alignment: 'good', assigned: false, out: false, killed: false, userType: USER_TYPES.PLAYER },
{ id: 'b', gameRole: 'Villager', alignment: 'good', assigned: true, out: false, killed: false, userType: USER_TYPES.PLAYER },
{ id: 'c', assigned: true, out: true, killed: false, userType: USER_TYPES.SPECTATOR }
],
[{ quantity: 2 }],
[{ quantity: 1 }, { quantity: 1 }],
false,
'a',
true,
@@ -50,7 +50,7 @@ describe('Events', () => {
spyOn(socket, 'to').and.callThrough();
spyOn(namespace.in(), 'emit').and.callThrough();
spyOn(namespace.to(), 'emit').and.callThrough();
spyOn(gameManager, 'isGameFull').and.callThrough();
spyOn(gameManager, 'isGameStartable').and.callThrough();
spyOn(GameStateCurator, 'mapPerson').and.callThrough();
spyOn(eventManager.publisher, 'publish').and.callThrough();
spyOn(eventManager, 'createMessageToPublish').and.stub();
@@ -60,38 +60,32 @@ describe('Events', () => {
describe(EVENT_IDS.PLAYER_JOINED, () => {
describe('stateChange', () => {
it('should let a player join and mark the game as full', async () => {
it('should let a player join and mark the game as startable', async () => {
await Events.find((e) => e.id === EVENT_IDS.PLAYER_JOINED)
.stateChange(game, { id: 'b', assigned: true }, { gameManager: gameManager });
expect(gameManager.isGameFull).toHaveBeenCalled();
expect(game.isFull).toEqual(true);
.stateChange(game, { id: 'd', assigned: true, userType: USER_TYPES.PLAYER }, { gameManager: gameManager });
expect(gameManager.isGameStartable).toHaveBeenCalled();
expect(game.isStartable).toEqual(true);
expect(game.people.find(p => p.id === 'b').assigned).toEqual(true);
});
it('should let a player join and mark the game as NOT full', async () => {
game.people.push({ id: 'd', assigned: false, userType: USER_TYPES.PLAYER });
it('should let too many players join and mark the game as NOT startable', async () => {
game.people.push({ id: 'e', assigned: true, userType: USER_TYPES.PLAYER });
game.people.push({ id: 'f', assigned: true, userType: USER_TYPES.PLAYER });
await Events.find((e) => e.id === EVENT_IDS.PLAYER_JOINED)
.stateChange(game, { id: 'b', assigned: true }, { gameManager: gameManager });
expect(gameManager.isGameFull).toHaveBeenCalled();
expect(game.isFull).toEqual(false);
expect(gameManager.isGameStartable).toHaveBeenCalled();
expect(game.isStartable).toEqual(false);
expect(game.people.find(p => p.id === 'b').assigned).toEqual(true);
});
it('should not let the player join if their id does not match some unassigned person', async () => {
await Events.find((e) => e.id === EVENT_IDS.PLAYER_JOINED)
.stateChange(game, { id: 'd', assigned: true }, { gameManager: gameManager });
expect(gameManager.isGameFull).not.toHaveBeenCalled();
expect(game.isFull).toEqual(false);
expect(game.people.find(p => p.id === 'd')).not.toBeDefined();
});
});
describe('communicate', () => {
it('should communicate the join event to the rooms sockets, sending the new player', async () => {
await Events.find((e) => e.id === EVENT_IDS.PLAYER_JOINED)
.communicate(game, { id: 'b', assigned: true }, { gameManager: gameManager });
.communicate(game, { id: 'd', assigned: true, userType: USER_TYPES.PLAYER }, { gameManager: gameManager });
expect(namespace.in).toHaveBeenCalledWith(game.accessCode);
expect(namespace.in().emit).toHaveBeenCalledWith(
globals.EVENTS.PLAYER_JOINED,
GameStateCurator.mapPerson({ id: 'b', assigned: true }),
game.isFull
GameStateCurator.mapPerson({ id: 'd', assigned: true, userType: USER_TYPES.PLAYER }),
game.isStartable
);
});
});
@@ -102,8 +96,8 @@ describe('Events', () => {
it('should add a spectator', async () => {
await Events.find((e) => e.id === EVENT_IDS.ADD_SPECTATOR)
.stateChange(game, { id: 'e', name: 'ghost', assigned: true }, { gameManager: gameManager });
expect(gameManager.isGameFull).not.toHaveBeenCalled();
expect(game.isFull).toEqual(false);
expect(gameManager.isGameStartable).not.toHaveBeenCalled();
expect(game.isStartable).toEqual(false);
expect(game.people.find(p => p.id === 'e').assigned).toEqual(true);
expect(game.people.find(p => p.id === 'e').name).toEqual('ghost');
});
@@ -197,18 +191,18 @@ describe('Events', () => {
describe(EVENT_IDS.START_GAME, () => {
describe('stateChange', () => {
it('should start the game', async () => {
game.isFull = true;
game.isStartable = true;
await Events.find((e) => e.id === EVENT_IDS.START_GAME)
.stateChange(game, { id: 'b', assigned: true }, { gameManager: gameManager });
expect(game.status).toEqual(STATUS.IN_PROGRESS);
});
it('should not start the game if it is not full', async () => {
it('should not start the game if it is not startable', async () => {
await Events.find((e) => e.id === EVENT_IDS.START_GAME)
.stateChange(game, { id: 'b', assigned: true }, { gameManager: gameManager });
expect(game.status).toEqual(STATUS.LOBBY);
});
it('should start the game and run the timer if the game has one', async () => {
game.isFull = true;
game.isStartable = true;
game.hasTimer = true;
game.timerParams = {};
spyOn(timerManager, 'runTimer').and.callFake((a, b) => {});

View File

@@ -37,8 +37,8 @@ describe('GameManager', () => {
'ABCD',
STATUS.LOBBY,
[{ id: 'a', name: 'person1', assigned: true, out: true, killed: false, userType: USER_TYPES.MODERATOR },
{ id: 'b', name: 'person2', gameRole: 'Villager', alignment: 'good', assigned: false, out: false, killed: false, userType: USER_TYPES.PLAYER }],
[{ quantity: 2 }],
{ id: 'b', name: 'person2', gameRole: 'Villager', alignment: 'good', assigned: true, out: false, killed: false, userType: USER_TYPES.PLAYER }],
[{ quantity: 1 }, { quantity: 1 }],
false,
'a',
true,
@@ -50,30 +50,26 @@ describe('GameManager', () => {
});
describe('#joinGame', () => {
it('should mark the game as full when all players have been assigned', async () => {
it('should mark the game as startable when the number of players equals the game size', async () => {
await gameManager.joinGame(game, 'Jill', 'x');
expect(game.isFull).toEqual(true);
expect(game.isStartable).toEqual(true);
});
it('should create a spectator if the game is already full and broadcast it to the room', () => {
game.people.find(p => p.id === 'b').assigned = true;
game.isFull = true;
it('should create a spectator if the game is already startable and broadcast it to the room', async () => {
await gameManager.joinGame(game, 'Jill', 'x');
game.isStartable = true;
spyOn(gameManager.namespace.in(), 'emit');
gameManager.joinGame(game, 'Jane', 'x');
await gameManager.joinGame(game, 'Jane', 'x');
expect(game.isFull).toEqual(true);
expect(game.isStartable).toEqual(true);
expect(game.people.filter(p => p.userType === USER_TYPES.SPECTATOR).length).toEqual(1);
});
});
describe('#restartGame', () => {
let shuffleSpy;
beforeEach(() => {
shuffleSpy = spyOn(gameManager, 'shuffle').and.stub();
});
beforeEach(() => {});
it('should reset all relevant game parameters', async () => {
game.status = STATUS.ENDED;
@@ -85,11 +81,10 @@ describe('GameManager', () => {
await gameManager.restartGame(game, namespace);
expect(game.status).toEqual(STATUS.IN_PROGRESS);
expect(game.status).toEqual(STATUS.LOBBY);
expect(player.userType).toEqual(USER_TYPES.PLAYER);
expect(player.out).toBeFalse();
expect(player.killed).toBeFalse();
expect(shuffleSpy).toHaveBeenCalled();
expect(emitSpy).toHaveBeenCalledWith(globals.EVENT_IDS.RESTART_GAME);
});
@@ -100,16 +95,12 @@ describe('GameManager', () => {
game.status = STATUS.ENDED;
const threadKillSpy = spyOn(timerManager.timerThreads.ABCD, 'kill');
const runTimerSpy = spyOn(timerManager, 'runTimer').and.stub();
const emitSpy = spyOn(namespace.in(), 'emit');
await gameManager.restartGame(game, namespace);
expect(game.status).toEqual(STATUS.IN_PROGRESS);
expect(game.timerParams.paused).toBeTrue();
expect(game.status).toEqual(STATUS.LOBBY);
expect(threadKillSpy).toHaveBeenCalled();
expect(runTimerSpy).toHaveBeenCalled();
expect(shuffleSpy).toHaveBeenCalled();
expect(emitSpy).toHaveBeenCalledWith(globals.EVENT_IDS.RESTART_GAME);
});
@@ -123,10 +114,9 @@ describe('GameManager', () => {
await gameManager.restartGame(game, namespace);
expect(game.status).toEqual(STATUS.IN_PROGRESS);
expect(game.status).toEqual(STATUS.LOBBY);
expect(game.currentModeratorId).toEqual('b');
expect(game.people.find(p => p.id === 'b').userType).toEqual(USER_TYPES.TEMPORARY_MODERATOR);
expect(shuffleSpy).toHaveBeenCalled();
expect(emitSpy).toHaveBeenCalledWith(globals.EVENT_IDS.RESTART_GAME);
});
});