|
6 | 6 | import { anything, instance, mock, verify, when } from 'ts-mockito';
|
7 | 7 | import { ApplicationShell } from '../../../client/common/application/applicationShell';
|
8 | 8 | import { IApplicationShell } from '../../../client/common/application/types';
|
| 9 | +import { SurveyAndInterpreterTipNotification } from '../../../client/common/experiments/groups'; |
| 10 | +import { ExperimentService } from '../../../client/common/experiments/service'; |
| 11 | +import { BrowserService } from '../../../client/common/net/browser'; |
9 | 12 | import { PersistentState, PersistentStateFactory } from '../../../client/common/persistentState';
|
10 |
| -import { IPersistentState } from '../../../client/common/types'; |
11 |
| -import { Common, Interpreters } from '../../../client/common/utils/localize'; |
| 13 | +import { IBrowserService, IExperimentService, IPersistentState } from '../../../client/common/types'; |
| 14 | +import { Common } from '../../../client/common/utils/localize'; |
12 | 15 | import { InterpreterSelectionTip } from '../../../client/interpreter/display/interpreterSelectionTip';
|
13 | 16 |
|
14 |
| -// tslint:disable:no-any |
15 | 17 | suite('Interpreters - Interpreter Selection Tip', () => {
|
16 | 18 | let selectionTip: InterpreterSelectionTip;
|
17 | 19 | let appShell: IApplicationShell;
|
18 | 20 | let storage: IPersistentState<boolean>;
|
| 21 | + let experimentService: IExperimentService; |
| 22 | + let browserService: IBrowserService; |
19 | 23 | setup(() => {
|
20 | 24 | const factory = mock(PersistentStateFactory);
|
21 | 25 | storage = mock(PersistentState);
|
22 | 26 | appShell = mock(ApplicationShell);
|
| 27 | + experimentService = mock(ExperimentService); |
| 28 | + browserService = mock(BrowserService); |
23 | 29 |
|
24 | 30 | when(factory.createGlobalPersistentState('InterpreterSelectionTip', false)).thenReturn(instance(storage));
|
25 | 31 |
|
26 |
| - selectionTip = new InterpreterSelectionTip(instance(appShell), instance(factory)); |
| 32 | + selectionTip = new InterpreterSelectionTip( |
| 33 | + instance(appShell), |
| 34 | + instance(factory), |
| 35 | + instance(experimentService), |
| 36 | + instance(browserService) |
| 37 | + ); |
27 | 38 | });
|
28 |
| - test('Do not show tip', async () => { |
| 39 | + test('Do not show notification if already shown', async () => { |
29 | 40 | when(storage.value).thenReturn(true);
|
30 | 41 |
|
31 | 42 | await selectionTip.activate();
|
32 | 43 |
|
33 | 44 | verify(appShell.showInformationMessage(anything(), anything())).never();
|
34 | 45 | });
|
35 |
| - test('Show tip and do not track it', async () => { |
| 46 | + test('Do not show notification if in neither experiments', async () => { |
36 | 47 | when(storage.value).thenReturn(false);
|
37 |
| - when(appShell.showInformationMessage(Interpreters.selectInterpreterTip(), Common.gotIt())).thenResolve(); |
| 48 | + when(experimentService.inExperiment(anything())).thenResolve(false); |
38 | 49 |
|
39 | 50 | await selectionTip.activate();
|
40 | 51 |
|
41 |
| - verify(appShell.showInformationMessage(Interpreters.selectInterpreterTip(), Common.gotIt())).once(); |
42 |
| - verify(storage.updateValue(true)).never(); |
| 52 | + verify(appShell.showInformationMessage(anything(), anything())).never(); |
| 53 | + verify(storage.updateValue(true)).once(); |
43 | 54 | });
|
44 |
| - test('Show tip and track it', async () => { |
| 55 | + test('Show tip if in tip experiment', async () => { |
45 | 56 | when(storage.value).thenReturn(false);
|
46 |
| - when(appShell.showInformationMessage(Interpreters.selectInterpreterTip(), Common.gotIt())).thenResolve( |
47 |
| - Common.gotIt() as any |
48 |
| - ); |
| 57 | + when(experimentService.inExperiment(SurveyAndInterpreterTipNotification.tipExperiment)).thenResolve(true); |
| 58 | + when(experimentService.inExperiment(SurveyAndInterpreterTipNotification.surveyExperiment)).thenResolve(false); |
| 59 | + |
| 60 | + await selectionTip.activate(); |
| 61 | + |
| 62 | + verify(appShell.showInformationMessage(anything(), Common.gotIt())).once(); |
| 63 | + verify(storage.updateValue(true)).once(); |
| 64 | + }); |
| 65 | + test('Show survey link if in survey experiment', async () => { |
| 66 | + when(experimentService.inExperiment(SurveyAndInterpreterTipNotification.tipExperiment)).thenResolve(false); |
| 67 | + when(experimentService.inExperiment(SurveyAndInterpreterTipNotification.surveyExperiment)).thenResolve(true); |
49 | 68 |
|
50 | 69 | await selectionTip.activate();
|
51 | 70 |
|
52 |
| - verify(appShell.showInformationMessage(Interpreters.selectInterpreterTip(), Common.gotIt())).once(); |
| 71 | + verify(appShell.showInformationMessage(anything(), Common.bannerLabelYes(), Common.bannerLabelNo())).once(); |
53 | 72 | verify(storage.updateValue(true)).once();
|
54 | 73 | });
|
| 74 | + test('Open survey link if in survey experiment and "Yes" is selected', async () => { |
| 75 | + when(experimentService.inExperiment(SurveyAndInterpreterTipNotification.tipExperiment)).thenResolve(false); |
| 76 | + when(experimentService.inExperiment(SurveyAndInterpreterTipNotification.surveyExperiment)).thenResolve(true); |
| 77 | + when(appShell.showInformationMessage(anything(), Common.bannerLabelYes(), Common.bannerLabelNo())).thenResolve( |
| 78 | + // tslint:disable-next-line: no-any |
| 79 | + Common.bannerLabelYes() as any |
| 80 | + ); |
| 81 | + |
| 82 | + await selectionTip.activate(); |
| 83 | + |
| 84 | + verify(browserService.launch(anything())).once(); |
| 85 | + }); |
55 | 86 | });
|
0 commit comments