-
Notifications
You must be signed in to change notification settings - Fork 4
Drops highlight #1552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Drops highlight #1552
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bab2f63
Drops highlight
prxt6529 fc8b3f8
WIP
prxt6529 765ca65
Merge branch 'main' into drops-highlight
simo6529 fb078d2
wip
simo6529 f2a8313
wip
simo6529 6ff4a54
Merge branch 'main' into drops-highlight
simo6529 5cf95a5
wip
simo6529 97ce2f5
wip
simo6529 dd5e1fb
Merge branch 'main' into drops-highlight
simo6529 aebff59
wip
simo6529 579e493
wip
simo6529 5eb5dff
wip
simo6529 d72f13c
wip
simo6529 c2dd74a
wip
simo6529 6faca45
Merge branch 'main' into drops-highlight
simo6529 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
174 changes: 174 additions & 0 deletions
174
__tests__/components/drops/view/HighlightDropWrapper.test.tsx
This file contains hidden or 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,174 @@ | ||
| import HighlightDropWrapper from "@/components/drops/view/HighlightDropWrapper"; | ||
| import { act, render, screen } from "@testing-library/react"; | ||
|
|
||
| beforeAll(() => { | ||
| if (typeof DOMRect === "undefined") { | ||
| // @ts-ignore | ||
| global.DOMRect = class DOMRect { | ||
| left: number; | ||
| top: number; | ||
| right: number; | ||
| bottom: number; | ||
| width: number; | ||
| height: number; | ||
| constructor(x = 0, y = 0, width = 0, height = 0) { | ||
| this.left = x; | ||
| this.top = y; | ||
| this.width = width; | ||
| this.height = height; | ||
| this.right = x + width; | ||
| this.bottom = y + height; | ||
| } | ||
| } as any; | ||
| } | ||
| if (typeof window.requestAnimationFrame === "undefined") { | ||
| // @ts-ignore | ||
| window.requestAnimationFrame = (cb: FrameRequestCallback) => | ||
| setTimeout(() => cb(Date.now()), 0) as unknown as number; | ||
| // @ts-ignore | ||
| window.cancelAnimationFrame = (id: number) => | ||
| clearTimeout(id as unknown as number); | ||
| } | ||
| }); | ||
|
|
||
| let gBCRSpy: jest.SpyInstance; | ||
| beforeEach(() => { | ||
| gBCRSpy = jest | ||
| .spyOn(HTMLElement.prototype, "getBoundingClientRect") | ||
| .mockImplementation(function () { | ||
| return { | ||
| left: 0, | ||
| top: 0, | ||
| right: 100, | ||
| bottom: 100, | ||
| width: 100, | ||
| height: 100, | ||
| x: 0, | ||
| y: 0, | ||
| toJSON: () => ({}), | ||
| } as unknown as DOMRect; | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (gBCRSpy) gBCRSpy.mockRestore(); | ||
| }); | ||
|
|
||
| jest.useFakeTimers(); | ||
|
simo6529 marked this conversation as resolved.
|
||
|
|
||
| describe("HighlightDropWrapper", () => { | ||
| it("renders children", () => { | ||
| render( | ||
| <HighlightDropWrapper active={false}> | ||
| <div data-testid="child" /> | ||
| </HighlightDropWrapper> | ||
| ); | ||
| expect(screen.getByTestId("child")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("applies highlight class when active and fades out after timeout", () => { | ||
| const { container } = render( | ||
| <HighlightDropWrapper active={true} highlightMs={1000} fadeMs={500}> | ||
| <div>drop</div> | ||
| </HighlightDropWrapper> | ||
| ); | ||
|
|
||
| const wrapper = container.firstChild as HTMLElement; | ||
|
|
||
| expect(wrapper).toHaveClass("tw-bg-[#25263f]"); | ||
| expect(wrapper).toHaveClass("tw-transition-colors"); | ||
| expect(wrapper.style.transitionDuration).not.toBe(""); | ||
|
|
||
| act(() => { | ||
| jest.advanceTimersByTime(1200); | ||
| }); | ||
|
|
||
| expect(wrapper).not.toHaveClass("tw-bg-[#25263f]"); | ||
| expect(wrapper).toHaveClass("tw-transition-colors"); | ||
| expect(wrapper).toHaveClass("tw-bg-transparent"); | ||
| expect(wrapper.style.transitionDuration).not.toBe(""); | ||
|
|
||
| act(() => { | ||
| jest.advanceTimersByTime(500); | ||
| }); | ||
|
|
||
| expect(wrapper).not.toHaveClass("tw-bg-[#25263f]"); | ||
| expect(wrapper).not.toHaveClass("tw-transition-colors"); | ||
| expect(wrapper).not.toHaveClass("tw-bg-transparent"); | ||
| expect(wrapper.style.transitionDuration).toBe(""); | ||
| }); | ||
|
|
||
| it("restarts highlight when reactivated", () => { | ||
| const { rerender, container } = render( | ||
| <HighlightDropWrapper active={true} highlightMs={1000}> | ||
| <div>drop</div> | ||
| </HighlightDropWrapper> | ||
| ); | ||
|
|
||
| act(() => { | ||
| jest.advanceTimersByTime(1200); | ||
| }); | ||
| expect(container.firstChild).not.toHaveClass("tw-bg-[#25263f]"); | ||
|
|
||
| rerender( | ||
| <HighlightDropWrapper active={false} highlightMs={1000}> | ||
| <div>drop</div> | ||
| </HighlightDropWrapper> | ||
| ); | ||
|
|
||
| act(() => { | ||
| jest.advanceTimersByTime(1); | ||
| }); | ||
|
|
||
| rerender( | ||
| <HighlightDropWrapper active={true} highlightMs={1000}> | ||
| <div>drop</div> | ||
| </HighlightDropWrapper> | ||
| ); | ||
|
|
||
| act(() => { | ||
| jest.advanceTimersByTime(1); | ||
| }); | ||
|
|
||
| expect(container.firstChild).toHaveClass("tw-bg-[#25263f]"); | ||
| expect(container.firstChild).toHaveClass("tw-transition-colors"); | ||
| }); | ||
|
|
||
| it("keeps highlight duration even if active resets immediately", () => { | ||
| const { rerender, container } = render( | ||
| <HighlightDropWrapper active={true} highlightMs={1000} fadeMs={500}> | ||
| <div>drop</div> | ||
| </HighlightDropWrapper> | ||
| ); | ||
|
|
||
| rerender( | ||
| <HighlightDropWrapper active={false} highlightMs={1000} fadeMs={500}> | ||
| <div>drop</div> | ||
| </HighlightDropWrapper> | ||
| ); | ||
|
|
||
| const wrapper = container.firstChild as HTMLElement; | ||
|
|
||
| expect(wrapper).toHaveClass("tw-bg-[#25263f]"); | ||
| expect(wrapper).toHaveClass("tw-transition-colors"); | ||
| expect(wrapper.style.transitionDuration).not.toBe(""); | ||
|
|
||
| act(() => { | ||
| jest.advanceTimersByTime(1200); | ||
| }); | ||
|
|
||
| expect(wrapper).not.toHaveClass("tw-bg-[#25263f]"); | ||
| expect(wrapper).toHaveClass("tw-transition-colors"); | ||
| expect(wrapper).toHaveClass("tw-bg-transparent"); | ||
| expect(wrapper.style.transitionDuration).not.toBe(""); | ||
|
|
||
| act(() => { | ||
| jest.advanceTimersByTime(500); | ||
| }); | ||
|
|
||
| expect(wrapper).not.toHaveClass("tw-bg-[#25263f]"); | ||
| expect(wrapper).not.toHaveClass("tw-transition-colors"); | ||
| expect(wrapper).not.toHaveClass("tw-bg-transparent"); | ||
| expect(wrapper.style.transitionDuration).toBe(""); | ||
| }); | ||
| }); | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.