Skip to content

Commit

Permalink
Added tests for Telemetry.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyanziano committed Jan 24, 2019
1 parent 5b438ac commit 81727fe
Show file tree
Hide file tree
Showing 25 changed files with 1,572 additions and 53 deletions.
8 changes: 8 additions & 0 deletions packages/app/client/src/commands/botCommands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,20 @@ describe('The bot commands', () => {
});

it('should make the appropriate calls to switch bots', () => {
const remoteCallArgs = [];
CommandServiceImpl.remoteCall = async (...args: any[]) => {
remoteCallArgs.push(args);
return true;
};
const spy = jest.spyOn(ActiveBotHelper, 'confirmAndSwitchBots');
const { handler } = registry.getCommand(
SharedConstants.Commands.Bot.Switch
);
handler({});
expect(spy).toHaveBeenCalledWith({});
expect(remoteCallArgs[0][0]).toBe(SharedConstants.Commands.Telemetry.TrackEvent);
expect(remoteCallArgs[0][1]).toBe('bot_open');
expect(remoteCallArgs[0][2]).toEqual({ method: 'bots_list', numOfServices: undefined });
});

it('should make the appropriate calls to close a bot', () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/app/client/src/commands/emulatorCommands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ describe('The emulator commands', () => {
title: 'Open transcript file',
}
);
expect(remoteCallSpy).toHaveBeenCalledWith(
SharedConstants.Commands.Telemetry.TrackEvent,
'transcriptFile_open',
{ method: 'file_menu' }
);

expect(callSpy).toHaveBeenCalledWith(
'transcript:open',
Expand Down
12 changes: 9 additions & 3 deletions packages/app/client/src/commands/uiCommands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
//
import { SharedConstants } from '@bfemulator/app-shared';
import { CommandRegistryImpl } from '@bfemulator/sdk-shared';

import {
CONTENT_TYPE_APP_SETTINGS,
DOCUMENT_ID_APP_SETTINGS,
Expand All @@ -57,8 +56,9 @@ import {
OpenBotDialogContainer,
SecretPromptDialogContainer,
} from '../ui/dialogs';

import { registerCommands } from './uiCommands';
import { CommandServiceImpl } from '../platform/commands/commandServiceImpl';

jest.mock('../ui/dialogs', () => ({
AzureLoginPromptDialogContainer: class {},
AzureLoginSuccessDialogContainer: class {},
Expand Down Expand Up @@ -153,10 +153,16 @@ describe('the uiCommands', () => {
});

it('should set the proper href on the theme tag when the SwitchTheme command is dispatched', () => {
const link = document.createElement('link');
const remoteCallSpy = jest.spyOn(CommandServiceImpl, 'remoteCall');
let link = document.createElement('link');
link.id = 'themeVars';
document.querySelector('head').appendChild(link);
registry.getCommand(Commands.SwitchTheme).handler('light', './light.css');
expect(link.href).toBe('http://localhost/light.css');
expect(remoteCallSpy).toHaveBeenCalledWith(
SharedConstants.Commands.Telemetry.TrackEvent,
'app_chooseTheme',
{ themeName: 'light' }
);
});
});
5 changes: 5 additions & 0 deletions packages/app/client/src/data/sagas/azureAuthSaga.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ describe('The azureAuthSaga', () => {
ct++;
}
expect(ct).toBe(5);
expect(remoteCallSpy).toHaveBeenCalledWith(SharedConstants.Commands.Telemetry.TrackEvent, 'signIn_failure');
});

it('should contain 6 steps when the Azure login dialog prompt is confirmed and auth succeeds', async () => {
Expand Down Expand Up @@ -257,6 +258,10 @@ describe('The azureAuthSaga', () => {
expect(store.getState().azureAuth.access_token).toBe(
'a valid access_token'
);
expect(remoteCallSpy).toHaveBeenCalledWith(
SharedConstants.Commands.Telemetry.TrackEvent,
'signIn_success'
);
});
});
});
21 changes: 16 additions & 5 deletions packages/app/client/src/data/sagas/resourceSagas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ describe('The ResourceSagas', () => {
});
});

describe(',when opening the resource in the Emulator', () => {
describe('when opening the resource in the Emulator', () => {
let mockResource;
beforeEach(() => {
mockResource = BotConfigWithPathImpl.serviceFromJSON({
Expand All @@ -256,9 +256,15 @@ describe('The ResourceSagas', () => {
expect(mockLocalCommandsCalled).toEqual([
{
commandName: 'chat:open',
args: ['the/file/path/chat.chat', true],
},
args: ['the/file/path/chat.chat', true]
}
]);
expect(mockRemoteCommandsCalled).toEqual([
{
commandName: SharedConstants.Commands.Telemetry.TrackEvent,
args: ['chatFile_open']
}
])
});

it('should open a transcript file', async () => {
Expand All @@ -267,9 +273,14 @@ describe('The ResourceSagas', () => {
expect(mockLocalCommandsCalled).toEqual([
{
commandName: 'transcript:open',
args: ['the/file/path/transcript.transcript'],
},
args: ['the/file/path/transcript.transcript']
}
]);
expect(mockRemoteCommandsCalled).toEqual([
{
commandName: SharedConstants.Commands.Telemetry.TrackEvent,
args: ['transcriptFile_open', { method: 'resources_pane' }]
}])
});
});

Expand Down
Loading

0 comments on commit 81727fe

Please sign in to comment.