Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bruceharrison1984 committed Jul 7, 2023
1 parent c41f63a commit 648f036
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 10 additions & 2 deletions packages/Schedulely/__tests__/layouts/EventWeekLayout.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DefaultEvent } from '@/components';
import { EventWeekLayout, getGridEndIndex, getGridStartIndex } from '@/layouts';
import { InternalCalendarEvent } from '@/types';
import { InternalCalendarEvent, WeekDay } from '@/types';
import { RenderResult, fireEvent, render } from '@testing-library/react';
import { vi } from 'vitest';

Expand Down Expand Up @@ -73,7 +73,11 @@ describe('EventWeekLayout', () => {
beforeEach(() => {
mockSetParentContainerRef.mockClear();
testObject = render(
<EventWeekLayout eventsInWeek={events} daysInweek={daysInWeek} />
<EventWeekLayout
eventsInWeek={events}
daysInweek={daysInWeek}
firstDayOfWeek={WeekDay.Sunday}
/>
);
});

Expand Down Expand Up @@ -119,6 +123,10 @@ describe('EventWeekLayout', () => {
expect(mockSetParentContainerRef).toHaveBeenCalledTimes(1));
});

describe.todo(
'replace getGridEndIndex and getGridStartIndex with getEventPosition'
);

describe('getGridEndIndex', () => {
it.each<{ eventEnd: Date; endOfWeek: Date; expected: number }>([
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
CalendarEvent,
InternalCalendarEvent,
} from '@/types/InternalCalendarEvent';
import { InternalCalendarEvent } from '@/types/InternalCalendarEvent';
import { WeekDay } from '@/types';
import {
useActions,
Expand All @@ -16,6 +13,15 @@ export interface EventLayoutProps {
firstDayOfWeek: WeekDay;
}

export const getGridStartIndex = (eventDate: Date, startOfWeek: Date) =>
eventDate <= startOfWeek ? 1 : eventDate.getDay() + 1; //add one because css-grid isn't zero-index'd

export const getGridEndIndex = (eventEndDate: Date, endOfWeek: Date) => {
if (eventEndDate > endOfWeek) return 8;
const end = eventEndDate.getDay() + 2; // add two because css-grid isn't zero index'd, and day of week is zero-index'd
return end;
};

export const getEventPosition = (
{ start, end }: InternalCalendarEvent,
daysInWeek: Date[],
Expand Down

0 comments on commit 648f036

Please sign in to comment.