blob: 1876a27678409e11253faa6119dacd37810051f5 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {trackPageChange} from './ga-helpers.js';
6
7describe('trackPageChange', () => {
8 beforeEach(() => {
9 global.ga = sinon.spy();
10 });
11
12 afterEach(() => {
13 global.ga.resetHistory();
14 });
15
16 it('sets page title', () => {
17 trackPageChange('list');
18 sinon.assert.calledWith(global.ga, 'set', 'title', 'Issue list');
19 });
20
21 it('sets user page title', () => {
22 trackPageChange('user-anything');
23 sinon.assert.calledWith(global.ga, 'set', 'title', 'A user page');
24 });
25
26 it('sets user location', () => {
27 trackPageChange('user-anything');
28 sinon.assert.calledWith(global.ga, 'set', 'location', 'A user page URL');
29 });
30
31 it('defaults dimension1', () => {
32 trackPageChange('list');
33 sinon.assert.calledWith(global.ga, 'set', 'dimension1', 'Not logged in');
34 });
35
36 it('sets dimension1 based on userDisplayName', () => {
37 trackPageChange('list', 'somebody');
38 sinon.assert.calledWith(global.ga, 'set', 'dimension1', 'Logged in');
39 });
40
41 it('sends pageview', () => {
42 trackPageChange('list');
43 sinon.assert.calledWith(global.ga, 'send', 'pageview');
44 });
45});