mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
refactor: migrate 5chan to the community hooks API (#1073)
* refactor(community-api): migrate 5chan to community hooks * fix(review): address PR feedback * fix(review): preserve legacy board context fallbacks * fix(review): address latest bot feedback * fix(review): use communityAddress in edit menu privileges
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import * as React from 'react';
|
||||
import { createElement } from 'react';
|
||||
import { createRoot, type Root } from 'react-dom/client';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import BlotterMessage from '../blotter-message';
|
||||
|
||||
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
||||
const act = (React as { act?: (cb: () => void | Promise<void>) => void | Promise<void> }).act as (cb: () => void | Promise<void>) => void | Promise<void>;
|
||||
|
||||
vi.mock('../blotter-message.module.css', () => ({
|
||||
default: {
|
||||
versionLink: 'versionLink',
|
||||
},
|
||||
}));
|
||||
|
||||
let container: HTMLDivElement;
|
||||
let root: Root;
|
||||
|
||||
describe('BlotterMessage', () => {
|
||||
beforeEach(() => {
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
root = createRoot(container);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
act(() => root.unmount());
|
||||
container.remove();
|
||||
});
|
||||
|
||||
it('normalizes legacy subplebbit wording without rewriting plain community text', async () => {
|
||||
await act(async () => {
|
||||
root.render(
|
||||
createElement(BlotterMessage, {
|
||||
entry: {
|
||||
id: 'manual-1',
|
||||
kind: 'manual',
|
||||
message: 'Moved a subplebbit into a community spotlight',
|
||||
timestamp: 1_710_000_000,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
expect(container.textContent).toContain('Moved a board into a community spotlight');
|
||||
expect(container.textContent).not.toContain('subplebbit');
|
||||
expect(container.textContent).not.toContain('board spotlight');
|
||||
});
|
||||
|
||||
it('normalizes release one-liners after the version prefix', async () => {
|
||||
await act(async () => {
|
||||
root.render(
|
||||
createElement(BlotterMessage, {
|
||||
entry: {
|
||||
id: 'release-1',
|
||||
kind: 'release',
|
||||
message: 'v0.7.0: Fix subplebbit loading in plebchan',
|
||||
timestamp: 1_710_000_000,
|
||||
version: '0.7.0',
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
expect(container.querySelector('a')?.getAttribute('href')).toBe('https://github.com/bitsocialnet/5chan/releases/tag/v0.7.0');
|
||||
expect(container.textContent).toContain('Fix board loading in 5chan');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user