Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Tracking for used Debug tool is incorrect #3589

Merged
merged 1 commit into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/services/debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class DebugService extends EventEmitter implements IDebugService {
await this.$analyticsService.trackEventActionInGoogleAnalytics({
action: TrackActionNames.Debug,
device,
additionalData: this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform) && (!options || !options.chrome) ? DebugTools.Inspector : DebugTools.Chrome,
additionalData: this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform) && options && options.inspector ? DebugTools.Inspector : DebugTools.Chrome,
projectDir: debugData.projectDir
});

Expand Down
50 changes: 49 additions & 1 deletion test/services/debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as stubs from "../stubs";
import { assert } from "chai";
import { EventEmitter } from "events";
import * as constants from "../../lib/common/constants";
import { CONNECTION_ERROR_EVENT_NAME, DebugCommandErrors } from "../../lib/constants";
import { CONNECTION_ERROR_EVENT_NAME, DebugCommandErrors, TrackActionNames, DebugTools } from "../../lib/constants";

const fakeChromeDebugPort = 123;
const fakeChromeDebugUrl = `fakeChromeDebugUrl?experiments=true&ws=localhost:${fakeChromeDebugPort}`;
Expand Down Expand Up @@ -231,5 +231,53 @@ describe("debugService", () => {
});
});
});

describe("tracks to google analytics", () => {
_.each([
{
testName: "Inspector when --inspector is passed",
debugOptions: { inspector: true },
additionalData: DebugTools.Inspector
},
{
testName: "Chrome when no options are passed",
debugOptions: null,
additionalData: DebugTools.Chrome
},
{
testName: "Chrome when --chrome is passed",
debugOptions: { chrome: true },
additionalData: DebugTools.Chrome
}], testCase => {

it(testCase.testName, async () => {
const testData = getDefaultTestData();
testData.deviceInformation.deviceInfo.platform = "iOS";

const testInjector = getTestInjectorForTestConfiguration(testData);
const analyticsService = testInjector.resolve<IAnalyticsService>("analyticsService");
let dataTrackedToGA: IEventActionData = null;
analyticsService.trackEventActionInGoogleAnalytics = async (data: IEventActionData): Promise<void> => {
dataTrackedToGA = data;
};

const debugService = testInjector.resolve<IDebugServiceBase>(DebugService);
const debugData = getDebugData();
await debugService.debug(debugData, testCase.debugOptions);
const devicesService = testInjector.resolve<Mobile.IDevicesService>("devicesService");
const device = devicesService.getDeviceByIdentifier(testData.deviceInformation.deviceInfo.identifier);

const expectedData = JSON.stringify({
action: TrackActionNames.Debug,
device,
additionalData: testCase.additionalData,
projectDir: debugData.projectDir
}, null, 2);

// Use JSON.stringify as the compared objects link to new instances of different classes.
assert.deepEqual(JSON.stringify(dataTrackedToGA, null, 2), expectedData);
});
});
});
});
});