- collapse run log data blocks whose pretty-printed JSON exceeds a byte or line limit, with a per-block toggle and an expand/collapse-all button next to the Logs heading - align data blocks and toggles with the context/message column - add a "Copy logs" button that copies the filtered logs as plain text with every data block expanded - add GET /manifest.json with the app name, version and run log data limits (RUN_LOG_DATA_COLLAPSE_BYTES / RUN_LOG_DATA_COLLAPSE_LINES) - load the manifest in the client stale-while-revalidate: localStorage copy first, refetched per page load and on tab focus after a while - show the server version in the sidebar footer, with a reload hint when it differs from the client build Closes #3
198 lines
5.9 KiB
TypeScript
198 lines
5.9 KiB
TypeScript
import { useState } from 'react';
|
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
import { expect, userEvent, within } from 'storybook/test';
|
|
import { LogOutput, type LogOutputEntry } from '../../src/ui/LogOutput/LogOutput';
|
|
import { formatLogText } from '../../src/ui/LogOutput/logText';
|
|
|
|
const meta: Meta<typeof LogOutput> = {
|
|
title: 'UI/LogOutput',
|
|
component: LogOutput,
|
|
tags: ['autodocs'],
|
|
parameters: { layout: 'padded' },
|
|
};
|
|
export default meta;
|
|
|
|
type Story = StoryObj<typeof LogOutput>;
|
|
|
|
const secondsAgo = (n: number) => new Date(Date.now() - n * 1000).toISOString();
|
|
|
|
export const Default: Story = {
|
|
args: {
|
|
startTime: secondsAgo(60),
|
|
entries: [
|
|
{
|
|
id: 0,
|
|
level: 'debug',
|
|
context: 'step:1',
|
|
message: 'Resolved credential alias "sdJwtKey" to a file credential',
|
|
createdAt: secondsAgo(61),
|
|
},
|
|
{
|
|
id: 1,
|
|
level: 'log',
|
|
context: 'step:1',
|
|
message: 'Step 1 started: Login with PKCS',
|
|
createdAt: secondsAgo(60),
|
|
},
|
|
{
|
|
id: 2,
|
|
level: 'log',
|
|
context: 'snippet:loginWithPkcs',
|
|
message: 'Snippet "loginWithPkcs" started',
|
|
createdAt: secondsAgo(58),
|
|
},
|
|
{
|
|
id: 3,
|
|
level: 'log',
|
|
context: 'snippet:loginWithPkcs',
|
|
message: 'Saved credential as run file:',
|
|
data: JSON.stringify({
|
|
id: '181d8ae2-4aee-4f33-a657-210efe7fe668',
|
|
name: 'credential.sd-jwt',
|
|
mimeType: 'application/octet-stream',
|
|
size: 1657,
|
|
sha256: '9c4226999c700a39bda30279907e4479a5b3920ccde5c75771ea0e264c638c0',
|
|
path: 'data/files/18/181d/181d8ae2-4aee-4f33-a657-210efe7fe668',
|
|
}),
|
|
createdAt: secondsAgo(57),
|
|
},
|
|
{
|
|
id: 4,
|
|
level: 'log',
|
|
context: 'snippet:loginWithPkcs',
|
|
message: 'Navigating to ID login: https://id.example.com',
|
|
createdAt: secondsAgo(57),
|
|
},
|
|
{
|
|
id: 5,
|
|
level: 'log',
|
|
context: 'assertion:pass',
|
|
message: 'Assertion passed: page must have redirected to cabinet URL',
|
|
createdAt: secondsAgo(40),
|
|
},
|
|
{
|
|
id: 6,
|
|
level: 'warn',
|
|
context: 'snippet:loginWithPkcs',
|
|
message: 'Retrying file upload after a transient error',
|
|
createdAt: secondsAgo(39),
|
|
},
|
|
{
|
|
id: 7,
|
|
level: 'log',
|
|
context: 'step:1',
|
|
message: 'Step 1 passed',
|
|
createdAt: secondsAgo(30),
|
|
},
|
|
{
|
|
id: 8,
|
|
level: 'error',
|
|
context: 'assertion:fail',
|
|
message: 'Assertion failed: Document validation must pass (got 422)',
|
|
createdAt: secondsAgo(10),
|
|
},
|
|
{
|
|
id: 9,
|
|
level: 'error',
|
|
context: 'step:2',
|
|
message: 'Step 2 failed: Document validation must pass (got 422)',
|
|
createdAt: secondsAgo(9),
|
|
},
|
|
],
|
|
},
|
|
};
|
|
|
|
export const Scrollable: Story = {
|
|
args: {
|
|
maxHeight: 160,
|
|
startTime: secondsAgo(60),
|
|
entries: Array.from({ length: 30 }, (_, i) => ({
|
|
id: i,
|
|
level: (['log', 'log', 'log', 'warn', 'error'] as const)[i % 5],
|
|
context: `step:${Math.floor(i / 6) + 1}`,
|
|
message: `Log entry ${i + 1}`,
|
|
createdAt: secondsAgo(60 - i * 2),
|
|
})),
|
|
},
|
|
};
|
|
|
|
const largeDataEntries: LogOutputEntry[] = [
|
|
{
|
|
id: 0,
|
|
level: 'log',
|
|
context: 'step:1',
|
|
message: 'Small payload:',
|
|
data: JSON.stringify({ status: 200 }),
|
|
createdAt: secondsAgo(20),
|
|
},
|
|
{
|
|
id: 1,
|
|
level: 'log',
|
|
context: 'step:1',
|
|
message: 'Large payload:',
|
|
data: JSON.stringify({
|
|
user: { id: 42, name: 'Jane Doe', roles: ['admin', 'qa'] },
|
|
token: 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0MiJ9',
|
|
}),
|
|
createdAt: secondsAgo(18),
|
|
},
|
|
{
|
|
id: 2,
|
|
level: 'warn',
|
|
context: 'step:2',
|
|
message: 'Another large payload:',
|
|
data: JSON.stringify(Array.from({ length: 8 }, (_, i) => ({ row: i }))),
|
|
createdAt: secondsAgo(10),
|
|
},
|
|
];
|
|
|
|
function LargeDataLog() {
|
|
const [expanded, setExpanded] = useState(false);
|
|
return (
|
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, alignItems: 'flex-start' }}>
|
|
<button type="button" onClick={() => setExpanded((v) => !v)}>
|
|
{expanded ? 'Collapse all' : 'Expand all'}
|
|
</button>
|
|
<LogOutput startTime={secondsAgo(20)} entries={largeDataEntries} dataExpanded={expanded} />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/** Data blocks over the default limits (256 bytes, 5 lines) start collapsed. */
|
|
export const LargeData: Story = {
|
|
render: () => <LargeDataLog />,
|
|
play: async ({ canvasElement }) => {
|
|
const canvas = within(canvasElement);
|
|
// Data blocks are syntax-highlighted into separate tokens, so check the log's text
|
|
const log = canvas.getByRole('log');
|
|
// Only the small payload is visible initially
|
|
await expect(log).toHaveTextContent('"status": 200');
|
|
await expect(log).not.toHaveTextContent('Jane Doe');
|
|
const toggles = canvas.getAllByRole('button', { name: /^Show data/ });
|
|
await expect(toggles).toHaveLength(2);
|
|
|
|
await userEvent.click(toggles[0]);
|
|
await expect(log).toHaveTextContent('Jane Doe');
|
|
await userEvent.click(canvas.getByRole('button', { name: 'Hide data' }));
|
|
await expect(log).not.toHaveTextContent('Jane Doe');
|
|
|
|
await userEvent.click(canvas.getByRole('button', { name: 'Expand all' }));
|
|
await expect(log).toHaveTextContent('Jane Doe');
|
|
await expect(canvas.getAllByRole('button', { name: 'Hide data' })).toHaveLength(2);
|
|
await userEvent.click(canvas.getByRole('button', { name: 'Collapse all' }));
|
|
await expect(log).not.toHaveTextContent('Jane Doe');
|
|
|
|
// The plain-text form always includes every data block
|
|
const text = formatLogText(largeDataEntries, largeDataEntries[0].createdAt);
|
|
await expect(text).toContain('[step:1] Large payload:\n {');
|
|
await expect(text).toContain('"name": "Jane Doe"');
|
|
},
|
|
};
|
|
|
|
export const Empty: Story = {
|
|
args: {
|
|
entries: [],
|
|
emptyMessage: 'No logs yet.',
|
|
},
|
|
};
|