@@ -21,7 +21,7 @@ import '@testing-library/jest-dom/vitest';
21
21
import { render , type RenderResult } from '@testing-library/svelte' ;
22
22
import userEvent from '@testing-library/user-event' ;
23
23
import { type Component , type ComponentProps } from 'svelte' ;
24
- import { beforeAll , beforeEach , expect , test , vi } from 'vitest' ;
24
+ import { beforeAll , beforeEach , describe , expect , test , vi } from 'vitest' ;
25
25
26
26
import type { FeedbackCategory } from '/@api/feedback' ;
27
27
@@ -57,6 +57,7 @@ function renderGitHubIssueFeedback(props: ComponentProps<typeof GitHubIssueFeedb
57
57
title : HTMLInputElement ;
58
58
description : HTMLTextAreaElement ;
59
59
preview : HTMLButtonElement ;
60
+ includeSystemInfo ?: HTMLElement ;
60
61
} & RenderResult < Component < ComponentProps < typeof GitHubIssueFeedback > > > {
61
62
const { getByRole, queryByTitle, ...restResult } = render ( GitHubIssueFeedback , props ) ;
62
63
@@ -71,25 +72,30 @@ function renderGitHubIssueFeedback(props: ComponentProps<typeof GitHubIssueFeedb
71
72
const preview = getByRole ( 'button' , { name : 'Preview on GitHub' } ) ;
72
73
expect ( preview ) . toBeInstanceOf ( HTMLButtonElement ) ;
73
74
75
+ // checkbox
76
+ const includeSystemInfo = queryByTitle ( 'Include system information' ) ?? undefined ;
77
+
74
78
return {
75
79
title : title as HTMLInputElement ,
76
80
description : description as HTMLTextAreaElement ,
77
81
preview : preview as HTMLButtonElement ,
82
+ includeSystemInfo,
78
83
getByRole,
79
84
queryByTitle,
80
85
...restResult ,
81
86
} ;
82
87
}
83
88
84
89
test ( 'Expect feedback form to to be GitHub issue feedback form' , async ( ) => {
85
- const { title, description } = renderGitHubIssueFeedback ( {
90
+ const { title, description, includeSystemInfo } = renderGitHubIssueFeedback ( {
86
91
category : 'bug' ,
87
92
onCloseForm : vi . fn ( ) ,
88
93
contentChange : vi . fn ( ) ,
89
94
} ) ;
90
95
91
96
expect ( title ) . toBeInTheDocument ( ) ;
92
97
expect ( description ) . toBeInTheDocument ( ) ;
98
+ expect ( includeSystemInfo ) . toBeInTheDocument ( ) ;
93
99
} ) ;
94
100
95
101
test ( 'Expect Preview on GitHub button to be disabled if there is no title or description' , async ( ) => {
@@ -184,3 +190,52 @@ test.each(['bug', 'feature'])('Expect %s to be included in previewOnGitHub call'
184
190
} ) ,
185
191
) ;
186
192
} ) ;
193
+
194
+ describe ( 'includeSystemInfo' , ( ) => {
195
+ test ( 'should not be visible on category feature' , async ( ) => {
196
+ const { includeSystemInfo } = renderGitHubIssueFeedback ( {
197
+ category : 'feature' ,
198
+ onCloseForm : vi . fn ( ) ,
199
+ contentChange : vi . fn ( ) ,
200
+ } ) ;
201
+ expect ( includeSystemInfo ) . toBeUndefined ( ) ;
202
+ } ) ;
203
+
204
+ test ( 'should be visible on category bug and enabled by default' , async ( ) => {
205
+ const { includeSystemInfo } = renderGitHubIssueFeedback ( {
206
+ category : 'bug' ,
207
+ onCloseForm : vi . fn ( ) ,
208
+ contentChange : vi . fn ( ) ,
209
+ } ) ;
210
+ expect ( includeSystemInfo ) . toBeInTheDocument ( ) ;
211
+
212
+ // enabled by default
213
+ expect ( includeSystemInfo ?. children ?. [ 0 ] ) . toHaveClass ( 'text-[var(--pd-input-checkbox-checked)]' ) ;
214
+ } ) ;
215
+
216
+ test ( 'uncheck the Include system information should set includeSystemInfo to false' , async ( ) => {
217
+ const { preview, title, description, includeSystemInfo } = renderGitHubIssueFeedback ( {
218
+ category : 'bug' ,
219
+ onCloseForm : vi . fn ( ) ,
220
+ contentChange : vi . fn ( ) ,
221
+ } ) ;
222
+
223
+ if ( ! includeSystemInfo ) throw new Error ( 'includeSystemInfo should be defined' ) ;
224
+
225
+ // type dummy data
226
+ await userEvent . type ( title , 'Bug title' ) ;
227
+ await userEvent . type ( description , 'Bug description' ) ;
228
+
229
+ // uncheck
230
+ await userEvent . click ( includeSystemInfo ) ;
231
+
232
+ // open in GitHub
233
+ await userEvent . click ( preview ) ;
234
+
235
+ expect ( previewOnGitHubMock ) . toHaveBeenCalledWith (
236
+ expect . objectContaining ( {
237
+ includeSystemInfo : false ,
238
+ } ) ,
239
+ ) ;
240
+ } ) ;
241
+ } ) ;
0 commit comments