Skip to content

Commit

Permalink
feat: remove unused gpt 4 experiment code (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto authored Oct 15, 2024
1 parent c4bed2e commit b89d9ec
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 81 deletions.
10 changes: 3 additions & 7 deletions src/components/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
import { Close } from '@openedx/paragon/icons';

import { clearMessages } from '../../data/thunks';
import { OPTIMIZELY_PROMPT_EXPERIMENT_KEY, OPTIMIZELY_PROMPT_EXPERIMENT_VARIATION_KEYS } from '../../data/optimizely';
import { showControlSurvey, showVariationSurvey } from '../../utils/surveyMonkey';
import { OPTIMIZELY_PROMPT_EXPERIMENT_KEY } from '../../data/optimizely';
import showSurvey from '../../utils/surveyMonkey';

import APIError from '../APIError';
import ChatBox from '../ChatBox';
Expand Down Expand Up @@ -79,11 +79,7 @@ const Sidebar = ({
setIsOpen(false);

if (messageList.length >= 2) {
if (enabledExperiment && variationKey === OPTIMIZELY_PROMPT_EXPERIMENT_VARIATION_KEYS.UPDATED_PROMPT) {
showVariationSurvey();
} else {
showControlSurvey();
}
showSurvey();
}
};

Expand Down
28 changes: 4 additions & 24 deletions src/components/Sidebar/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import { usePromptExperimentDecision } from '../../experiments';
import { render as renderComponent } from '../../utils/utils.test';
import { initialState } from '../../data/slice';
import { OPTIMIZELY_PROMPT_EXPERIMENT_KEY, OPTIMIZELY_PROMPT_EXPERIMENT_VARIATION_KEYS } from '../../data/optimizely';
import { showControlSurvey, showVariationSurvey } from '../../utils/surveyMonkey';
import showSurvey from '../../utils/surveyMonkey';

import Sidebar from '.';

jest.mock('../../utils/surveyMonkey', () => ({
showControlSurvey: jest.fn(),
showVariationSurvey: jest.fn(),
}));
jest.mock('../../utils/surveyMonkey', () => jest.fn());

jest.mock('@edx/frontend-platform/analytics', () => ({
sendTrackEvent: jest.fn(),
Expand Down Expand Up @@ -124,23 +121,7 @@ describe('<Sidebar />', () => {
}],
};

it('should call showVariationSurvey if experiment is enabled', () => {
usePromptExperimentDecision.mockReturnValue([{
enabled: true,
variationKey: OPTIMIZELY_PROMPT_EXPERIMENT_VARIATION_KEYS.UPDATED_PROMPT,
}]);

render(undefined, defaultState);

act(() => {
screen.queryByTestId('close-button').click();
});

expect(showVariationSurvey).toHaveBeenCalled();
expect(showControlSurvey).not.toHaveBeenCalled();
});

it('should call showControlSurvey if experiment disabled', () => {
it('should call showSurvey', () => {
render(undefined, {
...defaultState,
experiments: {},
Expand All @@ -150,8 +131,7 @@ describe('<Sidebar />', () => {
screen.queryByTestId('close-button').click();
});

expect(showControlSurvey).toHaveBeenCalled();
expect(showVariationSurvey).not.toHaveBeenCalled();
expect(showSurvey).toHaveBeenCalled();
});

it('should dispatch clearMessages() and call sendTrackEvent() with the expected props on clear', () => {
Expand Down
11 changes: 2 additions & 9 deletions src/utils/surveyMonkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@
// This function contains the script provided by SuveryMonkey,
// which is used to embed the survey in the html upon this function
// being called after a learner closes the chat window for the control group.
const showControlSurvey = () => {
const showSurvey = () => {
(function (t, e, s, o) { let n; let c; let l; t.SMCX = t.SMCX || [], e.getElementById(o) || (n = e.getElementsByTagName(s), c = n[n.length - 1], l = e.createElement(s), l.type = 'text/javascript', l.async = !0, l.id = o, l.src = 'https://widget.surveymonkey.com/collect/website/js/tRaiETqnLgj758hTBazgd30kMLlLtc4okiu60NJiBPZxbfwe_2FCDOk5JO3Imfyeqk.js', c.parentNode.insertBefore(l, c)); }(window, document, 'script', 'smcx-sdk'));
};

const showVariationSurvey = () => {
(function (t, e, s, o) { let n; let c; let l; t.SMCX = t.SMCX || [], e.getElementById(o) || (n = e.getElementsByTagName(s), c = n[n.length - 1], l = e.createElement(s), l.type = 'text/javascript', l.async = !0, l.id = o, l.src = 'https://widget.surveymonkey.com/collect/website/js/tRaiETqnLgj758hTBazgd3i4lLmPCzca7_2BgAvTEbjU2dNWmi5l435XUxCEkddDIn.js', c.parentNode.insertBefore(l, c)); }(window, document, 'script', 'smcx-sdk'));
};

export {
showControlSurvey,
showVariationSurvey,
};
export default showSurvey;
44 changes: 3 additions & 41 deletions src/widgets/Xpert.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Xpert from './Xpert';

import * as surveyMonkey from '../utils/surveyMonkey';
import { render, createRandomResponseForTesting } from '../utils/utils.test';
import { OPTIMIZELY_PROMPT_EXPERIMENT_VARIATION_KEYS } from '../data/optimizely';
import { usePromptExperimentDecision } from '../experiments';

jest.mock('@edx/frontend-platform/analytics');
Expand Down Expand Up @@ -372,7 +371,7 @@ test('popup modal should close and display CTA', async () => {
expect(screen.queryByTestId('action-message')).toBeVisible();
});
test('survey monkey survey should appear after closing sidebar', async () => {
const controlSurvey = jest.spyOn(surveyMonkey, 'showControlSurvey').mockReturnValueOnce(1);
const survey = jest.spyOn(surveyMonkey, 'default').mockReturnValueOnce(1);
const user = userEvent.setup();

const surveyState = {
Expand All @@ -399,43 +398,6 @@ test('survey monkey survey should appear after closing sidebar', async () => {
await user.click(screen.queryByTestId('close-button'));

// assert mock called
expect(controlSurvey).toBeCalledTimes(1);
controlSurvey.mockRestore();
});

test('survey monkey variation survey should appear if user is in experiment', async () => {
const variationSurvey = jest.spyOn(surveyMonkey, 'showVariationSurvey').mockReturnValueOnce(1);
const user = userEvent.setup();

usePromptExperimentDecision.mockReturnValue([{
enabled: true,
variationKey: OPTIMIZELY_PROMPT_EXPERIMENT_VARIATION_KEYS.UPDATED_PROMPT,
}]);

const surveyState = {
learningAssistant: {
currentMessage: '',
messageList: [
{ role: 'user', content: 'hi', timestamp: new Date() },
{ role: 'user', content: 'hi', timestamp: new Date() + 1 },
],
apiIsLoading: false,
apiError: false,
disclosureAcknowledged: true,
sidebarIsOpen: false,
},
};
render(<Xpert courseId={courseId} contentToolsEnabled={false} unitId={unitId} />, { preloadedState: surveyState });

// wait for button to appear
await screen.findByTestId('toggle-button');

await user.click(screen.queryByTestId('toggle-button'));

// click close
await user.click(screen.queryByTestId('close-button'));

// assert mock called
expect(variationSurvey).toBeCalledTimes(1);
variationSurvey.mockRestore();
expect(survey).toBeCalledTimes(1);
survey.mockRestore();
});

0 comments on commit b89d9ec

Please sign in to comment.