|
| 1 | +import { |
| 2 | + buildBulkRoundRows, |
| 3 | + defaultSelectedRoundIds, |
| 4 | + mergeRoundOrder, |
| 5 | + scheduleOrderedRoundIds, |
| 6 | +} from './bulkRoundRows'; |
| 7 | +import { |
| 8 | + buildActivity, |
| 9 | + buildEvent, |
| 10 | + buildPerson, |
| 11 | + buildRound, |
| 12 | + buildWcifWithEvents, |
| 13 | +} from '../../../store/reducers/_tests_/helpers'; |
| 14 | +import type { AssignmentCode, Competition, EventId } from '@wca/helpers'; |
| 15 | +import { describe, expect, it } from 'vitest'; |
| 16 | + |
| 17 | +const assignment = (activityId: number, assignmentCode: AssignmentCode) => ({ |
| 18 | + activityId, |
| 19 | + assignmentCode, |
| 20 | + stationNumber: null, |
| 21 | +}); |
| 22 | + |
| 23 | +const registration = (registrantId: number, eventIds: EventId[]) => ({ |
| 24 | + status: 'accepted' as const, |
| 25 | + eventIds, |
| 26 | + isCompeting: true, |
| 27 | + comments: undefined, |
| 28 | + wcaRegistrationId: registrantId, |
| 29 | +}); |
| 30 | + |
| 31 | +const buildCompetition = (): Competition => { |
| 32 | + const round333 = buildActivity({ |
| 33 | + id: 1, |
| 34 | + activityCode: '333-r1', |
| 35 | + startTime: '2024-01-01T11:00:00Z', |
| 36 | + endTime: '2024-01-01T11:30:00Z', |
| 37 | + childActivities: [ |
| 38 | + buildActivity({ id: 101, activityCode: '333-r1-g1' }), |
| 39 | + buildActivity({ id: 102, activityCode: '333-r1-g2' }), |
| 40 | + ], |
| 41 | + }); |
| 42 | + const round333Second = buildActivity({ |
| 43 | + id: 2, |
| 44 | + activityCode: '333-r2', |
| 45 | + startTime: '2024-01-01T10:00:00Z', |
| 46 | + endTime: '2024-01-01T10:30:00Z', |
| 47 | + childActivities: [buildActivity({ id: 201, activityCode: '333-r2-g1' })], |
| 48 | + }); |
| 49 | + const distributedRound = buildActivity({ |
| 50 | + id: 3, |
| 51 | + activityCode: '333fm-r1', |
| 52 | + childActivities: [], |
| 53 | + }); |
| 54 | + |
| 55 | + return buildWcifWithEvents( |
| 56 | + [round333, round333Second, distributedRound], |
| 57 | + [ |
| 58 | + buildEvent({ |
| 59 | + id: '333', |
| 60 | + rounds: [ |
| 61 | + buildRound({ id: '333-r1' }), |
| 62 | + buildRound({ |
| 63 | + id: '333-r2', |
| 64 | + results: [{ personId: 1, ranking: 1, attempts: [], best: 0, average: 0 }], |
| 65 | + }), |
| 66 | + ], |
| 67 | + }), |
| 68 | + buildEvent({ |
| 69 | + id: '333fm' as EventId, |
| 70 | + rounds: [buildRound({ id: '333fm-r1' })], |
| 71 | + }), |
| 72 | + ], |
| 73 | + [ |
| 74 | + buildPerson({ |
| 75 | + registrantId: 1, |
| 76 | + registration: registration(1, ['333' as EventId]), |
| 77 | + assignments: [assignment(101, 'competitor'), assignment(102, 'staff-judge')], |
| 78 | + }), |
| 79 | + buildPerson({ |
| 80 | + registrantId: 2, |
| 81 | + registration: registration(2, ['333' as EventId]), |
| 82 | + assignments: [assignment(201, 'competitor')], |
| 83 | + }), |
| 84 | + ] |
| 85 | + ); |
| 86 | +}; |
| 87 | + |
| 88 | +describe('bulkRoundRows', () => { |
| 89 | + it('builds normal non-distributed round review rows', () => { |
| 90 | + const rows = buildBulkRoundRows(buildCompetition()); |
| 91 | + |
| 92 | + expect(rows.map((row) => row.roundId)).toEqual(['333-r1', '333-r2']); |
| 93 | + expect(rows[0]).toMatchObject({ |
| 94 | + label: '333 Round 1', |
| 95 | + roundSize: 2, |
| 96 | + existingGroupCount: 2, |
| 97 | + competitorAssignmentCount: 1, |
| 98 | + staffAssignmentCount: 1, |
| 99 | + warnings: [], |
| 100 | + selectable: true, |
| 101 | + }); |
| 102 | + expect(rows[1]).toMatchObject({ |
| 103 | + roundSize: 1, |
| 104 | + selectable: true, |
| 105 | + }); |
| 106 | + expect(defaultSelectedRoundIds(rows)).toEqual(new Set(['333-r1'])); |
| 107 | + }); |
| 108 | + |
| 109 | + it('orders rows by schedule and merges persisted order with current rounds', () => { |
| 110 | + const rows = buildBulkRoundRows(buildCompetition()); |
| 111 | + |
| 112 | + expect(scheduleOrderedRoundIds(rows)).toEqual(['333-r2', '333-r1']); |
| 113 | + expect(mergeRoundOrder(['333-r2', '333-r1', '222-r1'], ['333-r1', 'stale-r1'])).toEqual([ |
| 114 | + '333-r1', |
| 115 | + '333-r2', |
| 116 | + '222-r1', |
| 117 | + ]); |
| 118 | + }); |
| 119 | +}); |
0 commit comments