fix: render logic for open courses and test coverage fix

This commit is contained in:
Jody Bailey
2023-06-06 16:56:13 +02:00
parent 55a647bb5b
commit f4c27f02ba
5 changed files with 31 additions and 15 deletions

View File

@@ -24,7 +24,7 @@ export const Dashboard = () => {
const showSelectSessionModal = reduxHooks.useShowSelectSessionModal();
// Hard coded to not show until experiment set-up logic is implemented
const showProductRecommendations = !initIsPending && !hasAvailableDashboards && hasCourses && true;
const showProductRecommendations = false && !initIsPending && !hasAvailableDashboards && hasCourses;
return (
<div id="dashboard-container" className="d-flex flex-column p-2 pt-0">

View File

@@ -7,19 +7,16 @@ import messages from '../messages';
import { courseShape, courseTypeToProductTypeMap } from '../utils';
import ProductCardContainer from './ProductCardContainer';
const MAX_OPEN_COURSE_RECOMMENDATIONS = 4;
const MIN_OPEN_COURSE_RECOMMENDATIONS = 2;
const LoadedView = ({ crossProductCourses, openCourses }) => {
const { formatMessage } = useIntl();
const includesCrossProductTypes = crossProductCourses.length === 2;
const finalProductList = useMemo(() => {
if (includesCrossProductTypes) {
const openCourseList = openCourses ? openCourses.slice(0, MIN_OPEN_COURSE_RECOMMENDATIONS) : [];
const openCourseList = openCourses ? openCourses.slice(0, 2) : [];
return crossProductCourses.concat(openCourseList);
}
return openCourses.slice(0, MAX_OPEN_COURSE_RECOMMENDATIONS);
return openCourses;
}, [crossProductCourses, openCourses, includesCrossProductTypes]);
const courseTypes = [...new Set(finalProductList.map((item) => courseTypeToProductTypeMap[item.courseType]))];

View File

@@ -15,4 +15,20 @@ describe('ProductRecommendations LoadedView', () => {
),
).toMatchSnapshot();
});
describe('with less than 2 cross product courses', () => {
it('passes in one course type and 4 open courses to the ProductCardContainer props', () => {
const wrapper = shallow(
<LoadedView
crossProductCourses={[mockCrossProductCourses[0]]}
openCourses={mockOpenCourses}
/>,
);
const productCardContainerProps = wrapper.find('ProductCardContainer').props();
expect(productCardContainerProps.courseTypes.length).toEqual(1);
expect(productCardContainerProps.courseTypes[0]).toEqual('Course');
expect(productCardContainerProps.finalProductList).toEqual(mockOpenCourses);
});
});
});

View File

@@ -11,16 +11,19 @@ describe('ProductRecommendations ProductCardHeader', () => {
it('matches snapshot', () => {
expect(shallow(<ProductCardHeader courseType={executiveEducationType} />)).toMatchSnapshot();
});
describe('with bootcamp courseType prop', () => {
it('renders a bootcamp header', () => {
const wrapper = shallow(<ProductCardHeader courseType={bootCampType} />);
it('renders a bootcamp header if the bootcamp course type is passed as a prop', () => {
const wrapper = shallow(<ProductCardHeader courseType={bootCampType} />);
expect(wrapper.find('h3').text()).toEqual(bootCampType);
expect(wrapper.find('h3').text()).toEqual(bootCampType);
});
});
it('renders a courses header if the courses course type is passed as a prop', () => {
const wrapper = shallow(<ProductCardHeader courseType={courseType} />);
describe('with course courseType prop', () => {
it('renders a courses header', () => {
const wrapper = shallow(<ProductCardHeader courseType={courseType} />);
expect(wrapper.find('h3').text()).toEqual(courseType);
expect(wrapper.find('h3').text()).toEqual(courseType);
});
});
});

View File

@@ -88,7 +88,7 @@ describe('ProductRecommendations hooks', () => {
cb();
expect(api.fetchProductRecommendations).toHaveBeenCalledWith(mostRecentCourseRunKey);
expect(setRequestState).not.toHaveBeenCalled();
expect(setData).not.toHaveBeenCalledWith(response.data);
expect(setData).not.toHaveBeenCalled();
await resolveFn(response);
expect(setRequestState).toHaveBeenCalledWith(RequestStates.completed);
expect(setData).toHaveBeenCalledWith(response.data);
@@ -103,7 +103,7 @@ describe('ProductRecommendations hooks', () => {
const unMount = cb();
expect(api.fetchProductRecommendations).toHaveBeenCalledWith(mostRecentCourseRunKey);
expect(setRequestState).not.toHaveBeenCalled();
expect(setData).not.toHaveBeenCalledWith(response.data);
expect(setData).not.toHaveBeenCalled();
unMount();
await resolveFn(response);
expect(setRequestState).not.toHaveBeenCalled();