52 lines
2.2 KiB
TypeScript
52 lines
2.2 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("BossRealtimeClient tracks whether the SSE stream is currently connected", async () => {
|
|
const source = await readSource("../android/app/src/main/java/com/hyzq/boss/BossRealtimeClient.java");
|
|
|
|
assert.match(source, /private volatile boolean connected;/, "expected realtime client to cache connection state");
|
|
assert.match(source, /boolean isConnected\(\)\s*\{\s*return connected;\s*\}/, "expected realtime client to expose connection state");
|
|
assert.match(source, /connected = true;/, "expected realtime client to flip connected once the SSE stream is ready");
|
|
assert.match(source, /connected = false;/, "expected realtime client to clear connected when the stream stops");
|
|
});
|
|
|
|
test("MainActivity only performs conversation polling when realtime is unavailable", async () => {
|
|
const source = await readSource("../android/app/src/main/java/com/hyzq/boss/MainActivity.java");
|
|
|
|
assert.match(
|
|
source,
|
|
/private boolean shouldAutoRefreshConversations\(\)\s*\{[\s\S]{0,240}!isRealtimeConnected\(\)/,
|
|
"expected root conversation polling to back off while realtime is healthy",
|
|
);
|
|
assert.match(
|
|
source,
|
|
/private boolean shouldMaintainConversationAutoRefresh\(\)/,
|
|
"expected root page to keep a lightweight fallback scheduler even when polling is paused",
|
|
);
|
|
});
|
|
|
|
test("ProjectDetailActivity keeps a fallback poller for chat pages when realtime disconnects", async () => {
|
|
const source = await readSource("../android/app/src/main/java/com/hyzq/boss/ProjectDetailActivity.java");
|
|
|
|
assert.match(
|
|
source,
|
|
/private static final long CONVERSATION_AUTO_REFRESH_MS = [\d_]+L;/,
|
|
"expected chat detail page to define a fallback polling cadence",
|
|
);
|
|
assert.match(
|
|
source,
|
|
/private boolean shouldAutoRefreshConversation\(\)\s*\{[\s\S]{0,260}!isRealtimeConnected\(\)/,
|
|
"expected chat detail fallback polling to only run when realtime is disconnected",
|
|
);
|
|
assert.match(
|
|
source,
|
|
/conversationAutoRefreshRunnable/,
|
|
"expected chat detail page to own an auto-refresh runnable for fallback polling",
|
|
);
|
|
});
|