Skip to content

Commit

Permalink
Merge branch 'master' into feat/react-query-route-loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz committed Mar 6, 2024
2 parents bc2a7a0 + 471e5cd commit dd6e06e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 31 deletions.
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"dependencies": {
"@edx/brand": "npm:@openedx/[email protected]",
"@edx/frontend-component-footer": "13.0.2",
"@edx/frontend-enterprise-catalog-search": "7.0.0",
"@edx/frontend-enterprise-hotjar": "4.0.0",
"@edx/frontend-enterprise-logistration": "6.0.0",
"@edx/frontend-enterprise-utils": "6.0.0",
"@edx/frontend-enterprise-catalog-search": "8.0.0",
"@edx/frontend-enterprise-hotjar": "5.0.0",
"@edx/frontend-enterprise-logistration": "7.0.0",
"@edx/frontend-enterprise-utils": "7.0.0",
"@edx/frontend-platform": "7.1.0",
"@loadable/component": "5.16.3",
"@lukemorales/query-key-factory": "1.3.4",
Expand Down
5 changes: 3 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
<link rel="dns-prefetch" href="<%= preconnectURL %>" />
<% }); %>

<% if (htmlWebpackPlugin.options.NODE_ENV === 'production' && htmlWebpackPlugin.options.OPTIMIZELY_PROJECT_ID) { %>
<% if (htmlWebpackPlugin.options.NODE_ENV==='production' && htmlWebpackPlugin.options.OPTIMIZELY_PROJECT_ID &&
htmlWebpackPlugin.options.DEPLOYMENT_ENV==='production') { %>
<script src="https://www.edx.org/optimizelyjs/<%= htmlWebpackPlugin.options.OPTIMIZELY_PROJECT_ID %>.js"></script>
<% } %>

<% if (htmlWebpackPlugin.options.NODE_ENV !== 'production' && htmlWebpackPlugin.options.OPTIMIZELY_PROJECT_ID) { %>
<% if (htmlWebpackPlugin.options.OPTIMIZELY_PROJECT_ID) { %>
<script src="https://cdn.optimizely.com/js/<%= htmlWebpackPlugin.options.OPTIMIZELY_PROJECT_ID %>.js"></script>
<% } %>
</head>
Expand Down
26 changes: 20 additions & 6 deletions src/components/search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ import AssignmentsOnlyEmptyState from './AssignmentsOnlyEmptyState';
import { EVENTS, isExperimentVariant, pushEvent } from '../../utils/optimizely';
import { useIsAssignmentsOnlyLearner } from '../app/data';

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

const Search = () => {
const config = getConfig();
const { pathwayUUID } = useParams();
Expand Down Expand Up @@ -130,12 +138,17 @@ const Search = () => {
const shouldDisplayBalanceAlert = hasNoEnterpriseOffersBalance || hasLowEnterpriseOffersBalance;

const { content_type: contentType } = refinements;
const hasRefinements = Object.keys(refinements).filter(refinement => refinement !== 'showAll').length > 0 && (contentType !== undefined ? contentType.length > 0 : true);
const hasRefinements = Object.keys(refinements).filter(refinement => refinement !== 'showAll').length > 0
&& (contentType !== undefined ? contentType.length > 0 : true);

const optimizelyPrequerySuggestionClickHandler = (courseKey) => {
if (isExperimentVariation) {
pushEvent(EVENTS.PREQUERY_SUGGESTION_CLICK, { courseKey });
}
const isPreQueryEnabled = enterpriseConfig.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 (
Expand All @@ -161,7 +174,8 @@ const Search = () => {
index={courseIndex}
filters={filters}
enterpriseConfig={enterpriseConfig}
optimizelyPrequerySuggestionClickHandler={optimizelyPrequerySuggestionClickHandler}
optimizelySuggestionClickHandler={optimizelySuggestionClickHandler}
isPreQueryEnabled={isPreQueryEnabled}
/>
</div>
)}
Expand Down
21 changes: 20 additions & 1 deletion src/components/search/tests/SearchSections.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { renderWithRouter } from '../../../utils/tests';
import '@testing-library/jest-dom';
import SearchProgram from '../SearchProgram';
import SearchPathway from '../SearchPathway';
import Search from '../Search';
import Search, { sendPushEvent } from '../Search';
import { UserSubsidyContext } from '../../enterprise-user-subsidy';
import { SUBSIDY_TYPE, SubsidyRequestsContext } from '../../enterprise-subsidy-requests';
import { EVENTS, pushEvent } from '../../../utils/optimizely';

const APP_CONFIG = {
ALGOLIA_INDEX_NAME: 'test-index-name',
Expand All @@ -27,6 +28,11 @@ jest.mock('@edx/frontend-platform/config', () => ({
getConfig: jest.fn(() => APP_CONFIG),
}));

jest.mock('../../../utils/optimizely', () => ({
...jest.requireActual('../../../utils/optimizely'),
pushEvent: jest.fn(),
}));

const searchContext1 = {
refinements: { showAll: 1, content_type: ['course'] },
dispatch: () => null,
Expand All @@ -45,6 +51,9 @@ const initialAppState = {
name: 'BearsRUs',
slug: 'test-enterprise-slug',
showIntegrationWarning: false,
enterpriseFeatures: {
featurePrequerySearchSuggestions: true,
},
},
authenticatedUser: { userId: 'test-user-id' },
algolia: {
Expand Down Expand Up @@ -166,4 +175,14 @@ 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 });
});
});
});
1 change: 1 addition & 0 deletions src/utils/optimizely.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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',
};

export const getActiveExperiments = () => {
Expand Down

0 comments on commit dd6e06e

Please sign in to comment.