Skip to content

Commit

Permalink
Merge pull request #805 from GeorgeBatt-SV/MOS-1472-single-address
Browse files Browse the repository at this point in the history
MOS-1472
  • Loading branch information
GeorgeBatt-SV authored Nov 27, 2024
2 parents 76086c4 + 2e0b1db commit 140faa3
Show file tree
Hide file tree
Showing 33 changed files with 1,008 additions and 416 deletions.
1 change: 1 addition & 0 deletions containers/mosaic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@types/node": "^22.5.5",
"@types/react": "18.3.5",
"@types/react-dom": "18.3.0",
"@types/react-places-autocomplete": "^7.2.14",
"@vitest/coverage-istanbul": "2.0.5",
"@vitest/ui": "2.0.5",
"copyfiles": "2.4.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ vi.mock("react-places-autocomplete", () => {
const getCommonAddressDrawerProps = () => ({
getOptionsCountries: getOptionsCountries,
getOptionsStates: getOptionsStates,
googleMapsApiKey: "",
googleMapsApiKey: "123",
handleClose: mockOnClose,
handleUnsavedChanges: mockOnUnsavedChanges,
onSave: mockOnSave,
});

describe("Address API components", () => {
describe.skip("Address API components", () => {
const tests: TestDef<Test>[] = [
{
name: "should place address components correctly for 337 Russell St, Hadley",
Expand Down
64 changes: 64 additions & 0 deletions containers/mosaic/src/__tests__/utils/object/isPlainObject.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type { TestDef } from "@simpleview/mochalib";
import { testArray } from "@simpleview/mochalib";
import isPlainObject from "@root/utils/object/isPlainObject";

describe(__dirname, () => {
interface Test {
value: any;
result: boolean;
}

const tests: TestDef<Test>[] = [
{
name: "should consider an empty object literal to a plain object",
args: {
value: {},
result: true,
},
},
{
name: "should consider an object created with new Object to be a plain object",
args: {
value: new Object(),
result: true,
},
},
{
name: "should consider a instantiated object to not be a plain object",
args: {
value: new Date(),
result: false,
},
},
{
name: "should consider a function to not be a plain object",
args: {
value: new Date(),
result: false,
},
},
{
name: "should consider an array literal to not be a plain object",
args: {
value: [],
result: false,
},
},
{
name: "should consider number to not be a plain object",
args: {
value: 1,
result: false,
},
},
{
name: "should consider a string literal to not be a plain object",
args: {
value: "Foo",
result: false,
},
},
];

testArray<Test>(tests, (test) => expect(isPlainObject(test.value)).toEqual(test.result));
});
124 changes: 124 additions & 0 deletions containers/mosaic/src/__tests__/utils/object/merge.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import type { TestDef } from "@simpleview/mochalib";
import { testArray } from "@simpleview/mochalib";
import merge from "@root/utils/object/merge";

describe(__dirname, () => {
interface Profile {
name?: string;
age?: number;
size?: {
height?: number;
weight?: number;
};
}

interface Test {
first: Profile;
second: Profile;
result: Profile;
}

const tests: TestDef<Test>[] = [
{
name: "should merge two objects with defined values",
args: {
first: {
name: "George",
age: 23,
},
second: {
name: "Lance",
},
result: {
name: "Lance",
age: 23,
},
},
},
{
name: "should merge two objects where the latter has explicit undefined values",
args: {
first: {
name: "George",
age: 23,
},
second: {
age: undefined,
},
result: {
name: "George",
age: undefined,
},
},
},
{
name: "should merge two objects recursively where nested properties are both objects",
args: {
first: {
name: "George",
size: {
height: 185,
weight: 90,
},
},
second: {
size: {
weight: 95,
},
},
result: {
name: "George",
size: {
height: 185,
weight: 95,
},
},
},
},
{
name: "should override a nested object with undefined value",
args: {
first: {
name: "George",
size: {
height: 185,
weight: 90,
},
},
second: {
size: undefined,
},
result: {
name: "George",
size: undefined,
},
},
},
{
name: "should merge nested objects and override nested properties",
args: {
first: {
name: "George",
size: {
height: 185,
weight: 90,
},
},
second: {
size: {
height: undefined,
},
},
result: {
name: "George",
size: {
height: undefined,
weight: 90,
},
},
},
},
];

testArray<Test>(tests, (test) => expect(merge(test.first, test.second)).toEqual(test.result));
});
13 changes: 8 additions & 5 deletions containers/mosaic/src/components/Field/FieldTypes.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FieldDefAddress } from "@root/components/Field/FormFieldAddress";
import type { FieldDefAddress, FieldDefAddressSingle } from "@root/components/Field/FormFieldAddress";
import type { FieldDefAdvancedSelection } from "@root/components/Field/FormFieldAdvancedSelection";
import type { FieldDefCheckbox } from "@root/components/Field/FormFieldCheckbox";
import type { FieldDefChip } from "@root/components/Field/FormFieldChips";
Expand All @@ -18,7 +18,7 @@ import type { FieldDefTextEditor } from "@root/components/Field/FormFieldTextEdi
import type { FieldDefToggle } from "@root/components/Field/FormFieldToggle";
import type { FieldDefUpload } from "@root/components/Field/FormFieldUpload";
import type { MosaicToggle } from "@root/types";
import type { ElementType, HTMLAttributes, MutableRefObject, ReactNode } from "react";
import type { ElementType, HTMLAttributes, MemoExoticComponent, MutableRefObject, ReactNode } from "react";
import type { FieldValueResolver, FormSpacing } from "../Form";
import type { FieldPath, FormMethods, FormState, Validator } from "../Form/useForm/types";
import type { FieldDefGroup } from "./FormFieldGroup/FormFieldGroupTypes";
Expand Down Expand Up @@ -187,7 +187,7 @@ export interface FieldDefBase<Type, T = any> {
getResolvedValue?: FieldValueResolver;
}

export type FieldDefCustom = FieldDefBase<(props?: any) => JSX.Element>;
export type FieldDefCustom = FieldDefBase<((props?: any) => JSX.Element) | MemoExoticComponent<(props?: any) => JSX.Element>>;

export type FieldDef =
| FieldDefText
Expand All @@ -205,6 +205,7 @@ export type FieldDef =
| FieldDefCheckbox
| FieldDefAdvancedSelection
| FieldDefAddress
| FieldDefAddressSingle
| FieldDefUpload
| FieldDefCustom
| FieldDefNumber
Expand All @@ -216,14 +217,16 @@ export type Head<T extends any[]> = T extends [ ...infer Head, any ] ? Head : an

export type DropParam<T extends (...args: any) => any, R = any> = (...args: Head<Parameters<T>>) => R;

export type FieldDefSanitized = Omit<FieldDef, "getResolvedValue" | "fields"> & {
export type FieldObj = Omit<FieldDef, "getResolvedValue" | "fields"> & {
getResolvedValue: DropParam<FieldValueResolver>;

order: number;

fields?: Record<string, FieldDefSanitized>;
fields?: Record<string, FieldObj>;
};

export type FieldDefSanitized = FieldDef;

export type FieldValidateOn = "onBlur" | "onChange" | "onBlurAmend" | "onBlurChange" | "onSubmit";

export interface FieldConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from "react";
import React from "react";
import type { ReactElement } from "react";
import { memo } from "react";
import PlacesAutocomplete from "react-places-autocomplete";
Expand Down Expand Up @@ -76,6 +76,7 @@ const AddressAutocomplete = (props: AddressAutocompleteProps): ReactElement => {
{...getInputProps({
placeholder: placeholder,
})}
fieldSize=""
onFocus={handleFocus}
onBlur={handleBlur}
disabled={disabled}
Expand Down
Loading

0 comments on commit 140faa3

Please sign in to comment.