Skip to content

Commit 8177ab1

Browse files
axel7083danivilla9
authored andcommitted
feat(feedback): adding frontend checkbox to include system info (podman-desktop#10116)
* feat(feedback): adding frontend checkbox to include system info Signed-off-by: axel7083 <[email protected]> * fix: text position Signed-off-by: axel7083 <[email protected]> * fix: adding missing line caught by @gastoner Signed-off-by: axel7083 <[email protected]> --------- Signed-off-by: axel7083 <[email protected]>
1 parent fc912f2 commit 8177ab1

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

packages/renderer/src/lib/feedback/feedbackForms/GitHubIssueFeedback.spec.ts

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import '@testing-library/jest-dom/vitest';
2121
import { render, type RenderResult } from '@testing-library/svelte';
2222
import userEvent from '@testing-library/user-event';
2323
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';
2525

2626
import 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

8489
test('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

95101
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'
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+
});

packages/renderer/src/lib/feedback/feedbackForms/GitHubIssueFeedback.svelte

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { Button, ErrorMessage, Link } from '@podman-desktop/ui-svelte';
2+
import { Button, Checkbox, ErrorMessage, Link } from '@podman-desktop/ui-svelte';
33
44
import FeedbackForm from '/@/lib/feedback/FeedbackForm.svelte';
55
import type { FeedbackCategory, GitHubIssue } from '/@api/feedback';
@@ -14,6 +14,8 @@ let { onCloseForm = () => {}, category = 'bug', contentChange }: Props = $props(
1414
1515
let issueTitle = $state('');
1616
let issueDescription = $state('');
17+
let includeSystemInfo: boolean = $state(true); // default to true
18+
1719
let issueValidationError = $derived.by(() => {
1820
if (!issueTitle) {
1921
if (!issueDescription) {
@@ -46,9 +48,10 @@ async function openGitHubIssues(): Promise<void> {
4648
4749
async function previewOnGitHub(): Promise<void> {
4850
const issueProperties: GitHubIssue = {
49-
category: category,
50-
title: issueTitle,
51-
description: issueDescription,
51+
category: $state.snapshot(category),
52+
title: $state.snapshot(issueTitle),
53+
description: $state.snapshot(issueDescription),
54+
includeSystemInfo: $state.snapshot(includeSystemInfo),
5255
};
5356
try {
5457
await window.previewOnGitHub(issueProperties);
@@ -86,6 +89,15 @@ async function previewOnGitHub(): Promise<void> {
8689
class="w-full p-2 outline-none text-sm bg-[var(--pd-input-field-focused-bg)] rounded-sm text-[var(--pd-input-field-focused-text)] placeholder-[var(--pd-input-field-placeholder-text)]"
8790
placeholder={descriptionPlaceholder}></textarea>
8891

92+
<!-- additional form content for bug category -->
93+
{#if category === 'bug'}
94+
<div class="flex flex-row align-items items-center mt-2">
95+
<Checkbox
96+
title="Include system information"
97+
bind:checked={includeSystemInfo} />
98+
<div>Include system information (os, architecture etc.)</div>
99+
</div>
100+
{/if}
89101
</svelte:fragment>
90102
<svelte:fragment slot="validation">
91103
{#if !issueTitle || !issueDescription}

0 commit comments

Comments
 (0)