Skip to content

Commit 52f045c

Browse files
committed
test(web): keep explorer resizing usable when storage fails
1 parent 4240d8e commit 52f045c

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎apps/web/src/components/files/FileExplorerPane.browser.test.tsx‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,42 @@ describe("FileExplorerPane", () => {
115115
expect(localStorage.getItem(STORAGE_KEY)).toBe("160");
116116
});
117117

118+
it("keeps keyboard and pointer resizing usable when browser storage rejects writes", async () => {
119+
using _storage = storedWidth(256);
120+
await using screen = await render(<PreviewRow width={600} />);
121+
const write = Storage.prototype.setItem;
122+
using _write = vi.spyOn(Storage.prototype, "setItem").mockImplementation(function (
123+
this: Storage,
124+
key,
125+
value,
126+
) {
127+
if (key === STORAGE_KEY) throw new DOMException("Storage is full", "QuotaExceededError");
128+
write.call(this, key, value);
129+
});
130+
using errors = vi.spyOn(console, "error").mockImplementation(() => {});
131+
// Synthetic pointer ids are not active browser pointers.
132+
using _capture = vi
133+
.spyOn(HTMLElement.prototype, "setPointerCapture")
134+
.mockImplementation(() => {});
135+
const explorer = screen.getByRole("complementary", { name: "File explorer" });
136+
const handle = screen.getByRole("separator", { name: "Resize file explorer" });
137+
138+
await userEvent.tab();
139+
await userEvent.keyboard("{ArrowLeft}");
140+
await expectWidth(explorer, 272);
141+
await expect.element(handle).toHaveAttribute("aria-valuenow", "272");
142+
expect(localStorage.getItem(STORAGE_KEY)).toBe("256");
143+
144+
drag(handle.element() as HTMLElement, -40);
145+
await expectWidth(explorer, 312);
146+
await expect.element(handle).toHaveAttribute("aria-valuenow", "312");
147+
await screen.rerender(<PreviewRow />);
148+
await expectWidth(explorer, 312);
149+
expect(localStorage.getItem(STORAGE_KEY)).toBe("256");
150+
expect(errors).toHaveBeenCalledTimes(2);
151+
expect(errors).toHaveBeenCalledWith("Could not persist panel width.", expect.any(Error));
152+
});
153+
118154
it("cleans up an active drag when the explorer is hidden", async () => {
119155
using _storage = storedWidth(256);
120156
await using screen = await render(<PreviewRow />);

‎apps/web/src/hooks/useResizableWidth.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function useResizableWidth(options: UseResizableWidthOptions): {
6161

6262
const setWidth = (value: number) => {
6363
const nextWidth = latestOptions.current.clamp(value);
64+
// Resizing remains usable for this session when browser storage is unavailable.
6465
setWidthState({ storageKey: latestOptions.current.storageKey, width: nextWidth });
6566
try {
6667
setLocalStorageItem(latestOptions.current.storageKey, nextWidth, WidthSchema);

0 commit comments

Comments
 (0)