diff --git a/ui/app/components/topo-viz.js b/ui/app/components/topo-viz.js
index eea9b2c84f9..6b9e98e7228 100644
--- a/ui/app/components/topo-viz.js
+++ b/ui/app/components/topo-viz.js
@@ -2,7 +2,6 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action, set } from '@ember/object';
import { run } from '@ember/runloop';
-import { task } from 'ember-concurrency';
import { scaleLinear } from 'd3-scale';
import { extent, deviation, mean } from 'd3-array';
import { line, curveBasis } from 'd3-shape';
diff --git a/ui/app/components/topo-viz/datacenter.js b/ui/app/components/topo-viz/datacenter.js
index 7ebe7f66b89..0750fc1eb08 100644
--- a/ui/app/components/topo-viz/datacenter.js
+++ b/ui/app/components/topo-viz/datacenter.js
@@ -1,10 +1,12 @@
import Component from '@glimmer/component';
-import { tracked } from '@glimmer/tracking';
-import { action } from '@ember/object';
export default class TopoVizDatacenter extends Component {
- @tracked scheduledAllocations = [];
- @tracked aggregatedNodeResources = { cpu: 0, memory: 0 };
+ get scheduledAllocations() {
+ return this.args.datacenter.nodes.reduce(
+ (all, node) => all.concat(node.allocations.filterBy('allocation.isScheduled')),
+ []
+ );
+ }
get aggregatedAllocationResources() {
return this.scheduledAllocations.reduce(
@@ -17,14 +19,8 @@ export default class TopoVizDatacenter extends Component {
);
}
- @action
- loadAllocations() {
- this.scheduledAllocations = this.args.datacenter.nodes.reduce(
- (all, node) => all.concat(node.allocations.filterBy('allocation.isScheduled')),
- []
- );
-
- this.aggregatedNodeResources = this.args.datacenter.nodes.reduce(
+ get aggregatedNodeResources() {
+ return this.args.datacenter.nodes.reduce(
(totals, node) => {
totals.cpu += node.cpu;
totals.memory += node.memory;
@@ -32,7 +28,5 @@ export default class TopoVizDatacenter extends Component {
},
{ cpu: 0, memory: 0 }
);
-
- this.args.onLoad && this.args.onLoad();
}
}
diff --git a/ui/app/templates/components/topo-viz.hbs b/ui/app/templates/components/topo-viz.hbs
index 1722842d546..7a367a3a5c8 100644
--- a/ui/app/templates/components/topo-viz.hbs
+++ b/ui/app/templates/components/topo-viz.hbs
@@ -2,15 +2,14 @@
{{#if @node.node.isDraining}}
diff --git a/ui/tests/integration/components/topo-viz/datacenter-test.js b/ui/tests/integration/components/topo-viz/datacenter-test.js
new file mode 100644
index 00000000000..3480aae8814
--- /dev/null
+++ b/ui/tests/integration/components/topo-viz/datacenter-test.js
@@ -0,0 +1,160 @@
+import { find } from '@ember/test-helpers';
+import { module, test } from 'qunit';
+import { setupRenderingTest } from 'ember-qunit';
+import hbs from 'htmlbars-inline-precompile';
+import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
+import { create } from 'ember-cli-page-object';
+import sinon from 'sinon';
+import faker from 'nomad-ui/mirage/faker';
+import topoVizDatacenterPageObject from 'nomad-ui/tests/pages/components/topo-viz/datacenter';
+
+const TopoVizDatacenter = create(topoVizDatacenterPageObject());
+
+const nodeGen = (name, datacenter, memory, cpu, allocations = []) => ({
+ datacenter,
+ memory,
+ cpu,
+ node: { name },
+ allocations: allocations.map(alloc => ({
+ memory: alloc.memory,
+ cpu: alloc.cpu,
+ memoryPercent: alloc.memory / memory,
+ cpuPercent: alloc.cpu / cpu,
+ allocation: {
+ id: faker.random.uuid(),
+ isScheduled: true,
+ },
+ })),
+});
+
+// Used in Array#reduce to sum by a property common to an array of objects
+const sumBy = prop => (sum, obj) => (sum += obj[prop]);
+
+module('Integration | Component | TopoViz::Datacenter', function(hooks) {
+ setupRenderingTest(hooks);
+
+ const commonProps = props => ({
+ isSingleColumn: true,
+ isDense: false,
+ heightScale: () => 50,
+ onAllocationSelect: sinon.spy(),
+ onNodeSelect: sinon.spy(),
+ ...props,
+ });
+
+ const commonTemplate = hbs`
+