Files
sencho/frontend/src/components/sidebar/__tests__/usePanelSessionStartedAt.test.tsx
T
Anso e20f1fe415 feat: add an inline deploy-progress style for the stack detail (#1355)
* feat: add an inline deploy-progress style for the stack detail

Deploy progress gains a presentation choice under Settings > Appearance >
Display: Modal (the default centered overlay) or Inline. In Inline style a
compact status band on the stack detail shows the running operation, its
elapsed time, the live phase, the latest output line, and the post-update
health gate result. A "View output" button opens the full log modal on
demand, a dismiss control clears the band, and the band auto-clears a few
seconds after a clean completion.

The live progress socket is lifted to an always-mounted owner so the band
streams without the modal; the default Modal style is unchanged. Operations
carry their node so a band never bleeds onto a same-named stack on another
node.

The stack detail's redundant "CONTAINERS" section heading is removed; the
band reserves that vertical space.

* fix: keep inline deploy progress reachable off the stack detail

Review of the inline presentation found a gap: a failed operation, an App
Store install, or navigating away leaves the inline session with no visible
surface, since the band only renders on the operation's own stack detail.
Restore the minimized pill as the inline fallback, shown only when the band
is not covering the session, so there is always a click-through to the log
without ever overlapping the band. Closing the modal for a failed op now
ends the session (the band has stepped aside) instead of only hiding it.

Also document the unsupported mid-operation style switch, and refresh the
deploy-progress, settings, appearance, and app-store docs for the renamed
"Deploy progress" setting and the Modal/Inline choice.
2026-06-11 10:33:57 -04:00

86 lines
3.0 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { renderHook } from '@testing-library/react';
import { usePanelSessionStartedAt } from '../usePanelSessionStartedAt';
import type { DeployPanelState } from '@/context/DeployFeedbackContext';
function panel(over: Partial<DeployPanelState> = {}): DeployPanelState {
return {
isOpen: false,
stackName: '',
nodeId: null,
action: 'deploy',
status: 'preparing',
progressUnavailable: false,
deploySessionId: '',
sessionId: 0,
...over,
};
}
describe('usePanelSessionStartedAt', () => {
beforeEach(() => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-01-01T00:00:00Z'));
});
afterEach(() => {
vi.useRealTimers();
});
it('returns null while the panel is closed', () => {
const { result } = renderHook((p: DeployPanelState) => usePanelSessionStartedAt(p), {
initialProps: panel(),
});
expect(result.current).toBeNull();
});
it('captures Date.now() when the panel opens', () => {
const { result, rerender } = renderHook((p: DeployPanelState) => usePanelSessionStartedAt(p), {
initialProps: panel(),
});
expect(result.current).toBeNull();
const opened = Date.now();
rerender(panel({ isOpen: true, stackName: 'web', sessionId: 1 }));
expect(result.current).toBe(opened);
});
it('resets the timestamp when sessionId changes even if isOpen stays true (same stack rerun)', () => {
const { result, rerender } = renderHook((p: DeployPanelState) => usePanelSessionStartedAt(p), {
initialProps: panel({ isOpen: true, stackName: 'web', sessionId: 1 }),
});
const first = result.current;
expect(first).not.toBeNull();
// Status flows to succeeded but the panel stays visible.
rerender(panel({ isOpen: true, stackName: 'web', status: 'succeeded', sessionId: 1 }));
expect(result.current).toBe(first);
// Advance the clock and trigger a same-stack rerun under a new sessionId.
vi.advanceTimersByTime(5_000);
rerender(panel({ isOpen: true, stackName: 'web', status: 'preparing', sessionId: 2 }));
expect(result.current).not.toBe(first);
expect(result.current).toBe((first ?? 0) + 5_000);
});
it('does not flap when the same panel session re-renders with no changes', () => {
const { result, rerender } = renderHook((p: DeployPanelState) => usePanelSessionStartedAt(p), {
initialProps: panel({ isOpen: true, stackName: 'web', sessionId: 1 }),
});
const captured = result.current;
vi.advanceTimersByTime(10_000);
rerender(panel({ isOpen: true, stackName: 'web', sessionId: 1, status: 'streaming' }));
expect(result.current).toBe(captured);
});
it('clears the timestamp when the panel closes', () => {
const { result, rerender } = renderHook((p: DeployPanelState) => usePanelSessionStartedAt(p), {
initialProps: panel({ isOpen: true, stackName: 'web', sessionId: 1 }),
});
expect(result.current).not.toBeNull();
rerender(panel({ isOpen: false, sessionId: 1 }));
expect(result.current).toBeNull();
});
});