Skip to content

Commit

Permalink
Merge 35f8c8c into 7903a71
Browse files Browse the repository at this point in the history
  • Loading branch information
Corina committed Nov 2, 2018
2 parents 7903a71 + 35f8c8c commit dcd2d1c
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 69 deletions.
65 changes: 6 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 36 additions & 1 deletion packages/app/client/src/commands/uiCommands.spec.ts
Expand Up @@ -18,15 +18,18 @@ import {
AzureLoginPromptDialogContainer,
AzureLoginSuccessDialogContainer,
BotCreationDialog,
ClientCertSelectDialogContainer,
DialogService,
PostMigrationDialogContainer,
SecretPromptDialogContainer
} from '../ui/dialogs';
import { CommandRegistryImpl } from '@bfemulator/sdk-shared';
import { SharedConstants } from '@bfemulator/app-shared';
import { registerCommands } from './uiCommands';
import * as editorHelpers from '../data/editorHelpers';
import { store } from '../data/store';
import { AzureAuthAction, AzureAuthWorkflow, invalidateArmToken } from '../data/action/azureAuthActions';
import { AzureAuthAction, AzureAuthWorkflow, invalidateArmToken, ArmTokenData } from '../data/action/azureAuthActions';
import { ProgressIndicatorAction, ProgressIndicatorPayload, UPDATE_PROGRESS_INDICATOR } from '../data/action/progressIndicatorActions';

const Commands = SharedConstants.Commands.UI;

Expand Down Expand Up @@ -57,6 +60,21 @@ describe('the uiCommands', () => {
expect(result).toBe(true);
});

it('should call DialogService.showDialog when the ShowPostMigrationDialog command is dispatched', async () => {
const spy = jest.spyOn(DialogService, 'showDialog');
const result = await registry.getCommand(Commands.ShowPostMigrationDialog).handler();
expect(spy).toHaveBeenCalledWith(PostMigrationDialogContainer);
expect(result).toBe(true);
});

it('should call DialogService.showDialog when the ShowSelectCertDialog command is dispatched', async () => {
let certs = ["cert", "cert2", "cert3"];
const spy = jest.spyOn(DialogService, 'showDialog');
const result = await registry.getCommand(Commands.ShowSelectCertDialog).handler(certs);
expect(spy).toHaveBeenCalledWith(ClientCertSelectDialogContainer, { certs });
expect(result).toBe(true);
});

describe('should dispatch the appropriate action to the store', () => {
it('when the SwitchNavBarTab command is dispatched', () => {
let arg: SelectNavBarAction = {} as SelectNavBarAction;
Expand Down Expand Up @@ -90,6 +108,23 @@ describe('the uiCommands', () => {
registry.getCommand(Commands.InvalidateAzureArmToken).handler();
expect(arg).toEqual(invalidateArmToken());
});

it('when the UpdateProgressIndicator command is dispatched', async() => {
const payload: ProgressIndicatorPayload = { label: 'string', progress: 42 };
let arg: ProgressIndicatorAction<ProgressIndicatorPayload> = {} as ProgressIndicatorAction<ProgressIndicatorPayload>;
store.dispatch = action => (arg as any) = action;
registry.getCommand(Commands.UpdateProgressIndicator).handler(payload);
expect(arg.payload).toEqual(payload);
expect(arg.type).toEqual(UPDATE_PROGRESS_INDICATOR);
});

it('when the ArmTokenReceivedOnStartup command is dispatched', async() => {
const armToken: ArmTokenData = { access_token: 'string' }
let arg: AzureAuthAction<ArmTokenData> = {} as AzureAuthAction<ArmTokenData>;
store.dispatch = action => (arg as any) = action;
registry.getCommand(Commands.ArmTokenReceivedOnStartup).handler(armToken);
expect(arg.payload).toEqual(armToken);
});
});

it('should set the proper href on the theme tag when the SwitchTheme command is dispatched', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/app/client/src/commands/uiCommands.ts
Expand Up @@ -37,6 +37,7 @@ import {
AzureLoginPromptDialogContainer,
AzureLoginSuccessDialogContainer,
BotCreationDialog,
ClientCertSelectDialogContainer,
DialogService,
PostMigrationDialogContainer,
SecretPromptDialogContainer
Expand All @@ -53,7 +54,6 @@ import { AzureAuthState } from '../data/reducer/azureAuthReducer';
import { ProgressIndicatorPayload, updateProgressIndicator } from '../data/action/progressIndicatorActions';
import { switchTheme } from '../data/action/themeActions';
import { Certificate } from 'electron';
import { ClientCertSelectDialogContainer } from '../ui/dialogs/clientCertSelectDialog/clientCertSelectDialogContainer';

/** Register UI commands (toggling UI) */
export function registerCommands(commandRegistry: CommandRegistry) {
Expand Down Expand Up @@ -123,15 +123,15 @@ export function registerCommands(commandRegistry: CommandRegistry) {
// ---------------------------------------------------------------------------
// Show post migration dialog on startup if the user has just been migrated
commandRegistry.registerCommand(UI.ShowPostMigrationDialog, () => {
DialogService.showDialog(PostMigrationDialogContainer);
return DialogService.showDialog(PostMigrationDialogContainer);
});

commandRegistry.registerCommand(UI.UpdateProgressIndicator, (value: ProgressIndicatorPayload) => {
store.dispatch(updateProgressIndicator(value));
});

commandRegistry.registerCommand(UI.ShowSelectCertDialog, (certs: Certificate[]) => {
return DialogService.showDialog(ClientCertSelectDialogContainer, {certs});
return DialogService.showDialog(ClientCertSelectDialogContainer, { certs });
});

}
Expand Up @@ -18,6 +18,7 @@ jest.mock('../dialogStyles.scss', () => ({}));
jest.mock('../../dialogs/', () => ({
AzureLoginSuccessDialogContainer: () => undefined,
BotCreationDialog: () => undefined,
ClientCertSelectDialogContainer: () => undefined,
DialogService: { showDialog: () => Promise.resolve(true) },
SecretPromptDialog: () => undefined
}));
Expand Down
Expand Up @@ -45,7 +45,7 @@ describe('The AzureLoginSuccessDialogContainer component should', () => {
it ('should call the cancel function with the checked state when the onDialogCancel function is called', () => {
const instance = node.instance();
const currentCheckedValue = instance.state.rememberMeChecked;
const {cancel} = instance.props;
const { cancel } = instance.props;
Object.defineProperty(instance, 'props', {
value: {
cancel
Expand Down
@@ -0,0 +1,110 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
//
// Microsoft Bot Framework: http://botframework.com
//
// Bot Framework Emulator Github:
// https://github.com/Microsoft/BotFramwork-Emulator
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIONb
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import * as React from 'react';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import { navBar } from '../../../data/reducer/navBar';
import { ClientCertSelectDialog } from './clientCertSelectDialog';
import { ClientCertSelectDialogContainer } from './clientCertSelectDialogContainer';
import { mount } from 'enzyme';
import { DialogService } from '../service';

jest.mock('./clientCertSelectDialog.scss', () => ({}));
jest.mock('../dialogStyles.scss', () => ({}));

jest.mock('../../dialogs/', () => ({
intializeIcons: () => undefined
}));

describe('ClientCertSelectDialogContainer component should', () => {
let wrapper;

beforeEach(() => {
const mockCerts = [
'cert1',
'cert2',
'cert3'
] as any;

wrapper = mount(
<Provider store={ createStore(navBar) } >
<ClientCertSelectDialogContainer certs={ mockCerts }/>
</Provider>
);
});

it('render without error', () => {
expect(wrapper.find(ClientCertSelectDialog)).not.toBe(null);
});

it('contain a dismiss function in the props', () => {
const prompt = wrapper.find(ClientCertSelectDialog);
expect( typeof(prompt.props() as any).dismiss).toBe('function');
});

it('update state when a certificate is clicked', () => {
const dialogComponent = wrapper.find(ClientCertSelectDialog);
expect('selectedIndex' in dialogComponent.state).toBeTruthy();
const selectedIndex = dialogComponent.state('selectedIndex');
expect(selectedIndex).toBe(-1);
const node = dialogComponent.instance();

const mockEvent: any = {
currentTarget: {
dataset: {
index: 0 // clicked on first cert
}
}
};
node.onCertListItemClick(mockEvent);
expect(node.state.selectedIndex).toBe(0);
});

it('select a certificate on dismiss', () => {
const dialogComponent = wrapper.find(ClientCertSelectDialog);
const node = dialogComponent.instance();

const mockEvent: any = {
currentTarget: {
dataset: {
index: 2 // clicked on cert
}
}
};
node.onCertListItemClick(mockEvent);
const spy = jest.spyOn(DialogService, 'hideDialog');
node.onDismissClick();
expect(spy).toHaveBeenCalledWith('cert3');
});
});

0 comments on commit dcd2d1c

Please sign in to comment.