Skip to content

Commit

Permalink
feat: persist cta dismissal and change survey trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto committed Oct 20, 2023
1 parent 5e2c482 commit a1b6291
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ const Sidebar = ({
const handleClick = () => {
setIsOpen(false);

// check to see if hotjar is available, then trigger hotjar event
// check to see if hotjar is available, then trigger hotjar event if user has sent and received a message
const hasWindow = typeof window !== 'undefined';
if (hasWindow && window.hj) {
if (hasWindow && window.hj && messageList.length >= 2) {
window.hj('event', 'ocm_learning_assistant_chat_closed');
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/components/ToggleXpertButton/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const ToggleXpert = ({
event.preventDefault();
event.stopPropagation();
setHasDismissed(true);
localStorage.setItem('dismissedLearningAssistantCallToAction', 'true');
sendTrackEvent('edx.ui.lms.learning_assistant.dismiss_action_message', {
course_id: courseId,
});
Expand Down Expand Up @@ -94,7 +95,7 @@ const ToggleXpert = ({
${contentToolsEnabled ? 'chat-content-tools-margin' : ''}`
}
>
{!hasDismissed && (
{(!localStorage.getItem('dismissedLearningAssistantCallToAction') && !hasDismissed) && (
<div
className="d-flex justify-content-end flex-row "
data-testid="action-message"
Expand Down
5 changes: 5 additions & 0 deletions src/widgets/Xpert.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const assertSidebarElementsNotInDOM = () => {
beforeEach(() => {
const responseMessage = createRandomResponseForTesting();
jest.spyOn(api, 'default').mockResolvedValue(responseMessage);
window.localStorage.clear();
});

test('initial load displays correct elements', () => {
Expand All @@ -62,6 +63,10 @@ test('clicking the call to action dismiss button removes the message', async ()
await user.click(screen.getByRole('button', { name: 'dismiss' }));
expect(screen.queryByTestId('toggle-button')).toBeVisible();
expect(screen.queryByTestId('action-message')).not.toBeInTheDocument();

// re-render exam, button to dismiss cta should not be there
render(<Xpert courseId={courseId} contentToolsEnabled={false} />, { preloadedState: initialState });
expect(screen.queryByRole('button', { name: 'dismiss' })).not.toBeInTheDocument();
});
test('clicking the call to action opens the sidebar', async () => {
const user = userEvent.setup();
Expand Down

0 comments on commit a1b6291

Please sign in to comment.