Skip to content

Commit 924a90b

Browse files
committed
fix: promises & add tests for FeatureSubFeatures
1 parent b04e673 commit 924a90b

29 files changed

+1200
-68
lines changed

biome.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@
9797
"a11y": {
9898
"useKeyWithClickEvents": "off",
9999
"noLabelWithoutControl": "off"
100+
},
101+
"nursery": {
102+
"useExhaustiveSwitchCases": "error",
103+
"noFloatingPromises": "error",
104+
"noMisusedPromises": "error"
100105
}
101106
}
102107
},

package-lock.json

Lines changed: 34 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
"@storybook/react-vite": "^10.1.11",
4949
"@tailwindcss/vite": "^4.1.18",
5050
"@tanstack/react-table": "^8.21.3",
51+
"@testing-library/dom": "^10.4.1",
52+
"@testing-library/react": "^16.3.2",
53+
"@testing-library/user-event": "^14.6.1",
5154
"@types/file-saver": "^2.0.7",
5255
"@types/json-schema": "^7.0.15",
5356
"@types/lodash": "^4.17.23",

src/components/device-page/HeaderDeviceSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const HeaderDeviceSelector = memo(({ currentSourceIdx, currentDevice, tab = "inf
2727
const onSelectHandler = useCallback(
2828
(option: SingleValue<SelectOption>) => {
2929
if (option) {
30-
navigate(option.link);
30+
void navigate(option.link);
3131
}
3232
},
3333
[navigate],

src/components/editors/ColorEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type ColorEditorProps = Omit<InputHTMLAttributes<HTMLInputElement>, "onChange" |
2727
value: AnyColor;
2828
format: ColorFormat;
2929
gamut: keyof typeof SUPPORTED_GAMUTS;
30-
onChange(color: AnyColor): void;
30+
onChange(color: AnyColor): Promise<void>;
3131
minimal?: boolean;
3232
};
3333

src/components/editors/EnumEditor.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type ValueWithLabelOrPrimitive = ValueWithLabel | number | string;
1313

1414
type EnumProps = {
1515
value?: ValueWithLabelOrPrimitive;
16-
onChange(value: unknown): void;
16+
onChange(value: unknown): Promise<void>;
1717
values: ValueWithLabelOrPrimitive[];
1818
minimal?: boolean;
1919
};
@@ -28,10 +28,10 @@ const EnumEditor = memo((props: EnumProps) => {
2828
const primitiveValue = isPrimitive(value);
2929

3030
const onSelectChange = useCallback(
31-
(e: ChangeEvent<HTMLSelectElement>) => {
31+
async (e: ChangeEvent<HTMLSelectElement>) => {
3232
const selectedValue = values.find((v) => (isPrimitive(v) ? v === e.target.value : v.value === Number.parseInt(e.target.value, 10)));
3333

34-
onChange(selectedValue);
34+
await onChange(selectedValue);
3535
},
3636
[values, onChange],
3737
);

src/components/editors/RangeEditor.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import EnumEditor, { type ValueWithLabelOrPrimitive } from "./EnumEditor.js";
44
type RangeProps = Omit<InputHTMLAttributes<HTMLInputElement>, "onChange" | "value"> & {
55
value: number | "";
66
unit?: string;
7-
onChange(value: number | null): void;
7+
onChange(value: number | null): Promise<void>;
88
steps?: ValueWithLabelOrPrimitive[];
99
minimal?: boolean;
1010
};
@@ -22,7 +22,14 @@ const RangeEditor = memo((props: RangeProps) => {
2222
setCurrentValue(e.target.value ? e.target.valueAsNumber : "");
2323
}, []);
2424

25-
const onSubmit = useCallback((e) => !e.target.validationMessage && onChange(currentValue === "" ? null : currentValue), [currentValue, onChange]);
25+
const onSubmit = useCallback(
26+
async (e) => {
27+
if (!e.target.validationMessage) {
28+
await onChange(currentValue === "" ? null : currentValue);
29+
}
30+
},
31+
[currentValue, onChange],
32+
);
2633

2734
return (
2835
<div className="flex flex-row flex-wrap gap-3 items-center">

src/components/editors/TextEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type InputHTMLAttributes, memo, useEffect, useState } from "react";
22

33
type TextProps = Omit<InputHTMLAttributes<HTMLInputElement>, "onChange"> & {
44
value: string;
5-
onChange(value: string): void;
5+
onChange(value: string): Promise<void>;
66
};
77

88
const TextEditor = memo((props: TextProps) => {

src/components/features/Binary.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ const Binary = memo((props: BinaryProps) => {
2121
const { t } = useTranslation("zigbee");
2222
const onButtonClick = useCallback((value: string | boolean) => onChange(property ? { [property]: value } : value), [property, onChange]);
2323
const onCheckboxChange = useCallback(
24-
(e: ChangeEvent<HTMLInputElement>) => {
24+
async (e: ChangeEvent<HTMLInputElement>) => {
2525
const checkedValue = e.target.checked ? valueOn : valueOff;
2626

27-
onChange(property ? { [property]: checkedValue } : checkedValue);
27+
await onChange(property ? { [property]: checkedValue } : checkedValue);
2828
},
2929
[valueOn, valueOff, property, onChange],
3030
);

src/components/features/Color.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ const Color = memo((props: ColorProps) => {
3737
return "cie1931";
3838
}, [device.definition]);
3939

40-
const onEditorChange = useCallback((color: AnyColor) => onChange({ [property ?? "color"]: color }), [property, onChange]);
40+
const onEditorChange = useCallback(
41+
async (color: AnyColor) => {
42+
await onChange({ [property ?? "color"]: color });
43+
},
44+
[property, onChange],
45+
);
4146

4247
return <ColorEditor onChange={onEditorChange} value={value} format={name} minimal={minimal} gamut={gamut} />;
4348
});

0 commit comments

Comments
 (0)