54 lines
2.9 KiB
TypeScript
54 lines
2.9 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
|
|
async function readSource(path: string) {
|
|
return readFile(new URL(path, import.meta.url), "utf8");
|
|
}
|
|
|
|
test("MainActivity debounces root realtime refresh bursts", async () => {
|
|
const source = await readSource("../android/app/src/main/java/com/hyzq/boss/MainActivity.java");
|
|
|
|
assert.match(source, /private static final long REALTIME_REFRESH_DEBOUNCE_MS = [\d_]+L;/);
|
|
assert.match(source, /private boolean realtimeRefreshScheduled(?: = false)?;/);
|
|
assert.match(source, /private final Runnable realtimeRefreshRunnable = new Runnable\(\)/);
|
|
assert.match(source, /scheduleRealtimeRefresh\(\)/);
|
|
assert.match(
|
|
source,
|
|
/private void scheduleRealtimeRefresh\(\)\s*\{[\s\S]*?if \(realtimeRefreshScheduled\) \{[\s\S]*?return;[\s\S]*?\}[\s\S]*?realtimeRefreshScheduled = true;[\s\S]*?uiHandler\.postDelayed\(realtimeRefreshRunnable, REALTIME_REFRESH_DEBOUNCE_MS\);[\s\S]*?\}/,
|
|
);
|
|
});
|
|
|
|
test("ProjectDetailActivity debounces realtime chat reload bursts", async () => {
|
|
const source = await readSource("../android/app/src/main/java/com/hyzq/boss/ProjectDetailActivity.java");
|
|
|
|
assert.match(source, /private static final long REALTIME_REFRESH_DEBOUNCE_MS = [\d_]+L;/);
|
|
assert.match(source, /private boolean realtimeReloadScheduled(?: = false)?;/);
|
|
assert.match(source, /private boolean realtimeReloadRequiresFullSnapshot;/);
|
|
assert.match(source, /private final Runnable realtimeReloadRunnable = new Runnable\(\)/);
|
|
assert.match(source, /scheduleRealtimeReload\(boolean requireFullSnapshot\)/);
|
|
assert.match(
|
|
source,
|
|
/private void scheduleRealtimeReload\(boolean requireFullSnapshot\)\s*\{[\s\S]*?realtimeReloadRequiresFullSnapshot = realtimeReloadRequiresFullSnapshot \|\| requireFullSnapshot;[\s\S]*?if \(realtimeReloadScheduled\) \{[\s\S]*?return;[\s\S]*?\}[\s\S]*?realtimeReloadScheduled = true;[\s\S]*?uiHandler\.postDelayed\(realtimeReloadRunnable, REALTIME_REFRESH_DEBOUNCE_MS\);[\s\S]*?\}/,
|
|
);
|
|
assert.doesNotMatch(
|
|
source,
|
|
/private void scheduleRealtimeReload\(boolean requireFullSnapshot\)\s*\{[\s\S]*?triggerRealtimeReload\(requireFullSnapshot\);[\s\S]*?\}/,
|
|
"chat page should debounce repeated realtime updates before reloading",
|
|
);
|
|
});
|
|
|
|
test("ConversationFolderActivity debounces realtime folder reload bursts", async () => {
|
|
const source = await readSource("../android/app/src/main/java/com/hyzq/boss/ConversationFolderActivity.java");
|
|
|
|
assert.match(source, /private static final long REALTIME_REFRESH_DEBOUNCE_MS = [\d_]+L;/);
|
|
assert.match(source, /private boolean realtimeReloadScheduled(?: = false)?;/);
|
|
assert.match(source, /private final Runnable realtimeReloadRunnable = new Runnable\(\)/);
|
|
assert.match(source, /scheduleRealtimeReload\(\)/);
|
|
assert.doesNotMatch(
|
|
source,
|
|
/runOnUiThread\(this::reload\)/,
|
|
"folder page should debounce repeated realtime updates before reloading",
|
|
);
|
|
});
|