@@ -7,12 +7,10 @@ import {
7
7
MockTemplateVersionVariable1 ,
8
8
MockTemplateVersionVariable2 ,
9
9
MockTemplateVersionVariable3 ,
10
- MockTemplateVersionVariable4 ,
11
- MockTemplateVersionVariable5 ,
12
10
renderWithAuth ,
13
11
} from "testHelpers/renderHelpers"
14
12
import CreateTemplatePage from "./CreateTemplatePage"
15
- import { screen , waitFor } from "@testing-library/react"
13
+ import { screen , waitFor , within } from "@testing-library/react"
16
14
import userEvent from "@testing-library/user-event"
17
15
import * as API from "api/api"
18
16
@@ -55,19 +53,19 @@ test("Create template with variables", async () => {
55
53
MockTemplateVersionVariable1 ,
56
54
MockTemplateVersionVariable2 ,
57
55
MockTemplateVersionVariable3 ,
58
- MockTemplateVersionVariable4 ,
59
- MockTemplateVersionVariable5 ,
60
56
] )
61
57
62
58
// Render page, fill the name and submit
63
- const { router } = await renderPage ( )
59
+ const { router, container } = await renderPage ( )
60
+ const form = container . querySelector ( "form" ) as HTMLFormElement
64
61
await userEvent . type ( screen . getByLabelText ( / N a m e / ) , "my-template" )
65
62
await userEvent . click (
66
- screen . getByRole ( "button" , { name : / c r e a t e t e m p l a t e / i } ) ,
63
+ within ( form ) . getByRole ( "button" , { name : / c r e a t e t e m p l a t e / i } ) ,
67
64
)
68
65
69
66
// Wait for the variables form to be rendered and fill it
70
67
await screen . findByText ( / V a r i a b l e s / )
68
+
71
69
// Type first variable
72
70
await userEvent . clear ( screen . getByLabelText ( / v a r .f i r s t _ v a r i a b l e / ) )
73
71
await userEvent . type (
@@ -79,28 +77,15 @@ test("Create template with variables", async () => {
79
77
await userEvent . type ( screen . getByLabelText ( / v a r .s e c o n d _ v a r i a b l e / ) , "2" )
80
78
// Select third variable on radio
81
79
await userEvent . click ( screen . getByLabelText ( / T r u e / ) )
82
- // Type fourth variable
83
- await userEvent . clear ( screen . getByLabelText ( / v a r .f o u r t h _ v a r i a b l e / ) )
84
- await userEvent . type (
85
- screen . getByLabelText ( / v a r .f o u r t h _ v a r i a b l e / ) ,
86
- "Fourth value" ,
87
- )
88
- // Type fifth variable
89
- await userEvent . clear ( screen . getByLabelText ( / v a r .f i f t h _ v a r i a b l e / ) )
90
- await userEvent . type (
91
- screen . getByLabelText ( / v a r .f i f t h _ v a r i a b l e / ) ,
92
- "Fifth value" ,
93
- )
94
80
// Setup the mock for the second template version creation before submit the form
95
81
jest . clearAllMocks ( )
96
82
jest
97
83
. spyOn ( API , "createTemplateVersion" )
98
84
. mockResolvedValue ( MockTemplateVersion )
99
85
jest . spyOn ( API , "createTemplate" ) . mockResolvedValue ( MockTemplate )
100
86
await userEvent . click (
101
- screen . getByRole ( "button" , { name : / c r e a t e t e m p l a t e / i } ) ,
87
+ within ( form ) . getByRole ( "button" , { name : / c r e a t e t e m p l a t e / i } ) ,
102
88
)
103
-
104
89
await waitFor ( ( ) => expect ( API . createTemplate ) . toBeCalledTimes ( 1 ) )
105
90
expect ( router . state . location . pathname ) . toEqual (
106
91
`/templates/${ MockTemplate . name } ` ,
@@ -115,8 +100,6 @@ test("Create template with variables", async () => {
115
100
{ name : "first_variable" , value : "First value" } ,
116
101
{ name : "second_variable" , value : "2" } ,
117
102
{ name : "third_variable" , value : "true" } ,
118
- { name : "fourth_variable" , value : "Fourth value" } ,
119
- { name : "fifth_variable" , value : "Fifth value" } ,
120
103
] ,
121
104
} )
122
105
} )
0 commit comments