From 27b2a3eab395ceac8803f98ada94595b4a567619 Mon Sep 17 00:00:00 2001 From: Paulo Trentin Date: Fri, 24 Jan 2025 17:06:32 -0300 Subject: [PATCH] Created a unit test to ensure selector's behavior --- .../test/should-show-launchpad-first.ts | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 client/state/selectors/test/should-show-launchpad-first.ts diff --git a/client/state/selectors/test/should-show-launchpad-first.ts b/client/state/selectors/test/should-show-launchpad-first.ts new file mode 100644 index 00000000000000..8d8402196d8406 --- /dev/null +++ b/client/state/selectors/test/should-show-launchpad-first.ts @@ -0,0 +1,54 @@ +import config from '@automattic/calypso-config'; +import { shouldShowLaunchpadFirst } from '../should-show-launchpad-first'; + +jest.mock( '@automattic/calypso-config', () => ( { + isEnabled: jest.fn(), +} ) ); + +describe( 'shouldShowLaunchpadFirst', () => { + beforeEach( () => { + jest.clearAllMocks(); + } ); + + it( 'should return true when site was created via onboarding flow and feature flag is enabled', () => { + ( config.isEnabled as jest.Mock ).mockReturnValue( true ); + const site = { + options: { + site_creation_flow: 'onboarding', + }, + }; + + expect( shouldShowLaunchpadFirst( site ) ).toBe( true ); + } ); + + it( 'should return false when site was created via onboarding flow but feature flag is disabled', () => { + ( config.isEnabled as jest.Mock ).mockReturnValue( false ); + const site = { + options: { + site_creation_flow: 'onboarding', + }, + }; + + expect( shouldShowLaunchpadFirst( site ) ).toBe( false ); + } ); + + it( 'should return false when site was not created via onboarding flow', () => { + ( config.isEnabled as jest.Mock ).mockReturnValue( true ); + const site = { + options: { + site_creation_flow: 'other', + }, + }; + + expect( shouldShowLaunchpadFirst( site ) ).toBe( false ); + } ); + + it( 'should return false when site has no creation flow information', () => { + ( config.isEnabled as jest.Mock ).mockReturnValue( true ); + const site = { + options: {}, + }; + + expect( shouldShowLaunchpadFirst( site ) ).toBe( false ); + } ); +} );