mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-10-09 15:58:34 +00:00
8083aece66
Schedule layout suppress store updates on the next animation frame so tab switches and resize drags no longer trigger React setState-during-render warnings in TerminalComponent. Co-authored-by: Cursor <cursoragent@cursor.com>
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import { terminalLayoutSuppressStore } from './terminalLayoutSuppressStore';
|
|
|
|
test('terminalLayoutSuppressStore tracks nested begin/end', () => {
|
|
assert.equal(terminalLayoutSuppressStore.getActive(), false);
|
|
terminalLayoutSuppressStore.begin();
|
|
assert.equal(terminalLayoutSuppressStore.getActive(), true);
|
|
terminalLayoutSuppressStore.begin();
|
|
assert.equal(terminalLayoutSuppressStore.getActive(), true);
|
|
terminalLayoutSuppressStore.end();
|
|
assert.equal(terminalLayoutSuppressStore.getActive(), true);
|
|
terminalLayoutSuppressStore.end();
|
|
assert.equal(terminalLayoutSuppressStore.getActive(), false);
|
|
});
|
|
|
|
test('terminalLayoutSuppressStore defers subscriber notifications', async () => {
|
|
let notifyCount = 0;
|
|
const unsubscribe = terminalLayoutSuppressStore.subscribe(() => {
|
|
notifyCount += 1;
|
|
});
|
|
|
|
terminalLayoutSuppressStore.begin();
|
|
assert.equal(notifyCount, 0, 'begin should not notify synchronously');
|
|
assert.equal(terminalLayoutSuppressStore.getActive(), true);
|
|
|
|
await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
|
assert.equal(notifyCount, 1, 'begin should notify after the current turn');
|
|
|
|
terminalLayoutSuppressStore.end();
|
|
assert.equal(notifyCount, 1, 'end should not notify synchronously');
|
|
assert.equal(terminalLayoutSuppressStore.getActive(), false);
|
|
|
|
await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
|
assert.equal(notifyCount, 2, 'end should notify after the current turn');
|
|
|
|
unsubscribe();
|
|
});
|