Skip to content

Commit

Permalink
Added user drawer test
Browse files Browse the repository at this point in the history
  • Loading branch information
villepynttari committed Jun 28, 2024
1 parent 05fe5a7 commit 79be0b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
33 changes: 6 additions & 27 deletions frontend/src/components/UserDrawer/UserDrawer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
// @ts-nocheck
import React from 'react';
import ReactDOM, { unmountComponentAtNode } from 'react-dom';
import { DateTime } from 'luxon';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import BookingDrawer from './BookingDrawer';
import { render, screen, waitFor } from '@testing-library/react';
import UserDrawer from './UserDrawer';

const fakeRoom = {
id: '123',
name: 'Amor',
building: 'Hermia 5',
capacity: 15,
features: ['TV', 'Whiteboard'],
nextCalendarEvent: DateTime.now().plus({ minutes: 30 }).toUTC().toISO(),
email: '[email protected]'
};
let container = null;

describe('BookingDrawer', () => {
describe('UserDrawer', () => {
beforeEach(() => {
// Setup a DOM element as a render target
container = document.createElement('div');
document.body.appendChild(container);
});

afterEach(() => {
// Cleanup on exiting
container.remove();
container = null;
});
Expand All @@ -36,21 +22,14 @@ describe('BookingDrawer', () => {
<UserDrawer
open={true}
toggle={jest.fn()}
bookRoom={userMock}
room={fakeRoom}
duration={15}
additionalDuration={0}
availableMinutes={30}
onAddTime={jest.fn()}
startingTime={'Now'}
name={'Test user'}
expandedFeaturesAll={jest.fn()}
setExpandedFeaturesAll={jest.fn()}
/>,
container
);

const bookButton = screen.queryByTestId('BookNowButton');
const bookButton = screen.queryByTestId('UserDrawerLogoutButton');
await waitFor(() => expect(bookButton).toBeTruthy());

fireEvent.click(bookButton);
expect(userMock).toBeCalledTimes(1);
});
});
4 changes: 2 additions & 2 deletions frontend/src/components/UserDrawer/UserDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ const UserDrawer = (props: userSettingsProps) => {
<DrawerContent>
<DrawerButtonSecondary
aria-label="settings drawer "
data-testid="BookNowButton"
data-testid="HandleAllFeatureCollapseButton"
onClick={handleAllFeaturesCollapse}
>
<Visibility aria-label="visibility" />
&nbsp;Show room resources
</DrawerButtonSecondary>
<DrawerButtonSecondary
aria-label="logout"
data-testid="Logout"
data-testid="UserDrawerLogoutButton"
onClick={doLogout}
>
<Logout aria-label={'logout'}></Logout>
Expand Down

0 comments on commit 79be0b2

Please sign in to comment.