waybetter-for-x/apps/desktop/tests/linkRouting.test.ts
2026-10-01 06:01:13 +07:00

58 lines
2.9 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { routableXPath } from '../src/inject/linkRouting.ts';
import { besideGroup, type GroupBox } from '../src/shell/paneModel.ts';
test('posts, profiles, hashtags, searches, lists and communities are routable', () => {
for (const [path, search] of [
['/playfishies/status/1840000000000000000', ''],
['/playfishies/status/1840000000000000000/quotes', ''],
['/CRTkafa', ''],
['/CRTkafa/', ''],
['/CRTkafa/media', ''],
['/CRTkafa/followers', ''],
['/hashtag/tauri', ''],
['/search', '?q=%24TSLA&src=cashtag_click'],
['/i/lists/123456', ''],
['/i/communities/987', ''],
] as const) assert.ok(routableXPath(path, search), path + search);
});
test('media viewers, X navigation pages and actions stay in place', () => {
for (const [path, search] of [
['/playfishies/status/1840000000000000000/photo/1', ''],
['/playfishies/status/1840000000000000000/video/1', ''],
['/playfishies/status/1840000000000000000/analytics', ''],
['/home', ''], ['/explore', ''], ['/notifications', ''], ['/messages', ''], ['/settings', ''], ['/i/bookmarks', ''],
['/compose/post', ''], ['/i/chat/123', ''], ['/search', ''], ['/logout', ''], ['/', ''],
['/waytoolonghandlename_x', ''], ['/i/spaces/1', ''],
] as const) assert.equal(routableXPath(path, search), false, path + search);
});
const group = (id: string, left: number, right: number, top = 0, bottom = 800, besideOf: string[] = []): GroupBox => ({ id, left, right, top, bottom, besideOf });
test('beside: the side pane this source opened before is reused', () => {
const source = group('a', 0, 600);
assert.equal(besideGroup(source, [source, group('c', 1200, 1800, 0, 800, ['a']), group('b', 600, 1200, 0, 800, ['a'])]), 'b');
});
test('beside: a feed the user opened next to it is never taken over', () => {
// Two feeds side by side (maybe two accounts): a link from the left one gets its own split.
const left = group('left', 0, 800);
assert.equal(besideGroup(left, [left, group('right', 800, 1600)]), null);
// A side pane opened for another source does not count either.
assert.equal(besideGroup(left, [left, group('side-of-other', 800, 1600, 0, 800, ['other'])]), null);
});
test('beside: nothing to the right means a new split', () => {
const source = group('b', 600, 1200);
assert.equal(besideGroup(source, [group('a', 0, 600, 0, 800, ['b']), source]), null);
assert.equal(besideGroup(group('only', 0, 1200), [group('only', 0, 1200)]), null);
});
test('beside: a group below or above the source does not count', () => {
const source = group('top', 0, 1200, 0, 400);
assert.equal(besideGroup(source, [source, group('bottom', 0, 1200, 400, 800, ['top'])]), null);
// A right column spanning both rows does.
assert.equal(besideGroup(group('tl', 0, 600, 0, 400), [group('bl', 0, 600, 400, 800), group('r', 600, 1200, 0, 800, ['tl'])]), 'r');
});