Refactors layout engine tests to use arrays
Updates tests to use arrays instead of Maps for storing layouts. This simplifies the data structures and allows for more straightforward assertions.
This commit is contained in:
parent
6ccc071587
commit
7fc401b1df
2 changed files with 20 additions and 22 deletions
|
|
@ -102,11 +102,11 @@ describe('AllDay Layout Engine - Pure Data Tests', () => {
|
||||||
const layouts = layoutEngine.calculateLayout(testCase.events);
|
const layouts = layoutEngine.calculateLayout(testCase.events);
|
||||||
|
|
||||||
// Verify we got layouts for all events
|
// Verify we got layouts for all events
|
||||||
expect(layouts.size).toBe(testCase.events.length);
|
expect(layouts.length).toBe(testCase.events.length);
|
||||||
|
|
||||||
// Check each expected result
|
// Check each expected result
|
||||||
testCase.expected.forEach(expected => {
|
testCase.expected.forEach(expected => {
|
||||||
const actualLayout = layouts.get(expected.id);
|
const actualLayout = layouts.find(layout => layout.calenderEvent.id === expected.id);
|
||||||
expect(actualLayout).toBeDefined();
|
expect(actualLayout).toBeDefined();
|
||||||
expect(actualLayout!.gridArea).toBe(expected.gridArea);
|
expect(actualLayout!.gridArea).toBe(expected.gridArea);
|
||||||
});
|
});
|
||||||
|
|
@ -168,16 +168,16 @@ describe('AllDay Layout Engine - Partial Week Views', () => {
|
||||||
const layouts = engine.calculateLayout(events);
|
const layouts = engine.calculateLayout(events);
|
||||||
|
|
||||||
// Both events are now visible since '112' ends on Wednesday (visible range start)
|
// Both events are now visible since '112' ends on Wednesday (visible range start)
|
||||||
expect(layouts.size).toBe(2);
|
expect(layouts.length).toBe(2);
|
||||||
expect(layouts.has('112')).toBe(true); // Now visible since it ends on Wed
|
expect(layouts.some(layout => layout.calenderEvent.id === '112')).toBe(true); // Now visible since it ends on Wed
|
||||||
expect(layouts.has('113')).toBe(true); // Still visible
|
expect(layouts.some(layout => layout.calenderEvent.id === '113')).toBe(true); // Still visible
|
||||||
|
|
||||||
const layout112 = layouts.get('112')!;
|
const layout112 = layouts.find(layout => layout.calenderEvent.id === '112')!;
|
||||||
expect(layout112.startColumn).toBe(1); // Clipped to Wed (first visible day)
|
expect(layout112.startColumn).toBe(1); // Clipped to Wed (first visible day)
|
||||||
expect(layout112.endColumn).toBe(1); // Wed only
|
expect(layout112.endColumn).toBe(1); // Wed only
|
||||||
expect(layout112.row).toBe(1);
|
expect(layout112.row).toBe(1);
|
||||||
|
|
||||||
const layout113 = layouts.get('113')!;
|
const layout113 = layouts.find(layout => layout.calenderEvent.id === '113')!;
|
||||||
expect(layout113.startColumn).toBe(2); // Thursday = column 2 in Wed-Fri view
|
expect(layout113.startColumn).toBe(2); // Thursday = column 2 in Wed-Fri view
|
||||||
expect(layout113.endColumn).toBe(3); // Friday = column 3
|
expect(layout113.endColumn).toBe(3); // Friday = column 3
|
||||||
expect(layout113.row).toBe(1);
|
expect(layout113.row).toBe(1);
|
||||||
|
|
@ -211,17 +211,17 @@ describe('AllDay Layout Engine - Partial Week Views', () => {
|
||||||
|
|
||||||
const layouts = engine.calculateLayout(events);
|
const layouts = engine.calculateLayout(events);
|
||||||
|
|
||||||
expect(layouts.size).toBe(2);
|
expect(layouts.length).toBe(2);
|
||||||
|
|
||||||
// First event should be clipped to start at Wed (column 1) and end at Fri (column 3)
|
// First event should be clipped to start at Wed (column 1) and end at Fri (column 3)
|
||||||
const firstLayout = layouts.get('114')!;
|
const firstLayout = layouts.find(layout => layout.calenderEvent.id === '114')!;
|
||||||
expect(firstLayout.startColumn).toBe(1); // Clipped to Wed (first visible day)
|
expect(firstLayout.startColumn).toBe(1); // Clipped to Wed (first visible day)
|
||||||
expect(firstLayout.endColumn).toBe(3); // Fri (now ends on Friday due to 2025-09-26T00:00:00)
|
expect(firstLayout.endColumn).toBe(3); // Fri (now ends on Friday due to 2025-09-26T00:00:00)
|
||||||
expect(firstLayout.columnSpan).toBe(3);
|
expect(firstLayout.columnSpan).toBe(3);
|
||||||
expect(firstLayout.gridArea).toBe('1 / 1 / 2 / 4');
|
expect(firstLayout.gridArea).toBe('1 / 1 / 2 / 4');
|
||||||
|
|
||||||
// Second event should span Thu-Fri, but clipped beyond visible range
|
// Second event should span Thu-Fri, but clipped beyond visible range
|
||||||
const secondLayout = layouts.get('115')!;
|
const secondLayout = layouts.find(layout => layout.calenderEvent.id === '115')!;
|
||||||
expect(secondLayout.startColumn).toBe(2); // Thu (actual start date) = column 2 in Wed-Fri view
|
expect(secondLayout.startColumn).toBe(2); // Thu (actual start date) = column 2 in Wed-Fri view
|
||||||
expect(secondLayout.endColumn).toBe(3); // Clipped to Fri (last visible day) = column 3
|
expect(secondLayout.endColumn).toBe(3); // Clipped to Fri (last visible day) = column 3
|
||||||
expect(secondLayout.columnSpan).toBe(2);
|
expect(secondLayout.columnSpan).toBe(2);
|
||||||
|
|
@ -256,11 +256,11 @@ describe('AllDay Layout Engine - Partial Week Views', () => {
|
||||||
|
|
||||||
const layouts = engine.calculateLayout(events);
|
const layouts = engine.calculateLayout(events);
|
||||||
|
|
||||||
expect(layouts.size).toBe(1); // Only Monday event should be included - weekend event should be filtered out
|
expect(layouts.length).toBe(1); // Only Monday event should be included - weekend event should be filtered out
|
||||||
expect(layouts.has('116')).toBe(true); // Monday event should be included
|
expect(layouts.some(layout => layout.calenderEvent.id === '116')).toBe(true); // Monday event should be included
|
||||||
expect(layouts.has('117')).toBe(false); // Weekend event should be filtered out
|
expect(layouts.some(layout => layout.calenderEvent.id === '117')).toBe(false); // Weekend event should be filtered out
|
||||||
|
|
||||||
const mondayLayout = layouts.get('116')!;
|
const mondayLayout = layouts.find(layout => layout.calenderEvent.id === '116')!;
|
||||||
expect(mondayLayout.startColumn).toBe(1); // Monday = column 1
|
expect(mondayLayout.startColumn).toBe(1); // Monday = column 1
|
||||||
expect(mondayLayout.endColumn).toBe(2); // Now ends on Tuesday due to 2025-09-23T00:00:00
|
expect(mondayLayout.endColumn).toBe(2); // Now ends on Tuesday due to 2025-09-23T00:00:00
|
||||||
expect(mondayLayout.row).toBe(1);
|
expect(mondayLayout.row).toBe(1);
|
||||||
|
|
|
||||||
|
|
@ -18,26 +18,24 @@ describe('AllDayManager - Manager Functionality', () => {
|
||||||
|
|
||||||
const layouts = allDayManager.calculateAllDayEventsLayout([event], weekDates);
|
const layouts = allDayManager.calculateAllDayEventsLayout([event], weekDates);
|
||||||
|
|
||||||
expect(layouts.size).toBe(1);
|
expect(layouts.length).toBe(1);
|
||||||
expect(layouts.has('test')).toBe(true);
|
expect(layouts[0].calenderEvent.id).toBe('test');
|
||||||
|
expect(layouts[0].startColumn).toBe(3); // Sept 24 is column 3
|
||||||
const layout = layouts.get('test');
|
expect(layouts[0].row).toBe(1);
|
||||||
expect(layout?.startColumn).toBe(3); // Sept 24 is column 3
|
|
||||||
expect(layout?.row).toBe(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle empty event list', () => {
|
it('should handle empty event list', () => {
|
||||||
const weekDates = ['2024-09-22', '2024-09-23', '2024-09-24', '2024-09-25', '2024-09-26'];
|
const weekDates = ['2024-09-22', '2024-09-23', '2024-09-24', '2024-09-25', '2024-09-26'];
|
||||||
const layouts = allDayManager.calculateAllDayEventsLayout([], weekDates);
|
const layouts = allDayManager.calculateAllDayEventsLayout([], weekDates);
|
||||||
|
|
||||||
expect(layouts.size).toBe(0);
|
expect(layouts.length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle empty week dates', () => {
|
it('should handle empty week dates', () => {
|
||||||
const event = createMockEvent('test', 'Test Event', '2024-09-24', '2024-09-24');
|
const event = createMockEvent('test', 'Test Event', '2024-09-24', '2024-09-24');
|
||||||
const layouts = allDayManager.calculateAllDayEventsLayout([event], []);
|
const layouts = allDayManager.calculateAllDayEventsLayout([event], []);
|
||||||
|
|
||||||
expect(layouts.size).toBe(0);
|
expect(layouts.length).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue