From fc6d98172aefd1b913c8a1e201248023691bddf0 Mon Sep 17 00:00:00 2001 From: Maham Akif Date: Mon, 25 Mar 2024 17:01:31 +0500 Subject: [PATCH] feat: add subtitle facet to SearchHeader --- packages/catalog-search/src/config/index.js | 4 ++ packages/catalog-search/src/data/constants.js | 8 +++ .../src/data/tests/constants.test.js | 53 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 packages/catalog-search/src/data/tests/constants.test.js diff --git a/packages/catalog-search/src/config/index.js b/packages/catalog-search/src/config/index.js index 9b7b3148..59c18ce1 100644 --- a/packages/catalog-search/src/config/index.js +++ b/packages/catalog-search/src/config/index.js @@ -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 = { @@ -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) + ), }; diff --git a/packages/catalog-search/src/data/constants.js b/packages/catalog-search/src/data/constants.js index bf11b32b..22917b84 100644 --- a/packages/catalog-search/src/data/constants.js +++ b/packages/catalog-search/src/data/constants.js @@ -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'; diff --git a/packages/catalog-search/src/data/tests/constants.test.js b/packages/catalog-search/src/data/tests/constants.test.js new file mode 100644 index 00000000..0cdffe58 --- /dev/null +++ b/packages/catalog-search/src/data/tests/constants.test.js @@ -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); + }); +});