Skip to content

Commit

Permalink
fix: removing outdated prequery optimizely code (#1179)
Browse files Browse the repository at this point in the history
* fix: removing outdated prequery optimizely code

* fix: lint changes
  • Loading branch information
kiram15 authored Sep 16, 2024
1 parent 979c771 commit 22c26df
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 51 deletions.
3 changes: 0 additions & 3 deletions src/components/app/data/hooks/useEnterpriseFeatures.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const mockEnterpriseLearnerData = {
activeEnterpriseCustomer: null,
activeEnterpriseCustomerUserRoleAssignments: [],
allLinkedEnterpriseCustomerUsers: [],
enterpriseFeatures: {
featurePrequerySearchSuggestions: true,
},
staffEnterpriseCustomer: null,
};
const mockEnterpriseFeatures = mockEnterpriseLearnerData.enterpriseFeatures;
Expand Down
28 changes: 0 additions & 28 deletions src/components/search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ import SearchPathway from './SearchPathway';
import PathwayModal from '../pathway/PathwayModal';
import SearchAcademy from './SearchAcademy';
import AssignmentsOnlyEmptyState from './AssignmentsOnlyEmptyState';
import { EVENTS, isExperimentVariant, pushEvent } from '../../utils/optimizely';
import {
useCanOnlyViewHighlights,
useDefaultSearchFilters,
useEnterpriseCustomer,
useEnterpriseFeatures,
useEnterpriseOffers,
useIsAssignmentsOnlyLearner,
useSubscriptions,
Expand All @@ -35,14 +33,6 @@ import SearchVideo from './SearchVideo';
import { hasActivatedAndCurrentSubscription } from './utils';
import VideoBanner from '../microlearning/VideoBanner';

export const sendPushEvent = (isPreQueryEnabled, courseKeyMetadata) => {
if (isPreQueryEnabled) {
pushEvent(EVENTS.PREQUERY_SUGGESTION_CLICK, { courseKeyMetadata });
} else {
pushEvent(EVENTS.SEARCH_SUGGESTION_CLICK, { courseKeyMetadata });
}
};

function useSearchPathwayModal() {
const [isLearnerPathwayModalOpen, openLearnerPathwayModal, close] = useToggle(false);
const { pathwayUUID } = useParams();
Expand All @@ -63,7 +53,6 @@ function useSearchPathwayModal() {
const Search = () => {
const config = getConfig();
const { data: enterpriseCustomer } = useEnterpriseCustomer();
const { data: enterpriseFeatures } = useEnterpriseFeatures();
const intl = useIntl();
const navigate = useNavigate();

Expand All @@ -89,11 +78,6 @@ const Search = () => {
closePathwayModal,
} = useSearchPathwayModal();

const isExperimentVariation = isExperimentVariant(
config.PREQUERY_SEARCH_EXPERIMENT_ID,
config.PREQUERY_SEARCH_EXPERIMENT_VARIANT_ID,
);

const { data: { subscriptionLicense } } = useSubscriptions();
const enableVideos = (
canOnlyViewHighlightSets === false
Expand Down Expand Up @@ -127,16 +111,6 @@ const Search = () => {
const { content_type: contentType } = refinements;
const hasRefinements = Object.keys(refinements).filter(refinement => refinement !== 'showAll').length > 0 && (contentType !== undefined ? contentType.length > 0 : true);

const isPreQueryEnabled = enterpriseFeatures?.featurePrequerySearchSuggestions
&& isExperimentVariation;

const optimizelySuggestionClickHandler = (courseKey) => {
// Programs pass in a list of keys. Optimizely does not accept array values
// so we are joining the items in the array.
const courseKeyMetadata = Array.isArray(courseKey) ? courseKey.join(', ') : courseKey;
sendPushEvent(isPreQueryEnabled, courseKeyMetadata);
};

return (
<>
<Helmet title={PAGE_TITLE} />
Expand All @@ -160,8 +134,6 @@ const Search = () => {
index={searchIndex}
filters={filters}
enterpriseConfig={enterpriseCustomer}
optimizelySuggestionClickHandler={optimizelySuggestionClickHandler}
isPreQueryEnabled={isPreQueryEnabled}
/>
</div>
)}
Expand Down
4 changes: 1 addition & 3 deletions src/components/search/tests/Search.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '../../skills-quiz/__mocks__/react-instantsearch-dom';
import { queryClient, renderWithRouter } from '../../../utils/tests';
import '@testing-library/jest-dom';
import Search from '../Search';
import { useDefaultSearchFilters, useEnterpriseFeatures, useEnterpriseCustomer } from '../../app/data';
import { useDefaultSearchFilters, useEnterpriseCustomer } from '../../app/data';
import { useAlgoliaSearch } from '../../../utils/hooks';
import { enterpriseCustomerFactory } from '../../app/data/services/data/__factories__';
import { features } from '../../../config';
Expand All @@ -31,7 +31,6 @@ jest.mock('../../app/data', () => ({
useContentHighlightsConfiguration: jest.fn(() => ({ data: {} })),
useCanOnlyViewHighlights: jest.fn(() => ({ data: false })),
useIsAssignmentsOnlyLearner: jest.fn().mockReturnValue(false),
useEnterpriseFeatures: jest.fn(),
useDefaultSearchFilters: jest.fn(),
}));
jest.mock('../../../utils/hooks', () => ({
Expand Down Expand Up @@ -76,7 +75,6 @@ describe('<Search />', () => {
beforeEach(() => {
jest.clearAllMocks();
useEnterpriseCustomer.mockReturnValue({ data: mockEnterpriseCustomer });
useEnterpriseFeatures.mockReturnValue({ data: { featurePrequerySearchSuggestions: false } });
useDefaultSearchFilters.mockReturnValue(mockFilter);
useAlgoliaSearch.mockReturnValue([{ search: jest.fn(), appId: 'test-app-id' }, { indexName: 'mock-index-name' }]);
});
Expand Down
16 changes: 2 additions & 14 deletions src/components/search/tests/SearchSections.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import { queryClient, renderWithRouter } from '../../../utils/tests';
import '@testing-library/jest-dom';
import SearchProgram from '../SearchProgram';
import SearchPathway from '../SearchPathway';
import Search, { sendPushEvent } from '../Search';
import { EVENTS, pushEvent } from '../../../utils/optimizely';
import { useDefaultSearchFilters, useEnterpriseFeatures, useEnterpriseCustomer } from '../../app/data';
import Search from '../Search';
import { useDefaultSearchFilters, useEnterpriseCustomer } from '../../app/data';
import { useAlgoliaSearch } from '../../../utils/hooks';
import { enterpriseCustomerFactory } from '../../app/data/services/data/__factories__';
import SearchVideo from '../SearchVideo';
Expand Down Expand Up @@ -86,7 +85,6 @@ describe('<Search />', () => {
beforeEach(() => {
jest.clearAllMocks();
useEnterpriseCustomer.mockReturnValue({ data: mockEnterpriseCustomer });
useEnterpriseFeatures.mockReturnValue({ data: { featurePrequerySearchSuggestions: false } });
useDefaultSearchFilters.mockReturnValue(mockFilter);
useAlgoliaSearch.mockReturnValue([{ search: jest.fn(), appId: 'test-app-id' }, { indexName: 'mock-index-name' }]);
});
Expand Down Expand Up @@ -163,14 +161,4 @@ describe('<Search />', () => {
);
expect(screen.getByText('Pathways (2 results)')).toBeInTheDocument();
});

describe('pushEvent', () => {
test.each([
[true, 'test-course-101', EVENTS.PREQUERY_SUGGESTION_CLICK],
[false, 'test-course-102', EVENTS.SEARCH_SUGGESTION_CLICK],
])('if isPrequeryEnabled is %p with course metadata %p, submit event %p', (isPrequeryEnabled, courseKeyMetadata, event) => {
sendPushEvent(isPrequeryEnabled, courseKeyMetadata);
expect(pushEvent).toHaveBeenCalledWith(event, { courseKeyMetadata });
});
});
});
2 changes: 0 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ initialize({
ENTERPRISE_SUBSIDY_BASE_URL: process.env.ENTERPRISE_SUBSIDY_BASE_URL || null,
EXPERIMENT_2_ID: process.env.EXPERIMENT_2_ID || null,
EXPERIMENT_2_VARIANT_2_ID: process.env.EXPERIMENT_2_VARIANT_2_ID || null,
PREQUERY_SEARCH_EXPERIMENT_ID: process.env.PREQUERY_SEARCH_EXPERIMENT_ID || null,
PREQUERY_SEARCH_EXPERIMENT_VARIANT_ID: process.env.PREQUERY_SEARCH_EXPERIMENT_VARIANT_ID || null,
});
},
},
Expand Down
1 change: 0 additions & 1 deletion src/utils/optimizely.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export const EVENTS = {
ENROLLMENT_CLICK: 'enterprise_learner_portal_enrollment_click',
FIRST_ENROLLMENT_CLICK: 'enterprise_learner_portal_first_enrollment_click',
PREQUERY_SUGGESTION_CLICK: 'enterprise_learner_portal_prequery_suggestions_click',
SEARCH_SUGGESTION_CLICK: 'enterprise_learner_portal_search_suggestions_click',
};

Expand Down

0 comments on commit 22c26df

Please sign in to comment.