Skip to content

Commit

Permalink
fix: remove pathways from customers search (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiram15 authored Jan 2, 2024
1 parent 8129aae commit d4625c9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
15 changes: 13 additions & 2 deletions packages/catalog-search/src/LearningTypeRadioFacet.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { Dropdown, Input } from '@edx/paragon';
import { SearchContext } from './SearchContext';
Expand All @@ -8,7 +9,7 @@ import {
import { features } from './config';
import { LEARNING_TYPE_COURSE, LEARNING_TYPE_PROGRAM, LEARNING_TYPE_PATHWAY } from './data/constants';

const LearningTypeRadioFacet = () => {
const LearningTypeRadioFacet = ({ enablePathways }) => {
const { refinements, dispatch } = useContext(SearchContext);
// only bold the dropdown title if the learning type is Course or Program
const typeCourseSelected = refinements.content_type && refinements.content_type.includes(LEARNING_TYPE_COURSE);
Expand Down Expand Up @@ -72,7 +73,9 @@ const LearningTypeRadioFacet = () => {
</span>
</Dropdown.Item>
{
features.ENABlE_PATHWAYS && (
// the first check is a global feature flag and the second is a check to see if
// the individual customer itself has enabled pathways
features.ENABlE_PATHWAYS && enablePathways && (
<Dropdown.Item as="label" className="mb-0 py-3 d-flex align-items-center">
<Input
type="radio"
Expand All @@ -93,4 +96,12 @@ const LearningTypeRadioFacet = () => {
);
};

LearningTypeRadioFacet.defaultProps = {
enablePathways: null,
};

LearningTypeRadioFacet.propTypes = {
enablePathways: PropTypes.bool,
};

export default LearningTypeRadioFacet;
6 changes: 4 additions & 2 deletions packages/catalog-search/src/SearchFilters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import LearningTypeRadioFacet from './LearningTypeRadioFacet';

export const FREE_ALL_TITLE = 'Free / All';

const SearchFilters = ({ variant }) => {
const SearchFilters = ({ variant, enablePathways }) => {
const { refinements, searchFacetFilters } = useContext(SearchContext);

const searchFacets = useMemo(
Expand Down Expand Up @@ -48,7 +48,7 @@ const SearchFilters = ({ variant }) => {
return (
<>
{filtersFromRefinements}
{features.LEARNING_TYPE_FACET && (<LearningTypeRadioFacet />)}
{features.LEARNING_TYPE_FACET && (<LearningTypeRadioFacet enablePathways={enablePathways} />)}
</>
);
},
Expand Down Expand Up @@ -76,10 +76,12 @@ const SearchFilters = ({ variant }) => {

SearchFilters.defaultProps = {
variant: STYLE_VARIANTS.inverse,
enablePathways: null,
};

SearchFilters.propTypes = {
variant: PropTypes.oneOf([STYLE_VARIANTS.default, STYLE_VARIANTS.inverse]),
enablePathways: PropTypes.bool,
};

export default SearchFilters;
10 changes: 6 additions & 4 deletions packages/catalog-search/src/SearchHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const SearchHeader = ({
index,
filters,
suggestionSubmitOverride,
enterpriseConfig: { slug },
enterpriseConfig: { slug, enablePathways },
disableSuggestionRedirect,
}) => {
const { refinements } = useContext(SearchContext);
Expand Down Expand Up @@ -64,7 +64,7 @@ const SearchHeader = ({
className={classNames('fe__searchbox-col', { 'fe__searchbox-col--default': variant === STYLE_VARIANTS.default })}
xs={12}
>
<SearchFilters className="mb-3" variant={variant} />
<SearchFilters className="mb-3" variant={variant} enablePathways={enablePathways} />
</Col>
</Row>
</Container>
Expand All @@ -78,7 +78,7 @@ SearchHeader.defaultProps = {
headerTitle: undefined,
hideTitle: false,
filters: '',
enterpriseConfig: { slug: undefined },
enterpriseConfig: { slug: undefined, enablePathways: undefined },
suggestionSubmitOverride: undefined,
disableSuggestionRedirect: false,
index: undefined,
Expand All @@ -91,7 +91,9 @@ SearchHeader.propTypes = {
hideTitle: PropTypes.bool,
index: PropTypes.shape({ search: PropTypes.func.isRequired }),
filters: PropTypes.string,
enterpriseConfig: PropTypes.shape({ slug: PropTypes.string }),
enterpriseConfig: PropTypes.shape(
{ slug: PropTypes.string, enablePathways: PropTypes.bool },
),
suggestionSubmitOverride: PropTypes.func,
disableSuggestionRedirect: PropTypes.bool,
};
Expand Down
24 changes: 18 additions & 6 deletions packages/catalog-search/src/tests/LearningTypeRadioFacet.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ describe('<LearningTypeRadioFacet />', () => {
});

test('LearningTypeRadioFacet is rendered and isnt bold initially', () => {
renderWithSearchContext(<LearningTypeRadioFacet />);
renderWithSearchContext(<LearningTypeRadioFacet enablePathways />);
expect(screen.getByText('Learning Type')).toBeInTheDocument();
expect(screen.getByText('Learning Type').classList.contains('font-weight-bold')).toBeFalsy();
});

test('LearningTypeRadioFacet displays all the options', async () => {
renderWithSearchContext(<LearningTypeRadioFacet />);
renderWithSearchContext(<LearningTypeRadioFacet enablePathways />);
expect(screen.getByText('Learning Type')).toBeInTheDocument();
fireEvent.click(screen.getByText('Learning Type'));
await waitFor(() => {
Expand All @@ -39,8 +39,20 @@ describe('<LearningTypeRadioFacet />', () => {
});
});

test('LearningTypeRadioFacet doesnt display pathways if false', async () => {
renderWithSearchContext(<LearningTypeRadioFacet enablePathways={false} />);
expect(screen.getByText('Learning Type')).toBeInTheDocument();
fireEvent.click(screen.getByText('Learning Type'));
await waitFor(() => {
expect(screen.getByText('Any')).toBeInTheDocument();
expect(screen.getByText('Courses')).toBeInTheDocument();
expect(screen.getByText('Programs')).toBeInTheDocument();
expect(screen.queryByText('Pathways')).not.toBeInTheDocument();
});
});

test('LearningTypeRadioFacet isnt bold when content type Any is selected', async () => {
renderWithSearchContext(<LearningTypeRadioFacet />);
renderWithSearchContext(<LearningTypeRadioFacet enablePathways />);
expect(screen.getByText('Learning Type')).toBeInTheDocument();
fireEvent.click(screen.getByText('Learning Type'));
await waitFor(() => {
Expand All @@ -50,7 +62,7 @@ describe('<LearningTypeRadioFacet />', () => {
});

test('LearningTypeRadioFacet is bold content type Courses is selected', async () => {
renderWithSearchContext(<LearningTypeRadioFacet />);
renderWithSearchContext(<LearningTypeRadioFacet enablePathways />);
expect(screen.getByText('Learning Type')).toBeInTheDocument();
fireEvent.click(screen.getByText('Learning Type'));
fireEvent.click(screen.getByTestId('learning-type-courses'));
Expand All @@ -61,7 +73,7 @@ describe('<LearningTypeRadioFacet />', () => {
});

test('LearningTypeRadioFacet is bold content type Courses is selected', async () => {
renderWithSearchContext(<LearningTypeRadioFacet />);
renderWithSearchContext(<LearningTypeRadioFacet enablePathways />);
expect(screen.getByText('Learning Type')).toBeInTheDocument();
fireEvent.click(screen.getByText('Learning Type'));
fireEvent.click(screen.getByTestId('learning-type-programs'));
Expand All @@ -72,7 +84,7 @@ describe('<LearningTypeRadioFacet />', () => {
});

test('LearningTypeRadioFacet is bold content type Courses is selected', async () => {
renderWithSearchContext(<LearningTypeRadioFacet />);
renderWithSearchContext(<LearningTypeRadioFacet enablePathways />);
expect(screen.getByText('Learning Type')).toBeInTheDocument();
fireEvent.click(screen.getByText('Learning Type'));
fireEvent.click(screen.getByTestId('learning-type-pathways'));
Expand Down

0 comments on commit d4625c9

Please sign in to comment.