Add the connections workspace (sidebar, editable slots, per-slot activity, removal dialog with focus wrapping), remove the downloadable local HTML and unreleased identity backup/restore, and start the 0.0.5 draft changelog. Restore the released 0.0.3/0.0.4 changelog entries. Enable focus emulation in browser checks so background tabs receive focus/blur events. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.8 KiB
TypeScript
33 lines
1.8 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { emptyConnection, updateConnection, HISTORY_LIMIT, type ConnectionActivity } from '../src/lib/connections.ts';
|
|
|
|
test('renaming and pairing preserve a slot identity and its activity', () => {
|
|
const initial = emptyConnection(2);
|
|
const activity: ConnectionActivity = { id: 'transfer', time: 1, direction: 'send', name: 'example.txt', size: 123, result: 'complete' };
|
|
const withHistory = updateConnection(initial, { activity });
|
|
const renamed = updateConnection(withHistory, { name: ' Work laptop ' });
|
|
const paired = updateConnection(renamed, { peerKey: '04' + 'a'.repeat(128) });
|
|
assert.equal(initial.name, 'Con 2');
|
|
assert.equal(paired.id, initial.id);
|
|
assert.equal(paired.name, 'Work laptop');
|
|
assert.deepEqual(paired.history, [activity]);
|
|
assert.equal(initial.history.length, 0);
|
|
assert.throws(() => updateConnection(paired, { name: ' ' }));
|
|
assert.throws(() => updateConnection(paired, { name: 'a'.repeat(81) }));
|
|
assert.throws(() => updateConnection(paired, { peerKey: 'invalid' }));
|
|
});
|
|
|
|
test('history is bounded, ordered, and does not duplicate an event', () => {
|
|
let connection = emptyConnection();
|
|
for (let i = 0; i < HISTORY_LIMIT + 10; i++) {
|
|
connection = updateConnection(connection, { activity: { id: String(i), time: i, direction: 'receive', name: 'file', size: 0, result: 'declined' } });
|
|
}
|
|
const last = connection.history.at(-1)!;
|
|
connection = updateConnection(connection, { activity: last });
|
|
assert.equal(connection.history.length, HISTORY_LIMIT);
|
|
assert.equal(connection.history[0]!.time, 10);
|
|
assert.throws(() => updateConnection(connection, { activity: { ...last, size: -1 } }));
|
|
assert.throws(() => updateConnection(connection, { activity: { ...last, direction: 'invalid' as 'send' } }));
|
|
});
|