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

     1  // Copyright 2019 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 { assert } from "chai";
    12  import {
    13    queryToString,
    14    queryByName,
    15  } from "./query";
    16  import { Location } from "history";
    17  
    18  const location: Location = {
    19    pathname: "/debug/chart",
    20    search: "?charts=%5B%7B%22metrics%22%3A%5B%7B%22downsampler%22%3A1%2C%22aggregator%22%3A2%2C%22derivative%22%3A0%2C%22perNode%22%3Afalse%2C%22source%22%3A%22%22%2C%22metric%22%3A%22cr.node.build.timestamp%22%7D%2C%7B%22downsampler%22%3A1%2C%22aggregator%22%3A2%2C%22derivative%22%3A0%2C%22perNode%22%3Afalse%2C%22source%22%3A%22%22%2C%22metric%22%3A%22cr.node.changefeed.poll_request_nanos-p50%22%7D%5D%2C%22axisUnits%22%3A0%7D%5D&start=1581478532&end=1581500132",
    21    hash: "",
    22    state: null,
    23    key: null,
    24  };
    25  
    26  describe("Query utils", () => {
    27    describe("queryToString", () => {
    28      it("make query to string", () => {
    29        assert.equal(queryToString({ a: "test" }), "a=test");
    30        assert.equal(queryToString({ a: "test", b: "test" }), "a=test&b=test");
    31        assert.equal(queryToString({ a: undefined }), "a=undefined");
    32      });
    33    });
    34    describe("queryByName", () => {
    35      it("get key from query", () => {
    36        assert.equal(queryByName(location, "start"), "1581478532");
    37        assert.equal(queryByName(location, "test"), null);
    38        assert.equal(queryByName(location, undefined), null);
    39      });
    40    });
    41  });