The four rematch channels, Series and SeriesGame, the series and first seat of a game, getSeriesScore and the texts in English and Turkish.
31 lines
1.6 KiB
TypeScript
31 lines
1.6 KiB
TypeScript
import { getSeriesScore, isSeriesOver, SeriesGame } from "../../src/models";
|
|
import { en, tr } from "../../src/localization";
|
|
|
|
const game = (result: SeriesGame["result"]): SeriesGame =>
|
|
({ gameId: "g", firstSeat: "player1", result, endReason: "completed", player1Store: 24, player2Store: 24 });
|
|
|
|
describe("series", () => {
|
|
it("counts the wins of each seat, leaving out draws and games without a winner", () => {
|
|
const games = [game("player1"), game("player2"), game("draw"), game("player1"), game(null)];
|
|
expect(getSeriesScore(games, "player1")).toEqual({ wins: 2, losses: 1 });
|
|
expect(getSeriesScore(games, "player2")).toEqual({ wins: 1, losses: 2 });
|
|
expect(getSeriesScore([], "player1")).toEqual({ wins: 0, losses: 0 });
|
|
});
|
|
|
|
it("knows which endings of a request end the series", () => {
|
|
expect(["declined", "left", "closed"].every((reason) => isSeriesOver(reason as any))).toBe(true);
|
|
expect(["withdrawn", "expired", "offline"].some((reason) => isSeriesOver(reason as any))).toBe(false);
|
|
});
|
|
|
|
it("has every rematch text in English and Turkish", () => {
|
|
const keys = ["Rematch", "No", "RematchWaiting", "RematchRequested", "RematchDeclined", "RematchWithdrawn",
|
|
"RematchNoAnswer", "RematchRequestExpired", "RematchOpponentGone", "RematchClosed", "Series",
|
|
"SeriesScoreText", "SeriesGameNumber", "SeriesCurrentGame", "SeriesEarlierGames", "MovedFirst", "EndedOnTime",
|
|
"EndedByLeaving"];
|
|
for (const key of keys) {
|
|
expect(en).toHaveProperty(key);
|
|
expect(tr).toHaveProperty(key);
|
|
}
|
|
});
|
|
});
|