From 330352e279640af97fcc95ba88b443421fcdab7d Mon Sep 17 00:00:00 2001 From: Dmitry Merkushin Date: Sat, 13 Jul 2024 21:41:56 -0600 Subject: [PATCH] Check if the the request hasn't started (#92665) It was not enough to check isPending, because isIdle is the status that we have before performing the request. Here, isPending is false, so it lets us to render component. That resulted in flakiness in the component and tests' behaviours. --- .../blocks/importer/wordpress/upgrade-plan/test/index.tsx | 8 ++++++-- .../wordpress/upgrade-plan/with-migration-sticker.tsx | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/client/blocks/importer/wordpress/upgrade-plan/test/index.tsx b/client/blocks/importer/wordpress/upgrade-plan/test/index.tsx index eb45a004708af..65ec53334e3e7 100644 --- a/client/blocks/importer/wordpress/upgrade-plan/test/index.tsx +++ b/client/blocks/importer/wordpress/upgrade-plan/test/index.tsx @@ -172,7 +172,10 @@ describe( 'UpgradePlan', () => { it( 'should call onCtaClick when the user clicks on the Continue button', async () => { const mockOnCtaClick = jest.fn(); - renderUpgradePlanComponent( getUpgradePlanProps( { onCtaClick: mockOnCtaClick } ) ); + renderUpgradePlanComponent( + getUpgradePlanProps( { onCtaClick: mockOnCtaClick } ), + UnwrappedUpgradePlan + ); await userEvent.click( screen.getByRole( 'button', { name: /Continue/ } ) ); @@ -183,7 +186,8 @@ describe( 'UpgradePlan', () => { const mockOnCtaClick = jest.fn(); renderUpgradePlanComponent( - getUpgradePlanProps( { ctaText: 'My Custom CTA', onCtaClick: mockOnCtaClick } ) + getUpgradePlanProps( { ctaText: 'My Custom CTA', onCtaClick: mockOnCtaClick } ), + UnwrappedUpgradePlan ); await userEvent.click( screen.getByRole( 'button', { name: /My Custom CTA/ } ) ); diff --git a/client/blocks/importer/wordpress/upgrade-plan/with-migration-sticker.tsx b/client/blocks/importer/wordpress/upgrade-plan/with-migration-sticker.tsx index 1ea45925906ba..656de51f49586 100644 --- a/client/blocks/importer/wordpress/upgrade-plan/with-migration-sticker.tsx +++ b/client/blocks/importer/wordpress/upgrade-plan/with-migration-sticker.tsx @@ -12,7 +12,7 @@ const withMigrationSticker = const { addMigrationSticker, - addMutationRest: { isPending }, + addMutationRest: { isIdle, isPending }, deleteMigrationSticker, } = useMigrationStickerMutation(); @@ -32,7 +32,7 @@ const withMigrationSticker = }; }, [ addMigrationSticker, deleteMigrationSticker, siteId ] ); - if ( isPending ) { + if ( isIdle || isPending ) { return ; }