1
1
import React from 'react' ;
2
2
3
- import { render , fireEvent , screen } from '@/test-utils/rtl' ;
3
+ import { render , fireEvent , screen , queryByRole } from '@/test-utils/rtl' ;
4
4
5
5
import losslessJsonStringify from '@/utils/lossless-json-stringify' ;
6
6
7
7
import WorkflowSummaryTabJsonView from '../workflow-summary-tab-json-view' ;
8
+ import { type Props } from '../workflow-summary-tab-json-view.types' ;
8
9
9
10
jest . mock ( '@/components/copy-text-button/copy-text-button' , ( ) =>
10
11
jest . fn ( ( { textToCopy } ) => < div > Copy Button: { textToCopy } </ div > )
@@ -27,36 +28,15 @@ jest.mock('@/components/pretty-json-skeleton/pretty-json-skeleton', () =>
27
28
) ;
28
29
29
30
describe ( 'WorkflowSummaryTabJsonView Component' , ( ) => {
30
- const losslessInputJson = {
31
- input : 'inputJson' ,
32
- long : BigInt ( '12345678901234567890' ) ,
33
- } ;
34
- const losselessResultJson = {
35
- result : 'resultJson' ,
36
- long : BigInt ( '12345678901234567891' ) ,
37
- } ;
38
-
39
31
it ( 'renders correctly with initial props' , ( ) => {
40
- const { getByText } = render (
41
- < WorkflowSummaryTabJsonView
42
- inputJson = { losslessInputJson }
43
- resultJson = { losselessResultJson }
44
- isWorkflowRunning = { false }
45
- />
46
- ) ;
32
+ const { getByText } = setup ( { } ) ;
47
33
48
34
expect ( getByText ( 'SegmentedControlRounded Mock' ) ) . toBeInTheDocument ( ) ;
49
35
expect ( getByText ( 'PrettyJson Mock' ) ) . toBeInTheDocument ( ) ;
50
36
} ) ;
51
37
52
38
it ( 'handles tab change' , ( ) => {
53
- render (
54
- < WorkflowSummaryTabJsonView
55
- inputJson = { losslessInputJson }
56
- resultJson = { losselessResultJson }
57
- isWorkflowRunning = { false }
58
- />
59
- ) ;
39
+ setup ( { } ) ;
60
40
61
41
// Mock the onChange event for SegmentedControlRounded
62
42
const segmentedControl = screen . getByText ( 'SegmentedControlRounded Mock' ) ;
@@ -65,13 +45,7 @@ describe('WorkflowSummaryTabJsonView Component', () => {
65
45
} ) ;
66
46
67
47
it ( 'renders loading state correctly' , ( ) => {
68
- const { getByText } = render (
69
- < WorkflowSummaryTabJsonView
70
- inputJson = { losslessInputJson }
71
- resultJson = { losselessResultJson }
72
- isWorkflowRunning = { true }
73
- />
74
- ) ;
48
+ const { getByText } = setup ( { isWorkflowRunning : true } ) ;
75
49
76
50
// Mock the onChange event for SegmentedControlRounded
77
51
const segmentedControl = screen . getByText ( 'SegmentedControlRounded Mock' ) ;
@@ -80,17 +54,76 @@ describe('WorkflowSummaryTabJsonView Component', () => {
80
54
} ) ;
81
55
82
56
it ( 'renders copy text button and pass the correct text' , ( ) => {
83
- const { getByText } = render (
84
- < WorkflowSummaryTabJsonView
85
- inputJson = { losslessInputJson }
86
- resultJson = { losselessResultJson }
87
- isWorkflowRunning = { true }
88
- />
89
- ) ;
57
+ const { getByText } = setup ( { isWorkflowRunning : true } ) ;
90
58
const copyButton = getByText ( / C o p y B u t t o n / ) ;
91
59
expect ( copyButton ) . toBeInTheDocument ( ) ;
92
60
expect ( copyButton . innerHTML ) . toMatch (
93
61
losslessJsonStringify ( losslessInputJson , null , '\t' )
94
62
) ;
95
63
} ) ;
64
+
65
+ it ( 'renders archived result correctly' , ( ) => {
66
+ const { getByText, getByRole } = setup ( { isArchived : true } ) ;
67
+ const segmentedControl = getByText ( 'SegmentedControlRounded Mock' ) ;
68
+ fireEvent . click ( segmentedControl ) ;
69
+ expect (
70
+ getByText ( 'Workflow is archived, result is only available in' )
71
+ ) . toBeInTheDocument ( ) ;
72
+ expect ( getByRole ( 'link' , { name : 'history' } ) ) . toBeInTheDocument ( ) ;
73
+ } ) ;
74
+
75
+ it ( 'should not render loading skeleton when isArchived is true and isWorkflowRunning is true' , ( ) => {
76
+ const { queryByText, getByText } = setup ( {
77
+ isArchived : true ,
78
+ isWorkflowRunning : true ,
79
+ } ) ;
80
+ const segmentedControl = getByText ( 'SegmentedControlRounded Mock' ) ;
81
+ fireEvent . click ( segmentedControl ) ;
82
+ expect ( queryByText ( 'Mock JSON skeleton' ) ) . not . toBeInTheDocument ( ) ;
83
+ expect (
84
+ queryByText ( 'Workflow is archived, result is only available in' )
85
+ ) . toBeInTheDocument ( ) ;
86
+ } ) ;
87
+
88
+ it ( 'should not render result when isArchived is true and isWorkflowRunning is false' , ( ) => {
89
+ const { queryByText, getByText } = setup ( {
90
+ isArchived : true ,
91
+ isWorkflowRunning : false ,
92
+ } ) ;
93
+ const segmentedControl = getByText ( 'SegmentedControlRounded Mock' ) ;
94
+ fireEvent . click ( segmentedControl ) ;
95
+ expect ( queryByText ( 'PrettyJson Mock' ) ) . not . toBeInTheDocument ( ) ;
96
+ expect (
97
+ queryByText ( 'Workflow is archived, result is only available in' )
98
+ ) . toBeInTheDocument ( ) ;
99
+ } ) ;
96
100
} ) ;
101
+
102
+ const losslessInputJson = {
103
+ input : 'inputJson' ,
104
+ long : BigInt ( '12345678901234567890' ) ,
105
+ } ;
106
+ const losselessResultJson = {
107
+ result : 'resultJson' ,
108
+ long : BigInt ( '12345678901234567891' ) ,
109
+ } ;
110
+
111
+ const setup = ( {
112
+ inputJson = losslessInputJson ,
113
+ resultJson = losselessResultJson ,
114
+ isWorkflowRunning = false ,
115
+ isArchived = false ,
116
+ } : Partial < Props > ) => {
117
+ return render (
118
+ < WorkflowSummaryTabJsonView
119
+ inputJson = { inputJson }
120
+ resultJson = { resultJson }
121
+ isWorkflowRunning = { isWorkflowRunning }
122
+ isArchived = { isArchived }
123
+ domain = "test-domain"
124
+ cluster = "test-cluster"
125
+ runId = "test-run-id"
126
+ workflowId = "test-workflow-id"
127
+ />
128
+ ) ;
129
+ } ;
0 commit comments