|
| 1 | + |
| 2 | +describe('Component: pfTopology', function() { |
| 3 | + var $scope, $compile, $timeout; |
| 4 | + |
| 5 | + beforeEach(module( |
| 6 | + 'patternfly.charts' |
| 7 | + )); |
| 8 | + |
| 9 | + beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_) { |
| 10 | + $compile = _$compile_; |
| 11 | + $scope = _$rootScope_; |
| 12 | + $timeout = _$timeout_; |
| 13 | + })); |
| 14 | + |
| 15 | + var compileTopology = function (markup, scope) { |
| 16 | + var el = $compile(markup)(scope); |
| 17 | + scope.$digest(); |
| 18 | + return angular.element(el); |
| 19 | + }; |
| 20 | + |
| 21 | + beforeEach(function() { |
| 22 | + var index = 0; |
| 23 | + var datasets = []; |
| 24 | + |
| 25 | + function sink(dataset) { |
| 26 | + datasets.push(dataset); |
| 27 | + } |
| 28 | + |
| 29 | + sink({ |
| 30 | + "items": { |
| 31 | + "ContainerManager10r20": { |
| 32 | + "name": "ocp-master.example.com", |
| 33 | + "kind": "ContainerManager", |
| 34 | + "miq_id": 10000000000020, |
| 35 | + "status": "Valid", |
| 36 | + "display_kind": "OpenshiftEnterprise" |
| 37 | + }, |
| 38 | + "ContainerNode10r14": { |
| 39 | + "name": "ocp-master.example.com", |
| 40 | + "kind": "ContainerNode", |
| 41 | + "miq_id": 10000000000014, |
| 42 | + "status": "Ready", |
| 43 | + "display_kind": "Node" |
| 44 | + }, |
| 45 | + "ContainerGroup10r240": { |
| 46 | + "name": "docker-registry-2-vrguw", |
| 47 | + "kind": "ContainerGroup", |
| 48 | + "miq_id": 10000000000240, |
| 49 | + "status": "Running", |
| 50 | + "display_kind": "Pod" |
| 51 | + }, |
| 52 | + "Container10r235": { |
| 53 | + "name": "registry", |
| 54 | + "kind": "Container", |
| 55 | + "miq_id": 10000000000235, |
| 56 | + "status": "Running", |
| 57 | + "display_kind": "Container" |
| 58 | + }, |
| 59 | + "ContainerReplicator10r56": { |
| 60 | + "name": "docker-registry-2", |
| 61 | + "kind": "ContainerReplicator", |
| 62 | + "miq_id": 10000000000056, |
| 63 | + "status": "OK", |
| 64 | + "display_kind": "Replicator" |
| 65 | + }, |
| 66 | + "ContainerService10r61": { |
| 67 | + "name": "docker-registry", |
| 68 | + "kind": "ContainerService", |
| 69 | + "miq_id": 10000000000061, |
| 70 | + "status": "Unknown", |
| 71 | + "display_kind": "Service" |
| 72 | + }, |
| 73 | + }, |
| 74 | + "relations": [ |
| 75 | + { |
| 76 | + "source": "ContainerManager10r20", |
| 77 | + "target": "ContainerNode10r14" |
| 78 | + }, { |
| 79 | + "source": "ContainerNode10r14", |
| 80 | + "target": "ContainerGroup10r240" |
| 81 | + }, { |
| 82 | + "source": "ContainerGroup10r240", |
| 83 | + "target": "Container10r235" |
| 84 | + }, { |
| 85 | + "source": "ContainerGroup10r240", |
| 86 | + "target": "ContainerReplicator10r56" |
| 87 | + }, { |
| 88 | + "source": "ContainerGroup10r240", |
| 89 | + "target": "ContainerService10r61" |
| 90 | + }, { |
| 91 | + "source": "ContainerNode10r14", |
| 92 | + "target": "ContainerGroup10r241" |
| 93 | + } |
| 94 | + ], |
| 95 | + "icons": { |
| 96 | + "AvailabilityZone": { |
| 97 | + "type": "glyph", |
| 98 | + "icon": "", |
| 99 | + "fontfamily": "PatternFlyIcons-webfont" |
| 100 | + }, |
| 101 | + "ContainerReplicator": { |
| 102 | + "type": "glyph", |
| 103 | + "icon": "", |
| 104 | + "fontfamily": "PatternFlyIcons-webfont" |
| 105 | + }, |
| 106 | + "ContainerGroup": { |
| 107 | + "type": "glyph", |
| 108 | + "icon": "", |
| 109 | + "fontfamily": "FontAwesome" |
| 110 | + }, |
| 111 | + "ContainerNode": { |
| 112 | + "type": "glyph", |
| 113 | + "icon": "", |
| 114 | + "fontfamily": "PatternFlyIcons-webfont" |
| 115 | + }, |
| 116 | + "ContainerService": { |
| 117 | + "type": "glyph", |
| 118 | + "icon": "", |
| 119 | + "fontfamily": "PatternFlyIcons-webfont" |
| 120 | + }, |
| 121 | + "ContainerRoute": { |
| 122 | + "type": "glyph", |
| 123 | + "icon": "", |
| 124 | + "fontfamily": "PatternFlyIcons-webfont" |
| 125 | + }, |
| 126 | + "Container": { |
| 127 | + "type": "glyph", |
| 128 | + "icon": "", |
| 129 | + "fontfamily": "FontAwesome" |
| 130 | + }, |
| 131 | + "Host": { |
| 132 | + "type": "glyph", |
| 133 | + "icon": "", |
| 134 | + "fontfamily": "PatternFlyIcons-webfont" |
| 135 | + }, |
| 136 | + "Vm": { |
| 137 | + "type": "glyph", |
| 138 | + "icon": "", |
| 139 | + "fontfamily": "PatternFlyIcons-webfont" |
| 140 | + }, |
| 141 | + "ContainerManager": { |
| 142 | + "type": "glyph", |
| 143 | + "icon": "", |
| 144 | + "fontfamily": "PatternFlyIcons-webfont" |
| 145 | + } |
| 146 | + } |
| 147 | + }); |
| 148 | + |
| 149 | + $scope.data = datasets[index]; |
| 150 | + |
| 151 | + var nodeKinds = { |
| 152 | + "ContainerReplicator": true, |
| 153 | + "ContainerGroup": true, |
| 154 | + "Container": true, |
| 155 | + "ContainerNode": true, |
| 156 | + "ContainerService": true, |
| 157 | + "Host": true, |
| 158 | + "Vm": true, |
| 159 | + "ContainerRoute": true, |
| 160 | + "ContainerManager": true |
| 161 | + }; |
| 162 | + |
| 163 | + $scope.kinds = nodeKinds; |
| 164 | + |
| 165 | + var icons = $scope.data.icons; |
| 166 | + $scope.nodes = {}; |
| 167 | + for(var kind in nodeKinds) { |
| 168 | + var icon = icons[kind]; |
| 169 | + $scope.nodes[kind] = { |
| 170 | + "name": kind, |
| 171 | + "enabled": nodeKinds[kind], |
| 172 | + "radius": 16, |
| 173 | + "textX": 0, |
| 174 | + "textY": 5, |
| 175 | + "height": 18, |
| 176 | + "width": 18, |
| 177 | + "icon": icon.icon, |
| 178 | + "fontFamily": icon.fontfamily |
| 179 | + }; |
| 180 | + } |
| 181 | + |
| 182 | + // Individual values can also be set for specific icons |
| 183 | + $scope.nodes.ContainerService.textY = 9; |
| 184 | + $scope.nodes.ContainerService.textX = -1; |
| 185 | + |
| 186 | + $scope.itemSelected = function (item) { |
| 187 | + var text = ""; |
| 188 | + if (item) { |
| 189 | + text = "Selected: " + item.name; |
| 190 | + } |
| 191 | + angular.element(document.getElementById("selected")).text(text); |
| 192 | + }; |
| 193 | + |
| 194 | + $scope.tooltip = function (node) { |
| 195 | + var status = [ |
| 196 | + 'Name: ' + node.item.name, |
| 197 | + 'Type: ' + node.item.kind, |
| 198 | + 'Status: ' + node.item.status |
| 199 | + ]; |
| 200 | + return status; |
| 201 | + }; |
| 202 | + }); |
| 203 | + |
| 204 | + afterEach(function() { |
| 205 | + d3.selectAll('pf-topology').remove(); |
| 206 | + }); |
| 207 | + |
| 208 | + it("should create an svg internally", function() { |
| 209 | + var element = compileTopology('<div><pf-topology items="data.items" relations="data.relations" kinds="kinds" icons="data.icons" nodes="nodes" item-selected="itemSelected(item)" search-text="searchText" show-labels="showLabels" tooltip-function="tooltip(node)"></pf-topology></div>', $scope); |
| 210 | + expect(element.find('svg')).not.toBe(undefined); |
| 211 | + }); |
| 212 | + |
| 213 | + it("should generate 6 nodes", function () { |
| 214 | + var elementDiv = '<pf-topology style="display: block; width: 200px; height: 200px;" items="data.items" relations="data.relations" kinds="kinds" icons="data.icons" nodes="nodes" item-selected="itemSelected(item)" search-text="searchText" show-labels="showLabels" tooltip-function="tooltip(node)"></pf-topology>'; |
| 215 | + var body = angular.element(document.body); |
| 216 | + body.append(elementDiv); |
| 217 | + compileTopology(body, $scope); |
| 218 | + var topologyElement = body.find('pf-topology svg g'); |
| 219 | + expect(topologyElement.length).toBe(6); |
| 220 | + }); |
| 221 | + |
| 222 | + it("should generate 5 lines", function () { |
| 223 | + var elementDiv = '<pf-topology style="display: block; width: 200px; height: 200px;" items="data.items" relations="data.relations" kinds="kinds" icons="data.icons" nodes="nodes" item-selected="itemSelected(item)" search-text="searchText" show-labels="showLabels" tooltip-function="tooltip(node)"></pf-topology>'; |
| 224 | + var body = angular.element(document.body); |
| 225 | + body.append(elementDiv); |
| 226 | + compileTopology(body, $scope); |
| 227 | + var topologyElement = body.find('pf-topology svg line'); |
| 228 | + expect(topologyElement.length).toBe(5); |
| 229 | + }); |
| 230 | + |
| 231 | + it("should hide/show the text labels", function () { |
| 232 | + var elementDiv = '<pf-topology style="display: block; width: 200px; height: 200px;" items="data.items" relations="data.relations" kinds="kinds" icons="data.icons" nodes="nodes" item-selected="itemSelected(item)" search-text="searchText" show-labels="showLabels" tooltip-function="tooltip(node)"></pf-topology>'; |
| 233 | + var body = angular.element(document.body); |
| 234 | + body.append(elementDiv); |
| 235 | + compileTopology(body, $scope); |
| 236 | + var topologyElement = body.find('pf-topology svg'); |
| 237 | + expect(topologyElement.find('text.visible').length).toBe(0); |
| 238 | + $scope.showLabels = true; |
| 239 | + $scope.$digest(); |
| 240 | + expect(topologyElement.find('text.visible').length).toBe(6); |
| 241 | + }); |
| 242 | + |
| 243 | + it("should update view on search", function () { |
| 244 | + var elementDiv = '<pf-topology style="display: block; width: 200px; height: 200px;" items="data.items" relations="data.relations" kinds="kinds" icons="data.icons" nodes="nodes" item-selected="itemSelected(item)" search-text="searchText" show-labels="showLabels" tooltip-function="tooltip(node)"></pf-topology>'; |
| 245 | + var body = angular.element(document.body); |
| 246 | + body.append(elementDiv); |
| 247 | + compileTopology(body, $scope); |
| 248 | + var disabledNodes = body.find('g[style="opacity: 0.2;"]') |
| 249 | + expect(disabledNodes.length).toBe(0); |
| 250 | + $scope.searchText = 'vrguw'; |
| 251 | + $scope.$digest(); |
| 252 | + disabledNodes = body.find('g[style="opacity: 0.2;"]') |
| 253 | + expect(disabledNodes.length).toBe(5); |
| 254 | + }); |
| 255 | +}); |
0 commit comments