Skip to content

Commit

Permalink
feat: add subtitle facet to SearchHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
Maham Akif authored and Maham Akif committed Mar 26, 2024
1 parent 83e8405 commit fc6d981
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/catalog-search/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const FEATURE_LANGUAGE_FACET = 'LANGUAGE_FACET';
export const FEATURE_PROGRAM_TITLES_FACET = 'PROGRAM_TITLES_FACET';
export const LEARNING_TYPE_FACET = 'LEARNING_TYPE_FACET';
export const FEATURE_ENABLE_PATHWAYS = 'ENABLE_PATHWAYS';
export const FEATURE_SUBTITLE_FACET = 'SUBTITLE_FACET';

// eslint-disable-next-line import/prefer-default-export
export const features = {
Expand All @@ -19,4 +20,7 @@ export const features = {
ENABlE_PATHWAYS: (
process.env.FEATURE_ENABLE_PATHWAYS || hasFeatureFlagEnabled(FEATURE_ENABLE_PATHWAYS)
),
SUBTITLE_FACET: (
process.env.FEATURE_SUBTITLE_FACET || hasFeatureFlagEnabled(FEATURE_SUBTITLE_FACET)
),
};
8 changes: 8 additions & 0 deletions packages/catalog-search/src/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ if (features.LEARNING_TYPE_FACET) {
});
}

if (features.SUBTITLE_FACET) {
SEARCH_FACET_FILTERS.push({
attribute: 'transcript_languages',
title: 'Subtitle',
isSortedAlphabetical: true,
});
}

export const BOOLEAN_FILTERS = [SHOW_ALL_NAME];
export const QUERY_PARAM_FOR_SEARCH_QUERY = 'q';
export const QUERY_PARAM_FOR_PAGE = 'page';
Expand Down
53 changes: 53 additions & 0 deletions packages/catalog-search/src/data/tests/constants.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
SEARCH_FACET_FILTERS,
ADDITIONAL_FACET_FILTERS,
} from '../constants';

jest.mock('../../config', () => ({
__esModule: true,
features: {
ENROLL_WITH_CODES: true,
LANGUAGE_FACET: true,
PROGRAM_TITLES_FACET: true,
LEARNING_TYPE_FACET: true,
ENABLE_PATHWAYS: true,
SUBTITLE_FACET: true,
},
}));

describe('Constants', () => {
test('Search facet filters are defined correctly', () => {
expect(SEARCH_FACET_FILTERS).toHaveLength(9);
});

test('Additional facet filters are defined correctly', () => {
expect(Array.isArray(ADDITIONAL_FACET_FILTERS)).toBe(true);
});

test('Language facet filter is added when feature is enabled', () => {
const languageFacet = SEARCH_FACET_FILTERS.find(
(facet) => facet.attribute === 'language',
);
expect(languageFacet).toBeDefined();
expect(languageFacet.title).toBe('Language');
expect(languageFacet.isSortedAlphabetical).toBe(true);
});

test('Learning type facet filter is added when feature is enabled', () => {
const learningTypeFacet = SEARCH_FACET_FILTERS.find(
(facet) => facet.attribute === 'content_type',
);
expect(learningTypeFacet).toBeDefined();
expect(learningTypeFacet.title).toBe('Learning type');
expect(learningTypeFacet.noDisplay).toBe(true);
});

test('Subtitle facet filter is added when feature is enabled', () => {
const subtitleFacet = SEARCH_FACET_FILTERS.find(
(facet) => facet.attribute === 'transcript_languages',
);
expect(subtitleFacet).toBeDefined();
expect(subtitleFacet.title).toBe('Subtitle');
expect(subtitleFacet.isSortedAlphabetical).toBe(true);
});
});

0 comments on commit fc6d981

Please sign in to comment.