@@ -2,6 +2,7 @@ import { screen, waitFor } from '@testing-library/react';
22import userEvent from '@testing-library/user-event' ;
33import React from 'react' ;
44import { Teaspoons , TeaspoonsContract } from 'src/libs/ajax/teaspoons/Teaspoons' ;
5+ import { mockPipelineRun } from 'src/pages/scientificServices/pipelines/utils/mock-utils' ;
56import { asMockedFn , partial , renderWithAppContexts as render } from 'src/testing/test-utils' ;
67
78import { JobHistory } from './JobHistory' ;
@@ -36,19 +37,8 @@ jest.mock('src/libs/nav', () => ({
3637
3738describe ( 'job history table' , ( ) => {
3839 it ( 'renders the job history table' , async ( ) => {
39- const pipelineRuns = [
40- {
41- id : '123' ,
42- description : 'Test Job' ,
43- status : 'RUNNING' ,
44- createdAt : '2023-10-01T00:00:00Z' ,
45- updatedAt : '2023-10-01T00:00:00Z' ,
46- pipelineVersion : 'v1.0.0' ,
47- pipelineName : 'array_imputation' ,
48- jobId : 'job-123' ,
49- timeSubmitted : '2023-10-01T00:00:00Z' ,
50- } ,
51- ] ;
40+ const pipelineRun = mockPipelineRun ( 'RUNNING' ) ;
41+ const pipelineRuns = [ pipelineRun ] ;
5242
5343 const mockPipelineRunResponse = {
5444 pageToken : 'nextPageToken' ,
@@ -65,25 +55,13 @@ describe('job history table', () => {
6555 render ( < JobHistory /> ) ;
6656
6757 expect ( await screen . findByText ( 'Job History' ) ) . toBeInTheDocument ( ) ;
68- expect ( screen . queryAllByText ( 'Test Job' ) ) . toHaveLength ( 2 ) ;
58+ expect ( screen . queryAllByText ( pipelineRun . description ! ) ) . toHaveLength ( 2 ) ;
6959 expect ( screen . getByText ( 'In Progress' ) ) . toBeInTheDocument ( ) ;
7060 } ) ;
7161
7262 it ( 'shows View Outputs button for SUCCEEDED jobs' , async ( ) => {
73- const pipelineRuns = [
74- {
75- id : '123' ,
76- jobId : 'job-123' ,
77- description : 'Successful Job' ,
78- status : 'SUCCEEDED' ,
79- timeSubmitted : '2023-10-01T00:00:00Z' ,
80- timeCompleted : '2023-10-01T01:00:00Z' ,
81- pipelineVersion : 'v1.0.0' ,
82- pipelineName : 'array_imputation' ,
83- createdAt : '2023-10-01T00:00:00Z' ,
84- updatedAt : '2023-10-01T01:00:00Z' ,
85- } ,
86- ] ;
63+ const pipelineRun = mockPipelineRun ( 'SUCCEEDED' ) ;
64+ const pipelineRuns = [ pipelineRun ] ;
8765
8866 const mockPipelineRunResponse = {
8967 pageToken : null ,
@@ -99,34 +77,19 @@ describe('job history table', () => {
9977
10078 render ( < JobHistory /> ) ;
10179
102- // Wait for the table to render with job data
10380 await waitFor ( ( ) => {
104- expect ( screen . getAllByText ( 'job-123' ) ) . toHaveLength ( 2 ) ;
81+ expect ( screen . getAllByText ( pipelineRun . jobId ) ) . toHaveLength ( 2 ) ;
10582 } ) ;
10683
107- // Verify the "View Outputs" button is present
10884 const viewOutputsButton = screen . getByText ( 'View Outputs' ) ;
10985 expect ( viewOutputsButton ) . toBeInTheDocument ( ) ;
11086
111- // Verify the "View Error" button is not present
11287 expect ( screen . queryByText ( 'View Error' ) ) . not . toBeInTheDocument ( ) ;
11388 } ) ;
11489
11590 it ( 'shows View Error button for FAILED jobs' , async ( ) => {
116- const pipelineRuns = [
117- {
118- id : '456' ,
119- jobId : 'job-456' ,
120- description : 'Failed Job' ,
121- status : 'FAILED' ,
122- timeSubmitted : '2023-10-01T00:00:00Z' ,
123- timeCompleted : '2023-10-01T01:00:00Z' ,
124- pipelineVersion : 'v1.0.0' ,
125- pipelineName : 'array_imputation' ,
126- createdAt : '2023-10-01T00:00:00Z' ,
127- updatedAt : '2023-10-01T01:00:00Z' ,
128- } ,
129- ] ;
91+ const pipelineRun = mockPipelineRun ( 'FAILED' ) ;
92+ const pipelineRuns = [ pipelineRun ] ;
13093
13194 const mockPipelineRunResponse = {
13295 pageToken : null ,
@@ -142,33 +105,19 @@ describe('job history table', () => {
142105
143106 render ( < JobHistory /> ) ;
144107
145- // Wait for the table to render with job data
146108 await waitFor ( ( ) => {
147- expect ( screen . getAllByText ( 'job-456' ) ) . toHaveLength ( 2 ) ;
109+ expect ( screen . getAllByText ( pipelineRun . jobId ) ) . toHaveLength ( 2 ) ;
148110 } ) ;
149111
150- // Verify the "View Error" button is present
151112 const viewErrorButton = screen . getByText ( 'View Error' ) ;
152113 expect ( viewErrorButton ) . toBeInTheDocument ( ) ;
153114
154- // Verify the "View Outputs" button is not present
155115 expect ( screen . queryByText ( 'View Outputs' ) ) . not . toBeInTheDocument ( ) ;
156116 } ) ;
157117
158118 it ( 'shows neither button for RUNNING jobs' , async ( ) => {
159- const pipelineRuns = [
160- {
161- id : '789' ,
162- jobId : 'job-789' ,
163- description : 'Running Job' ,
164- status : 'RUNNING' ,
165- timeSubmitted : '2023-10-01T00:00:00Z' ,
166- pipelineVersion : 'v1.0.0' ,
167- pipelineName : 'array_imputation' ,
168- createdAt : '2023-10-01T00:00:00Z' ,
169- updatedAt : '2023-10-01T00:30:00Z' ,
170- } ,
171- ] ;
119+ const pipelineRun = mockPipelineRun ( 'RUNNING' ) ;
120+ const pipelineRuns = [ pipelineRun ] ;
172121
173122 const mockPipelineRunResponse = {
174123 pageToken : null ,
@@ -184,40 +133,25 @@ describe('job history table', () => {
184133
185134 render ( < JobHistory /> ) ;
186135
187- // Wait for the table to render with job data
188136 await waitFor ( ( ) => {
189- expect ( screen . getAllByText ( 'job-789' ) ) . toHaveLength ( 2 ) ;
137+ expect ( screen . getAllByText ( pipelineRun . jobId ) ) . toHaveLength ( 2 ) ;
190138 } ) ;
191139
192- // Verify neither button is present
193140 expect ( screen . queryByText ( 'View Outputs' ) ) . not . toBeInTheDocument ( ) ;
194141 expect ( screen . queryByText ( 'View Error' ) ) . not . toBeInTheDocument ( ) ;
195142 expect ( screen . getByText ( 'In Progress' ) ) . toBeInTheDocument ( ) ;
196143 } ) ;
197144
198145 it ( 'opens the outputs modal when View Outputs button is clicked' , async ( ) => {
199- const pipelineRuns = [
200- {
201- id : '123' ,
202- jobId : 'job-123' ,
203- description : 'Successful Job' ,
204- status : 'SUCCEEDED' ,
205- timeSubmitted : '2023-10-01T00:00:00Z' ,
206- timeCompleted : '2023-10-01T01:00:00Z' ,
207- pipelineVersion : 'v1.0.0' ,
208- pipelineName : 'array_imputation' ,
209- createdAt : '2023-10-01T00:00:00Z' ,
210- updatedAt : '2023-10-01T01:00:00Z' ,
211- } ,
212- ] ;
146+ const pipelineRun = mockPipelineRun ( 'SUCCEEDED' ) ;
147+ const pipelineRuns = [ pipelineRun ] ;
213148
214149 const mockPipelineRunResponse = {
215150 pageToken : null ,
216151 results : pipelineRuns ,
217152 totalResults : 1 ,
218153 } ;
219154
220- // Mock the pipeline run results that will be requested by the modal
221155 const mockPipelineRunResult = {
222156 pipelineRunReport : {
223157 outputs : {
@@ -235,42 +169,26 @@ describe('job history table', () => {
235169
236170 render ( < JobHistory /> ) ;
237171
238- // Wait for the table to render
239172 await waitFor ( ( ) => {
240- expect ( screen . getAllByText ( 'job-123' ) ) . toHaveLength ( 2 ) ;
173+ expect ( screen . getAllByText ( pipelineRun . jobId ) ) . toHaveLength ( 2 ) ;
241174 } ) ;
242175
243- // Click the "View Outputs" button
244176 const user = userEvent . setup ( ) ;
245177 await user . click ( screen . getByText ( 'View Outputs' ) ) ;
246178
247- // Verify the modal is opened
248- expect ( await screen . findByText ( 'Pipeline Outputs - job-123' ) ) . toBeInTheDocument ( ) ;
179+ expect ( await screen . findByText ( 'Pipeline Outputs' , { exact : false } ) ) . toBeInTheDocument ( ) ;
249180 } ) ;
250181
251182 it ( 'opens the error modal when View Error button is clicked' , async ( ) => {
252- const pipelineRuns = [
253- {
254- id : '456' ,
255- jobId : 'job-456' ,
256- description : 'Failed Job' ,
257- status : 'FAILED' ,
258- timeSubmitted : '2023-10-01T00:00:00Z' ,
259- timeCompleted : '2023-10-01T01:00:00Z' ,
260- pipelineVersion : 'v1.0.0' ,
261- pipelineName : 'array_imputation' ,
262- createdAt : '2023-10-01T00:00:00Z' ,
263- updatedAt : '2023-10-01T01:00:00Z' ,
264- } ,
265- ] ;
183+ const pipelineRun = mockPipelineRun ( 'FAILED' ) ;
184+ const pipelineRuns = [ pipelineRun ] ;
266185
267186 const mockPipelineRunResponse = {
268187 pageToken : null ,
269188 results : pipelineRuns ,
270189 totalResults : 1 ,
271190 } ;
272191
273- // Mock the pipeline run results that will be requested by the modal
274192 const mockPipelineRunResult = {
275193 errorReport : {
276194 message : 'Test error message' ,
@@ -287,16 +205,13 @@ describe('job history table', () => {
287205
288206 render ( < JobHistory /> ) ;
289207
290- // Wait for the table to render
291208 await waitFor ( ( ) => {
292- expect ( screen . getAllByText ( 'job-456' ) ) . toHaveLength ( 2 ) ;
209+ expect ( screen . getAllByText ( pipelineRun . jobId ) ) . toHaveLength ( 2 ) ;
293210 } ) ;
294211
295- // Click the "View Error" button
296212 const user = userEvent . setup ( ) ;
297213 await user . click ( screen . getByText ( 'View Error' ) ) ;
298214
299- // Verify the modal is opened
300- expect ( await screen . findByText ( 'Pipeline Error - job-456' ) ) . toBeInTheDocument ( ) ;
215+ expect ( await screen . findByText ( 'Pipeline Error' , { exact : false } ) ) . toBeInTheDocument ( ) ;
301216 } ) ;
302217} ) ;
0 commit comments