diff --git a/src/components/app/data/hooks/useEnterpriseCustomer.test.jsx b/src/components/app/data/hooks/useEnterpriseCustomer.test.jsx index e01fa3e1f..b98c3d25a 100644 --- a/src/components/app/data/hooks/useEnterpriseCustomer.test.jsx +++ b/src/components/app/data/hooks/useEnterpriseCustomer.test.jsx @@ -4,7 +4,7 @@ import { AppContext } from '@edx/frontend-platform/react'; import { MemoryRouter, Route, Routes } from 'react-router-dom'; import { authenticatedUserFactory, enterpriseCustomerFactory } from '../services/data/__factories__'; import useEnterpriseCustomer from './useEnterpriseCustomer'; -import { queryClient } from '../../../../utils/tests'; +import { generateTestPermutations, queryClient } from '../../../../utils/tests'; import { fetchEnterpriseLearnerDashboard, fetchEnterpriseLearnerData } from '../services'; jest.mock('../services', () => ({ @@ -76,19 +76,19 @@ describe('useEnterpriseCustomer', () => { fetchEnterpriseLearnerData.mockResolvedValue(mockEnterpriseLearnerData); fetchEnterpriseLearnerDashboard.mockResolvedValue(mockBFFDashboardData); }); - it.each([ - { isMatchedBFFRoute: false }, - { isMatchedBFFRoute: true }, - ])('should return enterprise customers correctly (%s)', async ({ isMatchedBFFRoute }) => { + it.each(generateTestPermutations({ + isMatchedBFFRoute: [false, true], + hasCustomSelect: [false, true], + }))('should return enterprise customers correctly (%s)', async ({ + isMatchedBFFRoute, + hasCustomSelect, + }) => { const mockSelect = jest.fn(data => data.transformed); const initialEntries = isMatchedBFFRoute ? ['/test-enterprise'] : ['/test-enterprise/search']; + const enterpriseLearnerHookArgs = hasCustomSelect ? { select: mockSelect } : {}; const { result, waitForNextUpdate } = renderHook( - () => { - if (isMatchedBFFRoute) { - return useEnterpriseCustomer({ select: mockSelect }); - } - return useEnterpriseCustomer(); - }, + () => (useEnterpriseCustomer(enterpriseLearnerHookArgs)), + { wrapper: ({ children }) => ( @@ -98,7 +98,7 @@ describe('useEnterpriseCustomer', () => { }, ); await waitForNextUpdate(); - if (isMatchedBFFRoute) { + if (hasCustomSelect) { expect(mockSelect).toHaveBeenCalledTimes(4); } else { expect(mockSelect).toHaveBeenCalledTimes(0); diff --git a/src/components/app/data/hooks/useEnterpriseFeatures.test.jsx b/src/components/app/data/hooks/useEnterpriseFeatures.test.jsx index 8a6f4eeab..4bea1d266 100644 --- a/src/components/app/data/hooks/useEnterpriseFeatures.test.jsx +++ b/src/components/app/data/hooks/useEnterpriseFeatures.test.jsx @@ -3,7 +3,7 @@ import { QueryClientProvider } from '@tanstack/react-query'; import { AppContext } from '@edx/frontend-platform/react'; import { MemoryRouter, Route, Routes } from 'react-router-dom'; import { authenticatedUserFactory, enterpriseCustomerFactory } from '../services/data/__factories__'; -import { queryClient } from '../../../../utils/tests'; +import { generateTestPermutations, queryClient } from '../../../../utils/tests'; import { fetchEnterpriseLearnerDashboard, fetchEnterpriseLearnerData } from '../services'; import { useEnterpriseFeatures } from './index'; @@ -75,19 +75,18 @@ describe('useEnterpriseFeatures', () => { fetchEnterpriseLearnerData.mockResolvedValue(mockEnterpriseLearnerData); }); - it.each([ - { isMatchedBFFRoute: false }, - { isMatchedBFFRoute: true }, - ])('should return enterprise features correctly (%s)', async ({ isMatchedBFFRoute }) => { + it.each(generateTestPermutations({ + isMatchedBFFRoute: [false, true], + hasCustomSelect: [false, true], + }))('should return enterprise features correctly (%s)', async ({ + isMatchedBFFRoute, + hasCustomSelect, + }) => { const mockSelect = jest.fn(data => data.transformed); const initialEntries = isMatchedBFFRoute ? ['/test-enterprise'] : ['/test-enterprise/search']; + const enterpriseLearnerHookArgs = hasCustomSelect ? { select: mockSelect } : {}; const { result, waitForNextUpdate } = renderHook( - () => { - if (isMatchedBFFRoute) { - return useEnterpriseFeatures({ select: mockSelect }); - } - return useEnterpriseFeatures(); - }, + () => (useEnterpriseFeatures(enterpriseLearnerHookArgs)), { wrapper: ({ children }) => ( @@ -97,7 +96,7 @@ describe('useEnterpriseFeatures', () => { }, ); await waitForNextUpdate(); - if (isMatchedBFFRoute) { + if (hasCustomSelect) { expect(mockSelect).toHaveBeenCalledTimes(4); } else { expect(mockSelect).toHaveBeenCalledTimes(0); diff --git a/src/components/app/data/hooks/useEnterpriseLearner.test.jsx b/src/components/app/data/hooks/useEnterpriseLearner.test.jsx index 5f7e5ab5e..ea55a3b6a 100644 --- a/src/components/app/data/hooks/useEnterpriseLearner.test.jsx +++ b/src/components/app/data/hooks/useEnterpriseLearner.test.jsx @@ -3,7 +3,7 @@ import { QueryClientProvider } from '@tanstack/react-query'; import { AppContext } from '@edx/frontend-platform/react'; import { MemoryRouter, useParams } from 'react-router-dom'; import { authenticatedUserFactory, enterpriseCustomerFactory } from '../services/data/__factories__'; -import { queryClient } from '../../../../utils/tests'; +import { generateTestPermutations, queryClient } from '../../../../utils/tests'; import { fetchEnterpriseLearnerDashboard, fetchEnterpriseLearnerData } from '../services'; import useEnterpriseLearner from './useEnterpriseLearner'; @@ -79,18 +79,18 @@ describe('useEnterpriseLearner', () => { fetchEnterpriseLearnerDashboard.mockResolvedValue(mockBFFDashboardData); useParams.mockReturnValue({ enterpriseSlug: mockEnterpriseCustomer.slug }); }); - it.each([ - { isMatchedBFFRoute: false }, - { isMatchedBFFRoute: true }, - ])('should return enterprise learners correctly (%s)', async ({ isMatchedBFFRoute }) => { + + it.each(generateTestPermutations({ + isMatchedBFFRoute: [false, true], + hasCustomSelect: [false, true], + }))('should return enterprise learners correctly (%s)', async ({ + isMatchedBFFRoute, + hasCustomSelect, + }) => { const mockSelect = jest.fn(data => data.transformed); + const enterpriseLearnerHookArgs = hasCustomSelect ? { select: mockSelect } : {}; const { result, waitForNextUpdate } = renderHook( - () => { - if (isMatchedBFFRoute) { - return useEnterpriseLearner({ select: mockSelect }); - } - return useEnterpriseLearner(); - }, + () => (useEnterpriseLearner(enterpriseLearnerHookArgs)), { wrapper: ({ children }) => Wrapper({ routes: isMatchedBFFRoute ? '/test-enterprise' : 'test-enterprise/search', @@ -98,8 +98,10 @@ describe('useEnterpriseLearner', () => { }), }, ); + await waitForNextUpdate(); - if (isMatchedBFFRoute) { + + if (hasCustomSelect) { expect(mockSelect).toHaveBeenCalledTimes(2); } else { expect(mockSelect).toHaveBeenCalledTimes(0);