mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-25 04:26:00 -05:00
Fix destination bracket text when many starting brackets
This commit is contained in:
@@ -76,10 +76,12 @@ export function PlacementsTable({
|
||||
const destinationBracket = (placement: number) =>
|
||||
bracket.tournament.brackets.find(
|
||||
(b) =>
|
||||
b.id !== bracket.id &&
|
||||
b.sources?.some(
|
||||
(s) => s.bracketIdx === 0 && s.placements.includes(placement),
|
||||
),
|
||||
b.idx ===
|
||||
Progression.destinationByPlacement({
|
||||
sourceBracketIdx: bracket.idx,
|
||||
placement,
|
||||
progression: bracket.tournament.ctx.settings.bracketProgression,
|
||||
}),
|
||||
);
|
||||
|
||||
const possibleDestinationBrackets = Progression.destinationsFromBracketIdx(
|
||||
|
||||
@@ -588,3 +588,41 @@ describe("destinationsFromBracketIdx", () => {
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("destinationByPlacement", () => {
|
||||
it("returns correct destination for a given placement", () => {
|
||||
const result = Progression.destinationByPlacement({
|
||||
sourceBracketIdx: 0,
|
||||
placement: 1,
|
||||
progression: progressions.roundRobinToSingleElimination,
|
||||
});
|
||||
expect(result).toBe(1);
|
||||
});
|
||||
|
||||
it("returns null if no destination for the given placement", () => {
|
||||
const result = Progression.destinationByPlacement({
|
||||
sourceBracketIdx: 0,
|
||||
placement: 5,
|
||||
progression: progressions.roundRobinToSingleElimination,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("returns correct destination for negative placements", () => {
|
||||
const result = Progression.destinationByPlacement({
|
||||
sourceBracketIdx: 0,
|
||||
placement: -1,
|
||||
progression: progressions.doubleEliminationWithUnderground,
|
||||
});
|
||||
expect(result).toBe(1);
|
||||
});
|
||||
|
||||
it("returns correct destination for many start brackets", () => {
|
||||
const result = Progression.destinationByPlacement({
|
||||
sourceBracketIdx: 1,
|
||||
placement: 1,
|
||||
progression: progressions.manyStartBrackets,
|
||||
});
|
||||
expect(result).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -699,3 +699,26 @@ export function destinationsFromBracketIdx(
|
||||
|
||||
return destinations;
|
||||
}
|
||||
|
||||
export function destinationByPlacement({
|
||||
sourceBracketIdx,
|
||||
placement,
|
||||
progression,
|
||||
}: {
|
||||
sourceBracketIdx: number;
|
||||
placement: number;
|
||||
progression: ParsedBracket[];
|
||||
}): number | null {
|
||||
const destinations = destinationsFromBracketIdx(
|
||||
sourceBracketIdx,
|
||||
progression,
|
||||
);
|
||||
|
||||
const destination = destinations.find((destinationBracketIdx) =>
|
||||
progression[destinationBracketIdx].sources?.some((source) =>
|
||||
source.placements.includes(placement),
|
||||
),
|
||||
);
|
||||
|
||||
return destination ?? null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user