-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 test(mutations): add mutations tests
- Loading branch information
1 parent
8bc3507
commit 82c9929
Showing
5 changed files
with
104 additions
and
7 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
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
82 changes: 82 additions & 0 deletions
82
src/frontend/lib/data/useMutate/__tests__/mutation-helpers.spec.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,82 @@ | ||
import { MutationHelpers } from "../mutation-helpers"; | ||
|
||
describe("MutationHelpers", () => { | ||
it("append", () => { | ||
const old = ["a", "b"]; | ||
const formData = "c"; | ||
expect(MutationHelpers.append(old, formData)).toEqual(["a", "b", "c"]); | ||
}); | ||
|
||
it("remove", () => { | ||
const old = ["a", "b", "c"]; | ||
const formData = "b"; | ||
expect(MutationHelpers.remove(old, formData)).toEqual(["a", "c"]); | ||
}); | ||
|
||
it("deleteByKey", () => { | ||
const old = [{ id: "a" }, { id: "b" }, { id: "c" }]; | ||
const key = "id"; | ||
const currentDataId = "b"; | ||
expect(MutationHelpers.deleteByKey(key)(old, currentDataId)).toEqual([ | ||
{ id: "a" }, | ||
{ id: "c" }, | ||
]); | ||
}); | ||
|
||
it("mergeArray", () => { | ||
const old = ["a", "b"]; | ||
const formData = ["c", "d"]; | ||
expect(MutationHelpers.mergeArray(old, formData)).toEqual([ | ||
"a", | ||
"b", | ||
"c", | ||
"d", | ||
]); | ||
}); | ||
|
||
it("mergeObject", () => { | ||
const old = { a: "a", b: "old" }; | ||
const formData = { b: "b" }; | ||
expect(MutationHelpers.mergeObject(old, formData)).toEqual({ | ||
a: "a", | ||
b: "b", | ||
}); | ||
}); | ||
|
||
it("replace", () => { | ||
const old = "a"; | ||
const formData = "b"; | ||
expect(MutationHelpers.replace(old, formData)).toEqual("b"); | ||
}); | ||
|
||
it("update", () => { | ||
const old = [{ id: "a" }, { id: "b" }]; | ||
const formData = { id: "b", data: "c" }; | ||
expect(MutationHelpers.update(old, formData)).toEqual([ | ||
{ id: "a" }, | ||
{ id: "b", data: "c" }, | ||
]); | ||
}); | ||
|
||
it("delete", () => { | ||
const old = [{ id: "a" }, { id: "b" }]; | ||
const currentDataId = "b"; | ||
expect(MutationHelpers.delete(old, currentDataId)).toEqual([{ id: "a" }]); | ||
}); | ||
|
||
it("sortOrder", () => { | ||
const old = [{ id: "a" }, { id: "b" }, { id: "c" }]; | ||
const order = ["c", "a", "b"]; | ||
expect(MutationHelpers.sortOrder(old, order)).toEqual([ | ||
{ id: "c" }, | ||
{ id: "a" }, | ||
{ id: "b" }, | ||
]); | ||
}); | ||
|
||
it("removeMany", () => { | ||
const old = ["a", "b", "c"]; | ||
const formData = ["b", "c"]; | ||
expect(MutationHelpers.removeMany(old, formData)).toEqual(["a"]); | ||
}); | ||
}); |
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