@@ -10,7 +10,8 @@ import { EnvironmentId, ThreadId } from "@t3tools/contracts";
1010import { HtmlRenderDialog } from "./HtmlRenderDialog" ;
1111import { HtmlRenderFrame } from "./HtmlRenderFrame" ;
1212
13- const { refresh, showError, openLink, openChangeRequestLink } = vi . hoisted ( ( ) => ( {
13+ const { cachedUrl, refresh, showError, openLink, openChangeRequestLink } = vi . hoisted ( ( ) => ( {
14+ cachedUrl : { lifeMs : 60 * 60_000 } ,
1415 refresh : vi . fn ( ) ,
1516 showError : vi . fn ( ) ,
1617 openLink : vi . fn ( ) ,
@@ -24,7 +25,7 @@ vi.mock("~/assets/assetUrls", () => ({
2425 useAssetUrlState : ( ) => ( {
2526 _tag : "Success" ,
2627 url : "https://environment.test/original.html" ,
27- expiresAt : Date . now ( ) + 60 * 60_000 ,
28+ expiresAt : Date . now ( ) + cachedUrl . lifeMs ,
2829 } ) ,
2930 useAssetUrlRefresh : ( ) => refresh ,
3031} ) ) ;
@@ -50,6 +51,7 @@ beforeEach(async () => {
5051 } ,
5152 ) ;
5253 refresh . mockReset ( ) ;
54+ cachedUrl . lifeMs = 60 * 60_000 ;
5355 openLink . mockReset ( ) . mockResolvedValue ( undefined ) ;
5456 openChangeRequestLink . mockReset ( ) . mockReturnValue ( false ) ;
5557 showError . mockClear ( ) ;
@@ -109,7 +111,8 @@ it("closes with the close button or Escape", async () => {
109111} ) ;
110112
111113async function renderInline ( ) {
112- await act ( ( ) =>
114+ // Async so a URL minted at mount lands inside act.
115+ await act ( async ( ) =>
113116 root . render (
114117 < HtmlRenderFrame
115118 environmentId = { EnvironmentId . make ( "environment" ) }
@@ -123,7 +126,7 @@ async function renderInline() {
123126 ) ;
124127}
125128
126- it ( "offers only full screen and opens with a fresh URL while keeping the inline page loaded" , async ( ) => {
129+ it ( "offers only full screen and opens with the inline URL while keeping the inline page loaded" , async ( ) => {
127130 await renderInline ( ) ;
128131 expect ( document . querySelector ( '[aria-label="Open in panel"]' ) ) . toBeNull ( ) ;
129132 const inlineFrame = document . querySelector ( "iframe" ) ! ;
@@ -132,11 +135,10 @@ it("offers only full screen and opens with a fresh URL while keeping the inline
132135 '[aria-label="Open full screen"]' ,
133136 ) ! ;
134137 expandButton . focus ( ) ;
135- refresh . mockResolvedValue ( "https://environment.test/renewed.html" ) ;
136138 await click ( "Open full screen" ) ;
137- expect ( refresh ) . toHaveBeenCalledOnce ( ) ;
139+ expect ( refresh ) . not . toHaveBeenCalled ( ) ;
138140 expect ( document . querySelector ( '[role="dialog"] iframe' ) ?. getAttribute ( "src" ) ) . toContain (
139- "https://environment.test/renewed .html#" ,
141+ "https://environment.test/original .html#" ,
140142 ) ;
141143 expect ( inlineFrame . src ) . toBe ( originalSrc ) ;
142144 await click ( "Close" ) ;
@@ -145,9 +147,26 @@ it("offers only full screen and opens with a fresh URL while keeping the inline
145147 expect ( document . activeElement ) . toBe ( expandButton ) ;
146148} ) ;
147149
148- it ( "routes links from the expanded page through its thread" , async ( ) => {
150+ // An inline URL near expiry is minted at mount, and full screen mints another.
151+ async function renderInlineNearExpiry ( ) {
152+ cachedUrl . lifeMs = 60_000 ;
153+ refresh . mockResolvedValueOnce ( "https://environment.test/inline.html" ) ;
149154 await renderInline ( ) ;
155+ expect ( refresh ) . toHaveBeenCalledOnce ( ) ;
156+ }
157+
158+ it ( "opens full screen with a fresh URL when the inline one is near expiry" , async ( ) => {
159+ await renderInlineNearExpiry ( ) ;
150160 refresh . mockResolvedValue ( "https://environment.test/renewed.html" ) ;
161+ await click ( "Open full screen" ) ;
162+ expect ( refresh ) . toHaveBeenCalledTimes ( 2 ) ;
163+ expect ( document . querySelector ( '[role="dialog"] iframe' ) ?. getAttribute ( "src" ) ) . toContain (
164+ "https://environment.test/renewed.html#" ,
165+ ) ;
166+ } ) ;
167+
168+ it ( "routes links from the expanded page through its thread" , async ( ) => {
169+ await renderInline ( ) ;
151170 openChangeRequestLink . mockReturnValue ( true ) ;
152171 await click ( "Open full screen" ) ;
153172 const frame = document . querySelector < HTMLIFrameElement > ( '[role="dialog"] iframe' ) ! ;
@@ -173,7 +192,7 @@ it("routes links from the expanded page through its thread", async () => {
173192it . each ( [ null , new Error ( "Disconnected" ) ] ) (
174193 "reports an unavailable URL instead of opening a blank page: %s" ,
175194 async ( failure ) => {
176- await renderInline ( ) ;
195+ await renderInlineNearExpiry ( ) ;
177196 if ( failure === null ) refresh . mockResolvedValue ( null ) ;
178197 else refresh . mockRejectedValue ( failure ) ;
179198 await click ( "Open full screen" ) ;
0 commit comments