@@ -166,6 +166,76 @@ describe("Artifact Processing Tests", () => {
166166 // expect(core.summary.addRaw).toHaveBeenCalledTimes(2);
167167 // }
168168 // });
169+
170+ it ( "should write test results data to the GitHub job summary" , ( ) => {
171+ if ( testResultsData ) {
172+ const actionName = process . env . GITHUB_ACTION || "" ;
173+
174+ // Mock getCoverageData to return null for this test (or mock it to return data if you want to test that path)
175+ const getCoverageDataSpy = jest . spyOn ( require ( './codeCoverageSummary' ) , 'getCoverageData' ) . mockReturnValue ( null ) ;
176+
177+ testResultsSummary . addSummary ( testResultsData , actionName ) ;
178+
179+ // Should be called 1 time since "All tests" heading is commented out and no coverage data
180+ expect ( core . summary . addHeading ) . toHaveBeenCalledTimes ( 1 ) ;
181+
182+ expect ( core . summary . addHeading ) . toHaveBeenNthCalledWith (
183+ 1 ,
184+ expect . stringContaining ( "MATLAB Test Results (" + actionName + ")" ) ,
185+ ) ;
186+ expect ( core . summary . addHeading ) . toHaveBeenNthCalledWith (
187+ 1 ,
188+ expect . stringContaining (
189+ '<a href="https://github.com/matlab-actions/run-tests/blob/main/README.md#view-test-results"' ,
190+ ) ,
191+ ) ;
192+ expect ( core . summary . addHeading ) . toHaveBeenNthCalledWith (
193+ 1 ,
194+ expect . stringContaining ( 'target="_blank"' ) ,
195+ ) ;
196+ expect ( core . summary . addHeading ) . toHaveBeenNthCalledWith (
197+ 1 ,
198+ expect . stringContaining ( "ℹ️</a>" ) ,
199+ ) ;
200+
201+ // Should be called 1 time (just the header, since detailed results are commented out)
202+ expect ( core . summary . addRaw ) . toHaveBeenCalledTimes ( 1 ) ;
203+
204+ getCoverageDataSpy . mockRestore ( ) ;
205+ }
206+ } ) ;
207+
208+ it ( "should write test results with coverage data to the GitHub job summary" , ( ) => {
209+ if ( testResultsData ) {
210+ const actionName = process . env . GITHUB_ACTION || "" ;
211+ const mockCoverageData = { /* your mock coverage data structure */ } ;
212+
213+ // Mock getCoverageData to return coverage data
214+ const getCoverageDataSpy = jest . spyOn ( require ( './codeCoverageSummary' ) , 'getCoverageData' ) . mockReturnValue ( mockCoverageData ) ;
215+ const generateCoverageTableHTMLSpy = jest . spyOn ( require ( './codeCoverageSummary' ) , 'generateCoverageTableHTML' ) . mockReturnValue ( '<table>Coverage</table>' ) ;
216+
217+ testResultsSummary . addSummary ( testResultsData , actionName ) ;
218+
219+ // Should be called 2 times (main heading + coverage heading)
220+ expect ( core . summary . addHeading ) . toHaveBeenCalledTimes ( 2 ) ;
221+
222+ expect ( core . summary . addHeading ) . toHaveBeenNthCalledWith (
223+ 1 ,
224+ expect . stringContaining ( "MATLAB Test Results (" + actionName + ")" ) ,
225+ ) ;
226+ expect ( core . summary . addHeading ) . toHaveBeenNthCalledWith (
227+ 2 ,
228+ "MATLAB Code Coverage" ,
229+ 3
230+ ) ;
231+
232+ // Should be called 2 times (header + coverage table)
233+ expect ( core . summary . addRaw ) . toHaveBeenCalledTimes ( 2 ) ;
234+
235+ getCoverageDataSpy . mockRestore ( ) ;
236+ generateCoverageTableHTMLSpy . mockRestore ( ) ;
237+ }
238+ } ) ;
169239} ) ;
170240
171241describe ( "HTML Structure Tests" , ( ) => {
0 commit comments