-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from Vincit/ilkka-duration-startingtime-tests…
…-and-more Ilkka duration startingtime and duration custom buttons & tests and more
- Loading branch information
Showing
11 changed files
with
350 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
frontend/src/components/BookingDrawer/DurationPicker.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* @vitest-environment happy-dom | ||
*/ | ||
|
||
// @ts-nocheck | ||
import { | ||
vi, | ||
expect, | ||
describe, | ||
it, | ||
beforeEach, | ||
afterEach, | ||
beforeAll, | ||
afterAll | ||
} from 'vitest'; | ||
|
||
// @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 DurationPicker from './DurationPicker'; | ||
|
||
let container = null; | ||
|
||
const testObj = { | ||
setExpandDurationTimePickerDrawer: (arg) => {} | ||
}; | ||
|
||
describe('Duration selection', () => { | ||
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; | ||
}); | ||
|
||
test('Custom duration can be selected', async () => { | ||
const handleDurationChange = vi.fn(); | ||
|
||
const spy = vi.spyOn(testObj, 'setExpandDurationTimePickerDrawer'); | ||
|
||
render( | ||
<DurationPicker | ||
bookingDuration={0} | ||
onChange={handleDurationChange} | ||
setExpandDurationTimePickerDrawer={spy} | ||
additionalDuration={0} | ||
/>, | ||
container | ||
); | ||
|
||
const customButton = screen.queryByTestId('DurationPickerCustom'); | ||
|
||
fireEvent.click(customButton); | ||
|
||
expect(testObj.setExpandDurationTimePickerDrawer).toBeCalledTimes(1); | ||
expect(testObj.setExpandDurationTimePickerDrawer).toHaveBeenCalledWith( | ||
true | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
frontend/src/components/DurationTimePickerDrawer/DurationTimePickerDrawer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/** | ||
* @vitest-environment happy-dom | ||
*/ | ||
|
||
// @ts-nocheck | ||
import { | ||
vi, | ||
expect, | ||
describe, | ||
it, | ||
beforeEach, | ||
afterEach, | ||
beforeAll, | ||
afterAll | ||
} from 'vitest'; | ||
|
||
// @ts-nocheck | ||
import React from 'react'; | ||
import ReactDOM, { unmountComponentAtNode } from 'react-dom'; | ||
import { DateTime } from 'luxon'; | ||
import { | ||
fireEvent, | ||
render, | ||
screen, | ||
waitFor, | ||
getByLabelText, | ||
getByText | ||
} from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import DurationTimePickerDrawer from './DurationTimePickerDrawer'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import dayjs from 'dayjs'; | ||
import { prettyDOM } from '@testing-library/dom'; | ||
|
||
let container = null; | ||
|
||
const testObj = { | ||
setExpandDurationTimePickerDrawer: (arg) => {}, | ||
setBookingDuration: vi.fn() | ||
}; | ||
|
||
describe('Duration selection from picker', () => { | ||
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; | ||
}); | ||
|
||
test('test with value 01:45 is selected when confirmed', () => { | ||
const handleDurationChange = vi.fn(); | ||
|
||
const spy = vi.spyOn(testObj, 'setExpandDurationTimePickerDrawer'); | ||
const spyDur = vi.spyOn(testObj, 'setBookingDuration'); | ||
|
||
const mm = 300; | ||
const maxDur = dayjs() | ||
.minute(mm % 60) | ||
.hour(Math.floor(mm / 60)); | ||
|
||
render( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DurationTimePickerDrawer | ||
open={true} | ||
toggle={(newOpen: any) => | ||
setExpandDurationTimePickerDrawer(newOpen) | ||
} | ||
bookingDuration={0} | ||
setBookingDuration={testObj.setBookingDuration} | ||
setExpandDurationTimePickerDrawer={ | ||
testObj.setExpandDurationTimePickerDrawer | ||
} | ||
maxDuration={maxDur} | ||
/> | ||
</LocalizationProvider>, | ||
container | ||
); | ||
|
||
const clock = screen.getByTestId('CustomDurationClock'); | ||
const minutes = getByLabelText(clock, 'Select minutes'); | ||
const min45 = getByText(minutes, '45'); | ||
fireEvent.click(min45); | ||
const hours = getByLabelText(clock, 'Select hours'); | ||
const hour1 = getByText(hours, '01'); | ||
fireEvent.click(hour1); | ||
|
||
const btn = screen.getByRole('button'); | ||
|
||
fireEvent.click(btn); | ||
|
||
expect(testObj.setExpandDurationTimePickerDrawer).toBeCalledTimes(1); | ||
expect(testObj.setExpandDurationTimePickerDrawer).toHaveBeenCalledWith( | ||
false | ||
); | ||
expect(testObj.setBookingDuration).toBeCalledTimes(1); | ||
expect(testObj.setBookingDuration).toHaveBeenCalledWith(105); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.