@@ -74,6 +74,7 @@ describe('ShareSheet', () => {
7474
7575 afterEach ( ( ) => {
7676 vi . restoreAllMocks ( ) ;
77+ document . documentElement . classList . remove ( 'dark' ) ;
7778 } ) ;
7879
7980 it ( 'does not render when isOpen is false' , ( ) => {
@@ -195,7 +196,10 @@ describe('ShareSheet', () => {
195196 ) ;
196197 } ) ;
197198
198- it ( 'handles Download PNG action' , async ( ) => {
199+ it ( 'handles Download PNG action in dark mode' , async ( ) => {
200+ // Add 'dark' class to document.documentElement
201+ document . documentElement . classList . add ( 'dark' ) ;
202+
199203 render ( < ShareSheet { ...defaultProps } /> ) ;
200204
201205 // Create a mock document element to satisfy the selector
@@ -207,7 +211,41 @@ describe('ShareSheet', () => {
207211 fireEvent . click ( downloadButton ! ) ;
208212
209213 const { toPng } = await import ( 'html-to-image' ) ;
210- expect ( toPng ) . toHaveBeenCalled ( ) ;
214+ expect ( toPng ) . toHaveBeenLastCalledWith (
215+ expect . any ( HTMLElement ) ,
216+ expect . objectContaining ( {
217+ backgroundColor : '#050505' ,
218+ } )
219+ ) ;
220+
221+ await waitFor ( ( ) => {
222+ expect ( screen . getByText ( 'Downloaded!' ) ) . toBeDefined ( ) ;
223+ } ) ;
224+
225+ document . body . removeChild ( mockRoot ) ;
226+ } ) ;
227+
228+ it ( 'handles Download PNG action in light mode' , async ( ) => {
229+ // Ensure 'dark' class is NOT on document.documentElement
230+ document . documentElement . classList . remove ( 'dark' ) ;
231+
232+ render ( < ShareSheet { ...defaultProps } /> ) ;
233+
234+ // Create a mock document element to satisfy the selector
235+ const mockRoot = document . createElement ( 'div' ) ;
236+ mockRoot . id = 'dashboard-root' ;
237+ document . body . appendChild ( mockRoot ) ;
238+
239+ const downloadButton = screen . getByText ( 'Download as PNG' ) . closest ( 'button' ) ;
240+ fireEvent . click ( downloadButton ! ) ;
241+
242+ const { toPng } = await import ( 'html-to-image' ) ;
243+ expect ( toPng ) . toHaveBeenLastCalledWith (
244+ expect . any ( HTMLElement ) ,
245+ expect . objectContaining ( {
246+ backgroundColor : '#ffffff' ,
247+ } )
248+ ) ;
211249
212250 await waitFor ( ( ) => {
213251 expect ( screen . getByText ( 'Downloaded!' ) ) . toBeDefined ( ) ;
0 commit comments