@@ -20,7 +20,18 @@ const baseRound: Activity = {
2020 extensions : [ ] ,
2121} ;
2222
23- const buildWcif = ( roundActivities : Activity [ ] ) : Competition => ( {
23+ const laterRound : Activity = {
24+ ...baseRound ,
25+ id : 2 ,
26+ name : '333 Round 2' ,
27+ activityCode : '333-r2' ,
28+ startTime : '2024-01-01T11:00:00Z' ,
29+ endTime : '2024-01-01T12:00:00Z' ,
30+ } ;
31+
32+ const buildWcifWithRooms = (
33+ rooms : Array < { id : number ; name ?: string ; activities : Activity [ ] } >
34+ ) : Competition => ( {
2435 schedule : {
2536 startDate : '2024-01-01' ,
2637 numberOfDays : 1 ,
@@ -33,15 +44,13 @@ const buildWcif = (roundActivities: Activity[]): Competition => ({
3344 countryIso2 : 'US' ,
3445 timezone : 'America/New_York' ,
3546 extensions : [ ] ,
36- rooms : [
37- {
38- id : 10 ,
39- name : 'Main Room' ,
40- activities : roundActivities ,
41- color : '#000' ,
42- extensions : [ ] ,
43- } ,
44- ] ,
47+ rooms : rooms . map ( ( { id, name, activities } ) => ( {
48+ id,
49+ name : name ?? `Room ${ id } ` ,
50+ activities,
51+ color : '#000' ,
52+ extensions : [ ] ,
53+ } ) ) ,
4554 } ,
4655 ] ,
4756 } ,
@@ -55,6 +64,9 @@ const buildWcif = (roundActivities: Activity[]): Competition => ({
5564 extensions : [ ] ,
5665} ) ;
5766
67+ const buildWcif = ( roundActivities : Activity [ ] ) : Competition =>
68+ buildWcifWithRooms ( [ { id : 10 , name : 'Main Room' , activities : roundActivities } ] ) ;
69+
5870describe ( 'group helpers' , ( ) => {
5971 it ( 'creates group assignments' , ( ) => {
6072 expect ( createGroupAssignment ( 1 , 2 , 'competitor' , 5 ) ) . toEqual ( {
@@ -106,6 +118,27 @@ describe('group helpers', () => {
106118 expect ( roundWithGroups . childActivities ?. [ 1 ] . startTime ) . toBe ( '2024-01-01T10:30:00.000Z' ) ;
107119 } ) ;
108120
121+ it ( 'splits round durations evenly and increments activity ids across multiple stages' , ( ) => {
122+ const wcif = buildWcif ( [ baseRound , laterRound ] ) ;
123+ const [ firstRound , secondRound ] = createGroupsAcrossStages ( wcif , [ baseRound , laterRound ] , {
124+ spreadGroupsAcrossAllStages : true ,
125+ groups : 3 ,
126+ } ) ;
127+
128+ expect ( firstRound . childActivities ?. map ( ( a ) => a . id ) ) . toEqual ( [ 3 , 4 , 5 ] ) ;
129+ expect ( secondRound . childActivities ?. map ( ( a ) => a . id ) ) . toEqual ( [ 6 , 7 , 8 ] ) ;
130+ expect ( firstRound . childActivities ?. map ( ( a ) => a . startTime ) ) . toEqual ( [
131+ '2024-01-01T10:00:00.000Z' ,
132+ '2024-01-01T10:20:00.000Z' ,
133+ '2024-01-01T10:40:00.000Z' ,
134+ ] ) ;
135+ expect ( firstRound . childActivities ?. map ( ( a ) => a . endTime ) ) . toEqual ( [
136+ '2024-01-01T10:20:00.000Z' ,
137+ '2024-01-01T10:40:00.000Z' ,
138+ '2024-01-01T11:00:00.000Z' ,
139+ ] ) ;
140+ } ) ;
141+
109142 it ( 'creates groups per room when not spreading across stages' , ( ) => {
110143 const wcif = buildWcif ( [ baseRound ] ) ;
111144 const [ roundWithGroups ] = createGroupsAcrossStages ( wcif , [ baseRound ] , {
@@ -119,6 +152,39 @@ describe('group helpers', () => {
119152 ] ) ;
120153 } ) ;
121154
155+ it ( 'uses per-room group counts when not spreading across stages' , ( ) => {
156+ const roomOneRound = { ...baseRound } ;
157+ const roomTwoRound : Activity = {
158+ ...baseRound ,
159+ id : 3 ,
160+ name : '444 Round 1' ,
161+ activityCode : '444-r1' ,
162+ } ;
163+
164+ const wcif = buildWcifWithRooms ( [
165+ { id : 10 , activities : [ roomOneRound ] } ,
166+ { id : 11 , activities : [ roomTwoRound ] } ,
167+ ] ) ;
168+
169+ const [ mainRoomRound , sideRoomRound ] = createGroupsAcrossStages (
170+ wcif ,
171+ [ roomOneRound , roomTwoRound ] ,
172+ {
173+ spreadGroupsAcrossAllStages : false ,
174+ groups : { 10 : 1 , 11 : 3 } ,
175+ }
176+ ) ;
177+
178+ expect ( mainRoomRound . childActivities ?. map ( ( a ) => a . activityCode ) ) . toEqual ( [ '333-r1-g1' ] ) ;
179+ expect ( sideRoomRound . childActivities ?. map ( ( a ) => a . activityCode ) ) . toEqual ( [
180+ '444-r1-g1' ,
181+ '444-r1-g2' ,
182+ '444-r1-g3' ,
183+ ] ) ;
184+ expect ( sideRoomRound . childActivities ?. [ 1 ] . startTime ) . toBe ( '2024-01-01T10:20:00.000Z' ) ;
185+ expect ( sideRoomRound . childActivities ?. [ 2 ] . endTime ) . toBe ( '2024-01-01T11:00:00.000Z' ) ;
186+ } ) ;
187+
122188 it ( 'calculates group sizes for a round id' , ( ) => {
123189 const group1 = {
124190 id : 2 ,
0 commit comments