github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/util/parseSplatParams.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 { assert } from "chai";
    12  import { createMemoryHistory, History } from "history";
    13  import { match as Match } from "react-router-dom";
    14  import { parseSplatParams } from "./parseSplatParams";
    15  
    16  describe("parseSplatParams", () => {
    17    let history: History;
    18    let match: Match;
    19  
    20    beforeEach(() => {
    21      history = createMemoryHistory({initialEntries: ["/"]});
    22      match = {
    23        path: "/",
    24        params: {},
    25        url: "http://localhost/",
    26        isExact: true,
    27      };
    28    });
    29  
    30    it("returns remaining part of location path", () => {
    31      history.push("/overview/map/region=us-west/zone=a");
    32      match.path = "/overview/map/";
    33  
    34      assert.equal(parseSplatParams(match, history.location), "region=us-west/zone=a");
    35    });
    36  
    37    it("trims out leading / from remaining path", () => {
    38      history.push("/overview/map/region=us-west/zone=a");
    39      match.path = "/overview/map";
    40  
    41      assert.equal(parseSplatParams(match, history.location), "region=us-west/zone=a");
    42    });
    43  
    44    it("returns empty string if path is fully matched", () => {
    45      history.push("/overview/map");
    46      match.path = "/overview/map";
    47  
    48      assert.equal(parseSplatParams(match, history.location), "");
    49    });
    50  });