-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #805 from GeorgeBatt-SV/MOS-1472-single-address
MOS-1472
- Loading branch information
Showing
33 changed files
with
1,008 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
containers/mosaic/src/__tests__/utils/object/isPlainObject.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
124
containers/mosaic/src/__tests__/utils/object/merge.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.