feat(hint): targets, automatic hints and formatting

Target fields on the admin hints page. The dashboard shows the four
automatic hints after admin hints when their condition is true, using
data Core already serves. HintText renders **bold** and safe links (app
path or https) as React elements, never HTML, in hints and news.
Auto-close without tick hides for this session, X for 7 days, tick + X
for good.
This commit is contained in:
lobo committed 2026-10-02 14:36:49 +02:00
1 parent ae904d946a
commit 8598024bce
14 files changed
+578 -53

No files matched your search

+50 -1
View File
@@ -17,9 +17,11 @@ const ACTIVE = {id: 2, textEn: 'Server update tonight', textDe: null, kind: 'DIS
const ENDED = {...ACTIVE, id: 1, textEn: 'Old news', startsAt: at(-3), endsAt: at(-2), status: 'ENDED', doneCount: 0};
const withRoutes = (routes) => fetchRoutes({
'GET /api/admin/hints': json(200, {results: [ACTIVE, ENDED]}),
'GET /api/admin/hints': json(200, {results: [ACTIVE, ENDED],
automatic: [{key: 'NO_STEAM', enabled: true}, {key: 'PILE_GREW', enabled: true}]}),
'POST /api/admin/hints': json(201, {id: 3}),
'PUT /api/admin/hints/2/end': json(204),
'PUT /api/admin/hints/auto/PILE_GREW': json(204),
...routes,
});
const calls = (method) => fetch.mock.calls.filter(([, init]) => (init?.method ?? 'GET') === method);
@@ -69,6 +71,53 @@ describe('AdminHintsPage', () => {
expect(screen.getByLabelText('ADMIN_HINTS.TEXT_EN').value).toBe('');
});
it('sends the target groups, empty ones as null', async () => {
renderPage();
await screen.findByText('Server update tonight');
fireEvent.change(screen.getByLabelText('ADMIN_HINTS.TEXT_EN'), {target: {value: 'News'}});
fireEvent.click(screen.getByLabelText('ADMIN_HINTS.TARGET_NO_STEAM'));
fireEvent.change(screen.getByLabelText('ADMIN_HINTS.TARGET_NEW_DAYS'), {target: {value: '7'}});
fireEvent.change(screen.getByLabelText('ADMIN_HINTS.TARGET_ROLE'), {target: {value: 'AUDITOR'}});
fireEvent.click(screen.getByText('ADMIN_HINTS.CREATE'));
await waitFor(() => expect(calls('POST')).toHaveLength(1));
expect(JSON.parse(calls('POST')[0][1].body)).toMatchObject({
targetNoSteam: true, targetRole: 'AUDITOR', targetNewDays: 7, targetEmptyLibrary: false});
await waitFor(() => expect(toast.success).toHaveBeenCalledWith('ADMIN_HINTS.CREATED'));
fireEvent.change(screen.getByLabelText('ADMIN_HINTS.TEXT_EN'), {target: {value: 'More news'}});
fireEvent.click(screen.getByText('ADMIN_HINTS.CREATE'));
await waitFor(() => expect(calls('POST')).toHaveLength(2));
expect(JSON.parse(calls('POST')[1][1].body)).toMatchObject({
targetNoSteam: false, targetRole: null, targetNewDays: null, targetEmptyLibrary: false});
});
it('shows the role labels for the role target', async () => {
renderPage();
expect(await screen.findByRole('option', {name: 'ROLES.AUDITOR'})).toBeTruthy();
});
it('turns an automatic hint off', async () => {
renderPage();
await screen.findByText('Server update tonight');
fireEvent.click(screen.getByLabelText('ADMIN_HINTS.AUTO_PILE_GREW'));
await waitFor(() => expect(toast.success).toHaveBeenCalledWith('ADMIN_HINTS.AUTO_SAVED'));
const [url, init] = calls('PUT')[0];
expect(url).toContain('/api/admin/hints/auto/PILE_GREW');
expect(JSON.parse(init.body)).toEqual({enabled: false});
});
it('previews bold text', async () => {
renderPage();
await screen.findByText('Server update tonight');
fireEvent.change(screen.getByLabelText('ADMIN_HINTS.TEXT_EN'), {target: {value: 'Read **this**'}});
expect(document.querySelector('[role="status"] strong').textContent).toBe('this');
});
it('explains an invalid time range', async () => {
withRoutes({'GET /api/admin/hints': json(200, {results: []}), 'POST /api/admin/hints': json(400, {code: 'INVALID_HINT'})});
renderPage();