@@ -166,13 +166,63 @@ describe("getImageDataUrlForCell", () => {
166166 ) ;
167167 } ) ;
168168
169- it ( "should restore original overflow style after capture" , async ( ) => {
169+ it ( "should pass style options to prevent clipping" , async ( ) => {
170+ vi . mocked ( toPng ) . mockResolvedValue ( mockDataUrl ) ;
171+
172+ await getImageDataUrlForCell ( "cell-1" as CellId ) ;
173+
174+ expect ( toPng ) . toHaveBeenCalledWith (
175+ mockElement ,
176+ expect . objectContaining ( {
177+ style : {
178+ maxHeight : "none" ,
179+ overflow : "visible" ,
180+ } ,
181+ } ) ,
182+ ) ;
183+ } ) ;
184+
185+ it ( "should pass scrollHeight as height option" , async ( ) => {
186+ // Set up element with scrollHeight
187+ Object . defineProperty ( mockElement , "scrollHeight" , {
188+ value : 500 ,
189+ configurable : true ,
190+ } ) ;
191+ vi . mocked ( toPng ) . mockResolvedValue ( mockDataUrl ) ;
192+
193+ await getImageDataUrlForCell ( "cell-1" as CellId ) ;
194+
195+ expect ( toPng ) . toHaveBeenCalledWith (
196+ mockElement ,
197+ expect . objectContaining ( {
198+ height : 500 ,
199+ } ) ,
200+ ) ;
201+ } ) ;
202+
203+ it ( "should pass scrollbar hiding styles via extraStyleContent" , async ( ) => {
204+ vi . mocked ( toPng ) . mockResolvedValue ( mockDataUrl ) ;
205+
206+ await getImageDataUrlForCell ( "cell-1" as CellId ) ;
207+
208+ expect ( toPng ) . toHaveBeenCalledWith (
209+ mockElement ,
210+ expect . objectContaining ( {
211+ extraStyleContent : expect . stringContaining ( "scrollbar-width: none" ) ,
212+ } ) ,
213+ ) ;
214+ } ) ;
215+
216+ it ( "should not modify the live DOM element" , async ( ) => {
170217 mockElement . style . overflow = "hidden" ;
218+ mockElement . style . maxHeight = "100px" ;
171219 vi . mocked ( toPng ) . mockResolvedValue ( mockDataUrl ) ;
172220
173221 await getImageDataUrlForCell ( "cell-1" as CellId ) ;
174222
223+ // DOM should remain unchanged
175224 expect ( mockElement . style . overflow ) . toBe ( "hidden" ) ;
225+ expect ( mockElement . style . maxHeight ) . toBe ( "100px" ) ;
176226 } ) ;
177227
178228 it ( "should throw error on failure" , async ( ) => {
@@ -183,34 +233,20 @@ describe("getImageDataUrlForCell", () => {
183233 ) ;
184234 } ) ;
185235
186- it ( "should cleanup even on failure" , async ( ) => {
187- mockElement . style . overflow = "scroll" ;
188- vi . mocked ( toPng ) . mockRejectedValue ( new Error ( "Capture failed" ) ) ;
189-
190- await expect ( getImageDataUrlForCell ( "cell-1" as CellId ) ) . rejects . toThrow ( ) ;
191-
192- expect ( document . body . classList . contains ( "printing" ) ) . toBe ( false ) ;
193- expect ( mockElement . style . overflow ) . toBe ( "scroll" ) ;
194- } ) ;
195-
196236 it ( "should handle concurrent captures correctly" , async ( ) => {
197237 // Create a second element
198238 const mockElement2 = document . createElement ( "div" ) ;
199239 mockElement2 . id = CellOutputId . create ( "cell-2" as CellId ) ;
200240 document . body . append ( mockElement2 ) ;
201241
202- vi . mocked ( toPng ) . mockImplementation ( async ( ) => {
203- // body.printing should not be added during cell captures
204- expect ( document . body . classList . contains ( "printing" ) ) . toBe ( false ) ;
205- return mockDataUrl ;
206- } ) ;
242+ vi . mocked ( toPng ) . mockResolvedValue ( mockDataUrl ) ;
207243
208244 const capture1 = getImageDataUrlForCell ( "cell-1" as CellId ) ;
209245 const capture2 = getImageDataUrlForCell ( "cell-2" as CellId ) ;
210246
211247 await Promise . all ( [ capture1 , capture2 ] ) ;
212248
213- expect ( document . body . classList . contains ( "printing" ) ) . toBe ( false ) ;
249+ expect ( toPng ) . toHaveBeenCalledTimes ( 2 ) ;
214250
215251 mockElement2 . remove ( ) ;
216252 } ) ;
@@ -266,23 +302,6 @@ describe("downloadHTMLAsImage", () => {
266302 expect ( mockAnchor . click ) . toHaveBeenCalled ( ) ;
267303 } ) ;
268304
269- it ( "should add body.printing class without prepare function" , async ( ) => {
270- vi . mocked ( toPng ) . mockImplementation ( async ( ) => {
271- expect ( document . body . classList . contains ( "printing" ) ) . toBe ( true ) ;
272- return mockDataUrl ;
273- } ) ;
274-
275- await downloadHTMLAsImage ( { element : mockElement , filename : "test" } ) ;
276- } ) ;
277-
278- it ( "should remove body.printing class after download without prepare" , async ( ) => {
279- vi . mocked ( toPng ) . mockResolvedValue ( mockDataUrl ) ;
280-
281- await downloadHTMLAsImage ( { element : mockElement , filename : "test" } ) ;
282-
283- expect ( document . body . classList . contains ( "printing" ) ) . toBe ( false ) ;
284- } ) ;
285-
286305 it ( "should use prepare function when provided" , async ( ) => {
287306 vi . mocked ( toPng ) . mockResolvedValue ( mockDataUrl ) ;
288307 const cleanup = vi . fn ( ) ;
@@ -406,24 +425,32 @@ describe("downloadCellOutputAsImage", () => {
406425 expect ( mockAnchor . download ) . toBe ( "result.png" ) ;
407426 } ) ;
408427
409- it ( "should apply cell-specific preparation" , async ( ) => {
410- vi . mocked ( toPng ) . mockImplementation ( async ( ) => {
411- // Check that cell-specific classes are applied
412- expect ( mockElement . style . overflow ) . toBe ( "visible" ) ;
413- return mockDataUrl ;
414- } ) ;
428+ it ( "should pass style options to toPng for full content capture" , async ( ) => {
429+ vi . mocked ( toPng ) . mockResolvedValue ( mockDataUrl ) ;
415430
416431 await downloadCellOutputAsImage ( "cell-1" as CellId , "result" ) ;
432+
433+ expect ( toPng ) . toHaveBeenCalledWith (
434+ mockElement ,
435+ expect . objectContaining ( {
436+ style : {
437+ maxHeight : "none" ,
438+ overflow : "visible" ,
439+ } ,
440+ } ) ,
441+ ) ;
417442 } ) ;
418443
419- it ( "should cleanup after download" , async ( ) => {
420- mockElement . style . overflow = "visible" ;
444+ it ( "should not modify the live DOM element" , async ( ) => {
445+ mockElement . style . overflow = "hidden" ;
446+ mockElement . style . maxHeight = "100px" ;
421447 vi . mocked ( toPng ) . mockResolvedValue ( mockDataUrl ) ;
422448
423449 await downloadCellOutputAsImage ( "cell-1" as CellId , "result" ) ;
424450
425- expect ( document . body . classList . contains ( "printing" ) ) . toBe ( false ) ;
426- expect ( mockElement . style . overflow ) . toBe ( "visible" ) ;
451+ // DOM should remain unchanged
452+ expect ( mockElement . style . overflow ) . toBe ( "hidden" ) ;
453+ expect ( mockElement . style . maxHeight ) . toBe ( "100px" ) ;
427454 } ) ;
428455} ) ;
429456
0 commit comments