test: Deprecate react-unit-test-utils 9/15 (#668)

This commit is contained in:
Diana Villalvazo
2025-06-24 11:50:11 -05:00
committed by GitHub
parent 6ae8180f99
commit cae7b1bba0
10 changed files with 193 additions and 658 deletions

View File

@@ -1,23 +1,47 @@
import React from 'react';
import { shallow } from '@edx/react-unit-test-utils';
import { render, screen } from '@testing-library/react';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import ProgramCard from './ProgramCard';
const props = {
data: {
numberOfCourses: 2,
bannerImgSrc: 'props.data.bannerImgSrc',
logoImgSrc: 'props.data.logoImgSrc',
title: 'props.data.title',
provider: 'props.data.provider',
programType: 'props.data.programType',
programUrl: 'props.data.programUrl',
programTypeUrl: 'props.data.programTypeUrl',
bannerImgSrc: 'test bannerImgSrc',
logoImgSrc: 'test logoImgSrc',
title: 'test title',
provider: 'test provider',
programType: 'test programType',
programUrl: 'test programUrl',
programTypeUrl: 'test programTypeUrl',
},
};
jest.unmock('@openedx/paragon');
jest.unmock('@edx/frontend-platform/i18n');
jest.unmock('react');
describe('RelatedProgramsModal ProgramCard', () => {
test('snapshot', () => {
expect(shallow(<ProgramCard {...props} />).snapshot).toMatchSnapshot();
describe('renders', () => {
beforeEach(() => render(<IntlProvider locale="en"><ProgramCard {...props} /></IntlProvider>));
it('bannerImg and logo', () => {
const logo = screen.getByRole('img', { name: `${props.data.provider} logo` });
const bannerImg = screen.getByRole('img', { name: /bannerAlt/i });
expect(logo).toBeInTheDocument();
expect(bannerImg).toBeInTheDocument();
});
it('title and subtitle', () => {
const title = screen.getByText(props.data.title);
const subtitle = screen.getByText(props.data.provider);
expect(title).toBeInTheDocument();
expect(subtitle).toBeInTheDocument();
});
it('badge', () => {
const badge = screen.getByText(props.data.programType);
expect(badge).toBeInTheDocument();
});
it('courses number', () => {
const coursesNumber = screen.getByText(`${props.data.numberOfCourses} Courses`);
expect(coursesNumber).toBeInTheDocument();
});
});
});