Files
cinny/src/app/state/room-list/utils.test.ts
T
jaredandClaude Opus 4.8 160c09e525 test: add suites for 8 simple state reducers + msgContent (+50)
Via subagent, all verified, no bugs:
- state/toast (7), room-list/roomList (6), inviteList (6), room-list/utils
  compareRoomsEqual (6), backupRestore (6), callEmbed dispose-on-replace (6),
  closedNavCategories factory + makeNavCategoryId (8).
- features/room/msgContent (5): getAudioMsgContent/getFileMsgContent incl.
  encrypted (content.file) vs plain (content.url) branch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 14:43:33 -04:00

36 lines
1.2 KiB
TypeScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { compareRoomsEqual } from './utils';
// compareRoomsEqual(a, b): length mismatch short-circuits to false, otherwise an
// order-sensitive element-by-element equality. The React hook in the same file
// (useBindRoomsWithMembershipsAtom) is not covered.
test('two empty arrays are equal', () => {
assert.equal(compareRoomsEqual([], []), true);
});
test('identical arrays are equal', () => {
assert.equal(compareRoomsEqual(['a', 'b', 'c'], ['a', 'b', 'c']), true);
});
test('different lengths are not equal', () => {
assert.equal(compareRoomsEqual(['a', 'b'], ['a', 'b', 'c']), false);
assert.equal(compareRoomsEqual(['a'], []), false);
});
test('same elements in a different order are not equal (order-sensitive)', () => {
assert.equal(compareRoomsEqual(['a', 'b'], ['b', 'a']), false);
});
test('a single differing element makes them unequal', () => {
assert.equal(compareRoomsEqual(['a', 'b', 'c'], ['a', 'x', 'c']), false);
});
test('reference equality is not required, only value equality', () => {
const a = ['a', 'b'];
const b = ['a', 'b'];
assert.notEqual(a, b);
assert.equal(compareRoomsEqual(a, b), true);
});