github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/util/analytics/trackPaginate.spec.ts (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  import { get, isString, isNumber } from "lodash";
    12  import { assert } from "chai";
    13  import { createSandbox } from "sinon";
    14  import { track } from "./trackPaginate";
    15  
    16  const sandbox = createSandbox();
    17  
    18  describe("trackPaginate", () => {
    19    const testPage = 5;
    20  
    21    afterEach(() => {
    22      sandbox.reset();
    23    });
    24  
    25    it("should only call track once", () => {
    26      const spy = sandbox.spy();
    27      track(spy)(testPage);
    28      assert.isTrue(spy.calledOnce);
    29    });
    30  
    31    it("should send the right event", () => {
    32      const spy = sandbox.spy();
    33      const expected = "Paginate";
    34  
    35      track(spy)(testPage);
    36  
    37      const sent = spy.getCall(0).args[0];
    38      const event = get(sent, "event");
    39  
    40      assert.isTrue(isString(event));
    41      assert.isTrue(event === expected);
    42    });
    43  
    44    it("should send the correct payload", () => {
    45      const spy = sandbox.spy();
    46  
    47      track(spy)(testPage);
    48  
    49      const sent = spy.getCall(0).args[0];
    50      const selectedPage = get(sent, "properties.selectedPage");
    51  
    52      assert.isTrue(isNumber(selectedPage));
    53      assert.isTrue(selectedPage === testPage);
    54    });
    55  });