Estate: prettier, and tests that kill the surviving mutants
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4d0ee78974
commit
c848626caa
7 changed files with 101 additions and 25 deletions
|
|
@ -19,7 +19,11 @@ const room = (id: string, name: string, alias?: string): EstateHierarchyRoom =>
|
|||
const hierarchy = [
|
||||
space(ROOT, 'GameCult', ['!general:gamecult.org', PROJECTS]),
|
||||
room('!general:gamecult.org', 'General', '#general:gamecult.org'),
|
||||
space(PROJECTS, 'Projects', ['!cultlib:gamecult.org', '!aeth:gamecult.org', '!misc:gamecult.org']),
|
||||
space(PROJECTS, 'Projects', [
|
||||
'!cultlib:gamecult.org',
|
||||
'!aeth:gamecult.org',
|
||||
'!misc:gamecult.org',
|
||||
]),
|
||||
room('!cultlib:gamecult.org', 'CultLib', '#cultlib:gamecult.org'),
|
||||
room('!aeth:gamecult.org', 'Aetheria', '#Aetheria:gamecult.org'),
|
||||
room('!misc:gamecult.org', 'Misc', '#misc:gamecult.org'),
|
||||
|
|
@ -43,7 +47,9 @@ const find = (tiers: ReturnType<typeof buildEstate>, roomId: string) =>
|
|||
|
||||
describe('buildEstate', () => {
|
||||
it('lists an invited project room as invited', () => {
|
||||
const tiers = buildEstate(input({ membership: new Map([['!cultlib:gamecult.org', 'invite']]) }));
|
||||
const tiers = buildEstate(
|
||||
input({ membership: new Map([['!cultlib:gamecult.org', 'invite']]) })
|
||||
);
|
||||
expect(find(tiers, '!cultlib:gamecult.org')?.state).toBe('invited');
|
||||
});
|
||||
|
||||
|
|
@ -84,7 +90,12 @@ describe('buildEstate', () => {
|
|||
|
||||
it('sorts steward groups by display label', () => {
|
||||
const projects = buildEstate(
|
||||
input({ mindLabels: new Map([['eureka', 'Zed'], ['void', 'Alpha']]) })
|
||||
input({
|
||||
mindLabels: new Map([
|
||||
['eureka', 'Zed'],
|
||||
['void', 'Alpha'],
|
||||
]),
|
||||
})
|
||||
).find((t) => t.id === PROJECTS)!;
|
||||
expect(projects.groups.map((g) => g.label)).toEqual(['Alpha', 'Zed']);
|
||||
});
|
||||
|
|
@ -116,11 +127,73 @@ describe('buildEstate', () => {
|
|||
membership: new Map([['!dm:gamecult.org', 'join']]),
|
||||
})
|
||||
);
|
||||
expect(tiers.map((t) => t.label)).toEqual(['GameCult', 'Projects', 'Workshop', 'Direct Messages']);
|
||||
expect(tiers.map((t) => t.label)).toEqual([
|
||||
'GameCult',
|
||||
'Projects',
|
||||
'Workshop',
|
||||
'Direct Messages',
|
||||
]);
|
||||
expect(tiers[0].loose.map((r) => r.name)).toEqual(['General']);
|
||||
expect(tiers[3].loose[0]).toMatchObject({ roomId: '!dm:gamecult.org', parentId: null });
|
||||
});
|
||||
|
||||
it('takes join servers from the matching children_state entry', () => {
|
||||
const tiers = buildEstate(
|
||||
input({
|
||||
hierarchy: [
|
||||
{
|
||||
...space(ROOT, 'GameCult', ['!a:gamecult.org', '!b:gamecult.org']),
|
||||
children_state: [
|
||||
{ state_key: '!a:gamecult.org', content: { via: ['one.example'] } },
|
||||
{ state_key: '!b:gamecult.org', content: { via: ['two.example'] } },
|
||||
],
|
||||
},
|
||||
room('!a:gamecult.org', 'A'),
|
||||
room('!b:gamecult.org', 'B'),
|
||||
],
|
||||
})
|
||||
);
|
||||
expect(find(tiers, '!a:gamecult.org')?.via).toEqual(['one.example']);
|
||||
expect(find(tiers, '!b:gamecult.org')?.via).toEqual(['two.example']);
|
||||
});
|
||||
|
||||
it('puts every room of one Mind in a single group', () => {
|
||||
const tiers = buildEstate(
|
||||
input({ stewardships: { eureka: ['CultLib', 'Aetheria'] } })
|
||||
);
|
||||
const projects = tiers.find((t) => t.id === PROJECTS)!;
|
||||
expect(projects.groups).toHaveLength(1);
|
||||
expect(projects.groups[0].rooms.map((r) => r.roomId)).toEqual([
|
||||
'!cultlib:gamecult.org',
|
||||
'!aeth:gamecult.org',
|
||||
]);
|
||||
});
|
||||
|
||||
it('sorts group labels without regard to case', () => {
|
||||
const projects = buildEstate(
|
||||
input({ mindLabels: new Map([['eureka', 'beta'], ['void', 'Alpha']]) })
|
||||
).find((t) => t.id === PROJECTS)!;
|
||||
expect(projects.groups.map((g) => g.label)).toEqual(['Alpha', 'beta']);
|
||||
});
|
||||
|
||||
it('omits a tier whose Space returned no rooms and the Direct tier when there are no DMs', () => {
|
||||
const tiers = buildEstate(
|
||||
input({
|
||||
hierarchy: [
|
||||
space(ROOT, 'GameCult', ['!general:gamecult.org', PROJECTS]),
|
||||
room('!general:gamecult.org', 'General'),
|
||||
space(PROJECTS, 'Projects', ['!hidden:gamecult.org']),
|
||||
],
|
||||
})
|
||||
);
|
||||
expect(tiers.map((t) => t.id)).toEqual([ROOT]);
|
||||
});
|
||||
|
||||
it('puts direct messages in the final tier, off any Space', () => {
|
||||
const tiers = buildEstate(input({ directRoomIds: ['!dm:gamecult.org'] }));
|
||||
expect(tiers[tiers.length - 1]).toMatchObject({ id: 'direct', groups: [] });
|
||||
});
|
||||
|
||||
it('is identical for identical inputs', () => {
|
||||
expect(buildEstate(input())).toEqual(buildEstate(input()));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@
|
|||
* a room it returns is never hidden by the client.
|
||||
*/
|
||||
|
||||
export const STEWARDSHIPS_EVENT_TYPE = 'org.gamecult.stewardships';
|
||||
|
||||
export type EstateHierarchyRoom = {
|
||||
room_id: string;
|
||||
name?: string;
|
||||
|
|
@ -77,7 +75,9 @@ export const stewardOfRoom = (
|
|||
const local = canonicalAlias.replace(/^#/, '').split(':')[0].toLowerCase();
|
||||
const mind = Object.keys(stewardships).find((m) => {
|
||||
const repos = stewardships[m];
|
||||
return Array.isArray(repos) && repos.some((r) => typeof r === 'string' && repoName(r) === local);
|
||||
return (
|
||||
Array.isArray(repos) && repos.some((r) => typeof r === 'string' && repoName(r) === local)
|
||||
);
|
||||
});
|
||||
return mind;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -48,6 +48,19 @@ describe('activateEstateRoom', () => {
|
|||
}
|
||||
);
|
||||
|
||||
it('falls back to the error message, then to a generic one', async () => {
|
||||
const named = recordingClient(vi.fn().mockRejectedValue(new Error('Boom')));
|
||||
expect(await activateEstateRoom(named.mx, room('joinable'))).toEqual({
|
||||
kind: 'refused',
|
||||
message: 'Boom',
|
||||
});
|
||||
const bare = recordingClient(vi.fn().mockRejectedValue({}));
|
||||
expect(await activateEstateRoom(bare.mx, room('joinable'))).toEqual({
|
||||
kind: 'refused',
|
||||
message: 'Could not join',
|
||||
});
|
||||
});
|
||||
|
||||
it('reports the server refusal and does not decide access itself', async () => {
|
||||
const refusal = Object.assign(new Error('M_FORBIDDEN'), {
|
||||
data: { error: 'You are not invited to this room.' },
|
||||
|
|
|
|||
|
|
@ -15,7 +15,11 @@ import { buildEstate, EstateHierarchyRoom, EstateTier, Stewardships } from './bu
|
|||
|
||||
const HIERARCHY_DEPTH = 10;
|
||||
|
||||
type AliasedRoom = { roomId: string; getCanonicalAlias(): string | null; getAltAliases(): string[] };
|
||||
type AliasedRoom = {
|
||||
roomId: string;
|
||||
getCanonicalAlias(): string | null;
|
||||
getAltAliases(): string[];
|
||||
};
|
||||
|
||||
const findLoadedRoom = (
|
||||
mx: ReturnType<typeof useMatrixClient>,
|
||||
|
|
|
|||
|
|
@ -151,11 +151,7 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize)
|
|||
<Route
|
||||
path={HOME_PATH}
|
||||
element={
|
||||
<PageRoot
|
||||
nav={
|
||||
<EstatePageNav path={HOME_PATH} />
|
||||
}
|
||||
>
|
||||
<PageRoot nav={<EstatePageNav path={HOME_PATH} />}>
|
||||
<Outlet />
|
||||
</PageRoot>
|
||||
}
|
||||
|
|
@ -176,11 +172,7 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize)
|
|||
<Route
|
||||
path={DIRECT_PATH}
|
||||
element={
|
||||
<PageRoot
|
||||
nav={
|
||||
<EstatePageNav path={DIRECT_PATH} />
|
||||
}
|
||||
>
|
||||
<PageRoot nav={<EstatePageNav path={DIRECT_PATH} />}>
|
||||
<Outlet />
|
||||
</PageRoot>
|
||||
}
|
||||
|
|
@ -200,11 +192,7 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize)
|
|||
path={SPACE_PATH}
|
||||
element={
|
||||
<RouteSpaceProvider>
|
||||
<PageRoot
|
||||
nav={
|
||||
<EstatePageNav path={SPACE_PATH} />
|
||||
}
|
||||
>
|
||||
<PageRoot nav={<EstatePageNav path={SPACE_PATH} />}>
|
||||
<Outlet />
|
||||
</PageRoot>
|
||||
</RouteSpaceProvider>
|
||||
|
|
|
|||
|
|
@ -76,4 +76,3 @@ export function SpaceTombstone({ roomId, replacementRoomId }: SpaceTombstoneProp
|
|||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ export enum AccountDataEvent {
|
|||
Direct = 'm.direct',
|
||||
IgnoredUserList = 'm.ignored_user_list',
|
||||
|
||||
|
||||
ElementRecentEmoji = 'io.element.recent_emoji',
|
||||
|
||||
PoniesUserEmotes = 'im.ponies.user_emotes',
|
||||
|
|
|
|||
Loading…
Reference in a new issue