2026-01-06 15:52:12 -05:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { render } from '../../test-utils/render.js';
|
|
|
|
|
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
|
|
|
import { HookStatusDisplay } from './HookStatusDisplay.js';
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
vi.restoreAllMocks();
|
|
|
|
|
vi.useRealTimers();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('<HookStatusDisplay />', () => {
|
2026-02-18 16:46:50 -08:00
|
|
|
it('should render a single executing hook', async () => {
|
2026-01-06 15:52:12 -05:00
|
|
|
const props = {
|
|
|
|
|
activeHooks: [{ name: 'test-hook', eventName: 'BeforeAgent' }],
|
|
|
|
|
};
|
2026-02-18 16:46:50 -08:00
|
|
|
const { lastFrame, waitUntilReady, unmount } = render(
|
|
|
|
|
<HookStatusDisplay {...props} />,
|
|
|
|
|
);
|
|
|
|
|
await waitUntilReady();
|
2026-01-06 15:52:12 -05:00
|
|
|
expect(lastFrame()).toMatchSnapshot();
|
|
|
|
|
unmount();
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-18 16:46:50 -08:00
|
|
|
it('should render multiple executing hooks', async () => {
|
2026-01-06 15:52:12 -05:00
|
|
|
const props = {
|
|
|
|
|
activeHooks: [
|
|
|
|
|
{ name: 'h1', eventName: 'BeforeAgent' },
|
|
|
|
|
{ name: 'h2', eventName: 'BeforeAgent' },
|
|
|
|
|
],
|
|
|
|
|
};
|
2026-02-18 16:46:50 -08:00
|
|
|
const { lastFrame, waitUntilReady, unmount } = render(
|
|
|
|
|
<HookStatusDisplay {...props} />,
|
|
|
|
|
);
|
|
|
|
|
await waitUntilReady();
|
2026-01-06 15:52:12 -05:00
|
|
|
expect(lastFrame()).toMatchSnapshot();
|
|
|
|
|
unmount();
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-18 16:46:50 -08:00
|
|
|
it('should render sequential hook progress', async () => {
|
2026-01-06 15:52:12 -05:00
|
|
|
const props = {
|
|
|
|
|
activeHooks: [
|
|
|
|
|
{ name: 'step', eventName: 'BeforeAgent', index: 1, total: 3 },
|
|
|
|
|
],
|
|
|
|
|
};
|
2026-02-18 16:46:50 -08:00
|
|
|
const { lastFrame, waitUntilReady, unmount } = render(
|
|
|
|
|
<HookStatusDisplay {...props} />,
|
|
|
|
|
);
|
|
|
|
|
await waitUntilReady();
|
2026-01-06 15:52:12 -05:00
|
|
|
expect(lastFrame()).toMatchSnapshot();
|
|
|
|
|
unmount();
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-18 16:46:50 -08:00
|
|
|
it('should return empty string if no active hooks', async () => {
|
2026-01-06 15:52:12 -05:00
|
|
|
const props = { activeHooks: [] };
|
2026-02-18 16:46:50 -08:00
|
|
|
const { lastFrame, waitUntilReady, unmount } = render(
|
|
|
|
|
<HookStatusDisplay {...props} />,
|
|
|
|
|
);
|
|
|
|
|
await waitUntilReady();
|
|
|
|
|
expect(lastFrame({ allowEmpty: true })).toBe('');
|
2026-01-06 15:52:12 -05:00
|
|
|
unmount();
|
|
|
|
|
});
|
2026-03-17 23:03:55 -07:00
|
|
|
|
|
|
|
|
it('should show generic message when only system/extension hooks are active', async () => {
|
|
|
|
|
const props = {
|
|
|
|
|
activeHooks: [
|
|
|
|
|
{ name: 'ext-hook', eventName: 'BeforeAgent', source: 'extensions' },
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
const { lastFrame, waitUntilReady, unmount } = render(
|
|
|
|
|
<HookStatusDisplay {...props} />,
|
|
|
|
|
);
|
|
|
|
|
await waitUntilReady();
|
|
|
|
|
expect(lastFrame()).toContain('Working...');
|
|
|
|
|
unmount();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('matches SVG snapshot for single hook', async () => {
|
|
|
|
|
const props = {
|
|
|
|
|
activeHooks: [
|
|
|
|
|
{ name: 'test-hook', eventName: 'BeforeAgent', source: 'user' },
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
const renderResult = render(<HookStatusDisplay {...props} />);
|
|
|
|
|
await renderResult.waitUntilReady();
|
|
|
|
|
await expect(renderResult).toMatchSvgSnapshot();
|
|
|
|
|
renderResult.unmount();
|
|
|
|
|
});
|
2026-01-06 15:52:12 -05:00
|
|
|
});
|