Skip to content

Commit

Permalink
Merge branch 'master' into srravich/1973-ngrok-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
srinaath authored Jan 28, 2020
2 parents 909a920 + 7234dcf commit e295d7e
Show file tree
Hide file tree
Showing 10 changed files with 597 additions and 84 deletions.
58 changes: 58 additions & 0 deletions packages/app/client/src/commands/electronCommands.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// 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 CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import { CommandServiceImpl, CommandRegistry, CommandServiceInstance } from '@bfemulator/sdk-shared';
import { SharedConstants } from '@bfemulator/app-shared';

import { ElectronCommands } from './electronCommands';

describe('The misc commands', () => {
let commandService: CommandServiceImpl;
let registry: CommandRegistry;

beforeAll(() => {
new ElectronCommands();
const decorator = CommandServiceInstance();
const descriptor = decorator({ descriptor: {} }, 'none') as any;
commandService = descriptor.descriptor.get();
registry = commandService.registry;
});

it('should toggle the dev tools for open inspectors', () => {
const dispatchEventSpy = jest.spyOn(window, 'dispatchEvent').mockImplementationOnce(ev => null);
const command = registry.getCommand(SharedConstants.Commands.Electron.ToggleDevTools);
command();

expect(dispatchEventSpy).toHaveBeenCalledWith(new Event('toggle-inspector-devtools'));
});
});
25 changes: 0 additions & 25 deletions packages/app/client/src/commands/electronCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,4 @@ export class ElectronCommands {
protected toggleDevTools() {
window.dispatchEvent(new Event('toggle-inspector-devtools'));
}

// ---------------------------------------------------------------------------
// An update is ready to install
@Command(Electron.UpdateAvailable)
protected emulatorUpdateAvailable(...args: any[]) {
// TODO: Show a notification
// eslint-disable-next-line no-console
console.log('Update available', ...args);
}

// ---------------------------------------------------------------------------
// Application is up to date
@Command(Electron.UpdateNotAvailable)
protected emulatorUpdateNotAvailable() {
// TODO: Show a notification
// eslint-disable-next-line no-console
console.log('Application is up to date');
}

// ---------------------------------------------------------------------------
// Open About dialog
@Command(Electron.ShowAboutDialog)
protected showAboutDialog() {
// TODO: Show about dialog (native dialog box)
}
}
110 changes: 110 additions & 0 deletions packages/app/client/src/commands/fileCommands.spec.ts
Original file line number Diff line number Diff line change
@@ -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 CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import { CommandServiceImpl, CommandRegistry, CommandServiceInstance } from '@bfemulator/sdk-shared';
import { SharedConstants } from '@bfemulator/app-shared';

import { addFile, removeFile, clear } from '../state/actions/fileActions';
import { addDocPendingChange } from '../state/actions/editorActions';

import { FileCommands } from './fileCommands';

const mockDispatch = jest.fn();
jest.mock('../state/store', () => ({
store: {
dispatch: action => mockDispatch(action),
},
}));

describe('The file commands', () => {
let commandService: CommandServiceImpl;
let registry: CommandRegistry;
const { File } = SharedConstants.Commands;

beforeAll(() => {
new FileCommands();
const decorator = CommandServiceInstance();
const descriptor = decorator({ descriptor: {} }, 'none') as any;
commandService = descriptor.descriptor.get();
registry = commandService.registry;
});

beforeEach(mockDispatch.mockClear);

it('should add a file to the store', () => {
const payload: any = {
type: 'leaf',
name: 'somefile.txt',
path: 'dir/somefile.txt',
};
const command = registry.getCommand(File.Add);
command(payload);

expect(mockDispatch).toHaveBeenCalledWith(addFile(payload));
});

it('should remove a file from the store', () => {
const payload: any = {
type: 'leaf',
name: 'somefile.txt',
path: 'dir/somefile.txt',
};
const command = registry.getCommand(File.Remove);
command(payload);

expect(mockDispatch).toHaveBeenCalledWith(removeFile(payload));
});

it('should clear the file store', () => {
const command = registry.getCommand(File.Clear);
command();

expect(mockDispatch).toHaveBeenCalledWith(clear());
});

it('should mark a file as changed (.chat file)', () => {
const filename = 'my-file.chat';
const command = registry.getCommand(File.Changed);
command(filename);

expect(mockDispatch).toHaveBeenCalledWith(addDocPendingChange(filename));
});

it('should mark a file as changed (.transcript file)', () => {
const filename = 'my-file.transcript';
const command = registry.getCommand(File.Changed);
command(filename);

expect(mockDispatch).toHaveBeenCalledWith(addDocPendingChange(filename));
});
});
64 changes: 64 additions & 0 deletions packages/app/client/src/commands/miscCommands.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// 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 CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import { CommandServiceImpl, CommandRegistry, CommandServiceInstance } from '@bfemulator/sdk-shared';
import { SharedConstants } from '@bfemulator/app-shared';

import { MiscCommands } from './miscCommands';

const mockState = {};
jest.mock('../state/store', () => ({
store: {
getState: () => mockState,
},
}));

describe('The misc commands', () => {
let commandService: CommandServiceImpl;
let registry: CommandRegistry;

beforeAll(() => {
new MiscCommands();
const decorator = CommandServiceInstance();
const descriptor = decorator({ descriptor: {} }, 'none') as any;
commandService = descriptor.descriptor.get();
registry = commandService.registry;
});

it('should return the store state', () => {
const command = registry.getCommand(SharedConstants.Commands.Misc.GetStoreState);
const state = command();

expect(state).toEqual(mockState);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,71 +31,52 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import { CommandServiceImpl, CommandRegistry, CommandServiceInstance } from '@bfemulator/sdk-shared';
import { SharedConstants } from '@bfemulator/app-shared';
import { Command } from '@bfemulator/sdk-shared';

export interface EmulatorSettings {
url?: string;
cwd?: string;
readonly cwdAsBase: string;
}
import { beginAdd, beginRemove } from '../state/actions/notificationActions';

class EmulatorSettingsImpl implements EmulatorSettings {
private _url: string;
private _cwd: string;
import { NotificationCommands } from './notificationCommands';

get url(): string {
if (!this._url || !this._url.length) {
throw new Error('Emulator url not set');
}
return this._url;
}
const mockNotification: any = {};
jest.mock('../utils', () => ({
getGlobal: () => mockNotification,
}));

set url(value: string) {
this._url = value;
}
const mockDispatch = jest.fn();
jest.mock('../state/store', () => ({
store: {
dispatch: action => mockDispatch(action),
},
}));

get cwd(): string {
if (!this._cwd || !this._cwd.length) {
throw new Error('Emulator cwd not set');
}
return this._cwd;
}
describe('The notification commands', () => {
let commandService: CommandServiceImpl;
let registry: CommandRegistry;
const { Notifications } = SharedConstants.Commands;

set cwd(value: string) {
this._cwd = value;
}
beforeAll(() => {
new NotificationCommands();
const decorator = CommandServiceInstance();
const descriptor = decorator({ descriptor: {} }, 'none') as any;
commandService = descriptor.descriptor.get();
registry = commandService.registry;
});

get cwdAsBase(): string {
let base = this.cwd || '';
if (!base.startsWith('/')) {
base = `/${base}`;
}
beforeEach(mockDispatch.mockClear);

return base;
}
}
it('should add a notifcation from the main process', () => {
const command = registry.getCommand(Notifications.Add);
command();

class EmulatorSettingsService {
private _emulator: EmulatorSettingsImpl;
expect(mockDispatch).toHaveBeenCalledWith(beginAdd(mockNotification));
});

get emulator(): EmulatorSettingsImpl {
return this._emulator;
}
it('should remove a notification', () => {
const id = 'someId';
const command = registry.getCommand(Notifications.Remove);
command(id);

public init() {
return null;
}

constructor() {
this._emulator = new EmulatorSettingsImpl();
}

@Command(SharedConstants.Commands.Settings.ReceiveGlobalSettings)
protected receiveGlobalSettings(settings: { url: string; cwd: string }): any {
this.emulator.url = (settings.url || '').replace('[::]', 'localhost');
this.emulator.cwd = (settings.cwd || '').replace(/\\/g, '/');
}
}

export const SettingsService = new EmulatorSettingsService();
expect(mockDispatch).toHaveBeenCalledWith(beginRemove(id));
});
});
Loading

0 comments on commit e295d7e

Please sign in to comment.