1- import { screen , waitFor } from '@testing-library/react' ;
1+ import { formatDatetime } from '@terra-ui-packages/core-utils' ;
2+ import { screen , waitFor , within } from '@testing-library/react' ;
23import userEvent from '@testing-library/user-event' ;
34import React from 'react' ;
45import { Teaspoons , TeaspoonsContract } from 'src/libs/ajax/teaspoons/Teaspoons' ;
@@ -174,6 +175,7 @@ describe('job history table', () => {
174175 ...mockPipelineRun ( 'SUCCEEDED' ) ,
175176 timeSubmitted : fifteenDaysAgo ,
176177 timeCompleted : fifteenDaysAgo ,
178+ outputExpirationDate : new Date ( Date . now ( ) ) . toISOString ( ) ,
177179 } ;
178180 const pipelineRuns = [ pipelineRun ] ;
179181
@@ -195,9 +197,21 @@ describe('job history table', () => {
195197 expect ( screen . getAllByText ( pipelineRun . jobId ) ) . toHaveLength ( 2 ) ;
196198 } ) ;
197199
198- const viewOutputsButton = screen . getByText ( 'View Outputs' ) ;
200+ const table = screen . getByRole ( 'table' ) ;
201+ const rows = within ( table ) . getAllByRole ( 'row' ) ;
202+ const dataRow = within ( rows [ 1 ] ) . getAllByRole ( 'cell' ) ;
203+
204+ const viewOutputsButton = within ( dataRow [ 7 ] ) . getByText ( 'View Outputs' ) ;
199205 expect ( viewOutputsButton ) . toBeInTheDocument ( ) ;
200206 expect ( viewOutputsButton ) . toBeDisabled ( ) ;
207+
208+ const user = userEvent . setup ( ) ;
209+ await user . hover ( viewOutputsButton ) ;
210+
211+ const tooltip = await within ( dataRow [ 7 ] ) . findByText (
212+ 'The outputs for this job have been deleted. Outputs are available for 14 days after job completion.'
213+ ) ;
214+ expect ( tooltip ) . toBeInTheDocument ( ) ;
201215 } ) ;
202216
203217 it ( 'shows View Error button for FAILED jobs' , async ( ) => {
@@ -462,6 +476,41 @@ describe('job history table', () => {
462476 const pipelineRun = {
463477 ...mockPipelineRun ( 'SUCCEEDED' ) ,
464478 timeCompleted : '2023-10-15T14:00:00Z' ,
479+ outputExpirationDate : '2023-10-29T14:00:00Z' ,
480+ } ;
481+ const pipelineRuns = [ pipelineRun ] ;
482+
483+ const mockPipelineRunResponse = {
484+ pageToken : null ,
485+ results : pipelineRuns ,
486+ totalResults : 1 ,
487+ } ;
488+
489+ asMockedFn ( Teaspoons ) . mockReturnValue (
490+ partial < TeaspoonsContract > ( {
491+ getAllPipelineRuns : jest . fn ( ) . mockReturnValue ( mockPipelineRunResponse ) ,
492+ } )
493+ ) ;
494+
495+ render ( < JobHistory /> ) ;
496+
497+ await waitFor ( ( ) => {
498+ expect ( screen . getAllByText ( pipelineRun . jobId ) ) . toHaveLength ( 2 ) ;
499+ } ) ;
500+
501+ const table = screen . getByRole ( 'table' ) ;
502+ const rows = within ( table ) . getAllByRole ( 'row' ) ;
503+ const cells = within ( rows [ 1 ] ) . getAllByRole ( 'cell' ) ;
504+ expect ( cells [ 5 ] ) . toHaveTextContent ( 'Oct 29, 2023' ) ;
505+ } ) ;
506+
507+ it ( 'displays the deletion date in red for job outputs expiring within 3 days' , async ( ) => {
508+ const twoDaysFromNow = new Date ( Date . now ( ) + 2 * 24 * 60 * 60 * 1000 ) . toISOString ( ) ;
509+ const twelveDaysAgo = new Date ( Date . now ( ) - 12 * 24 * 60 * 60 * 1000 ) . toISOString ( ) ;
510+ const pipelineRun = {
511+ ...mockPipelineRun ( 'SUCCEEDED' ) ,
512+ timeCompleted : twelveDaysAgo ,
513+ outputExpirationDate : twoDaysFromNow ,
465514 } ;
466515 const pipelineRuns = [ pipelineRun ] ;
467516
@@ -483,7 +532,15 @@ describe('job history table', () => {
483532 expect ( screen . getAllByText ( pipelineRun . jobId ) ) . toHaveLength ( 2 ) ;
484533 } ) ;
485534
486- expect ( screen . getByText ( 'Oct 15, 2023' ) ) . toBeInTheDocument ( ) ;
535+ const table = screen . getByRole ( 'table' ) ;
536+ const rows = within ( table ) . getAllByRole ( 'row' ) ;
537+ const cells = within ( rows [ 1 ] ) . getAllByRole ( 'cell' ) ;
538+ expect ( cells [ 5 ] ) . toHaveTextContent ( formatDatetime ( twoDaysFromNow ) ) ;
539+
540+ // assert the date text is in red
541+ const deletionDateDiv = within ( cells [ 5 ] ) . getByText ( formatDatetime ( twoDaysFromNow ) ) . parentElement ! ;
542+ const style = window . getComputedStyle ( deletionDateDiv ) ;
543+ expect ( style . color ) . toBe ( 'rgb(219, 50, 20)' ) ;
487544 } ) ;
488545 } ) ;
489546} ) ;
0 commit comments