@@ -468,7 +468,7 @@ describe('AuditResults Component', () => {
468468 expect ( screen . getByTestId ( 'custom-modal' ) ) . toBeInTheDocument ( ) ;
469469 } ) ;
470470
471- expect ( screen . getByTestId ( 'modal-title' ) ) . toHaveTextContent ( 'Purged Entity Details: guid-4' ) ;
471+ expect ( screen . getByTestId ( 'modal-title' ) ) . toHaveTextContent ( 'Auto Purge Entity Details: guid-4' ) ;
472472 } ) ;
473473
474474 it ( 'should close purge modal when close button is clicked' , async ( ) => {
@@ -1304,6 +1304,25 @@ describe('AuditResults Component', () => {
13041304 } ) ;
13051305 } ) ;
13061306
1307+ it ( 'should show empty-drawer fallback message when PURGED count > 0 but GUID list is empty' , async ( ) => {
1308+ const auditDataForSummary = [ {
1309+ guid : 'audit-empty-sum' ,
1310+ operation : 'PURGE' ,
1311+ params : JSON . stringify ( [ 'req-1' ] ) ,
1312+ result : JSON . stringify ( {
1313+ requestedCount : 1 , purgedCount : 5 , purgedDependenciesCount : 0 ,
1314+ failedCount : 0 , skippedCount : 0 , executionFailed : false , runId : 'test-empty'
1315+ } )
1316+ } ] ;
1317+ render ( < AuditResults componentProps = { { auditData : auditDataForSummary } } row = { { original : { guid : 'audit-empty-sum' } } } /> ) ;
1318+
1319+ fireEvent . click ( screen . getByText ( 'PURGED' ) ) ;
1320+
1321+ await waitFor ( ( ) => {
1322+ expect ( screen . getByText ( 'Entity list not available for summary audits — see purgefailure.log' ) ) . toBeInTheDocument ( ) ;
1323+ } ) ;
1324+ } ) ;
1325+
13071326 it ( 'should NOT trigger action when Failed card is clicked (display only)' , ( ) => {
13081327 render ( < AuditResults componentProps = { { auditData : summaryAuditData } } row = { { original : { guid : 'audit-sum' } } } /> ) ;
13091328
@@ -1476,6 +1495,73 @@ describe('AuditResults Component', () => {
14761495 } ) ;
14771496
14781497
1498+ describe ( 'Summary fetch logic (useEffect)' , ( ) => {
1499+ afterEach ( ( ) => {
1500+ jest . clearAllMocks ( ) ;
1501+ } ) ;
1502+
1503+ it ( '(1) successful summary fetch populates cards' , async ( ) => {
1504+ ( fetchApi as jest . Mock ) . mockResolvedValueOnce ( {
1505+ data : [ {
1506+ action : 'PURGE' ,
1507+ details : '{"requestedCount": 10, "purgedCount": 8, "purgedDependenciesCount": 2, "failedCount": 0, "skippedCount": 0, "executionFailed": false, "runId": "run-fetch-1"}'
1508+ } ]
1509+ } ) ;
1510+
1511+ const auditData = [ { guid : 'fetch-test-1' , operation : 'PURGE' , params : '[]' , result : 'run-fetch-1' } ] ;
1512+ render ( < AuditResults componentProps = { { auditData } } row = { { original : { guid : 'fetch-test-1' } } } /> ) ;
1513+
1514+ await waitFor ( ( ) => {
1515+ expect ( screen . getAllByText ( '10' ) . length ) . toBeGreaterThan ( 0 ) ;
1516+ } ) ;
1517+ } ) ;
1518+
1519+ it ( '(2) fetch failure falls back to parsed result' , async ( ) => {
1520+ ( fetchApi as jest . Mock ) . mockRejectedValueOnce ( new Error ( 'Fetch failed' ) ) ;
1521+
1522+ const fallbackResult = JSON . stringify ( {
1523+ requestedCount : 5 , purgedCount : 5 , purgedDependenciesCount : 0 ,
1524+ failedCount : 0 , skippedCount : 0 , executionFailed : false , runId : 'run-fallback'
1525+ } ) ;
1526+ const auditData = [ { guid : 'fetch-test-2' , operation : 'PURGE' , params : '[]' , result : fallbackResult } ] ;
1527+ render ( < AuditResults componentProps = { { auditData } } row = { { original : { guid : 'fetch-test-2' } } } /> ) ;
1528+
1529+ await waitFor ( ( ) => {
1530+ expect ( screen . getAllByText ( '5' ) . length ) . toBeGreaterThan ( 0 ) ;
1531+ } ) ;
1532+ } ) ;
1533+
1534+ it ( '(3) loading skeleton shows while fetching' , async ( ) => {
1535+ let resolvePromise : any ;
1536+ const promise = new Promise ( ( resolve ) => {
1537+ resolvePromise = resolve ;
1538+ } ) ;
1539+ ( fetchApi as jest . Mock ) . mockReturnValueOnce ( promise ) ;
1540+
1541+ const auditData = [ { guid : 'fetch-test-3' , operation : 'PURGE' , params : '[]' , result : 'run-fetch-3' } ] ;
1542+ render ( < AuditResults componentProps = { { auditData } } row = { { original : { guid : 'fetch-test-3' } } } /> ) ;
1543+
1544+ expect ( document . querySelector ( '.MuiSkeleton-root' ) ) . toBeInTheDocument ( ) ;
1545+
1546+ resolvePromise ( { data : [ ] } ) ;
1547+ await waitFor ( ( ) => {
1548+ expect ( document . querySelector ( '.MuiSkeleton-root' ) ) . not . toBeInTheDocument ( ) ;
1549+ } ) ;
1550+ } ) ;
1551+
1552+ it ( '(4) AbortController cancels on unmount' , ( ) => {
1553+ const abortSpy = jest . spyOn ( AbortController . prototype , 'abort' ) ;
1554+
1555+ const auditData = [ { guid : 'fetch-test-4' , operation : 'PURGE' , params : '[]' , result : 'run-fetch-4' } ] ;
1556+ const { unmount } = render ( < AuditResults componentProps = { { auditData } } row = { { original : { guid : 'fetch-test-4' } } } /> ) ;
1557+
1558+ unmount ( ) ;
1559+
1560+ expect ( abortSpy ) . toHaveBeenCalled ( ) ;
1561+ abortSpy . mockRestore ( ) ;
1562+ } ) ;
1563+ } ) ;
1564+
14791565 describe ( 'Copy Run ID' , ( ) => {
14801566 it ( 'should copy Run ID to clipboard and show Copied tooltip' , async ( ) => {
14811567 const auditData = [ { guid : 'audit-1' , operation : 'PURGE' , params : '["a"]' , result : '["a"]' , runId : 'test-run-1' } ] ;
0 commit comments