Skip to content

Commit

Permalink
chore: Update test for mapToStore enterpriseSlug
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Dec 14, 2022
1 parent edce596 commit d77cd5e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 43 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const ContentHighlightsCardItemsContainer = ({ enterpriseSlug, isLoading, highli
key={uuid}
cardImageUrl="https://picsum.photos/200/300"
title={title}
hyperlink={generateAboutPageUrl(enterpriseSlug, contentType.toLowerCase(), contentKey)}
contentType={contentType.toLowerCase()}
hyperlink={generateAboutPageUrl(enterpriseSlug, contentType?.toLowerCase(), contentKey)}
contentType={contentType?.toLowerCase()}
partners={authoringOrganizations}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ContentConfirmContentCard = ({ enterpriseSlug, original }) => {
<React.Fragment key={key}>
<ContentHighlightCardItem
title={title}
hyperlink={generateAboutPageUrl(enterpriseSlug, contentType.toLowerCase(), aggregationKey.split(':')[1])}
hyperlink={generateAboutPageUrl(enterpriseSlug, contentType?.toLowerCase(), aggregationKey?.split(':')[1])}
contentType={contentType}
partners={partners}
cardImageUrl={cardImageUrl || originalImageUrl}
Expand Down Expand Up @@ -72,7 +72,7 @@ ContentConfirmContentCard.propTypes = {
}).isRequired,
};

const mapStateToProps = state => ({
export const mapStateToProps = state => ({
enterpriseSlug: state.portalConfiguration.enterpriseSlug,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ContentSearchResultCard = ({ enterpriseSlug, original }) => {
return (
<ContentHighlightCardItem
title={title}
hyperlink={generateAboutPageUrl(enterpriseSlug, contentType.toLowerCase(), aggregationKey.split(':')[1])}
hyperlink={generateAboutPageUrl(enterpriseSlug, contentType?.toLowerCase(), aggregationKey?.split(':')[1])}
contentType={contentType}
partners={partners}
cardImageUrl={cardImageUrl || originalImageUrl}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ const BaseHighlightStepperSelectContentDataTable = ({
searchResults,
}) => {
const [currentView, setCurrentView] = useState(defaultActiveStateValue);

const tableData = useMemo(() => camelCaseObject(searchResults?.hits || []), [searchResults]);
const searchResultsItemCount = searchResults?.nbHits || 0;
const searchResultsPageCount = searchResults?.nbPages || 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import React, { useState } from 'react';
import { screen, render, fireEvent } from '@testing-library/react';
import { screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import algoliasearch from 'algoliasearch/lite';
import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';
import { renderWithRouter } from '@edx/frontend-enterprise-utils';
import ContentConfirmContentCard from '../ContentConfirmContentCard';
import { testCourseData, testCourseAggregation, FOOTER_TEXT_BY_CONTENT_TYPE } from '../../data/constants';
import { ContentHighlightsContext } from '../../ContentHighlightsContext';
import { configuration } from '../../../../config';

const mockStore = configureMockStore();
const initialState = {
portalConfiguration:
{
enterpriseSlug: 'test-enterprise',
},
};

const searchClient = algoliasearch(
configuration.ALGOLIA.APP_ID,
configuration.ALGOLIA.SEARCH_API_KEY,
);

const ContentHighlightContentCardWrapper = () => {
const ContentHighlightContentCardWrapper = ({
// eslint-disable-next-line react/prop-types
store = mockStore(initialState),
}) => {
const contextValue = useState({
stepperModal: {
isOpen: false,
Expand All @@ -24,15 +38,18 @@ const ContentHighlightContentCardWrapper = () => {
searchClient,
});
return (
<ContentHighlightsContext.Provider value={contextValue}>
{testCourseData.map((original) => <ContentConfirmContentCard original={original} />)}
</ContentHighlightsContext.Provider>
<Provider store={store}>
<ContentHighlightsContext.Provider value={contextValue}>
{testCourseData.map((original) => <ContentConfirmContentCard original={original} />)}
</ContentHighlightsContext.Provider>
</Provider>
);
};

describe('<ContentConfirmContentCard />', () => {
it('renders the correct content', () => {
render(<ContentHighlightContentCardWrapper />);
renderWithRouter(<ContentHighlightContentCardWrapper />);

for (let i = 0; i < testCourseData.length; i++) {
expect(screen.getByText(testCourseData[i].title)).toBeInTheDocument();
expect(screen.getByText(testCourseData[i].firstEnrollablePaidSeatPrice, { exact: false })).toBeInTheDocument();
Expand All @@ -42,7 +59,8 @@ describe('<ContentConfirmContentCard />', () => {
}
});
it('deletes the correct content', () => {
render(<ContentHighlightContentCardWrapper />);
renderWithRouter(<ContentHighlightContentCardWrapper />);

const deleteButton = screen.getAllByRole('button', { 'aria-label': 'Delete' });
fireEvent.click(deleteButton[0]);
for (let i = 0; i < testCourseData.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const mockStore = configureMockStore([thunk]);
const initialState = {
portalConfiguration: {
enterpriseSlug: 'test-enterprise',
enterpriseId: 'test-enterprise-id',
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ import { screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import algoliasearch from 'algoliasearch/lite';
import { renderWithRouter } from '@edx/frontend-enterprise-utils';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { Provider } from 'react-redux';
import HighlightStepperConfirmContent, { BaseReviewContentSelections, SelectedContent } from '../HighlightStepperConfirmContent';
import {
testCourseAggregation,
} from '../../data/constants';
import { ContentHighlightsContext } from '../../ContentHighlightsContext';
import { configuration } from '../../../../config';

const mockStore = configureMockStore([thunk]);
const initialState = {
portalConfiguration:
{
enterpriseSlug: 'test-enterprise',
},
};

const searchClient = algoliasearch(
configuration.ALGOLIA.APP_ID,
configuration.ALGOLIA.SEARCH_API_KEY,
Expand All @@ -29,9 +40,11 @@ const HighlightStepperConfirmContentWrapper = ({ children, currentSelectedRowIds
searchClient,
});
return (
<ContentHighlightsContext.Provider value={contextValue}>
{children}
</ContentHighlightsContext.Provider>
<Provider store={mockStore(initialState)}>
<ContentHighlightsContext.Provider value={contextValue}>
{children}
</ContentHighlightsContext.Provider>
</Provider>
);
};

Expand Down

0 comments on commit d77cd5e

Please sign in to comment.