Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/containers/PersonalSchedule/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Competition, Person } from '@wca/helpers';
import { parseActivityCodeFlexible } from '@/lib/activityCodes';
import { formatBriefActivityName, getAllAssignments, getGroupedAssignmentsByDate } from './utils';

jest.mock('@/i18n', () => ({
__esModule: true,
default: {
t: (key: string) => key,
},
t: (key: string) => key,
}));

const wcif = {
id: 'WC2025',
schedule: {
venues: [
{
id: 1,
name: 'Venue',
timezone: 'America/Los_Angeles',
rooms: [],
},
],
},
events: [],
} as unknown as Competition;

const worldsAssignmentsPerson = {
registrantId: 215,
assignments: [],
registration: {
eventIds: [],
},
extensions: [
{
id: 'com.competitiongroups.worldsassignments',
data: {
assignments: [
{
staff: 'Stage Stream - Main',
startTime: '2025-07-03T18:00:00Z',
endTime: '2025-07-03T19:00:00Z',
},
],
},
},
],
} as unknown as Person;

describe('PersonalSchedule utils', () => {
it('creates parse-safe activities for worlds assignments with free-form staff names', () => {
const [assignment] = getAllAssignments(wcif, worldsAssignmentsPerson);

expect(assignment.activity).toBeDefined();
const activity = assignment.activity!;

expect(activity.activityCode).toBe('other-misc');
expect(() => parseActivityCodeFlexible(activity.activityCode)).not.toThrow();
expect(formatBriefActivityName(activity)).toBe('Stage Stream - Main');
});

it('includes days that only have worlds assignments', () => {
const [scheduleDay] = getGroupedAssignmentsByDate(wcif, worldsAssignmentsPerson);

expect(scheduleDay.date).toBe('Thursday, 7/3/2025');
expect(scheduleDay.assignments).toHaveLength(1);
expect(scheduleDay.assignments[0].assignment.assignmentCode).toBe('Stage Stream - Main');
});
});
11 changes: 1 addition & 10 deletions src/containers/PersonalSchedule/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const getExtraAssignments = (person: Person) => {
activityId: -1,
stationNumber: null,
activity: {
activityCode: 'other-' + assignment.staff,
activityCode: 'other-misc',
startTime: assignment.startTime,
endTime: assignment.endTime,
childActivities: [],
Expand Down Expand Up @@ -148,15 +148,6 @@ export const getGroupedAssignmentsByDate = (wcif: Competition, person: Person) =

const scheduledDays = allAssignments
.map((a) => {
if (a.type === 'extra') {
return {
approxDateTime: 0,
date: '',
dateParts: [],
assignments: [],
};
}

if (!a.activity) {
return {
approxDateTime: 0,
Expand Down
Loading