Skip to content

Commit

Permalink
chore: custom select tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Feb 25, 2025
1 parent e51d9f2 commit 684f993
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
24 changes: 12 additions & 12 deletions src/components/app/data/hooks/useEnterpriseCustomer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down Expand Up @@ -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 }) => (
<Wrapper initialEntries={initialEntries}>
Expand All @@ -98,7 +98,7 @@ describe('useEnterpriseCustomer', () => {
},
);
await waitForNextUpdate();
if (isMatchedBFFRoute) {
if (hasCustomSelect) {
expect(mockSelect).toHaveBeenCalledTimes(4);
} else {
expect(mockSelect).toHaveBeenCalledTimes(0);
Expand Down
23 changes: 11 additions & 12 deletions src/components/app/data/hooks/useEnterpriseFeatures.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 }) => (
<Wrapper initialEntries={initialEntries}>
Expand All @@ -97,7 +96,7 @@ describe('useEnterpriseFeatures', () => {
},
);
await waitForNextUpdate();
if (isMatchedBFFRoute) {
if (hasCustomSelect) {
expect(mockSelect).toHaveBeenCalledTimes(4);
} else {
expect(mockSelect).toHaveBeenCalledTimes(0);
Expand Down
26 changes: 14 additions & 12 deletions src/components/app/data/hooks/useEnterpriseLearner.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -79,27 +79,29 @@ 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',
children,
}),
},
);

await waitForNextUpdate();
if (isMatchedBFFRoute) {

if (hasCustomSelect) {
expect(mockSelect).toHaveBeenCalledTimes(2);
} else {
expect(mockSelect).toHaveBeenCalledTimes(0);
Expand Down

0 comments on commit 684f993

Please sign in to comment.