Skip to content

Commit

Permalink
#1237 - updated implementation to use API instead of internals (#1247)
Browse files Browse the repository at this point in the history
* #1237 - updated implemenation to use API instead of internals
* Fixed coverage analysis to include the entire codebase instead of just imports within a spec
  • Loading branch information
Justin Wilaby authored Jan 24, 2019
1 parent dde2f5a commit 56f9cd5
Show file tree
Hide file tree
Showing 225 changed files with 1,832 additions and 12,821 deletions.
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"lint:fix": "lerna run lint:fix --no-bail",
"start": "cd packages\\app\\client && npm run start",
"test": "jest --no-cache",
"test:coveralls": "jest --runInBand --bail --coverage --coverageReporters=text-lcov | coveralls"
"test:coveralls": "jest --runInBand --coverage --coverageReporters=text-lcov | coveralls"
},
"devDependencies": {
"@babel/cli": "^7.1.0",
Expand All @@ -27,6 +27,14 @@
"transform": {
"^.+\\.(tsx|ts|js)$": "./babel-jest-config"
},
"collectCoverageFrom": [
"<rootDir>/packages/**/src/**/?(*.)(ts)?(x)",
"!<rootDir>/packages/**/src/**/?(*.)(d).(ts)",
"!<rootDir>/packages/**/src/**/?(*.)(spec|test).(ts)?(x)",
"!**/node_modules/**",
"!**/lib/**",
"!**/build/**"
],
"testURL": "http://localhost",
"testMatch": [
"<rootDir>/packages/**/src/**/?(*.)(spec|test).(ts)?(x)"
Expand Down
2 changes: 1 addition & 1 deletion packages/app/client/src/commands/botCommands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('The bot commands', () => {
);
handler([{}]);

expect(dispatchSpy).toHaveBeenCalledWith(BotActions.load([{}]));
expect(dispatchSpy).toHaveBeenCalledWith(BotActions.loadBotInfos([{}]));
expect(remoteCallSpy).toHaveBeenCalledWith(
SharedConstants.Commands.Electron.UpdateFileMenu
);
Expand Down
4 changes: 2 additions & 2 deletions packages/app/client/src/commands/botCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function registerCommands(commandRegistry: CommandRegistryImpl) {
commandRegistry.registerCommand(
Commands.Bot.SyncBotList,
async (bots: BotInfo[]): Promise<void> => {
store.dispatch(BotActions.load(bots));
store.dispatch(BotActions.loadBotInfos(bots));
await CommandServiceImpl.remoteCall(Commands.Electron.UpdateFileMenu);
}
);
Expand All @@ -104,7 +104,7 @@ export function registerCommands(commandRegistry: CommandRegistryImpl) {
commandRegistry.registerCommand(
Commands.Bot.SetActive,
async (bot: BotConfigWithPath, botDirectory: string) => {
store.dispatch(BotActions.setActive(bot));
store.dispatch(BotActions.setActiveBot(bot));
store.dispatch(FileActions.setRoot(botDirectory));
await Promise.all([
CommandServiceImpl.remoteCall(Commands.Electron.UpdateFileMenu),
Expand Down
19 changes: 11 additions & 8 deletions packages/app/client/src/commands/notificationCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import { SharedConstants } from '@bfemulator/app-shared';
import { Notification } from '@bfemulator/app-shared';
import { Notification, SharedConstants } from '@bfemulator/app-shared';
import { CommandRegistryImpl } from '@bfemulator/sdk-shared';

import * as NotificationActions from '../data/action/notificationActions';
Expand All @@ -44,12 +43,16 @@ export function registerCommands(commandRegistry: CommandRegistryImpl) {
const Commands = SharedConstants.Commands.Notifications;
// ---------------------------------------------------------------------------
// Adds a notification from the main side to the store / notification manager
commandRegistry.registerCommand(Commands.Add, () => {
const notification: Notification = getGlobal(
SharedConstants.NOTIFICATION_FROM_MAIN
);
store.dispatch(NotificationActions.beginAdd(notification));
});
commandRegistry.registerCommand(
Commands.Add,
(notification: Notification) => {
if (!notification) {
notification = getGlobal(SharedConstants.NOTIFICATION_FROM_MAIN);
}

store.dispatch(NotificationActions.beginAdd(notification));
}
);

// ---------------------------------------------------------------------------
// Removes a notification from the store / notification manager
Expand Down
107 changes: 54 additions & 53 deletions packages/app/client/src/data/action/botActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,94 +32,95 @@
//

import { BotInfo } from '@bfemulator/app-shared';
import { BotConfigWithPath } from '@bfemulator/sdk-shared';
import {
BotConfigWithPath,
StartConversationParams,
} from '@bfemulator/sdk-shared';

export enum BotActions {
load = 'BOT/LOAD',
setActive = 'BOT/SET_ACTIVE',
export enum BotActionType {
close = 'BOT/CLOSE',
browse = 'BOT/BROWSE',
hashGenerated = 'BOT/HASH_GENERATED',
load = 'BOT/LOAD',
open = 'BOT/OPEN',
openViaUrl = 'BOT/OPEN_VIA_URL',
openViaFilePath = 'BOT/OPEN_VIA_FILE_PATH',
setActive = 'BOT/SET_ACTIVE',
}

export interface LoadBotAction {
type: BotActions.load;
payload: {
bots: BotInfo[];
};
export interface BotAction<T = any> {
readonly type: BotActionType;
payload: T;
}

export interface SetActiveBotAction {
type: BotActions.setActive;
payload: {
bot: BotConfigWithPath;
};
export interface BotConfigWithPathPayload {
bot: BotConfigWithPath;
}

export interface CloseBotAction {
type: BotActions.close;
payload: {};
export interface BotInfosPayload {
bots: BotInfo[];
}

export interface BrowseBotAction {
type: BotActions.browse;
payload: {};
export interface HashPayload {
hash: string;
}

export interface BotHashAction {
type: BotActions.hashGenerated;
payload: { hash: string };
export function botHashGenerated(hash: string): BotAction<HashPayload> {
return {
type: BotActionType.hashGenerated,
payload: { hash },
};
}

export type BotAction =
| LoadBotAction
| SetActiveBotAction
| CloseBotAction
| BrowseBotAction
| BotHashAction;

export function load(bots: BotInfo[]): LoadBotAction {
// prune bad bots
bots = bots.filter(bot => !!bot);
export function browse(): BotAction<{}> {
return {
type: BotActionType.browse,
payload: {},
};
}

export function closeBot(): BotAction<{}> {
return {
type: BotActions.load,
payload: {
bots,
},
type: BotActionType.close,
payload: {},
};
}

/**
*
* @param bot The new active bot
*/
export function setActive(bot: BotConfigWithPath): SetActiveBotAction {
export function loadBotInfos(bots: BotInfo[]): BotAction<BotInfosPayload> {
// prune bad bots
bots = bots.filter(bot => !!bot);

return {
type: BotActions.setActive,
type: BotActionType.load,
payload: {
bot,
bots,
},
};
}

export function close(): CloseBotAction {
export function openBotViaFilePathAction(path: string): BotAction<string> {
return {
type: BotActions.close,
payload: {},
type: BotActionType.openViaFilePath,
payload: path,
};
}

export function browse(): BrowseBotAction {
export function openBotViaUrlAction(
params: Partial<StartConversationParams>
): BotAction<Partial<StartConversationParams>> {
return {
type: BotActions.browse,
payload: {},
type: BotActionType.openViaUrl,
payload: params,
};
}

export function botHashGenerated(hash: string): BotHashAction {
export function setActiveBot(
bot: BotConfigWithPath
): BotAction<BotConfigWithPathPayload> {
return {
type: BotActions.hashGenerated,
payload: { hash },
type: BotActionType.setActive,
payload: {
bot,
},
};
}
2 changes: 1 addition & 1 deletion packages/app/client/src/data/action/chatActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import LogEntry from '@bfemulator/emulator-core/lib/types/log/entry';
import { LogEntry } from '@bfemulator/sdk-shared';
import { Action } from 'redux';

export enum ChatActions {
Expand Down
19 changes: 12 additions & 7 deletions packages/app/client/src/data/reducer/bot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@
import { BotInfo } from '@bfemulator/app-shared';
import { BotConfigWithPath } from '@bfemulator/sdk-shared';

import { BotAction, close, load, setActive } from '../action/botActions';
import {
BotAction,
closeBot,
loadBotInfos,
setActiveBot,
} from '../action/botActions';

import { bot, BotState } from './bot';

Expand Down Expand Up @@ -63,7 +68,7 @@ describe('Bot reducer tests', () => {
};

it('should set a bot as active', () => {
const action = setActive(testbot);
const action = setActiveBot(testbot);
const state = bot(DEFAULT_STATE, action);
expect(state.activeBot).toEqual(testbot);
});
Expand Down Expand Up @@ -92,7 +97,7 @@ describe('Bot reducer tests', () => {
botFiles: testbots,
};

const action = setActive(testbot);
const action = setActiveBot(testbot);
const endingState = bot(startingState, action);
expect(endingState.botFiles[0].path).toBe('somePath');
});
Expand All @@ -117,7 +122,7 @@ describe('Bot reducer tests', () => {
} as any,
};

const action = setActive(testbot);
const action = setActiveBot(testbot);
const endingState = bot(startingState, action);
const activeBot = endingState.activeBot;

Expand Down Expand Up @@ -151,7 +156,7 @@ describe('Bot reducer tests', () => {
} as any,
};

const action = setActive(testbot);
const action = setActiveBot(testbot);
const endingState = bot(startingState, action);
const activeBot = endingState.activeBot;

Expand Down Expand Up @@ -179,7 +184,7 @@ describe('Bot reducer tests', () => {
},
null,
];
const action = load(bots);
const action = loadBotInfos(bots);
const state = bot(DEFAULT_STATE, action);
expect(state.botFiles).not.toEqual(bots);
expect(state.botFiles.length).toBe(3);
Expand Down Expand Up @@ -212,7 +217,7 @@ describe('Bot reducer tests', () => {
services: [],
} as any,
};
const action = close();
const action = closeBot();
const endingState = bot(startingState, action);
expect(endingState.activeBot).toBe(null);
});
Expand Down
10 changes: 5 additions & 5 deletions packages/app/client/src/data/reducer/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
botsAreTheSame,
} from '@bfemulator/sdk-shared';

import { BotAction, BotActions } from '../action/botActions';
import { BotAction, BotActionType } from '../action/botActions';

export interface BotState {
activeBot: BotConfigWithPath;
Expand All @@ -54,12 +54,12 @@ const DEFAULT_STATE: BotState = {

export function bot(state: BotState = DEFAULT_STATE, action: BotAction) {
switch (action.type) {
case BotActions.load: {
case BotActionType.load: {
state = setBotFilesState(action.payload.bots, state);
break;
}

case BotActions.setActive: {
case BotActionType.setActive: {
// move active bot up to the top of the recent bots list
const mostRecentBot = state.botFiles.find(
botArg => botArg && botArg.path === action.payload.bot.path
Expand All @@ -82,13 +82,13 @@ export function bot(state: BotState = DEFAULT_STATE, action: BotAction) {
break;
}

case BotActions.close: {
case BotActionType.close: {
// close the active bot
state = setActiveBot(null, state);
break;
}

case BotActions.hashGenerated:
case BotActionType.hashGenerated:
return { ...state, activeBotDigest: action.payload.hash };

default:
Expand Down
2 changes: 1 addition & 1 deletion packages/app/client/src/data/reducer/chat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import LogEntry from '@bfemulator/emulator-core/lib/types/log/entry';
import { LogEntry } from '@bfemulator/sdk-shared';

import {
addTranscript,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// 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 { ClientAwareSettings } from '@bfemulator/app-shared/built';
import { ClientAwareSettings } from '@bfemulator/app-shared';

import {
CLIENT_AWARE_SETTINGS_CHANGED,
Expand Down
Loading

0 comments on commit 56f9cd5

Please sign in to comment.