mirror of
https://github.com/Zakkaus/doona.git
synced 2026-12-05 16:02:03 +00:00
apps/lite is a separate Vite app (Astryx, React 19, StyleX) on the same honk API, for people who want to switch nodes and edit groups, subscriptions, nodes, routing and DNS without the observability pages. Every change goes into a draft and one review dialog shows it in plain words before it is written; dae syntax stays in the text editor. It has light and dark themes and a demo mode backed by an in-browser mock. Browser, motion and performance checks in apps/lite/scripts run under Playwright, CI runs `pnpm -C apps/lite check`, and the UI rules are in apps/lite/UI-RULES.md. It is linted with the repository config.
73 lines
3.3 KiB
TypeScript
73 lines
3.3 KiB
TypeScript
import {beforeEach, describe, expect, it, vi} from 'vitest';
|
|
import type {ConfigSource, Provider} from '../../../src/api/model';
|
|
import {readSubscriptionEntries} from '../../../src/dae/subscriptions';
|
|
import {applyContent, refreshProvider, type Connection} from '../src/api';
|
|
import {refreshAdded, stageSubscription} from '../src/subscriptionDraft';
|
|
import {stageDraft} from '../src/useFeatureDraft';
|
|
|
|
vi.mock('../src/api', async original => ({...(await original<typeof import('../src/api')>()), applyContent: vi.fn(), refreshProvider: vi.fn()}));
|
|
|
|
const source = {
|
|
id: 'main',
|
|
writable: true,
|
|
content: `subscription {
|
|
a: 'https://a.example/feed'
|
|
b: 'https://b.example/feed'
|
|
}
|
|
`
|
|
} as ConfigSource;
|
|
const connection = {api: {config: async () => ({sources: [source]})}} as unknown as Connection;
|
|
const provider = (id: string) => ({id, name: id, kind: 'subscription'}) as Provider;
|
|
|
|
function pageDraft() {
|
|
let state: ReturnType<typeof stageDraft>;
|
|
return {
|
|
get state() {
|
|
return state;
|
|
},
|
|
get content() {
|
|
return state?.content ?? source.content;
|
|
},
|
|
stage: (content: string, key: string, summary: string) => {
|
|
state = stageDraft(state, source, content, key, summary);
|
|
}
|
|
};
|
|
}
|
|
|
|
beforeEach(() => vi.clearAllMocks());
|
|
|
|
describe('subscription writes', () => {
|
|
it('stages a delete next to another entry staged edit instead of applying either', async () => {
|
|
const draft = pageDraft();
|
|
await stageSubscription(connection, source, draft, {kind: 'edit', name: 'a', url: 'https://a2.example/feed'}, 'edit a');
|
|
await stageSubscription(connection, source, draft, {kind: 'delete', name: 'b', url: ''}, 'delete b');
|
|
expect(applyContent).not.toHaveBeenCalled();
|
|
expect(draft.state?.source).toBe(source);
|
|
expect(draft.state?.summary).toEqual({'subscription:a': 'edit a', 'subscription:b': 'delete b'});
|
|
expect(readSubscriptionEntries(draft.content).map(entry => [entry.tag, entry.url])).toEqual([['a', 'https://a2.example/feed']]);
|
|
});
|
|
|
|
it('stages an add with its interval', async () => {
|
|
const draft = pageDraft();
|
|
await stageSubscription(connection, source, draft, {kind: 'add', name: 'c', url: 'https://c.example/feed', interval: 3600}, 'add c');
|
|
expect(applyContent).not.toHaveBeenCalled();
|
|
expect(readSubscriptionEntries(draft.content).find(entry => entry.tag === 'c')).toMatchObject({url: 'https://c.example/feed', interval: 3600});
|
|
});
|
|
|
|
it('refreshes only subscriptions the apply added and reports a failed refresh as partial', async () => {
|
|
vi.mocked(refreshProvider)
|
|
.mockResolvedValueOnce({} as never)
|
|
.mockRejectedValueOnce(new Error('offline'));
|
|
const notice = await refreshAdded(connection, [provider('a')], [provider('a'), provider('c'), provider('d')]);
|
|
expect(vi.mocked(refreshProvider).mock.calls.map(call => call[1])).toEqual(['c', 'd']);
|
|
expect(notice).toEqual({key: 'refreshPartial'});
|
|
});
|
|
|
|
it('reports a degraded refresh as partial and a clean one as nothing', async () => {
|
|
vi.mocked(refreshProvider).mockResolvedValueOnce({degraded: true} as never);
|
|
expect(await refreshAdded(connection, [], [provider('c')])).toEqual({key: 'refreshPartial'});
|
|
vi.mocked(refreshProvider).mockResolvedValueOnce({} as never);
|
|
expect(await refreshAdded(connection, [], [provider('c')])).toBeUndefined();
|
|
});
|
|
});
|