fix(ui): green both lobby scores on a tie, mute a 0:0 board
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 54s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m7s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 54s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m7s
The lobby tinted only the viewer's own number, and a tie counted as "leading" — so an even score showed only the viewer's number green, reading as if the viewer were ahead. A fresh 0:0 board did the same, accenting the start of a game where nobody has scored. scoreStanding is now per-seat: the viewer's seat stays green when leading or tied and red when trailing; an opponent's seat greens only when it ties the viewer for the lead, so an equal non-zero score paints both numbers green. When the top score is 0 (nobody has moved) every number is left muted, like a finished game.
This commit is contained in:
@@ -126,22 +126,42 @@ describe('scoreStanding', () => {
|
||||
{ ...seat(1, 'opp'), score: oppScore },
|
||||
],
|
||||
});
|
||||
const at = (g: GameView, accountId: string): Seat => g.seats.find((s) => s.accountId === accountId)!;
|
||||
|
||||
it('greens a leading or tied active game, reds a losing one', () => {
|
||||
expect(scoreStanding(withScores('active', 30, 10), ME)).toBe('win');
|
||||
expect(scoreStanding(withScores('active', 10, 10), ME)).toBe('win'); // a tie counts as green
|
||||
expect(scoreStanding(withScores('active', 5, 10), ME)).toBe('lose');
|
||||
it('greens the leading viewer and reds a trailing one; the opponent stays muted', () => {
|
||||
const lead = withScores('active', 30, 10);
|
||||
expect(scoreStanding(lead, ME, at(lead, ME))).toBe('win');
|
||||
expect(scoreStanding(lead, ME, at(lead, 'opp'))).toBeNull(); // a trailing opponent is not coloured
|
||||
|
||||
const behind = withScores('active', 5, 10);
|
||||
expect(scoreStanding(behind, ME, at(behind, ME))).toBe('lose');
|
||||
expect(scoreStanding(behind, ME, at(behind, 'opp'))).toBeNull(); // a leading opponent is not coloured
|
||||
});
|
||||
|
||||
it('greens both seats on an equal non-zero score', () => {
|
||||
const tie = withScores('active', 10, 10);
|
||||
expect(scoreStanding(tie, ME, at(tie, ME))).toBe('win');
|
||||
expect(scoreStanding(tie, ME, at(tie, 'opp'))).toBe('win');
|
||||
});
|
||||
|
||||
it('leaves a fresh 0:0 board muted (nobody has scored yet)', () => {
|
||||
const fresh = withScores('active', 0, 0);
|
||||
expect(scoreStanding(fresh, ME, at(fresh, ME))).toBeNull();
|
||||
expect(scoreStanding(fresh, ME, at(fresh, 'opp'))).toBeNull();
|
||||
});
|
||||
|
||||
it('is null for any non-active game (open or finished)', () => {
|
||||
expect(scoreStanding(withScores('finished', 30, 10), ME)).toBeNull();
|
||||
expect(scoreStanding(withScores('open', 0, 0), ME)).toBeNull();
|
||||
const fin = withScores('finished', 30, 10);
|
||||
expect(scoreStanding(fin, ME, at(fin, ME))).toBeNull();
|
||||
const op = withScores('open', 0, 0);
|
||||
expect(scoreStanding(op, ME, at(op, ME))).toBeNull();
|
||||
});
|
||||
|
||||
it('is null when the viewer is not seated or has no opponent', () => {
|
||||
expect(scoreStanding(withScores('active', 30, 10), 'stranger')).toBeNull();
|
||||
const g = withScores('active', 30, 10);
|
||||
expect(scoreStanding(g, 'stranger', at(g, ME))).toBeNull();
|
||||
const solo: GameView = { ...game('g', 'active', 0, 0), seats: [{ ...seat(0, ME), score: 9 }] };
|
||||
expect(scoreStanding(solo, ME)).toBeNull();
|
||||
expect(scoreStanding(solo, ME, solo.seats[0])).toBeNull();
|
||||
});
|
||||
|
||||
it('compares against the strongest opponent in a multiplayer game', () => {
|
||||
@@ -151,10 +171,26 @@ describe('scoreStanding', () => {
|
||||
seats: [
|
||||
{ ...seat(0, ME), score: 40 },
|
||||
{ ...seat(1, 'a'), score: 35 },
|
||||
{ ...seat(2, 'b'), score: 50 }, // b is ahead -> losing
|
||||
{ ...seat(2, 'b'), score: 50 }, // b is ahead -> the viewer is losing
|
||||
],
|
||||
};
|
||||
expect(scoreStanding(g3, ME)).toBe('lose');
|
||||
expect(scoreStanding(g3, ME, at(g3, ME))).toBe('lose');
|
||||
expect(scoreStanding(g3, ME, at(g3, 'b'))).toBeNull(); // a leading opponent is not coloured
|
||||
});
|
||||
|
||||
it('greens every seat tied with the viewer for the lead in a multiplayer game', () => {
|
||||
const g3: GameView = {
|
||||
...game('g', 'active', 0, 0),
|
||||
players: 3,
|
||||
seats: [
|
||||
{ ...seat(0, ME), score: 40 },
|
||||
{ ...seat(1, 'a'), score: 40 }, // tied with the viewer for the lead -> green
|
||||
{ ...seat(2, 'b'), score: 20 }, // trailing -> muted
|
||||
],
|
||||
};
|
||||
expect(scoreStanding(g3, ME, at(g3, ME))).toBe('win');
|
||||
expect(scoreStanding(g3, ME, at(g3, 'a'))).toBe('win');
|
||||
expect(scoreStanding(g3, ME, at(g3, 'b'))).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user