Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dxw/js-cop-games
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0d7d017b8ed0fd0e10695a5e9e80517f9a6d2691
Choose a base ref
..
head repository: dxw/js-cop-games
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d2e837ef615328c0ff215186703c16aa2556044c
Choose a head ref
Showing with 14 additions and 12 deletions.
  1. +7 −5 server/machines/lobby.test.ts
  2. +7 −7 server/machines/lobby.ts
12 changes: 7 additions & 5 deletions server/machines/lobby.test.ts
Original file line number Diff line number Diff line change
@@ -86,13 +86,15 @@ describe("lobbyMachine", () => {

describe("On playerLeaves", () => {
it("transitions from OnePlayer to Empty state", () => {
expect(
lobbyMachine.transition("OnePlayer", "playerLeaves").value
).toBe("Empty");
expect(lobbyMachine.transition("OnePlayer", "playerLeaves").value).toBe(
"Empty",
);
});

it("transitions from Multiple players to one player when player leaves", () => {
expect(lobbyMachine.transition("MultiplePlayers", "playerLeaves").value).toBe("OnePlayer")
expect(
lobbyMachine.transition("MultiplePlayers", "playerLeaves").value,
).toBe("OnePlayer");
});

it("transitions from GameStart to OnePlayer if there is only one player left", () => {
@@ -110,7 +112,7 @@ describe("lobbyMachine", () => {
});
});

actor.send({ type: "playerClicksStart"});
actor.send({ type: "playerClicksStart" });
expect(actor.getSnapshot().value).toBe("GameStart");

actor.send({ type: "playerLeaves", socketId: "id" });
14 changes: 7 additions & 7 deletions server/machines/lobby.ts
Original file line number Diff line number Diff line change
@@ -33,7 +33,8 @@ export const isNewPlayer = (
{ player }: { player: Player },
) => players.map((player) => player.socketId).indexOf(player.socketId) === -1;

export const isOnlyPlayer = ({ players }: { players: Array<Player> }) => players.length === 1;
export const isOnlyPlayer = ({ players }: { players: Array<Player> }) =>
players.length === 1;

export const lobbyMachine = createMachine(
{
@@ -74,11 +75,10 @@ export const lobbyMachine = createMachine(
},
GameStart: {
entry: ["setQuestion"],
always:
{
target: "OnePlayer",
cond: "isOnlyPlayer",
},
always: {
target: "OnePlayer",
cond: "isOnlyPlayer",
},
on: {
playerLeaves: { actions: "removePlayer" },
},
@@ -92,7 +92,7 @@ export const lobbyMachine = createMachine(
}),
removePlayer: assign({
players: ({ players }, { socketId }) =>
players.filter((p) => p.socketId !== socketId),
players.filter((p) => p.socketId !== socketId),
}),
setQuestion: assign({
selectedQuestion: ({ questions }) => {