Skip to content

Commit

Permalink
Merge pull request #180 from Vincit/feature/ilkka-advanced-booking
Browse files Browse the repository at this point in the history
Feature/ilkka advanced booking
  • Loading branch information
iltelko2 authored Jul 23, 2024
2 parents 3956139 + c77fd80 commit 039a66e
Show file tree
Hide file tree
Showing 16 changed files with 1,154 additions and 675 deletions.
198 changes: 7 additions & 191 deletions frontend/src/components/AvailableRoomList/AvailableRoomList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ describe('AvailableRoomList', () => {
setExpandTimePickerDrawer: vi.fn(),
setPreferences: vi.fn(),
setStartingTime: vi.fn(),
updateData: vi.fn()
updateData: vi.fn(),
bookingLoading: 'false',
handleCardClick: (room: Room) => {
availableRoomDefaultMocks.expandTimePickerDrawer = true;
availableRoomDefaultMocks.selectedRoom = room;
},
selectedRoom: fakeRooms[0]
};
it('renders room data', async () => {
render(
Expand Down Expand Up @@ -199,194 +205,4 @@ describe('AvailableRoomList', () => {
const items = screen.queryAllByTestId('AvailableRoomListCard');
await waitFor(() => expect(items).toHaveLength(1));
});

it('renders booking drawer', async () => {
render(
<AvailableRoomList
rooms={fakeRooms}
bookings={fakeBookings}
bookingDuration={15}
startingTime="Now"
expandedFeaturesAll
{...availableRoomDefaultMocks}
/>,
container
);

const card = screen.queryAllByTestId('CardActiveArea')[0];
await waitFor(() => expect(card).toBeTruthy());

fireEvent.click(card);

const drawer = screen.queryAllByTestId('BookingDrawer')[0];
await waitFor(() => expect(drawer).toBeTruthy());
});

it('default books for a room for 15 minutes', async () => {
const startTime = now.toUTC().toISO();
mockedMakeBooking.mockResolvedValueOnce({
duration: 15,
roomId: fakeRooms[0].id,
startTime: startTime,
title: 'Reservation from Get a Room!'
});

render(
<AvailableRoomList
rooms={fakeRooms}
bookings={fakeBookings}
bookingDuration={15}
startingTime="Now"
expandedFeaturesAll
{...availableRoomDefaultMocks}
/>,
container
);

const card = screen.queryAllByTestId('CardActiveArea');
fireEvent.click(card[0]);
const bookButton = screen.queryByTestId('BookNowButton');
if (!bookButton) {
throw new Error('No book button');
}
fireEvent.click(bookButton);

await waitFor(() =>
expect(mockedMakeBooking).toHaveBeenCalledWith(
{
duration: 15,
roomId: fakeRooms[0].id,
startTime: startTime,
title: 'Reservation from Get a Room!'
},
true
)
);
});

it('books for a room for 30 minutes', async () => {
const startTime = now.toUTC().toISO();
mockedMakeBooking.mockResolvedValueOnce({
duration: 30,
roomId: fakeRooms[0].id,
startTime: startTime,
title: 'Reservation from Get a Room!'
});

render(
<AvailableRoomList
rooms={fakeRooms}
bookings={fakeBookings}
bookingDuration={30}
startingTime="Now"
expandedFeaturesAll
{...availableRoomDefaultMocks}
/>,
container
);

const card = screen.queryAllByTestId('CardActiveArea');
fireEvent.click(card[0]);
const bookButton = screen.queryByTestId('BookNowButton');
if (!bookButton) {
throw new Error('Button not found');
}
fireEvent.click(bookButton);

await waitFor(() =>
expect(makeBooking).toHaveBeenCalledWith(
{
duration: 30,
roomId: fakeRooms[0].id,
startTime: startTime,
title: 'Reservation from Get a Room!'
},
true
)
);
});

it('books for a room for 60 minutes', async () => {
const startTime = now.toUTC().toISO();
mockedMakeBooking.mockResolvedValueOnce({
duration: 30,
roomId: fakeRooms[0].id,
startTime: startTime,
title: 'Reservation from Get a Room!'
});

const { container: HTMLElement } = render(
<AvailableRoomList
rooms={fakeRooms}
bookings={fakeBookings}
bookingDuration={60}
startingTime="Now"
expandedFeaturesAll
{...availableRoomDefaultMocks}
/>,
container
);

const card = screen.queryAllByTestId('CardActiveArea');
fireEvent.click(card[0]);
const bookButton = screen.queryByTestId('BookNowButton');
if (!bookButton) {
throw new Error('Button not found');
}
fireEvent.click(bookButton);

await waitFor(() =>
expect(mockedMakeBooking).toHaveBeenCalledWith(
{
duration: 60,
roomId: fakeRooms[0].id,
startTime: startTime,
title: 'Reservation from Get a Room!'
},
true
)
);
});

it('books for a room for 120 minutes', async () => {
const startTime = now.toUTC().toISO();
mockedMakeBooking.mockResolvedValueOnce({
duration: 30,
roomId: fakeRooms[0].id,
startTime: startTime,
title: 'Reservation from Get a Room!'
});

render(
<AvailableRoomList
rooms={fakeRooms}
bookings={fakeBookings}
bookingDuration={120}
startingTime="Now"
expandedFeaturesAll
{...availableRoomDefaultMocks}
/>,
container
);

const card = screen.queryAllByTestId('CardActiveArea');
fireEvent.click(card[0]);
const bookButton = screen.queryByTestId('BookNowButton');
if (!bookButton) {
throw new Error('Button not found');
}
fireEvent.click(bookButton);

await waitFor(() =>
expect(mockedMakeBooking).toHaveBeenCalledWith(
{
duration: 120,
roomId: fakeRooms[0].id,
startTime: startTime,
title: 'Reservation from Get a Room!'
},
true
)
);
});
});
Loading

0 comments on commit 039a66e

Please sign in to comment.