@@ -3,6 +3,7 @@ import "../../index.css";
33import { act } from "react" ;
44import { createRoot , type Root } from "react-dom/client" ;
55import { afterEach , beforeEach , expect , it , vi } from "vite-plus/test" ;
6+ import { page , userEvent } from "vite-plus/test/browser" ;
67
78import { ComposerBannerStack } from "./ComposerBannerStack" ;
89
@@ -58,3 +59,53 @@ it("only offers notice details when the description cannot fit", async () => {
5859 await nextFrame ( ) ;
5960 expect ( hasDetails ( ) ) . toBe ( true ) ;
6061} ) ;
62+
63+ it ( "keeps only the usage limit attached while an active goal waits in the collapsible stack" , async ( ) => {
64+ await act ( async ( ) =>
65+ root . render (
66+ < ComposerBannerStack
67+ items = { [
68+ {
69+ id : "goal" ,
70+ variant : "default" ,
71+ priority : "activity" ,
72+ icon : null ,
73+ title : "Goal active" ,
74+ description : "Finish the banner fix" ,
75+ } ,
76+ {
77+ id : "limit" ,
78+ variant : "default" ,
79+ priority : "urgent" ,
80+ icon : null ,
81+ title : "Usage limit reached" ,
82+ } ,
83+ ] }
84+ /> ,
85+ ) ,
86+ ) ;
87+
88+ const visibleBanners = ( ) =>
89+ Array . from ( container . querySelectorAll ( '[data-slot="composer-banner"]' ) ) . filter ( ( banner ) =>
90+ banner . checkVisibility ( { checkOpacity : true , checkVisibilityCSS : true } ) ,
91+ ) ;
92+ const limit = page . getByText ( "Usage limit reached" , { exact : true } ) ;
93+ const goal = page . getByText ( "Goal active" , { exact : true } ) ;
94+
95+ expect ( visibleBanners ( ) ) . toHaveLength ( 1 ) ;
96+ await expect . element ( limit ) . toBeVisible ( ) ;
97+ await expect . element ( goal ) . not . toBeVisible ( ) ;
98+ expect ( container . querySelector ( '[data-slot="composer-banner-attachment"]' ) ?. textContent ) . toBe (
99+ "Usage limit reached" ,
100+ ) ;
101+
102+ await act ( async ( ) => page . getByRole ( "button" , { name : "Show other notices" } ) . click ( ) ) ;
103+ await expect . element ( goal ) . toBeVisible ( ) ;
104+ await expect . element ( limit ) . toBeVisible ( ) ;
105+ await expect . poll ( visibleBanners ) . toHaveLength ( 2 ) ;
106+
107+ await act ( async ( ) => userEvent . keyboard ( "{Escape}" ) ) ;
108+ await expect . element ( goal ) . not . toBeVisible ( ) ;
109+ await expect . element ( limit ) . toBeVisible ( ) ;
110+ expect ( visibleBanners ( ) ) . toHaveLength ( 1 ) ;
111+ } ) ;
0 commit comments