1
- import { render , screen } from '@testing-library/react'
1
+ import { render , screen , within } from '@testing-library/react'
2
2
import userEvent from '@testing-library/user-event'
3
3
import { createMemoryHistory } from 'history'
4
4
import React from 'react'
@@ -58,7 +58,7 @@ describe('Report Incident', () => {
58
58
}
59
59
it ( 'renders a department form element that allows user input' , async ( ) => {
60
60
setup ( [ Permissions . ViewIncident , Permissions . ResolveIncident ] )
61
- const departmentInput = await screen . findByPlaceholderText ( / i n c i d e n t s \. r e p o r t s \. d e p a r t m e n t / i)
61
+ const departmentInput = screen . getByLabelText ( / i n c i d e n t s \. r e p o r t s \. d e p a r t m e n t / i)
62
62
63
63
expect ( departmentInput ) . toBeEnabled ( )
64
64
expect ( departmentInput ) . toBeInTheDocument ( )
@@ -67,9 +67,9 @@ describe('Report Incident', () => {
67
67
expect ( departmentInput ) . toHaveDisplayValue ( 'Engineering Bay' )
68
68
} )
69
69
70
- test ( 'renders a category form element that allows user input' , async ( ) => {
70
+ it ( 'renders a category form element that allows user input' , async ( ) => {
71
71
setup ( [ Permissions . ViewIncident , Permissions . ResolveIncident ] )
72
- const categoryInput = await screen . findByPlaceholderText ( / i n c i d e n t s \. r e p o r t s \. c a t e g o r y \b / i)
72
+ const categoryInput = screen . getByLabelText ( / i n c i d e n t s \. r e p o r t s \. c a t e g o r y \b / i)
73
73
74
74
expect ( categoryInput ) . toBeEnabled ( )
75
75
expect ( categoryInput ) . toBeInTheDocument ( )
@@ -78,11 +78,9 @@ describe('Report Incident', () => {
78
78
expect ( categoryInput ) . toHaveDisplayValue ( 'Warp Engine' )
79
79
} )
80
80
81
- test ( 'renders a category item form element that allows user input' , async ( ) => {
81
+ it ( 'renders a category item form element that allows user input' , async ( ) => {
82
82
setup ( [ Permissions . ViewIncident , Permissions . ResolveIncident ] )
83
- const categoryItemInput = await screen . findByPlaceholderText (
84
- / i n c i d e n t s \. r e p o r t s \. c a t e g o r y i t e m / i,
85
- )
83
+ const categoryItemInput = screen . getByLabelText ( / i n c i d e n t s \. r e p o r t s \. c a t e g o r y i t e m / i)
86
84
87
85
expect ( categoryItemInput ) . toBeInTheDocument ( )
88
86
expect ( categoryItemInput ) . toBeEnabled ( )
@@ -91,38 +89,38 @@ describe('Report Incident', () => {
91
89
expect ( categoryItemInput ) . toHaveDisplayValue ( 'Warp Coil' )
92
90
} )
93
91
94
- test ( 'renders a description formField element that allows user input' , async ( ) => {
92
+ it ( 'renders a description formField element that allows user input' , async ( ) => {
95
93
setup ( [ Permissions . ViewIncident , Permissions . ResolveIncident ] )
96
- const inputArr = await screen . findAllByRole ( 'textbox' , { name : / r e q u i r e d / i } )
97
- const descriptionInput = inputArr [ inputArr . length - 1 ]
94
+ const descriptionInput = screen . getByLabelText ( / i n c i d e n t s \. r e p o r t s \. d e s c r i p t i o n / i)
98
95
99
96
expect ( descriptionInput ) . toBeInTheDocument ( )
100
97
expect ( descriptionInput ) . toBeEnabled ( )
101
98
102
99
userEvent . type ( descriptionInput , 'Geordi requested analysis' )
103
100
expect ( descriptionInput ) . toHaveDisplayValue ( 'Geordi requested analysis' )
104
101
} )
105
- test ( ' renders action save button after all the input fields are filled out' , async ( ) => {
106
- setup ( [ Permissions . ViewIncident , Permissions . ResolveIncident ] )
107
- const departmentInput = await screen . findByPlaceholderText ( / i n c i d e n t s \. r e p o r t s \. d e p a r t m e n t / i)
108
- const categoryInput = await screen . findByPlaceholderText ( / i n c i d e n t s \. r e p o r t s \. c a t e g o r y \b / i)
109
- const categoryItemInput = await screen . findByPlaceholderText (
110
- / i n c i d e n t s \. r e p o r t s \. c a t e g o r y i t e m / i,
111
- )
112
- const inputArr = await screen . findAllByRole ( 'textbox' , { name : / r e q u i r e d / i } )
113
- const descriptionInput = inputArr [ inputArr . length - 1 ]
114
102
115
- userEvent . type ( departmentInput , 'Engineering Bay' )
116
- userEvent . type ( categoryInput , 'Warp Engine' )
117
- userEvent . type ( categoryItemInput , 'Warp Coil' )
118
- userEvent . type ( descriptionInput , 'Geordi requested analysis' )
103
+ // ! Remove test? Save button is always rendered regardless of input values
104
+ // it(' renders action save button after all the input fields are filled out', async () => {
105
+ // setup([Permissions.ViewIncident, Permissions.ResolveIncident])
119
106
120
- userEvent . click (
121
- screen . getByRole ( 'button' , {
122
- name : / i n c i d e n t s \. r e p o r t s \. n e w / i,
123
- } ) ,
124
- )
125
- } )
107
+ // expect(screen.queryByRole('button', { name: /incidents\.reports\.new/i })).not.toBeInTheDocument()
108
+ // const departmentInput = screen.getByLabelText(/incidents\.reports\.department/i)
109
+ // const categoryInput = screen.getByLabelText(/incidents\.reports\.category\b/i)
110
+ // const categoryItemInput = screen.getByLabelText(/incidents\.reports\.categoryitem/i)
111
+ // const descriptionInput = screen.getByLabelText(/incidents\.reports\.description/i)
112
+
113
+ // userEvent.type(departmentInput, 'Engineering Bay')
114
+ // userEvent.type(categoryInput, 'Warp Engine')
115
+ // userEvent.type(categoryItemInput, 'Warp Coil')
116
+ // userEvent.type(descriptionInput, 'Geordi requested analysis')
117
+
118
+ // userEvent.click(
119
+ // screen.getByRole('button', {
120
+ // name: /incidents\.reports\.new/i,
121
+ // }),
122
+ // )
123
+ // })
126
124
127
125
it ( 'should display errors if validation fails' , async ( ) => {
128
126
const error = {
@@ -144,14 +142,13 @@ describe('Report Incident', () => {
144
142
} ) ,
145
143
)
146
144
147
- const departmentInput = await screen . findByPlaceholderText ( / i n c i d e n t s \. r e p o r t s \. d e p a r t m e n t / i)
148
- const categoryInput = await screen . findByPlaceholderText ( / i n c i d e n t s \. r e p o r t s \. c a t e g o r y \b / i)
149
- const categoryItemInput = await screen . findByPlaceholderText (
150
- / i n c i d e n t s \. r e p o r t s \. c a t e g o r y i t e m / i,
145
+ const departmentInput = screen . getByLabelText ( / i n c i d e n t s \. r e p o r t s \. d e p a r t m e n t / i)
146
+ const categoryInput = screen . getByLabelText ( / i n c i d e n t s \. r e p o r t s \. c a t e g o r y \b / i)
147
+ const categoryItemInput = screen . getByLabelText ( / i n c i d e n t s \. r e p o r t s \. c a t e g o r y i t e m / i)
148
+ const descriptionInput = screen . getByLabelText ( / i n c i d e n t s \. r e p o r t s \. d e s c r i p t i o n / i)
149
+ const dateInput = within ( await screen . findByTestId ( 'dateOfIncidentDateTimePicker' ) ) . getByRole (
150
+ 'textbox' ,
151
151
)
152
- const inputArr = await screen . findAllByRole ( 'textbox' )
153
- const descriptionInput = inputArr [ inputArr . length - 2 ]
154
- const dateInput = inputArr [ 0 ]
155
152
156
153
const invalidInputs = container . querySelectorAll ( '.is-invalid' )
157
154
expect ( invalidInputs ) . toHaveLength ( 5 )
0 commit comments