1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 03:36:18 +02:00
metamask-extension/test/e2e/metrics.spec.js
Mark Stacey cc1161a52a
Add metrics e2e test (#9784)
An e2e test has been added that uses the new mock Segment server to
verify that the three initial page metric events are sent correctly.

Using the mock Segment server requires a special build with this mock
Segment server hostname embedded, so a distinct job for building and
running this test was required. As such, it was left out of the
`run-all.sh` script.
2020-12-01 17:54:56 -03:30

58 lines
2.0 KiB
JavaScript

const { strict: assert } = require('assert')
const { By, Key } = require('selenium-webdriver')
const { withFixtures } = require('./helpers')
/**
* WARNING: These tests must be run using a build created with `yarn build:test:metrics`, so that it has
* the correct Segment host and write keys set. Otherwise this test will fail.
*/
describe('Segment metrics', function () {
this.timeout(0)
it('should send first three Page metric events upon fullscreen page load', async function () {
const ganacheOptions = {
accounts: [
{
secretKey:
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
balance: 25000000000000000000,
},
],
}
await withFixtures(
{
fixtures: 'metrics-enabled',
ganacheOptions,
title: this.test.title,
mockSegment: true,
},
async ({ driver, segmentSpy }) => {
const passwordField = await driver.findElement(By.css('#password'))
await passwordField.sendKeys('correct horse battery staple')
await passwordField.sendKeys(Key.ENTER)
// find arbitary element to ensure Home page has loaded
await driver.findElement(By.css('[data-testid="eth-overview-send"]'))
assert.ok(segmentSpy.called, 'Segment should receive metrics')
assert.ok(
segmentSpy.callCount >= 3,
'At least 3 segment events should be sent',
)
const firstSegmentEvent = segmentSpy.getCall(0).args[0]
assert.equal(firstSegmentEvent.name, 'Home')
assert.equal(firstSegmentEvent.context.page.path, '/')
const secondSegmentEvent = segmentSpy.getCall(1).args[0]
assert.equal(secondSegmentEvent.name, 'Unlock Page')
assert.equal(secondSegmentEvent.context.page.path, '/unlock')
const thirdSegmentEvent = segmentSpy.getCall(2).args[0]
assert.equal(thirdSegmentEvent.name, 'Home')
assert.equal(thirdSegmentEvent.context.page.path, '/')
},
)
})
})