Skip to content

Commit 59652a5

Browse files
committed
Fixed and added tests for state consolidation.
1 parent ecc2c8a commit 59652a5

File tree

146 files changed

+4002
-639
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+4002
-639
lines changed

packages/app/client/src/commands/botCommands.spec.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ import {
3939
} from '@bfemulator/sdk-shared';
4040
import { combineReducers, createStore } from 'redux';
4141

42-
import * as BotActions from '../data/action/botActions';
43-
import { bot } from '../data/reducer/bot';
44-
import { resources } from '../data/reducer/resourcesReducer';
42+
import * as BotActions from '../state/actions/botActions';
43+
import { bot } from '../state/reducers/bot';
44+
import { resources } from '../state/reducers/resourcesReducer';
4545
import { ActiveBotHelper } from '../ui/helpers/activeBotHelper';
4646

4747
import { BotCommands } from './botCommands';
@@ -98,7 +98,7 @@ const mockStore = createStore(combineReducers({ bot, resources }), {
9898
bot: { botFiles: [mockBotInfo] },
9999
});
100100

101-
jest.mock('../data/store', () => ({
101+
jest.mock('../state/store', () => ({
102102
get store() {
103103
return mockStore;
104104
},
@@ -156,16 +156,6 @@ describe('The bot commands', () => {
156156
expect(switchSpy).toHaveBeenCalledWith({ path: 'some/path.bot' });
157157
});
158158

159-
it('should make the appropriate calls to sync the bot list', () => {
160-
const dispatchSpy = jest.spyOn(mockStore, 'dispatch');
161-
const remoteCallSpy = jest.spyOn(commandService, 'remoteCall');
162-
const handler = registry.getCommand(SharedConstants.Commands.Bot.SyncBotList);
163-
handler([{}]);
164-
165-
expect(dispatchSpy).toHaveBeenCalledWith(BotActions.loadBotInfos([{}]));
166-
expect(remoteCallSpy).toHaveBeenCalledWith(SharedConstants.Commands.Electron.UpdateFileMenu);
167-
});
168-
169159
it('should make the appropriate call when setting the active bot', async () => {
170160
const remoteCallArgs = [];
171161
commandService.remoteCall = async (...args: any[]) => {

packages/app/client/src/commands/botCommands.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
chatsDirectoryUpdated,
4444
transcriptDirectoryUpdated,
4545
transcriptsUpdated,
46-
} from '../state/actions/resourcesAction';
46+
} from '../state/actions/resourcesActions';
4747
import { pathExistsInRecentBots } from '../state/helpers/botHelpers';
4848
import { store } from '../state/store';
4949
import { ActiveBotHelper } from '../ui/helpers/activeBotHelper';

packages/app/client/src/commands/emulatorCommands.spec.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ import { newNotification, SharedConstants } from '@bfemulator/app-shared';
3434
import { combineReducers, createStore } from 'redux';
3535
import { CommandRegistry, CommandServiceImpl, CommandServiceInstance } from '@bfemulator/sdk-shared';
3636

37-
import { clientAwareSettingsChanged } from '../data/action/clientAwareSettingsActions';
38-
import { beginAdd } from '../data/action/notificationActions';
39-
import { bot } from '../data/reducer/bot';
40-
import { chat } from '../data/reducer/chat';
41-
import { clientAwareSettings } from '../data/reducer/clientAwareSettingsReducer';
42-
import { editor } from '../data/reducer/editor';
43-
import { framework } from '../data/reducer/frameworkSettingsReducer';
44-
import { RootState } from '../data/store';
45-
import { frameworkSettingsChanged } from '../data/action/frameworkSettingsActions';
37+
import { clientAwareSettingsChanged } from '../state/actions/clientAwareSettingsActions';
38+
import { beginAdd } from '../state/actions/notificationActions';
39+
import { bot } from '../state/reducers/bot';
40+
import { chat } from '../state/reducers/chat';
41+
import { clientAwareSettings } from '../state/reducers/clientAwareSettings';
42+
import { editor } from '../state/reducers/editor';
43+
import { framework } from '../state/reducers/framework';
44+
import { RootState } from '../state/store';
45+
import { setFrameworkSettings } from '../state/actions/frameworkSettingsActions';
4646

4747
import { EmulatorCommands } from './emulatorCommands';
4848

@@ -51,7 +51,7 @@ const mockEndpoint = {
5151
};
5252

5353
let mockStore;
54-
jest.mock('../data/store', () => ({
54+
jest.mock('../state/store', () => ({
5555
get store() {
5656
return mockStore;
5757
},
@@ -121,7 +121,7 @@ describe('The emulator commands', () => {
121121

122122
it('should open a new emulator tabbed document for an endpoint and use the custom user id', () => {
123123
let state: RootState = mockStore.getState();
124-
mockStore.dispatch(frameworkSettingsChanged({ ...state.framework, userGUID: 'customUserId' }));
124+
mockStore.dispatch(setFrameworkSettings({ ...state.framework, userGUID: 'customUserId' }));
125125
const handler = registry.getCommand(SharedConstants.Commands.Emulator.NewLiveChat);
126126
const documentId = handler(mockEndpoint, false);
127127
state = mockStore.getState();

packages/app/client/src/commands/settingsCommands.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ import { CommandRegistry, CommandServiceImpl, CommandServiceInstance } from '@bf
3535
import { SharedConstants } from '@bfemulator/app-shared';
3636
import { combineReducers, createStore } from 'redux';
3737

38-
import { clientAwareSettings } from '../data/reducer/clientAwareSettingsReducer';
39-
import { store } from '../data/store';
40-
import { clientAwareSettingsChanged } from '../data/action/clientAwareSettingsActions';
38+
import { clientAwareSettings } from '../state/reducers/clientAwareSettings';
39+
import { store } from '../state/store';
40+
import { clientAwareSettingsChanged } from '../state/actions/clientAwareSettingsActions';
4141

4242
import { SettingsCommands } from './settingsCommands';
4343

4444
const mockStore = createStore(combineReducers({ clientAwareSettings }));
45-
jest.mock('../data/store', () => ({
45+
jest.mock('../state/store', () => ({
4646
get store() {
4747
return mockStore;
4848
},

packages/app/client/src/commands/uiCommands.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ import { SharedConstants } from '@bfemulator/app-shared';
3434
import { CommandRegistry, CommandServiceImpl, CommandServiceInstance } from '@bfemulator/sdk-shared';
3535

3636
import { CONTENT_TYPE_APP_SETTINGS, DOCUMENT_ID_APP_SETTINGS } from '../constants';
37-
import { AzureAuthAction, AzureAuthWorkflow, invalidateArmToken } from '../data/action/azureAuthActions';
38-
import { EditorActions, OpenEditorAction } from '../data/action/editorActions';
39-
import { NavBarActions, SelectNavBarAction } from '../data/action/navBarActions';
40-
import * as editorHelpers from '../data/editorHelpers';
41-
import { store } from '../data/store';
37+
import { AzureAuthAction, AzureAuthWorkflow, invalidateArmToken } from '../state/actions/azureAuthActions';
38+
import { EditorActions, OpenEditorAction } from '../state/actions/editorActions';
39+
import { NavBarActions, SelectNavBarAction } from '../state/actions/navBarActions';
40+
import * as editorHelpers from '../state/helpers/editorHelpers';
41+
import { store } from '../state/store';
4242
import {
4343
AzureLoginPromptDialogContainer,
4444
AzureLoginSuccessDialogContainer,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license.
4+
//
5+
// Microsoft Bot Framework: http://botframework.com
6+
//
7+
// Bot Framework Emulator Github:
8+
// https://github.com/Microsoft/BotFramwork-Emulator
9+
//
10+
// Copyright (c) Microsoft Corporation
11+
// All rights reserved.
12+
//
13+
// MIT License:
14+
// Permission is hereby granted, free of charge, to any person obtaining
15+
// a copy of this software and associated documentation files (the
16+
// "Software"), to deal in the Software without restriction, including
17+
// without limitation the rights to use, copy, modify, merge, publish,
18+
// distribute, sublicense, and/or sell copies of the Software, and to
19+
// permit persons to whom the Software is furnished to do so, subject to
20+
// the following conditions:
21+
//
22+
// The above copyright notice and this permission notice shall be
23+
// included in all copies or substantial portions of the Software.
24+
//
25+
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
26+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32+
//
33+
34+
import {
35+
BotActionType,
36+
load,
37+
setActive,
38+
setDirectory,
39+
close,
40+
mockAndSetActive,
41+
botHashGenerated,
42+
browse,
43+
closeBot,
44+
openBotViaFilePathAction,
45+
openBotViaUrlAction,
46+
restartConversation,
47+
} from './botActions';
48+
49+
describe('bot actions', () => {
50+
it('should create a load action', () => {
51+
const bots = [{}, null, undefined, {}];
52+
const action = load(bots);
53+
54+
expect(action.type).toBe(BotActionType.load);
55+
expect(action.payload).toEqual({ bots: [{}, {}] });
56+
});
57+
58+
it('should create a setActive action', () => {
59+
const bot: any = {};
60+
const action = setActive(bot);
61+
62+
expect(action.type).toBe(BotActionType.setActive);
63+
expect(action.payload).toEqual({ bot: {} });
64+
});
65+
66+
it('should create a setDirectory action', () => {
67+
const directory = '/some/directory';
68+
const action = setDirectory(directory);
69+
70+
expect(action.type).toBe(BotActionType.setDirectory);
71+
expect(action.payload).toEqual({ directory });
72+
});
73+
74+
it('should create a close action', () => {
75+
const action = close();
76+
77+
expect(action.type).toBe(BotActionType.close);
78+
expect(action.payload).toEqual({});
79+
});
80+
81+
it('should create a mockAndSetActive action', () => {
82+
const mock: any = { name: 'mockBot', someMockProperty: true };
83+
const action = mockAndSetActive(mock);
84+
85+
expect(action.type).toBe(BotActionType.setActive);
86+
expect(action.payload).toEqual({
87+
bot: {
88+
version: '',
89+
name: 'mockBot',
90+
description: '',
91+
services: [],
92+
padlock: '',
93+
someMockProperty: true,
94+
},
95+
});
96+
});
97+
98+
it('should create a botHashGenerated action', () => {
99+
const hash = 'someHash';
100+
const action = botHashGenerated(hash);
101+
102+
expect(action.type).toBe(BotActionType.hashGenerated);
103+
expect(action.payload).toEqual({ hash });
104+
});
105+
106+
it('should create a browse action', () => {
107+
const action = browse();
108+
109+
expect(action.type).toBe(BotActionType.browse);
110+
expect(action.payload).toEqual({});
111+
});
112+
113+
it('should create a closeBot action', () => {
114+
const action = closeBot();
115+
116+
expect(action.type).toBe(BotActionType.close);
117+
expect(action.payload).toEqual({});
118+
});
119+
120+
it('should create an openBotViaFilePathAction', () => {
121+
const action = openBotViaFilePathAction('some/path');
122+
123+
expect(action.type).toBe(BotActionType.openViaFilePath);
124+
expect(action.payload).toBe('some/path');
125+
});
126+
127+
it('should create an openBotViaUrlAction action', () => {
128+
const action = openBotViaUrlAction({});
129+
130+
expect(action.type).toBe(BotActionType.openViaUrl);
131+
expect(action.payload).toEqual({});
132+
});
133+
134+
it('should create a restartConversation action', () => {
135+
const conversationId = 'someConvoId';
136+
const documentId = 'someDocId';
137+
const action = restartConversation(conversationId, documentId);
138+
139+
expect(action.type).toBe(BotActionType.restartConversation);
140+
expect(action.payload).toEqual({ conversationId, documentId });
141+
});
142+
});

packages/app/client/src/state/actions/botActions.ts

-12
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,6 @@ export function closeBot(): BotAction<{}> {
155155
};
156156
}
157157

158-
export function loadBotInfos(bots: BotInfo[]): BotAction<BotInfosPayload> {
159-
// prune bad bots
160-
bots = bots.filter(bot => !!bot);
161-
162-
return {
163-
type: BotActionType.load,
164-
payload: {
165-
bots,
166-
},
167-
};
168-
}
169-
170158
export function openBotViaFilePathAction(path: string): BotAction<string> {
171159
return {
172160
type: BotActionType.openViaFilePath,

0 commit comments

Comments
 (0)