Pin phone sheets to the visible viewport, and let people correct login and organizer errors.
This commit is contained in:
1 parent
27d74e510c
commit
39807ef452
17 files changed
+236
-16
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import { renderHook, act } from "@testing-library/react";
|
||||
import { describe, it, expect, afterEach } from "vitest";
|
||||
import { useVisualViewportHeight } from "../../../app/hooks/useVisualViewportHeight";
|
||||
|
||||
describe("useVisualViewportHeight", () => {
|
||||
const original = window.visualViewport;
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(window, "visualViewport", {
|
||||
configurable: true,
|
||||
value: original,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns undefined when disabled", () => {
|
||||
const { result } = renderHook(() => useVisualViewportHeight(false));
|
||||
expect(result.current).toBeUndefined();
|
||||
});
|
||||
|
||||
it("tracks height and the iOS keyboard offset", () => {
|
||||
const listeners = new Map<string, Set<() => void>>();
|
||||
const vp = {
|
||||
height: 800,
|
||||
offsetTop: 0,
|
||||
addEventListener: (type: string, fn: () => void) => {
|
||||
const set = listeners.get(type) ?? new Set();
|
||||
set.add(fn);
|
||||
listeners.set(type, set);
|
||||
},
|
||||
removeEventListener: (type: string, fn: () => void) => {
|
||||
listeners.get(type)?.delete(fn);
|
||||
},
|
||||
};
|
||||
Object.defineProperty(window, "visualViewport", {
|
||||
configurable: true,
|
||||
value: vp,
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useVisualViewportHeight(true));
|
||||
expect(result.current).toEqual({ height: 800, offsetTop: 0 });
|
||||
|
||||
act(() => {
|
||||
vp.height = 420;
|
||||
vp.offsetTop = 120;
|
||||
listeners.get("scroll")?.forEach((fn) => fn());
|
||||
});
|
||||
|
||||
expect(result.current).toEqual({ height: 420, offsetTop: 120 });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user