@@ -23,7 +23,7 @@ describe('Test New Query Component', () => {
23
23
it ( 'renders the Test New Query heading' , ( ) => {
24
24
renderWithRouter ( < TestNewQuery /> ) ;
25
25
// will check if the heading 'Test Your Query!' is rendering on the screen
26
- expect ( screen . getByText ( / T e s t Y o u r Q u e r y ! / i ) ) . toBeInTheDocument ( ) ;
26
+ expect ( screen . getByRole ( 'heading' , { name : / T e s t N e w Q u e r y / i } ) ) . toBeInTheDocument ( ) ;
27
27
} ) ;
28
28
29
29
//? Testing (2): input fields render
@@ -106,13 +106,28 @@ describe('Test New Query Component', () => {
106
106
//? Testing (6): clicking Save Query button triggers Post Req
107
107
it ( 'checks if clicking Save Query button triggers req to the BE' , async ( ) => {
108
108
// mocking running a query so we have queryResult
109
- const getMockResponse : AxiosResponse < string [ ] > = {
110
- data : [
111
- 'Name: My Test Query' ,
112
- 'Query: SELECT * FROM users' ,
113
- 'Date Run: 2025-04-11' ,
114
- 'Execution Time: 0.42' ,
115
- ] ,
109
+ const getMockResponse : AxiosResponse < { metrics : string [ ] ; otherMetrics : any [ ] } > = {
110
+ data : {
111
+ metrics : [
112
+ 'Query Name: Testing Sunday' ,
113
+ 'Query: SELECT * FROM people' ,
114
+ 'Date Run: 2025-04-11' ,
115
+ 'Execution Time: 0.042' ,
116
+ ] ,
117
+ otherMetrics : [
118
+ {
119
+ planningTime : 1.932 ,
120
+ actualTotalTime : 0.025 ,
121
+ totalCost : 2.87 ,
122
+ nodeType : 'Seq Scan' ,
123
+ relationName : 'people' ,
124
+ planRows : 87 ,
125
+ actualRows : 87 ,
126
+ sharedHit : 2 ,
127
+ sharedRead : 0 ,
128
+ } ,
129
+ ] ,
130
+ } ,
116
131
status : 200 ,
117
132
statusText : 'OK' ,
118
133
headers : { } ,
@@ -128,7 +143,7 @@ describe('Test New Query Component', () => {
128
143
} ;
129
144
// mocking the axios Get Req w/ a mocked response
130
145
const mockGet = jest . spyOn ( axios , 'get' ) . mockResolvedValue ( getMockResponse ) ;
131
- const mockPost = jest . spyOn ( axios , 'post' ) . mockResolvedValue ( { getMockResponse } ) ;
146
+ const mockPost = jest . spyOn ( axios , 'post' ) . mockResolvedValue ( postMockResponse ) ;
132
147
133
148
renderWithRouter ( < TestNewQuery /> ) ;
134
149
@@ -171,14 +186,29 @@ describe('Test New Query Component', () => {
171
186
it ( 'checks if clicking Run Query button renders a table with results' , async ( ) : Promise < void > => {
172
187
// mocking the axios Get Req w/ a mocked response
173
188
// using TS to define the response
174
- const mockData : string [ ] = [
175
- 'Query Name: My Test Query' ,
176
- 'Query: SELECT * FROM users' ,
177
- 'Query Date: 2025-04-11' ,
178
- 'Exec Time: 0.42' ,
179
- ] ;
189
+ const mockData = {
190
+ metrics : [
191
+ 'Query Name: My Test Query' ,
192
+ 'Query: SELECT * FROM users' ,
193
+ 'Date Run: 2025-04-11' ,
194
+ 'Execution Time: 0.042' ,
195
+ ] ,
196
+ otherMetrics : [
197
+ {
198
+ planningTime : 1.932 ,
199
+ actualTotalTime : 0.025 ,
200
+ totalCost : 2.87 ,
201
+ nodeType : 'Seq Scan' ,
202
+ relationName : 'people' ,
203
+ planRows : 87 ,
204
+ actualRows : 87 ,
205
+ sharedHit : 2 ,
206
+ sharedRead : 0 ,
207
+ } ,
208
+ ] ,
209
+ } ;
180
210
// using TS to define the response
181
- const mockResponse : AxiosResponse < string [ ] > = {
211
+ const mockResponse : AxiosResponse < { metrics : string [ ] ; otherMetrics : any [ ] } > = {
182
212
data : mockData ,
183
213
status : 200 ,
184
214
statusText : 'OK' ,
@@ -210,6 +240,7 @@ describe('Test New Query Component', () => {
210
240
} ) ;
211
241
212
242
await userEvent . click ( runQueryButton ) ;
243
+ screen . debug ( ) ;
213
244
214
245
// will wait for QUery Results heading to render
215
246
await waitFor ( ( ) => {
@@ -220,7 +251,7 @@ describe('Test New Query Component', () => {
220
251
expect ( screen . getByText ( / M y T e s t Q u e r y / i) ) . toBeInTheDocument ( ) ;
221
252
expect ( screen . getByText ( / S E L E C T \* F R O M u s e r s / i) ) . toBeInTheDocument ( ) ;
222
253
expect ( screen . getByText ( / 2 0 2 5 - 0 4 - 1 1 / i) ) . toBeInTheDocument ( ) ;
223
- expect ( screen . getByText ( / 0 .4 2 / i) ) . toBeInTheDocument ( ) ;
254
+ expect ( screen . getByText ( / 0 .0 4 2 / i) ) . toBeInTheDocument ( ) ;
224
255
225
256
// remove mock before next test
226
257
mockGet . mockRestore ( ) ;
0 commit comments