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

     1  // Copyright 2018 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 { assert } from "chai";
    10  
    11  import { LocalityTree } from "src/redux/localities";
    12  import { LocationTree } from "src/redux/locations";
    13  import { renderAsMap } from "./layout";
    14  
    15  const locationTree: LocationTree = {
    16    zone: {
    17      "us-west": {
    18        latitude: 12.3,
    19        longitude: 45.6,
    20        locality_key: "zone",
    21        locality_value: "us-west",
    22      },
    23    },
    24  };
    25  
    26  function shouldRenderAsCircle(locality: LocalityTree) {
    27    assert.equal(
    28      renderAsMap(locationTree, locality),
    29      false,
    30      `${JSON.stringify(locationTree)} should render as a circle, but will render as a map`,
    31    );
    32  }
    33  
    34  function shouldRenderAsMap(locality: LocalityTree) {
    35    assert.equal(
    36      renderAsMap(locationTree, locality),
    37      true,
    38      `${JSON.stringify(locationTree)} should render as a map, but will render as a circle`,
    39    );
    40  }
    41  
    42  describe("renderAsMap", function() {
    43    describe("for locality with child nodes", function() {
    44      it("returns false", function() {
    45        const locality: LocalityTree = {
    46          tiers: [],
    47          localities: {
    48            zone: {
    49              "us-west": {
    50                tiers: [{ key: "zone", value: "us-west" }],
    51                localities: {},
    52                nodes: [
    53                  {
    54                    desc: {
    55                      node_id: 1,
    56                    },
    57                  },
    58                ],
    59              },
    60            },
    61          },
    62          nodes: [
    63            {
    64              desc: {
    65                node_id: 1,
    66              },
    67            },
    68          ],
    69        };
    70  
    71        shouldRenderAsCircle(locality);
    72      });
    73    });
    74  
    75    describe("when child locality does not have location", function() {
    76      it("returns false", function() {
    77        const locality: LocalityTree = {
    78          tiers: [],
    79          localities: {
    80            zone: {
    81              "us-east": {
    82                tiers: [{ key: "zone", value: "us-east" }],
    83                localities: {},
    84                nodes: [
    85                  {
    86                    desc: {
    87                      node_id: 1,
    88                    },
    89                  },
    90                ],
    91              },
    92            },
    93          },
    94          nodes: [],
    95        };
    96  
    97        shouldRenderAsCircle(locality);
    98      });
    99    });
   100  
   101    describe("when child locality has location", function() {
   102      it("returns true", function() {
   103        const locality: LocalityTree = {
   104          tiers: [],
   105          localities: {
   106            zone: {
   107              "us-west": {
   108                tiers: [{ key: "zone", value: "us-west" }],
   109                localities: {},
   110                nodes: [
   111                  {
   112                    desc: {
   113                      node_id: 1,
   114                    },
   115                  },
   116                ],
   117              },
   118            },
   119          },
   120          nodes: [],
   121        };
   122  
   123        shouldRenderAsMap(locality);
   124      });
   125    });
   126  });