Repository navigation
fix(mobile): dragging a microphone or environment route now saves its new place #26096
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
Changes from all commits
Commits
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
75 changes: 75 additions & 0 deletions
75
apps/mobile/src/features/settings/components/SettingsDragHandle.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,75 @@ | ||
| import type { ReactNode } from "react"; | ||
| import { act } from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import { describe, expect, it, vi } from "vite-plus/test"; | ||
|
|
||
| type PanEvent = { readonly translationY: number }; | ||
| type PanHandlers = { | ||
| onStart?: () => void; | ||
| onUpdate?: (event: PanEvent) => void; | ||
| onFinalize?: (event: PanEvent, success: boolean) => void; | ||
| }; | ||
|
|
||
| const pans = vi.hoisted(() => [] as PanHandlers[]); | ||
|
|
||
| vi.mock("react-native", () => ({ | ||
| View: ({ children }: { children?: ReactNode }) => <div>{children}</div>, | ||
| })); | ||
| vi.mock("react-native-gesture-handler", () => ({ | ||
| GestureDetector: ({ children }: { children?: ReactNode }) => children, | ||
| Gesture: { | ||
| Pan: () => { | ||
| const handlers: PanHandlers = {}; | ||
| pans.push(handlers); | ||
| const pan = { | ||
| minDistance: () => pan, | ||
| shouldCancelWhenOutside: () => pan, | ||
| runOnJS: () => pan, | ||
| onStart: (callback: PanHandlers["onStart"]) => ((handlers.onStart = callback), pan), | ||
| onUpdate: (callback: PanHandlers["onUpdate"]) => ((handlers.onUpdate = callback), pan), | ||
| onFinalize: (callback: PanHandlers["onFinalize"]) => ( | ||
| (handlers.onFinalize = callback), | ||
| pan | ||
| ), | ||
| }; | ||
| return pan; | ||
| }, | ||
| }, | ||
| })); | ||
| vi.mock("../../../components/ui/AppSymbol", () => ({ SymbolView: () => null })); | ||
|
|
||
| import { SettingsDragHandle } from "./SettingsDragHandle"; | ||
|
|
||
| describe("SettingsDragHandle", () => { | ||
| // The worklets Babel plugin copies values a gesture callback closes over when the gesture is | ||
| // built, so a drop must not read a translation tracked in a local variable. | ||
| it("reports the released translation when the pan ends", () => { | ||
| pans.length = 0; | ||
| const onEnd = vi.fn(); | ||
| const root = createRoot(document.createElement("div")); | ||
| act(() => | ||
| root.render( | ||
| <SettingsDragHandle | ||
| title="Built-in microphone" | ||
| canMoveUp | ||
| canMoveDown | ||
| onStart={() => {}} | ||
| onMove={() => {}} | ||
| onEnd={onEnd} | ||
| onStep={() => {}} | ||
| />, | ||
| ), | ||
| ); | ||
| const pan = pans.at(-1)!; | ||
|
|
||
| act(() => { | ||
| pan.onStart?.(); | ||
| pan.onUpdate?.({ translationY: 64 }); | ||
| pan.onUpdate?.({ translationY: 130 }); | ||
| pan.onFinalize?.({ translationY: 130 }, true); | ||
| }); | ||
|
|
||
| expect(onEnd).toHaveBeenCalledWith(130, false); | ||
| act(() => root.unmount()); | ||
| }); | ||
| }); | ||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the final translation differ from the last update.
The previous tracked-variable implementation would also report
130here, so this test passes with the reported bug. Change the last update to a different value, such as100, and keep finalization at130. Confirm that the test then fails against the previous implementation. As per path instructions, “Tests should cover meaningful logic or observable behavior; avoid static-markup assertions and tests that merely mirror implementation or assert callback wiring.”Proposed test change
Committable suggestion
Sources: Coding guidelines, Path instructions