@@ -2,13 +2,15 @@ import React from 'react';
2
2
3
3
import { screen , waitFor } from '@testing-library/react' ;
4
4
import userEvent from '@testing-library/user-event' ;
5
+ import { useModel } from '@src/generic/model-store' ; // eslint-disable-line import/no-unresolved
5
6
6
7
import * as api from '../data/api' ;
7
8
import Xpert from './Xpert' ;
8
9
9
10
import * as surveyMonkey from '../utils/surveyMonkey' ;
10
11
import { render , createRandomResponseForTesting } from '../utils/utils.test' ;
11
- import { usePromptExperimentDecision } from '../experiments' ;
12
+ import { useAuditTrialExperimentDecision , usePromptExperimentDecision } from '../experiments' ;
13
+ import { OPTIMIZELY_AUDIT_TRIAL_LENGTH_EXPERIMENT_VARIATION_KEYS } from '../data/optimizely' ;
12
14
13
15
jest . mock ( '@edx/frontend-platform/analytics' ) ;
14
16
jest . mock ( '@edx/frontend-platform/auth' , ( ) => ( {
@@ -18,12 +20,18 @@ jest.mock('@edx/frontend-platform/auth', () => ({
18
20
jest . mock ( '../experiments' , ( ) => ( {
19
21
ExperimentsProvider : ( { children } ) => children ,
20
22
usePromptExperimentDecision : jest . fn ( ) ,
23
+ useAuditTrialExperimentDecision : jest . fn ( ( ) => [ {
24
+ enabled : true ,
25
+ variationKey : 'test' ,
26
+ } ] ) ,
21
27
} ) ) ;
22
28
23
29
jest . mock ( '../utils/scroll' , ( ) => ( {
24
30
scrollToBottom : jest . fn ( ) ,
25
31
} ) ) ;
26
32
33
+ useModel . mockImplementation ( ( ) => ( { isStaff : false } ) ) ;
34
+
27
35
const initialState = {
28
36
learningAssistant : {
29
37
currentMessage : '' ,
@@ -73,7 +81,6 @@ test('doesn\'t load if not enabled', async () => {
73
81
74
82
// button to open chat should not be in the DOM
75
83
await waitFor ( ( ) => expect ( screen . queryByTestId ( 'toggle-button' ) ) . not . toBeInTheDocument ( ) ) ;
76
- // expect(screen.queryByTestId('toggle-button')).not.toBeVisible();
77
84
await waitFor ( ( ) => ( expect ( screen . queryByTestId ( 'action-message' ) ) . not . toBeInTheDocument ( ) ) ) ;
78
85
} ) ;
79
86
test ( 'initial load displays correct elements' , async ( ) => {
@@ -349,3 +356,16 @@ test('survey monkey survey should appear after closing sidebar', async () => {
349
356
expect ( survey ) . toHaveBeenCalledTimes ( 1 ) ;
350
357
survey . mockRestore ( ) ;
351
358
} ) ;
359
+ test ( 'Xpert is not rendered for control group' , async ( ) => {
360
+ useAuditTrialExperimentDecision . mockReturnValue ( [ {
361
+ enabled : true ,
362
+ variationKey : OPTIMIZELY_AUDIT_TRIAL_LENGTH_EXPERIMENT_VARIATION_KEYS . CONTROL ,
363
+ } ] ) ;
364
+
365
+ render (
366
+ < Xpert courseId = { courseId } contentToolsEnabled = { false } unitId = { unitId } /> ,
367
+ { preloadedState : initialState } ,
368
+ ) ;
369
+
370
+ await waitFor ( ( ) => expect ( screen . queryByTestId ( 'toggle-button' ) ) . not . toBeInTheDocument ( ) ) ;
371
+ } ) ;
0 commit comments