diff --git a/src/components/Sidebar/index.jsx b/src/components/Sidebar/index.jsx index 8f925154..70edc2b9 100644 --- a/src/components/Sidebar/index.jsx +++ b/src/components/Sidebar/index.jsx @@ -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'; @@ -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(); } }; diff --git a/src/components/Sidebar/index.test.jsx b/src/components/Sidebar/index.test.jsx index 1f02709c..9a57c70e 100644 --- a/src/components/Sidebar/index.test.jsx +++ b/src/components/Sidebar/index.test.jsx @@ -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(), @@ -124,23 +121,7 @@ describe('', () => { }], }; - 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: {}, @@ -150,8 +131,7 @@ describe('', () => { 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', () => { diff --git a/src/utils/surveyMonkey.js b/src/utils/surveyMonkey.js index f1b03b52..35f458ab 100644 --- a/src/utils/surveyMonkey.js +++ b/src/utils/surveyMonkey.js @@ -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; diff --git a/src/widgets/Xpert.test.jsx b/src/widgets/Xpert.test.jsx index 81721577..f1ecede5 100644 --- a/src/widgets/Xpert.test.jsx +++ b/src/widgets/Xpert.test.jsx @@ -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'); @@ -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 = { @@ -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(, { 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(); });