1
- import { render , waitFor , within , fireEvent , screen } from '@testing-library/react' ;
1
+ import { render , waitFor , within , fireEvent , screen , cleanup } from '@testing-library/react' ;
2
2
import { MockedProvider } from '@apollo/client/testing' ;
3
3
import userEvent from '@testing-library/user-event' ;
4
4
import { MemoryRouter , Route , Routes } from 'react-router-dom' ;
5
5
import { HSM } from './HSM' ;
6
- import {
7
- TEMPLATE_MOCKS ,
8
- getHSMTemplateTypeMedia ,
9
- getHSMTemplateTypeText ,
10
- } from 'containers/Template/Template.test.helper' ;
6
+ import { HSM_TEMPLATE_MOCKS , getHSMTemplateTypeMedia , getHSMTemplateTypeText } from 'mocks/Template' ;
7
+ import { setNotification } from 'common/notification' ;
11
8
12
- const mocks = TEMPLATE_MOCKS ;
9
+ const mocks = HSM_TEMPLATE_MOCKS ;
10
+
11
+ vi . mock ( 'common/notification' , async ( importOriginal ) => {
12
+ const mod = await importOriginal < typeof import ( 'common/notification' ) > ( ) ;
13
+ return {
14
+ ...mod ,
15
+ setNotification : vi . fn ( ( ...args ) => {
16
+ return args [ 1 ] ;
17
+ } ) ,
18
+ } ;
19
+ } ) ;
13
20
14
21
beforeEach ( ( ) => {
15
- vi . restoreAllMocks ( ) ;
22
+ cleanup ( ) ;
16
23
} ) ;
17
24
18
25
vi . mock ( 'lexical-beautiful-mentions' , async ( importOriginal ) => {
@@ -80,6 +87,7 @@ describe('Add mode', () => {
80
87
</ MemoryRouter >
81
88
</ MockedProvider >
82
89
) ;
90
+
83
91
const user = userEvent . setup ( ) ;
84
92
85
93
test ( 'check for validations for the HSM form' , async ( ) => {
@@ -120,7 +128,6 @@ describe('Add mode', () => {
120
128
const inputs = screen . getAllByRole ( 'textbox' ) ;
121
129
122
130
fireEvent . change ( inputs [ 0 ] , { target : { value : 'element_name' } } ) ;
123
- fireEvent . change ( inputs [ 1 ] , { target : { value : 'element_name' } } ) ;
124
131
const lexicalEditor = inputs [ 2 ] ;
125
132
126
133
await user . click ( lexicalEditor ) ;
@@ -144,11 +151,19 @@ describe('Add mode', () => {
144
151
await waitFor ( ( ) => {
145
152
expect ( screen . getByText ( 'Hi, How are you {{1}}' ) ) . toBeInTheDocument ( ) ;
146
153
} ) ;
147
- fireEvent . change ( inputs [ 1 ] , { target : { value : 'element_name' } } ) ;
148
154
149
155
fireEvent . change ( screen . getByPlaceholderText ( 'Define value' ) , { target : { value : 'User' } } ) ;
150
156
157
+ autocompletes [ 3 ] . focus ( ) ;
158
+ fireEvent . keyDown ( autocompletes [ 3 ] , { key : 'ArrowDown' } ) ;
159
+ fireEvent . click ( screen . getByText ( 'Messages' ) , { key : 'Enter' } ) ;
160
+ fireEvent . change ( inputs [ 1 ] , { target : { value : 'title' } } ) ;
161
+
151
162
fireEvent . click ( screen . getByTestId ( 'submitActionButton' ) ) ;
163
+
164
+ await waitFor ( ( ) => {
165
+ expect ( setNotification ) . toHaveBeenCalled ( ) ;
166
+ } ) ;
152
167
} ) ;
153
168
154
169
test ( 'it should add and remove variables' , async ( ) => {
@@ -176,6 +191,10 @@ describe('Add mode', () => {
176
191
} ) ;
177
192
178
193
fireEvent . click ( screen . getAllByTestId ( 'delete-variable' ) [ 0 ] ) ;
194
+
195
+ await waitFor ( ( ) => {
196
+ expect ( screen . queryByPlaceholderText ( 'Define value ' ) ) . not . toBeInTheDocument ( ) ;
197
+ } ) ;
179
198
} ) ;
180
199
181
200
test ( 'it adds quick reply buttons' , async ( ) => {
@@ -224,7 +243,10 @@ describe('Add mode', () => {
224
243
fireEvent . click ( screen . getByText ( 'ACCOUNT_UPDATE' ) , { key : 'Enter' } ) ;
225
244
226
245
fireEvent . click ( screen . getByTestId ( 'submitActionButton' ) ) ;
227
- fireEvent . click ( screen . getByTestId ( 'submitActionButton' ) ) ;
246
+
247
+ await waitFor ( ( ) => {
248
+ expect ( setNotification ) . toHaveBeenCalled ( ) ;
249
+ } ) ;
228
250
} ) ;
229
251
230
252
test ( 'it adds call to action buttons' , async ( ) => {
@@ -272,7 +294,10 @@ describe('Add mode', () => {
272
294
fireEvent . click ( screen . getByText ( 'ACCOUNT_UPDATE' ) , { key : 'Enter' } ) ;
273
295
274
296
fireEvent . click ( screen . getByTestId ( 'submitActionButton' ) ) ;
275
- fireEvent . click ( screen . getByTestId ( 'submitActionButton' ) ) ;
297
+
298
+ await waitFor ( ( ) => {
299
+ expect ( setNotification ) . toHaveBeenCalled ( ) ;
300
+ } ) ;
276
301
} ) ;
277
302
278
303
test ( 'adding attachments' , async ( ) => {
0 commit comments