@@ -166,6 +166,9 @@ describe('Moisture Content Screen page', () => {
166166 . find ( 'td:nth-last-child(1) svg' )
167167 . click ( ) ;
168168
169+ // Wait for the delete API to finish
170+ cy . wait ( '@deleteReplicate' ) ;
171+
169172 // Assert row count stabilizes
170173 cy . get ( '.activity-result-container tbody tr' )
171174 . should ( 'have.length' , 3 ) ;
@@ -686,7 +689,7 @@ describe('Moisture Content Screen page', () => {
686689 } ) ;
687690
688691 it ( 'Check Calculate average button functionality' , ( ) => {
689- // Wait for table to have at least one row with content
692+ // Wait for the table to have at least one row
690693 cy . waitForTableData ( '.activity-result-container' ) ;
691694
692695 // Click the 'Calculate average' button
@@ -695,12 +698,16 @@ describe('Moisture Content Screen page', () => {
695698 . contains ( 'Calculate average' )
696699 . click ( ) ;
697700
698- // Wait for the mocked POST request and load fixture
699- cy . wait ( '@postCalcAvg' ) . then ( ( interception ) => {
700- expect ( interception . response ! . statusCode ) . to . eq ( 200 ) ;
701+ // Wait for the POST request and assert the response
702+ cy . wait ( '@postCalcAvg' ) . then ( ( { response } ) => {
703+ // Make sure response exists
704+ if ( ! response ) throw new Error ( 'Intercepted response is undefined' ) ;
705+
706+ // Assert status code
707+ expect ( response . statusCode ) . to . eq ( 200 ) ;
701708
702- // Get the mocked average from the fixture
703- const { body : { averageMc } } = interception . response ! ;
709+ // Destructure the mocked averageMc from the response body
710+ const { averageMc } = response . body ;
704711
705712 // Assert the displayed average matches the mocked value
706713 cy . get ( '.activity-summary' )
0 commit comments