@jobber/components-native 0.95.1-CLEANUPfi-c27afbd.0 → 0.95.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.95.1
|
|
3
|
+
"version": "0.95.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"react-native-safe-area-context": "^5.4.0",
|
|
97
97
|
"react-native-svg": ">=12.0.0"
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "e51bd48b5eaa0e15ffb13f3c7745527c40997454"
|
|
100
100
|
}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
waitFor,
|
|
9
9
|
} from "@testing-library/react-native";
|
|
10
10
|
import type { TextStyle } from "react-native";
|
|
11
|
-
import { Platform } from "react-native";
|
|
11
|
+
import { Button, Platform } from "react-native";
|
|
12
12
|
import { FormProvider, useForm } from "react-hook-form";
|
|
13
13
|
import type { InputTextProps } from "./InputText";
|
|
14
14
|
import { InputText } from "./InputText";
|
|
@@ -623,6 +623,120 @@ describe("InputText", () => {
|
|
|
623
623
|
});
|
|
624
624
|
});
|
|
625
625
|
});
|
|
626
|
+
|
|
627
|
+
describe("with FormProvider", () => {
|
|
628
|
+
const mockOnSubmit = jest.fn();
|
|
629
|
+
const inputName = "testInput";
|
|
630
|
+
const inputAccessibilityLabel = "Test Input";
|
|
631
|
+
const saveButtonText = "Save";
|
|
632
|
+
|
|
633
|
+
function FormWithProvider({
|
|
634
|
+
defaultValue,
|
|
635
|
+
}: {
|
|
636
|
+
readonly defaultValue?: string;
|
|
637
|
+
}) {
|
|
638
|
+
const formMethods = useForm();
|
|
639
|
+
|
|
640
|
+
return (
|
|
641
|
+
<FormProvider {...formMethods}>
|
|
642
|
+
<InputText
|
|
643
|
+
name={inputName}
|
|
644
|
+
defaultValue={defaultValue}
|
|
645
|
+
accessibilityLabel={inputAccessibilityLabel}
|
|
646
|
+
/>
|
|
647
|
+
<Button
|
|
648
|
+
onPress={formMethods.handleSubmit(values => mockOnSubmit(values))}
|
|
649
|
+
title={saveButtonText}
|
|
650
|
+
accessibilityLabel={saveButtonText}
|
|
651
|
+
/>
|
|
652
|
+
</FormProvider>
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
beforeEach(() => {
|
|
657
|
+
mockOnSubmit.mockClear();
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
describe("defaultValue prop sets form value", () => {
|
|
661
|
+
it("sets form value to string when defaultValue is provided", async () => {
|
|
662
|
+
const testValue = "test value";
|
|
663
|
+
const { getByLabelText } = render(
|
|
664
|
+
<FormWithProvider defaultValue={testValue} />,
|
|
665
|
+
);
|
|
666
|
+
|
|
667
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
668
|
+
await waitFor(() => {
|
|
669
|
+
fireEvent.press(saveButton);
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
673
|
+
[inputName]: testValue,
|
|
674
|
+
});
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
it("sets form value to undefined when defaultValue is undefined", async () => {
|
|
678
|
+
const { getByLabelText } = render(<FormWithProvider />);
|
|
679
|
+
|
|
680
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
681
|
+
await waitFor(() => {
|
|
682
|
+
fireEvent.press(saveButton);
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
686
|
+
[inputName]: undefined,
|
|
687
|
+
});
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
it("sets form value to undefined when defaultValue is empty string", async () => {
|
|
691
|
+
const { getByLabelText } = render(<FormWithProvider defaultValue="" />);
|
|
692
|
+
|
|
693
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
694
|
+
await waitFor(() => {
|
|
695
|
+
fireEvent.press(saveButton);
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
699
|
+
[inputName]: undefined,
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
describe("input value updates form value", () => {
|
|
705
|
+
it("updates form value when input text is changed", async () => {
|
|
706
|
+
const { getByLabelText } = render(
|
|
707
|
+
<FormWithProvider defaultValue="initial" />,
|
|
708
|
+
);
|
|
709
|
+
|
|
710
|
+
const input = getByLabelText(inputAccessibilityLabel);
|
|
711
|
+
fireEvent.changeText(input, "new value");
|
|
712
|
+
|
|
713
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
714
|
+
await waitFor(() => {
|
|
715
|
+
fireEvent.press(saveButton);
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
719
|
+
[inputName]: "new value",
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
it("preserves defaultValue when input is not interacted with", async () => {
|
|
724
|
+
const testValue = "preserved value";
|
|
725
|
+
const { getByLabelText } = render(
|
|
726
|
+
<FormWithProvider defaultValue={testValue} />,
|
|
727
|
+
);
|
|
728
|
+
|
|
729
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
730
|
+
await waitFor(() => {
|
|
731
|
+
fireEvent.press(saveButton);
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
735
|
+
[inputName]: testValue,
|
|
736
|
+
});
|
|
737
|
+
});
|
|
738
|
+
});
|
|
739
|
+
});
|
|
626
740
|
});
|
|
627
741
|
|
|
628
742
|
describe("Transform", () => {
|
|
@@ -40,7 +40,7 @@ export function useFormController<T>({
|
|
|
40
40
|
name: fieldName,
|
|
41
41
|
control,
|
|
42
42
|
rules: validations,
|
|
43
|
-
defaultValue: value
|
|
43
|
+
defaultValue: typeof value === "boolean" ? value : value || undefined,
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
// The naming convention established by react-hook-form for arrays of fields is, for example, "emails.0.description".
|