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