1
1
import React from 'react' ;
2
- import { render , fireEvent , screen } from '@testing-library/react' ;
2
+ import { render , fireEvent , screen , within } from '@testing-library/react' ;
3
3
import '@testing-library/jest-dom/extend-expect' ;
4
4
5
5
import { server } from '../../../test/server.mock' ;
6
- import { createFakeOfficeWithSlots , createFakeSystemAdminUser } from '../../../test/data' ;
6
+ import {
7
+ createFakeConfig ,
8
+ createFakeOfficeWithSlots ,
9
+ createFakeSystemAdminUser ,
10
+ } from '../../../test/data' ;
7
11
import { TestContext } from '../../../test/TestContext' ;
8
- import { mockGetBookings , mockGetOffice , mockGetOffices } from '../../../test/handlers' ;
12
+ import {
13
+ mockGetBookings ,
14
+ mockGetConfig ,
15
+ mockGetOffice ,
16
+ mockGetOffices ,
17
+ } from '../../../test/handlers' ;
9
18
10
19
import Home from './Home' ;
11
20
12
21
test ( 'Selecting an office' , async ( ) => {
13
- const office = createFakeOfficeWithSlots ( ) ;
14
- const user = createFakeSystemAdminUser ( [ office ] ) ;
15
- server . use ( mockGetOffices ( [ office ] ) , mockGetBookings ( [ ] ) , mockGetOffice ( office ) ) ;
22
+ const config = createFakeConfig ( ) ;
23
+ const office = createFakeOfficeWithSlots ( config ) ;
24
+ const user = createFakeSystemAdminUser ( [ office ] , { quota : 2 } ) ;
25
+ server . use (
26
+ mockGetConfig ( config ) ,
27
+ mockGetOffices ( [ office ] ) ,
28
+ mockGetBookings ( [ ] ) ,
29
+ mockGetOffice ( office )
30
+ ) ;
16
31
render (
17
32
< TestContext user = { user } >
18
33
< Home />
@@ -21,11 +36,20 @@ test('Selecting an office', async () => {
21
36
22
37
await screen . findByRole ( 'heading' , { level : 2 , name : 'Select your office' } ) ;
23
38
24
- fireEvent . click ( screen . getByRole ( 'button' , { name : office . name } ) ) ;
39
+ const main = within ( screen . getByRole ( 'main' ) ) ;
40
+
41
+ fireEvent . click ( main . getByRole ( 'button' , { name : office . name } ) ) ;
25
42
26
- await screen . findByRole ( 'heading' , { level : 2 , name : office . name } ) ;
27
- expect ( screen . getByText ( / Y o u c a n m a k e / i) ) . toHaveTextContent ( `You can make 5 booking per week` ) ;
28
- expect ( screen . getByText ( / d a i l y c a p a c i t y / i) ) . toHaveTextContent (
29
- `The Office has a daily capacity of 100 and car park capacity of 100.`
43
+ await main . findByRole ( 'heading' , { level : 2 , name : office . name } ) ;
44
+ expect ( main . getByText ( / Y o u c a n m a k e / i) ) . toHaveTextContent (
45
+ `You can make ${ user . quota } booking per week`
46
+ ) ;
47
+ expect ( main . getByText ( / d a i l y c a p a c i t y / i) ) . toHaveTextContent (
48
+ `The Office has a daily capacity of ${ office . quota } and car park capacity of ${ office . parkingQuota } .`
30
49
) ;
50
+ expect ( main . getByText ( / b o o k i n g s r e m a i n i n g / i) ) . toHaveTextContent (
51
+ `${ user . quota } bookings remaining`
52
+ ) ;
53
+
54
+ await main . findAllByRole ( 'button' , { name : 'Book' } ) ;
31
55
} ) ;
0 commit comments