Debounce Android realtime refresh bursts
This commit is contained in:
49
tests/android-realtime-refresh-debounce.test.ts
Normal file
49
tests/android-realtime-refresh-debounce.test.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
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.doesNotMatch(
|
||||
source,
|
||||
/runOnUiThread\(this::refreshCurrentTab\)/,
|
||||
"root page should coalesce bursts instead of refreshing immediately for each event",
|
||||
);
|
||||
});
|
||||
|
||||
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 final Runnable realtimeReloadRunnable = new Runnable\(\)/);
|
||||
assert.match(source, /scheduleRealtimeReload\(\)/);
|
||||
assert.doesNotMatch(
|
||||
source,
|
||||
/runOnUiThread\(this::triggerRealtimeReload\)/,
|
||||
"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",
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user