@@ -20,6 +20,8 @@ const mockStore = {
2020
2121const mockDownloadFn = vi . fn ( ) ;
2222
23+ const mockExcelDownloadFn = vi . hoisted ( ( ) => vi . fn ( ) ) ;
24+
2325const mockInfoQuery = {
2426 data : [ ]
2527} ;
@@ -53,6 +55,10 @@ vi.mock('@/hooks/useInstrumentInfoQuery', () => ({
5355 useInstrumentInfoQuery : ( ) => mockInfoQuery
5456} ) ) ;
5557
58+ vi . mock ( '@/utils/excel' , ( ) => ( {
59+ downloadSubjectTableExcel : mockExcelDownloadFn
60+ } ) ) ;
61+
5662vi . mock ( '@/hooks/useInstrumentRecords' , ( ) => ( {
5763 useInstrumentRecords : ( ) => mockInstrumentRecords
5864} ) ) ;
@@ -124,6 +130,51 @@ describe('useInstrumentVisualization', () => {
124130 ) ;
125131 } ) ;
126132 } ) ;
133+ describe ( 'Excel' , ( ) => {
134+ it ( 'Should download' , ( ) => {
135+ const { result } = renderHook ( ( ) => useInstrumentVisualization ( { params : { subjectId : 'testId' } } ) ) ;
136+ const { dl, records } = result . current ;
137+ act ( ( ) => dl ( 'Excel' ) ) ;
138+ expect ( records ) . toBeDefined ( ) ;
139+ expect ( mockExcelDownloadFn ) . toHaveBeenCalledTimes ( 1 ) ;
140+ const [ filename , getContentFn ] = mockExcelDownloadFn . mock . calls [ 0 ] ?? [ ] ;
141+ expect ( filename ) . toMatch ( '.xlsx' ) ;
142+ const excelContents = getContentFn ;
143+
144+ expect ( excelContents ) . toEqual ( [
145+ {
146+ GroupID : 'testGroupId' ,
147+ subjectId : 'testId' ,
148+ // eslint-disable-next-line perfectionist/sort-objects
149+ Date : '2025-04-30' ,
150+ someValue : 'abc'
151+ }
152+ ] ) ;
153+ } ) ;
154+ } ) ;
155+ describe ( 'Excel Long' , ( ) => {
156+ it ( 'Should download' , ( ) => {
157+ const { result } = renderHook ( ( ) => useInstrumentVisualization ( { params : { subjectId : 'testId' } } ) ) ;
158+ const { dl, records } = result . current ;
159+ act ( ( ) => dl ( 'Excel Long' ) ) ;
160+ expect ( records ) . toBeDefined ( ) ;
161+ expect ( mockExcelDownloadFn ) . toHaveBeenCalledTimes ( 1 ) ;
162+
163+ const [ filename , getContentFn ] = mockExcelDownloadFn . mock . calls [ 0 ] ?? [ ] ;
164+ expect ( filename ) . toMatch ( '.xlsx' ) ;
165+ const excelContents = getContentFn ;
166+
167+ expect ( excelContents ) . toEqual ( [
168+ {
169+ Date : '2025-04-30' ,
170+ GroupID : 'testGroupId' ,
171+ SubjectID : 'testId' ,
172+ Value : 'abc' ,
173+ Variable : 'someValue'
174+ }
175+ ] ) ;
176+ } ) ;
177+ } ) ;
127178 describe ( 'JSON' , ( ) => {
128179 it ( 'Should download' , async ( ) => {
129180 const { result } = renderHook ( ( ) => useInstrumentVisualization ( { params : { subjectId : 'testId' } } ) ) ;
0 commit comments