@@ -2,33 +2,72 @@ import { renderToStaticMarkup } from "react-dom/server";
22import { describe , expect , it } from "vite-plus/test" ;
33
44import {
5+ dismissThreadErrorBannerForSession ,
56 getThreadErrorBannerKey ,
7+ isThreadErrorBannerDismissedForSession ,
68 shouldShowThreadErrorBanner ,
79 ThreadErrorBanner ,
810} from "./ThreadErrorBanner" ;
911
1012describe ( "ThreadErrorBanner" , ( ) => {
1113 it ( "stays hidden after its current error is dismissed" , ( ) => {
12- const dismissedKey = getThreadErrorBannerKey ( "env:thread" , "Aborted" ) ;
14+ const bannerKey = getThreadErrorBannerKey ( "env:thread-a" , "Aborted" ) ;
15+ dismissThreadErrorBannerForSession ( bannerKey ) ;
1316
14- expect ( shouldShowThreadErrorBanner ( "env:thread" , "Aborted" , null ) ) . toBe ( true ) ;
15- expect ( shouldShowThreadErrorBanner ( "env:thread" , "Aborted" , dismissedKey ) ) . toBe ( false ) ;
17+ expect (
18+ shouldShowThreadErrorBanner (
19+ "env:thread-a" ,
20+ "Aborted" ,
21+ isThreadErrorBannerDismissedForSession ( bannerKey ) ,
22+ ) ,
23+ ) . toBe ( false ) ;
1624 } ) ;
1725
1826 it ( "reappears when a new error arrives on the same thread" , ( ) => {
19- const dismissedKey = getThreadErrorBannerKey ( "env:thread" , "Aborted" ) ;
27+ dismissThreadErrorBannerForSession ( getThreadErrorBannerKey ( "env:thread-b" , "Turn failed" ) ) ;
28+ const newErrorKey = getThreadErrorBannerKey ( "env:thread-b" , "Provider crashed" ) ;
2029
21- expect ( shouldShowThreadErrorBanner ( "env:thread" , "Turn failed" , dismissedKey ) ) . toBe ( true ) ;
30+ expect ( isThreadErrorBannerDismissedForSession ( newErrorKey ) ) . toBe ( false ) ;
31+ expect (
32+ shouldShowThreadErrorBanner (
33+ "env:thread-b" ,
34+ "Provider crashed" ,
35+ isThreadErrorBannerDismissedForSession ( newErrorKey ) ,
36+ ) ,
37+ ) . toBe ( true ) ;
2238 } ) ;
2339
2440 it ( "scopes dismissals to the thread that dismissed them" , ( ) => {
25- const dismissedKey = getThreadErrorBannerKey ( "env:thread" , "Aborted" ) ;
41+ dismissThreadErrorBannerForSession ( getThreadErrorBannerKey ( "env:thread-c" , "Aborted" ) ) ;
42+ const otherThreadKey = getThreadErrorBannerKey ( "env:other-thread" , "Aborted" ) ;
2643
27- expect ( shouldShowThreadErrorBanner ( "env:other-thread" , "Aborted" , dismissedKey ) ) . toBe ( true ) ;
44+ expect ( isThreadErrorBannerDismissedForSession ( otherThreadKey ) ) . toBe ( false ) ;
45+ expect (
46+ shouldShowThreadErrorBanner (
47+ "env:other-thread" ,
48+ "Aborted" ,
49+ isThreadErrorBannerDismissedForSession ( otherThreadKey ) ,
50+ ) ,
51+ ) . toBe ( true ) ;
52+ } ) ;
53+
54+ it ( "keeps a dismissal across visiting threads with no error" , ( ) => {
55+ const bannerKey = getThreadErrorBannerKey ( "env:thread-d" , "Aborted" ) ;
56+ dismissThreadErrorBannerForSession ( bannerKey ) ;
57+
58+ expect ( shouldShowThreadErrorBanner ( "env:thread-d" , null , false ) ) . toBe ( false ) ;
59+ expect ( isThreadErrorBannerDismissedForSession ( bannerKey ) ) . toBe ( true ) ;
60+ expect (
61+ shouldShowThreadErrorBanner (
62+ "env:thread-d" ,
63+ "Aborted" ,
64+ isThreadErrorBannerDismissedForSession ( bannerKey ) ,
65+ ) ,
66+ ) . toBe ( false ) ;
2867 } ) ;
2968
3069 it ( "never shows a null error" , ( ) => {
31- expect ( shouldShowThreadErrorBanner ( "env:thread" , null , null ) ) . toBe ( false ) ;
70+ expect ( shouldShowThreadErrorBanner ( "env:thread-e " , null , false ) ) . toBe ( false ) ;
3271 } ) ;
3372 it ( "aligns the warning and dismiss icons with the first line of a multi-line error" , ( ) => {
3473 const markup = renderToStaticMarkup (
0 commit comments