Replace polling with websocket live sync

This commit is contained in:
2026-04-02 02:31:59 +03:00
parent 9a3785deb9
commit c04847b21c
15 changed files with 596 additions and 28 deletions

View File

@@ -0,0 +1,30 @@
import { describe, expect, it } from 'vitest';
import { fallbackDashboardSnapshot } from '../../src/data/mockDashboard';
import { buildSnapshotPatch } from './liveSync';
describe('buildSnapshotPatch', () => {
it('returns only changed top-level dashboard sections', () => {
const nextSnapshot = {
...fallbackDashboardSnapshot,
traffic: {
...fallbackDashboardSnapshot.traffic,
totalBytes: fallbackDashboardSnapshot.traffic.totalBytes + 512,
},
};
expect(buildSnapshotPatch(fallbackDashboardSnapshot, nextSnapshot)).toEqual({
traffic: nextSnapshot.traffic,
});
});
it('returns a full patch when no previous snapshot exists', () => {
expect(buildSnapshotPatch(null, fallbackDashboardSnapshot)).toEqual({
service: fallbackDashboardSnapshot.service,
traffic: fallbackDashboardSnapshot.traffic,
users: fallbackDashboardSnapshot.users,
attention: fallbackDashboardSnapshot.attention,
userRecords: fallbackDashboardSnapshot.userRecords,
system: fallbackDashboardSnapshot.system,
});
});
});