Skip to content

Commit

Permalink
Fixed tests and addressed PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyanziano committed Jan 29, 2020
1 parent 4666dc4 commit ee52ca1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
12 changes: 7 additions & 5 deletions packages/app/client/src/state/sagas/botSagas.ts
Expand Up @@ -162,18 +162,20 @@ export class BotSagas {

// telemetry
if (!action.payload.isFromBotFile) {
BotSagas.commandService.remoteCall(SharedConstants.Commands.Telemetry.TrackEvent, 'bot_open', {
numOfServices: 0,
source: 'url',
});
BotSagas.commandService
.remoteCall(SharedConstants.Commands.Telemetry.TrackEvent, 'bot_open', {
numOfServices: 0,
source: 'url',
})
.catch(_ => void 0);
}
BotSagas.commandService
.remoteCall(SharedConstants.Commands.Telemetry.TrackEvent, 'livechat_open', {
isDebug: action.payload.mode === 'debug',
isGov: action.payload.channelService === 'azureusgovernment',
isRemote: !isLocalHostUrl(action.payload.endpoint),
})
.catch();
.catch(_ => void 0);
}
}

Expand Down
24 changes: 12 additions & 12 deletions packages/app/client/src/state/sagas/frameworkSettingsSagas.spec.ts
Expand Up @@ -106,8 +106,8 @@ describe('The frameworkSettingsSagas', () => {
});

it('should register the expected generators', () => {
const it = frameworkSettingsSagas();
expect(it.next().value).toEqual(
const gen = frameworkSettingsSagas();
expect(gen.next().value).toEqual(
takeEvery(FrameworkActionType.SAVE_FRAMEWORK_SETTINGS, FrameworkSettingsSagas.saveFrameworkSettings)
);
});
Expand All @@ -127,16 +127,16 @@ describe('The frameworkSettingsSagas', () => {
userGUID: 'some-user-id',
ngrokPath: 'some/different/path/to/ngrok',
};
const it = FrameworkSettingsSagas.saveFrameworkSettings(saveFrameworkSettingsAction(updatedSettings));
const gen = FrameworkSettingsSagas.saveFrameworkSettings(saveFrameworkSettingsAction(updatedSettings));
// selector to get the active document from the state
const selector = it.next().value;
const selector = gen.next().value;
expect(selector).toEqual(select(activeDocumentSelector));
const value = selector.SELECT.selector(mockStore.getState());
// put the dirty state to false
expect(it.next(value).value).toEqual(put(EditorActions.setDirtyFlag(value.documentId, false)));
expect(it.next().value).toEqual(put(setFrameworkSettings(updatedSettings)));
expect(it.next().value).toEqual(select(getFrameworkSettings));
expect(it.next(currentSettings).value).toEqual(
expect(gen.next(value).value).toEqual(put(EditorActions.setDirtyFlag(value.documentId, false)));
expect(gen.next().value).toEqual(put(setFrameworkSettings(updatedSettings)));
expect(gen.next().value).toEqual(select(getFrameworkSettings));
expect(gen.next(currentSettings).value).toEqual(
call(
[commandService, commandService.remoteCall],
SharedConstants.Commands.Telemetry.TrackEvent,
Expand All @@ -149,16 +149,16 @@ describe('The frameworkSettingsSagas', () => {
}
)
);
expect(it.next().done).toBe(true);
expect(gen.next().done).toBe(true);
});

it('should send a notification when saving the settings fails', () => {
const it = FrameworkSettingsSagas.saveFrameworkSettings(saveFrameworkSettingsAction({}));
it.next();
const gen = FrameworkSettingsSagas.saveFrameworkSettings(saveFrameworkSettingsAction({}));
gen.next();
const errMsg = `Error while saving emulator settings: oh noes!`;
const notification = newNotification(errMsg);
notification.timestamp = jasmine.any(Number) as any;
notification.id = jasmine.any(String) as any;
expect(it.throw('oh noes!').value).toEqual(put(beginAdd(notification)));
expect(gen.throw('oh noes!').value).toEqual(put(beginAdd(notification)));
});
});
6 changes: 4 additions & 2 deletions packages/app/client/src/utils/getSettingsDelta.spec.ts
Expand Up @@ -34,23 +34,25 @@ describe('getSettingsDelta', () => {
it('should return an object containing the delta between 2 settings objects', () => {
const currentSettings: Partial<FrameworkSettings> = {
autoUpdate: true,
locale: 'en-us',
use10Tokens: true,
usePrereleases: true,
userGUID: 'some-id',
};
const updatedSettings: Partial<FrameworkSettings> = {
autoUpdate: true,
runNgrokAtStartup: true,
use10Tokens: false,
usePrereleases: false,
userGUID: 'some-other-id',
runNgrokAtStartup: true,
};

expect(getSettingsDelta(currentSettings, updatedSettings)).toEqual({
locale: undefined,
runNgrokAtStartup: true,
use10Tokens: false,
usePrereleases: false,
userGUID: 'some-other-id',
runNgrokAtStartup: true,
});
});

Expand Down
7 changes: 7 additions & 0 deletions packages/app/client/src/utils/getSettingsDelta.ts
Expand Up @@ -38,12 +38,19 @@ export function getSettingsDelta(
updatedSettings: FrameworkSettings
): Partial<FrameworkSettings> {
const delta: Partial<FrameworkSettings> = {};
// get delta for keys present in updated settings
for (const key in updatedSettings) {
const prevVal = prevSettings[key];
const updatedVal = updatedSettings[key];
if (prevVal !== updatedVal) {
delta[key] = updatedVal;
}
}
// get delta for any keys that were deleted from updated settings
for (const key in prevSettings) {
if (!Object.prototype.hasOwnProperty.call(updatedSettings, key)) {
delta[key] = undefined;
}
}
return Object.keys(delta).length ? delta : undefined;
}
4 changes: 2 additions & 2 deletions packages/app/main/src/telemetry/telemetryService.spec.ts
Expand Up @@ -125,7 +125,7 @@ describe('TelemetryService', () => {
});

it('should track events', () => {
Object.assign(global, { __JEST_ENV__: false });
global['__JEST_ENV__'] = false;
const mockStartup = jest.fn(() => null);
(TelemetryService as any).startup = mockStartup;
const mockAutoCollect = jest.fn(() => mockAppInsights);
Expand All @@ -148,6 +148,6 @@ describe('TelemetryService', () => {
toolName: 'bf-emulator',
},
});
Object.assign(global, { __JEST_ENV__: true });
global['__JEST_ENV__'] = true;
});
});

0 comments on commit ee52ca1

Please sign in to comment.