-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix sample selection with map panel (#4739)
* clear records on page refresh * refactor as independent hook, add hook test * rm useRef * fixing selections with partial index records * add range tests * relay cleanup tweak * typos
- Loading branch information
1 parent
380ab4c
commit 1fdd870
Showing
7 changed files
with
159 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { act, renderHook } from "@testing-library/react-hooks"; | ||
import { describe, expect, it } from "vitest"; | ||
import useRecords from "./useRecords"; | ||
|
||
describe("useRecords", () => { | ||
it("return new records when clear string changes", () => { | ||
const { result, rerender } = renderHook( | ||
(clear: string) => useRecords(clear), | ||
{ initialProps: "one" } | ||
); | ||
expect(result.current.size).toBe(0); | ||
|
||
act(() => { | ||
result.current.set("one", 1); | ||
}); | ||
|
||
expect(result.current.size).toBe(1); | ||
|
||
rerender("two"); | ||
|
||
expect(result.current.size).toBe(0); | ||
}); | ||
}); |
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,10 @@ | ||
import { useMemo } from "react"; | ||
|
||
export type Records = Map<string, number>; | ||
|
||
export default (clear: string) => { | ||
return useMemo(() => { | ||
clear; | ||
return new Map<string, number>(); | ||
}, [clear]); | ||
}; |
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
29 changes: 29 additions & 0 deletions
29
app/packages/core/src/components/Grid/useSelectSample.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,29 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { addRange, removeRange } from "./useSelectSample"; | ||
|
||
describe("range selection tests", () => { | ||
it("adds a range, and includes selections without an index record", () => { | ||
const result = addRange( | ||
2, | ||
new Set(["0", "other"]), | ||
new Map([ | ||
["0", 0], | ||
["1", 1], | ||
["2", 2], | ||
]) | ||
); | ||
expect(result).toStrictEqual(new Set(["0", "1", "2", "other"])); | ||
}); | ||
|
||
it("removes a range, and includes selections without an index record", () => { | ||
const result = removeRange( | ||
1, | ||
new Set(["0", "1", "other"]), | ||
new Map([ | ||
["0", 0], | ||
["1", 1], | ||
]) | ||
); | ||
expect(result).toStrictEqual(new Set(["other"])); | ||
}); | ||
}); |
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