From d96d5526b53692cdd2b91abe89e9bf4f801a7d3f Mon Sep 17 00:00:00 2001
From: Adam Setch
Date: Wed, 22 Jan 2025 17:09:25 -0500
Subject: [PATCH] refactor: simplify fields
Signed-off-by: Adam Setch
---
src/renderer/components/fields/Checkbox.tsx | 9 +-
.../components/fields/FieldLabel.test.tsx | 14 +
src/renderer/components/fields/FieldLabel.tsx | 14 +
src/renderer/components/fields/RadioGroup.tsx | 73 ++---
.../__snapshots__/FieldLabel.test.tsx.snap | 76 +++++
.../__snapshots__/RadioGroup.test.tsx.snap | 290 ++++++++----------
.../settings/AppearanceSettings.tsx | 8 +-
.../__snapshots__/Filters.test.tsx.snap | 3 +-
.../__snapshots__/Settings.test.tsx.snap | 275 ++++++++---------
9 files changed, 389 insertions(+), 373 deletions(-)
create mode 100644 src/renderer/components/fields/FieldLabel.test.tsx
create mode 100644 src/renderer/components/fields/FieldLabel.tsx
create mode 100644 src/renderer/components/fields/__snapshots__/FieldLabel.test.tsx.snap
diff --git a/src/renderer/components/fields/Checkbox.tsx b/src/renderer/components/fields/Checkbox.tsx
index d44e24cc8..70de2ecac 100644
--- a/src/renderer/components/fields/Checkbox.tsx
+++ b/src/renderer/components/fields/Checkbox.tsx
@@ -1,4 +1,5 @@
import type { FC, ReactNode } from 'react';
+import { cn } from '../../utils/cn';
import { Tooltip } from './Tooltip';
export interface ICheckbox {
@@ -26,10 +27,10 @@ export const Checkbox: FC = (props: ICheckbox) => {
diff --git a/src/renderer/components/fields/FieldLabel.test.tsx b/src/renderer/components/fields/FieldLabel.test.tsx
new file mode 100644
index 000000000..31f76978d
--- /dev/null
+++ b/src/renderer/components/fields/FieldLabel.test.tsx
@@ -0,0 +1,14 @@
+import { render } from '@testing-library/react';
+import { FieldLabel, type IFieldLabel } from './FieldLabel';
+
+describe('renderer/components/fields/FieldLabel.tsx', () => {
+ const props: IFieldLabel = {
+ name: 'appearance',
+ label: 'Appearance',
+ };
+
+ it('should render', () => {
+ const tree = render(
);
+ expect(tree).toMatchSnapshot();
+ });
+});
diff --git a/src/renderer/components/fields/FieldLabel.tsx b/src/renderer/components/fields/FieldLabel.tsx
new file mode 100644
index 000000000..633d1225d
--- /dev/null
+++ b/src/renderer/components/fields/FieldLabel.tsx
@@ -0,0 +1,14 @@
+import type { FC } from 'react';
+
+export interface IFieldLabel {
+ name: string;
+ label: string;
+}
+
+export const FieldLabel: FC
= (props: IFieldLabel) => {
+ return (
+
+ );
+};
diff --git a/src/renderer/components/fields/RadioGroup.tsx b/src/renderer/components/fields/RadioGroup.tsx
index d193d74e5..990254158 100644
--- a/src/renderer/components/fields/RadioGroup.tsx
+++ b/src/renderer/components/fields/RadioGroup.tsx
@@ -1,64 +1,43 @@
import type { ChangeEvent, FC } from 'react';
import type { RadioGroupItem } from '../../types';
-import { cn } from '../../utils/cn';
+import { FieldLabel } from './FieldLabel';
export interface IRadioGroup {
name: string;
label: string;
options: RadioGroupItem[];
value: string;
- disabled?: boolean;
onChange: (event: ChangeEvent) => void;
- className?: string;
}
export const RadioGroup: FC = (props: IRadioGroup) => {
return (
-
-
-
-
-
+
+
-
- {props.options.map((item) => {
- return (
-
-
-
-
- );
- })}
-
+
+ {props.options.map((item) => {
+ const name = `${props.name}_${item.value.toLowerCase()}`;
+
+ return (
+
+
+
+
+ );
+ })}
);
diff --git a/src/renderer/components/fields/__snapshots__/FieldLabel.test.tsx.snap b/src/renderer/components/fields/__snapshots__/FieldLabel.test.tsx.snap
new file mode 100644
index 000000000..8e06a68ea
--- /dev/null
+++ b/src/renderer/components/fields/__snapshots__/FieldLabel.test.tsx.snap
@@ -0,0 +1,76 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`renderer/components/fields/FieldLabel.tsx should render 1`] = `
+{
+ "asFragment": [Function],
+ "baseElement":
+
+
+
+ ,
+ "container":
+
+
,
+ "debug": [Function],
+ "findAllByAltText": [Function],
+ "findAllByDisplayValue": [Function],
+ "findAllByLabelText": [Function],
+ "findAllByPlaceholderText": [Function],
+ "findAllByRole": [Function],
+ "findAllByTestId": [Function],
+ "findAllByText": [Function],
+ "findAllByTitle": [Function],
+ "findByAltText": [Function],
+ "findByDisplayValue": [Function],
+ "findByLabelText": [Function],
+ "findByPlaceholderText": [Function],
+ "findByRole": [Function],
+ "findByTestId": [Function],
+ "findByText": [Function],
+ "findByTitle": [Function],
+ "getAllByAltText": [Function],
+ "getAllByDisplayValue": [Function],
+ "getAllByLabelText": [Function],
+ "getAllByPlaceholderText": [Function],
+ "getAllByRole": [Function],
+ "getAllByTestId": [Function],
+ "getAllByText": [Function],
+ "getAllByTitle": [Function],
+ "getByAltText": [Function],
+ "getByDisplayValue": [Function],
+ "getByLabelText": [Function],
+ "getByPlaceholderText": [Function],
+ "getByRole": [Function],
+ "getByTestId": [Function],
+ "getByText": [Function],
+ "getByTitle": [Function],
+ "queryAllByAltText": [Function],
+ "queryAllByDisplayValue": [Function],
+ "queryAllByLabelText": [Function],
+ "queryAllByPlaceholderText": [Function],
+ "queryAllByRole": [Function],
+ "queryAllByTestId": [Function],
+ "queryAllByText": [Function],
+ "queryAllByTitle": [Function],
+ "queryByAltText": [Function],
+ "queryByDisplayValue": [Function],
+ "queryByLabelText": [Function],
+ "queryByPlaceholderText": [Function],
+ "queryByRole": [Function],
+ "queryByTestId": [Function],
+ "queryByText": [Function],
+ "queryByTitle": [Function],
+ "rerender": [Function],
+ "unmount": [Function],
+}
+`;
diff --git a/src/renderer/components/fields/__snapshots__/RadioGroup.test.tsx.snap b/src/renderer/components/fields/__snapshots__/RadioGroup.test.tsx.snap
index e0ef716ea..5f74db2a9 100644
--- a/src/renderer/components/fields/__snapshots__/RadioGroup.test.tsx.snap
+++ b/src/renderer/components/fields/__snapshots__/RadioGroup.test.tsx.snap
@@ -6,90 +6,21 @@ exports[`renderer/components/fields/RadioGroup.tsx should render 1`] = `
"baseElement":
- ,
- "container":
-
-
-
-
-
+ Appearance
+
+
-