1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
import { describe, it, expect } from 'vitest';
import { shouldAutoRefresh } from './refresh-policy';
const idle = { visible: true, online: true, navigating: false };
describe('shouldAutoRefresh', () => {
it('refreshes a list page when the tab is visible and idle', () => {
expect(shouldAutoRefresh({ routeId: '/groceries', ...idle })).toBe(true);
expect(shouldAutoRefresh({ routeId: '/groceries/catalog', ...idle })).toBe(
true,
);
expect(shouldAutoRefresh({ routeId: '/projects/[id]', ...idle })).toBe(
true,
);
});
it('never refreshes a page holding an in-progress edit', () => {
expect(shouldAutoRefresh({ routeId: '/grocery/[id]', ...idle })).toBe(
false,
);
expect(
shouldAutoRefresh({
routeId: '/projects/[projectId]/routine/[routineId]',
...idle,
}),
).toBe(false);
expect(shouldAutoRefresh({ routeId: '/login', ...idle })).toBe(false);
});
it('holds off while hidden, offline or mid-navigation', () => {
const routeId = '/groceries';
expect(shouldAutoRefresh({ routeId, ...idle, visible: false })).toBe(false);
expect(shouldAutoRefresh({ routeId, ...idle, online: false })).toBe(false);
expect(shouldAutoRefresh({ routeId, ...idle, navigating: true })).toBe(
false,
);
});
it('holds off when the route is not resolved yet', () => {
expect(shouldAutoRefresh({ routeId: null, ...idle })).toBe(false);
expect(shouldAutoRefresh({ routeId: undefined, ...idle })).toBe(false);
});
});
|