@@ -20,6 +20,7 @@ jest.mock('@tanstack/react-query');
20
20
21
21
describe ( 'SigneeListSummary' , ( ) => {
22
22
const mockedUseQuery = jest . mocked ( useQuery ) ;
23
+ const mockedUseNodeItem = jest . mocked ( useNodeItem ) ;
23
24
24
25
beforeEach ( ( ) => {
25
26
jest . resetAllMocks ( ) ;
@@ -29,7 +30,7 @@ describe('SigneeListSummary', () => {
29
30
instanceGuid : 'instanceGuid' ,
30
31
taskId : 'taskId' ,
31
32
} ) ;
32
- jest . mocked ( useNodeItem ) . mockReturnValue ( 'summary_title ' as unknown as ReturnType < typeof useNodeItem > ) ;
33
+ mockedUseNodeItem . mockReturnValue ( 'title ' as unknown as ReturnType < typeof useNodeItem > ) ;
33
34
jest . mocked ( Lang ) . mockImplementation ( ( { id } : { id : string } ) => id ) ;
34
35
} ) ;
35
36
@@ -41,7 +42,12 @@ describe('SigneeListSummary', () => {
41
42
} as unknown as UseQueryResult ) ;
42
43
43
44
// Test case
44
- render ( < SigneeListSummary componentNode = { { } as LayoutNode < 'SigneeList' > } /> ) ;
45
+ render (
46
+ < SigneeListSummary
47
+ titleOverride = { null }
48
+ componentNode = { { } as LayoutNode < 'SigneeList' > }
49
+ /> ,
50
+ ) ;
45
51
46
52
// Assertion
47
53
expect ( mockedUseQuery ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -56,7 +62,12 @@ describe('SigneeListSummary', () => {
56
62
} as unknown as UseQueryResult ) ;
57
63
58
64
// Test case
59
- render ( < SigneeListSummary componentNode = { { } as LayoutNode < 'SigneeList' > } /> ) ;
65
+ render (
66
+ < SigneeListSummary
67
+ titleOverride = { null }
68
+ componentNode = { { } as LayoutNode < 'SigneeList' > }
69
+ /> ,
70
+ ) ;
60
71
61
72
// Assertion
62
73
expect ( mockedUseQuery ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -71,7 +82,12 @@ describe('SigneeListSummary', () => {
71
82
} as unknown as UseQueryResult ) ;
72
83
73
84
// Test case
74
- render ( < SigneeListSummary componentNode = { { } as LayoutNode < 'SigneeList' > } /> ) ;
85
+ render (
86
+ < SigneeListSummary
87
+ titleOverride = { null }
88
+ componentNode = { { } as LayoutNode < 'SigneeList' > }
89
+ /> ,
90
+ ) ;
75
91
76
92
// Assertion
77
93
expect ( mockedUseQuery ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -86,7 +102,12 @@ describe('SigneeListSummary', () => {
86
102
} as unknown as UseQueryResult ) ;
87
103
88
104
// Test case
89
- render ( < SigneeListSummary componentNode = { { } as LayoutNode < 'SigneeList' > } /> ) ;
105
+ render (
106
+ < SigneeListSummary
107
+ titleOverride = { null }
108
+ componentNode = { { } as LayoutNode < 'SigneeList' > }
109
+ /> ,
110
+ ) ;
90
111
91
112
// Assertion
92
113
expect ( mockedUseQuery ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -132,13 +153,84 @@ describe('SigneeListSummary', () => {
132
153
} as unknown as UseQueryResult ) ;
133
154
134
155
// Test case
135
- render ( < SigneeListSummary componentNode = { { } as LayoutNode < 'SigneeList' > } /> ) ;
156
+ render (
157
+ < SigneeListSummary
158
+ titleOverride = { undefined }
159
+ componentNode = { { } as LayoutNode < 'SigneeList' > }
160
+ /> ,
161
+ ) ;
136
162
137
163
// Assertion
138
164
expect ( mockedUseQuery ) . toHaveBeenCalledTimes ( 1 ) ;
139
- screen . getByText ( 'summary_title ' ) ;
165
+ screen . getByText ( 'title ' ) ;
140
166
screen . getByText ( 'Signee 1' ) ;
141
167
screen . getByText ( "Signee 2, signee_list_summary.on_behalf_of Signee 2's organisation" ) ;
142
168
expect ( screen . queryByText ( / S i g n e e 3 / i) ) . not . toBeInTheDocument ( ) ;
143
169
} ) ;
170
+
171
+ it ( 'should render original title if summary override title is undefined' , ( ) => {
172
+ mockedUseQuery . mockReturnValue ( {
173
+ data : [ ] satisfies SigneeState [ ] ,
174
+ isLoading : false ,
175
+ error : null ,
176
+ } as unknown as UseQueryResult ) ;
177
+
178
+ mockedUseNodeItem . mockReturnValue ( 'originalTitle' as unknown as ReturnType < typeof useNodeItem > ) ;
179
+
180
+ // Test case
181
+ render (
182
+ < SigneeListSummary
183
+ titleOverride = { undefined }
184
+ componentNode = { { } as LayoutNode < 'SigneeList' > }
185
+ /> ,
186
+ ) ;
187
+
188
+ // Assertion
189
+ expect ( mockedUseQuery ) . toHaveBeenCalledTimes ( 1 ) ;
190
+ screen . getByText ( 'originalTitle' ) ;
191
+ } ) ;
192
+
193
+ it ( 'should not render title if originalTitle and overrideTitle are not set' , ( ) => {
194
+ mockedUseQuery . mockReturnValue ( {
195
+ data : [ ] satisfies SigneeState [ ] ,
196
+ isLoading : false ,
197
+ error : null ,
198
+ } as unknown as UseQueryResult ) ;
199
+
200
+ mockedUseNodeItem . mockReturnValue ( undefined ) ;
201
+
202
+ // Test case
203
+ render (
204
+ < SigneeListSummary
205
+ titleOverride = { undefined }
206
+ componentNode = { { } as LayoutNode < 'SigneeList' > }
207
+ /> ,
208
+ ) ;
209
+
210
+ // Assertion
211
+ expect ( mockedUseQuery ) . toHaveBeenCalledTimes ( 1 ) ;
212
+ screen . getByText ( 'signee_list_summary.no_signatures' ) ;
213
+ expect ( screen . queryByText ( 'title' ) ) . not . toBeInTheDocument ( ) ;
214
+ } ) ;
215
+
216
+ it . each ( [ null , '' ] ) ( 'should not render title if summary title override is null or empty string' , ( titleOverride ) => {
217
+ mockedUseQuery . mockReturnValue ( {
218
+ data : [ ] satisfies SigneeState [ ] ,
219
+ isLoading : false ,
220
+ error : null ,
221
+ } as unknown as UseQueryResult ) ;
222
+
223
+ // Test case
224
+ render (
225
+ < SigneeListSummary
226
+ titleOverride = { titleOverride }
227
+ componentNode = { { } as LayoutNode < 'SigneeList' > }
228
+ /> ,
229
+ ) ;
230
+
231
+ // Assertion
232
+ expect ( mockedUseQuery ) . toHaveBeenCalledTimes ( 1 ) ;
233
+ screen . getByText ( 'signee_list_summary.no_signatures' ) ;
234
+ expect ( screen . queryByText ( 'title' ) ) . not . toBeInTheDocument ( ) ;
235
+ } ) ;
144
236
} ) ;
0 commit comments