github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/ccl/src/views/clusterviz/containers/map/index.spec.tsx (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Licensed as a CockroachDB Enterprise file under the Cockroach Community
     4  // License (the "License"); you may not use this file except in compliance with
     5  // the License. You may obtain a copy of the License at
     6  //
     7  //     https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt
     8  
     9  import React from "react";
    10  import { assert } from "chai";
    11  import { shallow } from "enzyme";
    12  import { createMemoryHistory, History } from "history";
    13  import { match as Match } from "react-router-dom";
    14  
    15  import "src/enzymeInit";
    16  import { ClusterVisualization } from "./index";
    17  import { Breadcrumbs } from "./breadcrumbs";
    18  
    19  describe("ClusterVisualization", () => {
    20    describe("parse tiers params from URL path", () => {
    21      let history: History;
    22      let match: Match;
    23  
    24      beforeEach(() => {
    25        history = createMemoryHistory();
    26        match = {
    27          path: "/overview/map",
    28          params: {},
    29          url: "http://localhost/overview/map",
    30          isExact: true,
    31        };
    32      });
    33  
    34      // parsed tiers from params are not stored in state and passed directly to <Breadcrumbs />
    35      // component so we can validate the parsed result by checking Breadcrumbs props.
    36      it("parses tiers as empty array for /overview/map path", () => {
    37        const wrapper = shallow(
    38          <ClusterVisualization
    39            history={history}
    40            location={history.location}
    41            clusterDataError={null}
    42            enterpriseEnabled={true}
    43            licenseDataExists={true}
    44            match={match}
    45          />,
    46        );
    47        history.push("/overview/map");
    48        wrapper.update();
    49        assert.lengthOf(wrapper.find(Breadcrumbs).prop("tiers"), 0);
    50      });
    51  
    52      it("parses multiple tiers in path for `/overview/map/region=us-west/az=a` path", () => {
    53        history.push("/overview/map/region=us-west/az=a");
    54        const wrapper = shallow(
    55          <ClusterVisualization
    56            history={history}
    57            location={history.location}
    58            clusterDataError={null}
    59            enterpriseEnabled={true}
    60            licenseDataExists={true}
    61            match={match}
    62          />,
    63        );
    64  
    65        wrapper.update();
    66        const expectedTiers = [
    67          { key: "region", value: "us-west"},
    68          { key: "az", value: "a"},
    69        ];
    70        assert.deepEqual(wrapper.find(Breadcrumbs).prop("tiers"), expectedTiers);
    71      });
    72    });
    73  });