@@ -21,7 +21,7 @@ import '@testing-library/jest-dom/vitest';
2121import { render , type RenderResult } from '@testing-library/svelte' ;
2222import userEvent from '@testing-library/user-event' ;
2323import { 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' ;
2525
2626import type { FeedbackCategory } from '/@api/feedback' ;
2727
@@ -57,6 +57,7 @@ function renderGitHubIssueFeedback(props: ComponentProps<typeof GitHubIssueFeedb
5757 title : HTMLInputElement ;
5858 description : HTMLTextAreaElement ;
5959 preview : HTMLButtonElement ;
60+ includeSystemInfo ?: HTMLElement ;
6061} & RenderResult < Component < ComponentProps < typeof GitHubIssueFeedback > > > {
6162 const { getByRole, queryByTitle, ...restResult } = render ( GitHubIssueFeedback , props ) ;
6263
@@ -71,25 +72,30 @@ function renderGitHubIssueFeedback(props: ComponentProps<typeof GitHubIssueFeedb
7172 const preview = getByRole ( 'button' , { name : 'Preview on GitHub' } ) ;
7273 expect ( preview ) . toBeInstanceOf ( HTMLButtonElement ) ;
7374
75+ // checkbox
76+ const includeSystemInfo = queryByTitle ( 'Include system information' ) ?? undefined ;
77+
7478 return {
7579 title : title as HTMLInputElement ,
7680 description : description as HTMLTextAreaElement ,
7781 preview : preview as HTMLButtonElement ,
82+ includeSystemInfo,
7883 getByRole,
7984 queryByTitle,
8085 ...restResult ,
8186 } ;
8287}
8388
8489test ( 'Expect feedback form to to be GitHub issue feedback form' , async ( ) => {
85- const { title, description } = renderGitHubIssueFeedback ( {
90+ const { title, description, includeSystemInfo } = renderGitHubIssueFeedback ( {
8691 category : 'bug' ,
8792 onCloseForm : vi . fn ( ) ,
8893 contentChange : vi . fn ( ) ,
8994 } ) ;
9095
9196 expect ( title ) . toBeInTheDocument ( ) ;
9297 expect ( description ) . toBeInTheDocument ( ) ;
98+ expect ( includeSystemInfo ) . toBeInTheDocument ( ) ;
9399} ) ;
94100
95101test ( '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'
184190 } ) ,
185191 ) ;
186192} ) ;
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