github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/util/analytics/trackStatementDetailsSubnavSelection.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 } from "lodash";
    12  import { assert } from "chai";
    13  import { createSandbox } from "sinon";
    14  import { track } from "./trackStatementDetailsSubnavSelection";
    15  
    16  const sandbox = createSandbox();
    17  
    18  describe("trackSubnavSelection", () => {
    19    const subNavKey = "subnav-test";
    20  
    21    afterEach(() => {
    22      sandbox.reset();
    23    });
    24  
    25    it("should only call track once", () => {
    26      const spy = sandbox.spy();
    27      track(spy)(subNavKey);
    28      assert.isTrue(spy.calledOnce);
    29    });
    30  
    31    it("should send a track call with the correct event", () => {
    32      const spy = sandbox.spy();
    33      const expected = "SubNavigation Selection";
    34  
    35      track(spy)(subNavKey);
    36  
    37      const sent = spy.getCall(0).args[0];
    38      const event = get(sent, "event");
    39  
    40      assert.isTrue(event === expected);
    41    });
    42  
    43    it("send the correct payload", () => {
    44      const spy = sandbox.spy();
    45  
    46      track(spy)(subNavKey);
    47  
    48      const sent = spy.getCall(0).args[0];
    49      const selection = get(sent, "properties.selection");
    50  
    51      assert.isTrue(selection === subNavKey);
    52    });
    53  });