diff --git a/src/components/fields/Checkbox.test.tsx b/src/components/fields/Checkbox.test.tsx new file mode 100644 index 000000000..95f3496e4 --- /dev/null +++ b/src/components/fields/Checkbox.test.tsx @@ -0,0 +1,18 @@ +import * as TestRenderer from 'react-test-renderer'; + +import { Checkbox, type ICheckbox } from './Checkbox'; + +describe('components/fields/Checkbox.tsx', () => { + const props: ICheckbox = { + name: 'appearance', + label: 'Appearance', + helpText: 'This is some helper text', + checked: true, + onChange: jest.fn(), + }; + + it('should render', () => { + const tree = TestRenderer.create(); + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/src/components/fields/Checkbox.tsx b/src/components/fields/Checkbox.tsx index 7321e26e9..20ca31646 100644 --- a/src/components/fields/Checkbox.tsx +++ b/src/components/fields/Checkbox.tsx @@ -1,42 +1,47 @@ -interface IFieldCheckbox { +import type { FC, ReactNode } from 'react'; + +export interface ICheckbox { name: string; label: string; + helpText?: ReactNode | string; checked: boolean; - onChange: (evt: React.ChangeEvent) => void; - placeholder?: string; disabled?: boolean; + onChange: (evt: React.ChangeEvent) => void; } -export const FieldCheckbox = (props: IFieldCheckbox) => { +export const Checkbox: FC = (props: ICheckbox) => { return ( -
-
- -
+
+
+
+ +
-
- - {props.placeholder && ( -
- {props.placeholder} -
- )} +
+ +
+ + {props.helpText && ( +
+ {props.helpText} +
+ )}
); }; diff --git a/src/components/fields/FieldInput.test.tsx b/src/components/fields/FieldInput.test.tsx new file mode 100644 index 000000000..e180d8f1b --- /dev/null +++ b/src/components/fields/FieldInput.test.tsx @@ -0,0 +1,28 @@ +import * as TestRenderer from 'react-test-renderer'; + +import { Form } from 'react-final-form'; +import { FieldInput, type IFieldInput } from './FieldInput'; + +describe('components/fields/FieldInput.tsx', () => { + const props: IFieldInput = { + name: 'appearance', + label: 'Appearance', + placeholder: 'This is some placeholder text', + helpText: 'This is some helper text', + }; + + it('should render', () => { + const tree = TestRenderer.create( +
{}} + hand + render={({ handleSubmit }) => ( + + + + )} + />, + ); + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/src/components/fields/FieldInput.tsx b/src/components/fields/FieldInput.tsx index 930932784..67a98cc2b 100644 --- a/src/components/fields/FieldInput.tsx +++ b/src/components/fields/FieldInput.tsx @@ -1,7 +1,7 @@ import type { FC, ReactNode } from 'react'; import { Field } from 'react-final-form'; -export interface IProps { +export interface IFieldInput { name: string; type?: string; label: string; @@ -10,10 +10,10 @@ export interface IProps { required?: boolean; } -export const FieldInput: FC = ({ +export const FieldInput: FC = ({ label, name, - placeholder = '', + placeholder, helpText, type = 'text', required = false, diff --git a/src/components/fields/RadioGroup.test.tsx b/src/components/fields/RadioGroup.test.tsx index 38763e925..4a902abe9 100644 --- a/src/components/fields/RadioGroup.test.tsx +++ b/src/components/fields/RadioGroup.test.tsx @@ -2,13 +2,13 @@ import { fireEvent, render, screen } from '@testing-library/react'; import * as TestRenderer from 'react-test-renderer'; -import { FieldRadioGroup } from './RadioGroup'; +import { type IRadioGroup, RadioGroup } from './RadioGroup'; -describe('components/fields/radiogroup.tsx', () => { - const props = { +describe('components/fields/RadioGroup.tsx', () => { + const props: IRadioGroup = { label: 'Appearance', name: 'appearance', - placeholder: 'This is some helper text', + helpText: 'This is some helper text', options: [ { label: 'Value 1', value: 'one' }, { label: 'Value 2', value: 'two' }, @@ -17,13 +17,20 @@ describe('components/fields/radiogroup.tsx', () => { value: 'two', }; - it('should render ', () => { - const tree = TestRenderer.create(); + it('should render', () => { + const tree = TestRenderer.create(); + expect(tree).toMatchSnapshot(); + }); + + it('should render as disabled', () => { + const mockProps = { ...props, disabled: true }; + + const tree = TestRenderer.create(); expect(tree).toMatchSnapshot(); }); it('should check that NProgress is getting called in getDerivedStateFromProps (loading)', () => { - render(); + render(); fireEvent.click(screen.getByLabelText('Value 1')); expect(props.onChange).toHaveBeenCalledTimes(1); }); diff --git a/src/components/fields/RadioGroup.tsx b/src/components/fields/RadioGroup.tsx index ebf5c18ec..c143b75b5 100644 --- a/src/components/fields/RadioGroup.tsx +++ b/src/components/fields/RadioGroup.tsx @@ -1,68 +1,70 @@ -import type { ChangeEvent } from 'react'; +import type { ChangeEvent, FC, ReactNode } from 'react'; import type { RadioGroupItem } from '../../types'; -export const FieldRadioGroup = ({ - label, - placeholder, - name, - options, - onChange, - value, -}: { +export interface IRadioGroup { name: string; label: string; - placeholder?: string; + helpText?: ReactNode | string; options: RadioGroupItem[]; - onChange: (event: ChangeEvent) => void; value: string; -}) => { - return ( -
-
- + disabled?: boolean; + onChange: (event: ChangeEvent) => void; +} - {placeholder && ( -
- {placeholder} -
- )} -
+export const RadioGroup: FC = (props: IRadioGroup) => { + return ( +
+
+
+ +
-
- {options.map((item) => { - return ( -
- -
+ ); + })} +
+ + {props.helpText && ( +
+ {props.helpText} +
+ )}
); }; diff --git a/src/components/fields/__snapshots__/Checkbox.test.tsx.snap b/src/components/fields/__snapshots__/Checkbox.test.tsx.snap new file mode 100644 index 000000000..0138d82b1 --- /dev/null +++ b/src/components/fields/__snapshots__/Checkbox.test.tsx.snap @@ -0,0 +1,38 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`components/fields/Checkbox.tsx should render 1`] = ` +
+
+
+ +
+
+ +
+
+
+ This is some helper text +
+
+`; diff --git a/src/components/fields/__snapshots__/FieldInput.test.tsx.snap b/src/components/fields/__snapshots__/FieldInput.test.tsx.snap new file mode 100644 index 000000000..145ed199a --- /dev/null +++ b/src/components/fields/__snapshots__/FieldInput.test.tsx.snap @@ -0,0 +1,35 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`components/fields/FieldInput.tsx should render 1`] = ` +
+
+ + +
+ This is some helper text +
+
+
+`; diff --git a/src/components/fields/__snapshots__/RadioGroup.test.tsx.snap b/src/components/fields/__snapshots__/RadioGroup.test.tsx.snap index 70e146f0e..4d6589d90 100644 --- a/src/components/fields/__snapshots__/RadioGroup.test.tsx.snap +++ b/src/components/fields/__snapshots__/RadioGroup.test.tsx.snap @@ -1,67 +1,148 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`components/fields/radiogroup.tsx should render 1`] = ` +exports[`components/fields/RadioGroup.tsx should render 1`] = `
- + +
- This is some helper text +
+ + +
+
+ + +
+ This is some helper text +
+
+`; + +exports[`components/fields/RadioGroup.tsx should render as disabled 1`] = ` +
+
-
- - + + +
+
+ + +
+
+ This is some helper text +
`; diff --git a/src/routes/Settings.tsx b/src/routes/Settings.tsx index 89eb56c25..7ce87b94a 100644 --- a/src/routes/Settings.tsx +++ b/src/routes/Settings.tsx @@ -16,8 +16,8 @@ import { } from 'react'; import { useNavigate } from 'react-router-dom'; -import { FieldCheckbox } from '../components/fields/Checkbox'; -import { FieldRadioGroup } from '../components/fields/RadioGroup'; +import { Checkbox } from '../components/fields/Checkbox'; +import { RadioGroup } from '../components/fields/RadioGroup'; import { AppContext } from '../context/App'; import { Theme } from '../types'; import { apiRequestAuth } from '../utils/api-requests'; @@ -118,7 +118,7 @@ export const SettingsRoute: FC = () => { Appearance - { updateSetting('theme', evt.target.value); }} /> - { } disabled={!colorScope} /> - {
- + Notifications - { updateSetting('participating', evt.target.checked) } /> - updateSetting('showBots', evt.target.checked)} /> - {
- + System - updateSetting('showNotificationsCountInTray', evt.target.checked) } + helpText="Changes will take effect after restarting the app" /> - { updateSetting('showNotifications', evt.target.checked) } /> - updateSetting('playSound', evt.target.checked)} /> {!isLinux && ( -
+
+
+
+
- -
-
- -
-
-
-
- -
-
-
+
- Show account hostname - + +
@@ -199,79 +211,91 @@ exports[`routes/Settings.tsx should render itself & its children 1`] = ` class="mb-3" > Notifications
- -
-
-
+
- Show only participating - + +
- -
-
- + +
+
+ +
- -
-
- + +
+
+ +
@@ -279,103 +303,124 @@ exports[`routes/Settings.tsx should render itself & its children 1`] = ` class="mb-3" > System
- +
+ +
+
+ +
- + Changes will take effect after restarting the app
- -
-
- + +
+
+ +
- -
-
-
+
- Play sound - + +
- -
-
- + +
+
+ +