2022-03-15 17:17:48 +01:00
|
|
|
const { strict: assert } = require('assert');
|
2023-07-19 21:56:31 +02:00
|
|
|
const {
|
|
|
|
withFixtures,
|
|
|
|
unlockWallet,
|
|
|
|
defaultGanacheOptions,
|
|
|
|
} = require('../helpers');
|
2022-10-28 10:42:12 +02:00
|
|
|
const FixtureBuilder = require('../fixture-builder');
|
2022-03-15 17:17:48 +01:00
|
|
|
|
2023-07-19 21:56:31 +02:00
|
|
|
describe('Unlock wallet', function () {
|
2022-03-15 17:17:48 +01:00
|
|
|
async function mockSegment(mockServer) {
|
|
|
|
return await mockServer
|
|
|
|
.forPost('https://api.segment.io/v1/batch')
|
|
|
|
.withJsonBodyIncluding({ batch: [{ type: 'page' }] })
|
|
|
|
.times(3)
|
|
|
|
.thenCallback(() => {
|
|
|
|
return {
|
|
|
|
statusCode: 200,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2023-07-19 21:56:31 +02:00
|
|
|
|
2022-03-15 17:17:48 +01:00
|
|
|
it('should send first three Page metric events upon fullscreen page load', async function () {
|
|
|
|
await withFixtures(
|
|
|
|
{
|
2022-10-28 10:42:12 +02:00
|
|
|
fixtures: new FixtureBuilder()
|
|
|
|
.withMetaMetricsController({
|
|
|
|
metaMetricsId: 'fake-metrics-id',
|
|
|
|
participateInMetaMetrics: true,
|
|
|
|
})
|
|
|
|
.build(),
|
2023-07-19 21:56:31 +02:00
|
|
|
ganacheOptions: defaultGanacheOptions,
|
2022-03-15 17:17:48 +01:00
|
|
|
title: this.test.title,
|
2023-04-19 16:36:23 +02:00
|
|
|
testSpecificMock: mockSegment,
|
2022-03-15 17:17:48 +01:00
|
|
|
},
|
2023-04-19 16:36:23 +02:00
|
|
|
async ({ driver, mockedEndpoint }) => {
|
2022-03-15 17:17:48 +01:00
|
|
|
await driver.navigate();
|
2023-07-19 21:56:31 +02:00
|
|
|
await unlockWallet(driver);
|
2022-03-15 17:17:48 +01:00
|
|
|
await driver.wait(async () => {
|
2023-04-19 16:36:23 +02:00
|
|
|
const isPending = await mockedEndpoint.isPending();
|
2022-03-15 17:17:48 +01:00
|
|
|
return isPending === false;
|
|
|
|
}, 10000);
|
2023-04-19 16:36:23 +02:00
|
|
|
const mockedRequests = await mockedEndpoint.getSeenRequests();
|
2022-03-15 17:17:48 +01:00
|
|
|
assert.equal(mockedRequests.length, 3);
|
|
|
|
const [firstMock, secondMock, thirdMock] = mockedRequests;
|
2023-07-19 21:56:31 +02:00
|
|
|
assertBatchValue(firstMock, 'Home', '/');
|
|
|
|
assertBatchValue(secondMock, 'Unlock Page', '/unlock');
|
|
|
|
assertBatchValue(thirdMock, 'Home', '/');
|
2022-03-15 17:17:48 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2023-07-19 21:56:31 +02:00
|
|
|
|
|
|
|
function assertBatchValue(mockRequest, assertedTitle, assertedPath) {
|
|
|
|
const [mockJson] = mockRequest.body.json.batch;
|
|
|
|
const { title, path } = mockJson.context.page;
|
|
|
|
assert.equal(title, assertedTitle);
|
|
|
|
assert.equal(path, assertedPath);
|
|
|
|
}
|