11// @vitest -environment jsdom
22import { describe , it , expect , vi , afterEach } from 'vitest' ;
33import { render , screen , cleanup , fireEvent } from '@testing-library/react' ;
4+ import { MemoryRouter } from 'react-router-dom' ;
45
56vi . mock ( '@mitzo/client' , ( ) => ( { } ) ) ;
67
78import { SessionBanner } from '../SessionBanner' ;
89
10+ function renderWithRouter ( ui : React . ReactElement ) {
11+ return render ( < MemoryRouter > { ui } </ MemoryRouter > ) ;
12+ }
13+
914afterEach ( ( ) => cleanup ( ) ) ;
1015
1116const bootContext = {
@@ -23,23 +28,25 @@ const bootContext = {
2328
2429describe ( 'SessionBanner' , ( ) => {
2530 it ( 'returns null when both props are null' , ( ) => {
26- const { container } = render ( < SessionBanner bootContext = { null } sessionContext = { null } /> ) ;
31+ const { container } = renderWithRouter (
32+ < SessionBanner bootContext = { null } sessionContext = { null } /> ,
33+ ) ;
2734 expect ( container . innerHTML ) . toBe ( '' ) ;
2835 } ) ;
2936
3037 it ( 'renders banner header when bootContext provided' , ( ) => {
31- render ( < SessionBanner bootContext = { bootContext } /> ) ;
38+ renderWithRouter ( < SessionBanner bootContext = { bootContext } /> ) ;
3239 expect ( screen . getByText ( / 5 s o u r c e s / ) ) . toBeTruthy ( ) ;
3340 expect ( screen . getByText ( / 4 \. 2 k / ) ) . toBeTruthy ( ) ;
3441 } ) ;
3542
3643 it ( 'renders session context summary when sessionContext provided' , ( ) => {
37- render ( < SessionBanner sessionContext = "Summary: Build the widget" /> ) ;
44+ renderWithRouter ( < SessionBanner sessionContext = "Summary: Build the widget" /> ) ;
3845 expect ( screen . getByText ( / B u i l d t h e w i d g e t / ) ) . toBeTruthy ( ) ;
3946 } ) ;
4047
4148 it ( 'expands to show full session context on click' , ( ) => {
42- render ( < SessionBanner sessionContext = "Summary: Build the widget\nStatus: active" /> ) ;
49+ renderWithRouter ( < SessionBanner sessionContext = "Summary: Build the widget\nStatus: active" /> ) ;
4350 // Session context text should not be visible initially (collapsed)
4451 expect ( screen . queryByText ( 'Session Context' ) ) . toBeNull ( ) ;
4552 // Click the banner header to expand
@@ -48,13 +55,15 @@ describe('SessionBanner', () => {
4855 } ) ;
4956
5057 it ( 'renders both boot and session context together' , ( ) => {
51- render ( < SessionBanner bootContext = { bootContext } sessionContext = "Summary: Test task" /> ) ;
58+ renderWithRouter (
59+ < SessionBanner bootContext = { bootContext } sessionContext = "Summary: Test task" /> ,
60+ ) ;
5261 expect ( screen . getByText ( / 5 s o u r c e s / ) ) . toBeTruthy ( ) ;
5362 expect ( screen . getByText ( / T e s t t a s k / ) ) . toBeTruthy ( ) ;
5463 } ) ;
5564
5665 it ( 'shows boot context details on nested toggle' , ( ) => {
57- render ( < SessionBanner bootContext = { bootContext } /> ) ;
66+ renderWithRouter ( < SessionBanner bootContext = { bootContext } /> ) ;
5867 // Expand the banner first
5968 fireEvent . click ( screen . getByRole ( 'button' , { name : / 5 s o u r c e s / } ) ) ;
6069 // Now toggle boot context details
@@ -64,7 +73,7 @@ describe('SessionBanner', () => {
6473 } ) ;
6574
6675 it ( 'opens full markdown modal via view-full button' , ( ) => {
67- render ( < SessionBanner bootContext = { bootContext } /> ) ;
76+ renderWithRouter ( < SessionBanner bootContext = { bootContext } /> ) ;
6877 // Expand the banner
6978 fireEvent . click ( screen . getByRole ( 'button' , { name : / 5 s o u r c e s / } ) ) ;
7079 // Click the ⧉ button
@@ -74,7 +83,7 @@ describe('SessionBanner', () => {
7483 } ) ;
7584
7685 it ( 'closes modal on close button click' , ( ) => {
77- render ( < SessionBanner bootContext = { bootContext } /> ) ;
86+ renderWithRouter ( < SessionBanner bootContext = { bootContext } /> ) ;
7887 fireEvent . click ( screen . getByRole ( 'button' , { name : / 5 s o u r c e s / } ) ) ;
7988 fireEvent . click ( screen . getByTitle ( 'View full markdown' ) ) ;
8089 expect ( screen . getByText ( 'Boot Context (Full Markdown)' ) ) . toBeTruthy ( ) ;
@@ -84,7 +93,7 @@ describe('SessionBanner', () => {
8493 } ) ;
8594
8695 it ( 'closes modal on Escape key' , ( ) => {
87- render ( < SessionBanner bootContext = { bootContext } /> ) ;
96+ renderWithRouter ( < SessionBanner bootContext = { bootContext } /> ) ;
8897 fireEvent . click ( screen . getByRole ( 'button' , { name : / 5 s o u r c e s / } ) ) ;
8998 fireEvent . click ( screen . getByTitle ( 'View full markdown' ) ) ;
9099 expect ( screen . getByText ( 'Boot Context (Full Markdown)' ) ) . toBeTruthy ( ) ;
0 commit comments