25 lines
1011 B
TypeScript
25 lines
1011 B
TypeScript
import { afterEach, describe, expect, it } from 'vitest';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { appStore } from '../lib/app';
|
|
import { UpdatesView } from './UpdatesView';
|
|
|
|
afterEach(() => appStore.set({ identity: null }));
|
|
|
|
describe('UpdatesView authorization', () => {
|
|
it('shows an authorization guard to non-administrators', () => {
|
|
appStore.set({ identity: { nickname: 'listener', isAdmin: false } });
|
|
const html = renderToStaticMarkup(<UpdatesView />);
|
|
expect(html).toContain('Administrator authentication required');
|
|
expect(html).not.toContain('Check now');
|
|
});
|
|
|
|
it('renders the update controls only for an administrator', () => {
|
|
appStore.set({ identity: { nickname: 'operator', isAdmin: true } });
|
|
const html = renderToStaticMarkup(<UpdatesView />);
|
|
expect(html).toContain('Check now');
|
|
expect(html).toContain('Update history');
|
|
expect(html).not.toContain('Administrator authentication required');
|
|
expect(html).toContain('aria-live="polite"');
|
|
});
|
|
});
|