fix(board status): resolve offline indicators with strict community refs

This commit is contained in:
Tommaso Casaburi
2026-04-17 12:51:14 +07:00
parent 1c2be5a172
commit 4cae9c3caa
7 changed files with 86 additions and 64 deletions
@@ -49,8 +49,14 @@ let latestValue: ReturnType<typeof useIsCommunityOffline>;
let container: HTMLDivElement;
let root: Root;
const HookHarness = ({ community }: { community?: { address?: string; state?: string; updatedAt?: number; updatingState?: string } }) => {
latestValue = useIsCommunityOffline(community as never);
const HookHarness = ({
community,
communityAddressHint,
}: {
community?: { address?: string; name?: string; publicKey?: string; state?: string; updatedAt?: number; updatingState?: string };
communityAddressHint?: string;
}) => {
latestValue = useIsCommunityOffline(community as never, communityAddressHint);
return null;
};
@@ -62,9 +68,12 @@ const flushEffects = async (count = 3) => {
}
};
const renderHook = async (community?: { address?: string; state?: string; updatedAt?: number; updatingState?: string }) => {
const renderHook = async (
community?: { address?: string; name?: string; publicKey?: string; state?: string; updatedAt?: number; updatingState?: string },
communityAddressHint?: string,
) => {
await act(async () => {
root.render(createElement(HookHarness, { community }));
root.render(createElement(HookHarness, { community, communityAddressHint }));
});
await flushEffects();
};
@@ -153,6 +162,24 @@ describe('useIsCommunityOffline', () => {
});
});
it('tracks strict-community objects with a canonical address hint instead of the undefined key', async () => {
await renderHook({ name: 'music.eth', publicKey: '12D3KooWBoardKey', state: 'updating', updatingState: 'fetching' }, 'music.eth');
expect(testState.requestedAddresses).toEqual(['music.eth']);
expect(testState.initializeMock).toHaveBeenCalledWith('music.eth');
expect(testState.setOfflineStateMock).toHaveBeenCalledWith('music.eth', {
state: 'updating',
updatedAt: undefined,
updatingState: 'fetching',
});
expect(latestValue).toEqual({
isOffline: false,
isOnlineStatusLoading: true,
offlineIconClass: 'yellowOfflineIcon',
offlineTitle: 'downloading board...',
});
});
it('treats recently updated boards as online', async () => {
const freshUpdatedAt = 1_704_067_205;
testState.communityOfflineState = {