import { render, screen } from '@testing-library/react'; import { IntlProvider } from '@edx/frontend-platform/i18n'; import { useCourseData } from 'hooks'; import CourseCardBanners from '.'; jest.mock('./CourseBanner', () => jest.fn(() =>
CourseBanner
)); jest.mock('./CertificateBanner', () => jest.fn(() =>
CertificateBanner
)); jest.mock('./CreditBanner', () => jest.fn(() =>
CreditBanner
)); jest.mock('./EntitlementBanner', () => jest.fn(() =>
EntitlementBanner
)); jest.mock('./RelatedProgramsBanner', () => jest.fn(() =>
RelatedProgramsBanner
)); const mockedComponents = [ 'CourseBanner', 'CertificateBanner', 'CreditBanner', 'EntitlementBanner', 'RelatedProgramsBanner', ]; jest.mock('hooks', () => ({ useCourseData: jest.fn(() => ({ enrollment: { isEnrolled: true, }, })), })); describe('CourseCardBanners', () => { const props = { cardId: 'test-card-id', }; it('renders default CourseCardBanners', () => { render(); mockedComponents.map((componentName) => { const mockedComponent = screen.getByText(componentName); return expect(mockedComponent).toBeInTheDocument(); }); }); it('render null with no courseData', () => { useCourseData.mockReturnValue(null); const { container } = render(); expect(container.firstChild).toBeNull(); }); it('render with isEnrolled false', () => { useCourseData.mockReturnValue({ enrollment: { isEnrolled: false } }); render(); const mockedComponentsIfNotEnrolled = mockedComponents.slice(-2); mockedComponentsIfNotEnrolled.map((componentName) => { const mockedComponent = screen.getByText(componentName); return expect(mockedComponent).toBeInTheDocument(); }); }); });