123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var App = require('app');
- var date = require('utils/date/date');
- require('models/host');
- require('views/main/charts/heatmap/heatmap_host');
- describe('App.MainChartsHeatmapHostView', function () {
- var view = App.MainChartsHeatmapHostView.create({
- templateName: '',
- controller: Em.Object.create(),
- content: {}
- });
- describe('#hostTemperatureStyle', function () {
- var testCases = [
- {
- title: 'if hostToSlotMap is null then hostTemperatureStyle should be empty',
- hostName: 'host',
- controller: Em.Object.create({
- hostToSlotMap: null,
- selectedMetric: {
- slotDefinitions: []
- }
- }),
- result: ''
- },
- {
- title: 'if hostName is null then hostTemperatureStyle should be empty',
- hostName: '',
- controller: Em.Object.create({
- hostToSlotMap: {},
- selectedMetric: {
- slotDefinitions: []
- }
- }),
- result: ''
- },
- {
- title: 'if slot less than 0 then hostTemperatureStyle should be empty',
- hostName: 'host1',
- controller: Em.Object.create({
- hostToSlotMap: {
- "host1": -1
- },
- selectedMetric: {
- slotDefinitions: []
- }
- }),
- result: ''
- },
- {
- title: 'if slotDefinitions is null then hostTemperatureStyle should be empty',
- hostName: 'host1',
- controller: Em.Object.create({
- hostToSlotMap: {
- "host1": 1
- },
- selectedMetric: {
- slotDefinitions: null
- }
- }),
- result: ''
- },
- {
- title: 'if slotDefinitions length not more than slot number then hostTemperatureStyle should be empty',
- hostName: 'host1',
- controller: Em.Object.create({
- hostToSlotMap: {
- "host1": 1
- },
- selectedMetric: {
- slotDefinitions: [{}]
- }
- }),
- result: ''
- },
- {
- title: 'if slotDefinitions correct then hostTemperatureStyle should be "style1"',
- hostName: 'host1',
- controller: Em.Object.create({
- hostToSlotMap: {
- "host1": 1
- },
- selectedMetric: {
- slotDefinitions: [
- Em.Object.create({cssStyle: 'style0'}),
- Em.Object.create({cssStyle: 'style1'})
- ]
- }
- }),
- result: 'style1'
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- view.set('content.hostName', test.hostName);
- view.set('controller', test.controller);
- expect(view.get('hostTemperatureStyle')).to.equal(test.result);
- });
- });
- });
- describe("#hostModelLink", function () {
- before(function () {
- sinon.stub(App.Host, 'find').returns(Em.Object.create({id: 'host1'}));
- });
- after(function () {
- App.Host.find.restore();
- });
- it("should return hostname", function () {
- view.set('content.hostName', 'host1');
- view.propertyDidChange('hostModelLink');
- expect(view.get('hostModelLink.id')).to.equal('host1');
- });
- });
- describe("#mouseEnter()", function () {
- beforeEach(function () {
- sinon.stub(view, 'getUsage').returns('usage');
- sinon.stub(view, 'getCpuUsage').returns('cpu_usage');
- sinon.stub(view, 'getHostComponents').returns(['c1']);
- sinon.stub(view, 'setMetric');
- sinon.stub(view, 'openDetailsBlock');
- this.mock = sinon.stub(App.MainChartsHeatmapHostDetailView, 'create');
- view.set('details', {});
- });
- afterEach(function () {
- view.getUsage.restore();
- view.getCpuUsage.restore();
- view.getHostComponents.restore();
- view.setMetric.restore();
- view.openDetailsBlock.restore();
- this.mock.restore();
- });
- it("set diskUsage", function () {
- var childView = Em.Object.create({
- details: {
- diskUsage: ''
- }
- });
- this.mock.returns(childView);
- view.set('content', {
- diskTotal: 100,
- diskFree: 50
- });
- view.mouseEnter();
- expect(childView.get('details.diskUsage')).to.equal('usage');
- expect(view.getUsage.calledWith(100, 50)).to.be.true;
- expect(view.setMetric.calledOnce).to.be.true;
- expect(view.openDetailsBlock.calledOnce).to.be.true;
- });
- it("set cpuUsage", function () {
- var childView = Em.Object.create({
- details: {
- cpuUsage: ''
- }
- });
- this.mock.returns(childView);
- view.set('content', {
- cpuSystem: 100,
- cpuUser: 50
- });
- view.mouseEnter();
- expect(childView.get('details.cpuUsage')).to.equal('cpu_usage');
- expect(view.getCpuUsage.calledWith(100, 50)).to.be.true;
- expect(view.setMetric.calledOnce).to.be.true;
- expect(view.openDetailsBlock.calledOnce).to.be.true;
- });
- it("set memoryUsage", function () {
- var childView = Em.Object.create({
- details: {
- memoryUsage: ''
- }
- });
- this.mock.returns(childView);
- view.set('content', {
- memTotal: 100,
- memFree: 50
- });
- view.mouseEnter();
- expect(childView.get('details.memoryUsage')).to.equal('usage');
- expect(view.getUsage.calledWith(100, 50)).to.be.true;
- expect(view.setMetric.calledOnce).to.be.true;
- expect(view.openDetailsBlock.calledOnce).to.be.true;
- });
- it("set hostComponents", function () {
- var childView = Em.Object.create({
- details: {
- hostComponents: ''
- }
- });
- this.mock.returns(childView);
- view.set('content', {
- hostComponents: ['host1']
- });
- view.mouseEnter();
- expect(childView.get('details.hostComponents')).to.eql(['c1']);
- expect(view.getHostComponents.calledWith(['host1'])).to.be.true;
- expect(view.setMetric.calledOnce).to.be.true;
- expect(view.openDetailsBlock.calledOnce).to.be.true;
- });
- it("set hostName", function () {
- var childView = Em.Object.create({
- details: {
- hostName: ''
- }
- });
- this.mock.returns(childView);
- view.set('content', {
- hostName: 'host1'
- });
- view.mouseEnter();
- expect(childView.get('details.hostName')).to.equal('host1');
- expect(view.setMetric.calledOnce).to.be.true;
- expect(view.openDetailsBlock.calledOnce).to.be.true;
- });
- });
- describe("#getUsage()", function () {
- var testCases = [
- {
- input: {
- total: null,
- free: null
- },
- expected: '0.0'
- },
- {
- input: {
- total: 100,
- free: null
- },
- expected: '0.0'
- },
- {
- input: {
- total: null,
- free: 50
- },
- expected: '0.0'
- },
- {
- input: {
- total: 0,
- free: 0
- },
- expected: '0.0'
- },
- {
- input: {
- total: 100,
- free: 50
- },
- expected: '50.0'
- }
- ];
- testCases.forEach(function (test) {
- it("total = " + test.input.total + "; free = " + test.input.free, function () {
- expect(view.getUsage(test.input.total, test.input.free)).to.equal(test.expected);
- });
- });
- });
- describe("#getCpuUsage()", function () {
- var testCases = [
- {
- input: {
- cpuSystem: null,
- cpuUser: null
- },
- expected: '0.0'
- },
- {
- input: {
- cpuSystem: 1.0,
- cpuUser: null
- },
- expected: '0.0'
- },
- {
- input: {
- cpuSystem: null,
- cpuUser: 1.0
- },
- expected: '0.0'
- },
- {
- input: {
- cpuSystem: 2.22,
- cpuUser: 1.0
- },
- expected: '3.2'
- }
- ];
- testCases.forEach(function (test) {
- it("cpuSystem = " + test.input.cpuSystem + "; cpuUser = " + test.input.cpuUser, function () {
- expect(view.getCpuUsage(test.input.cpuSystem, test.input.cpuUser)).to.equal(test.expected);
- });
- });
- });
- describe("#getHostComponents()", function () {
- beforeEach(function () {
- sinon.stub(App.format, 'role', function (name) {
- return name;
- });
- sinon.stub(App, 'get').returns('non-client');
- });
- afterEach(function () {
- App.format.role.restore();
- App.get.restore();
- });
- it("should return host-components", function () {
- expect(view.getHostComponents(['is-client', 'non-client', 'non-client'])).to.equal('non-client, non-client');
- });
- });
- describe("#setMetric()", function () {
- var viewObject;
- beforeEach(function () {
- sinon.stub(date, 'timingFormat').returns('time');
- viewObject = Em.Object.create({
- details: {}
- });
- });
- afterEach(function () {
- date.timingFormat.restore();
- });
- it("selected metric is null", function () {
- view.set('controller.selectedMetric', null);
- view.setMetric(viewObject, {});
- expect(viewObject.get('details')).to.be.empty;
- });
- it("metric name is null", function () {
- view.set('controller.selectedMetric', Em.Object.create({
- name: null,
- hostToValueMap: {}
- }));
- view.setMetric(viewObject, {});
- expect(viewObject.get('details')).to.be.empty;
- });
- it("host value is undefined", function () {
- view.set('controller.selectedMetric', Em.Object.create({
- name: 'm1',
- hostToValueMap: {}
- }));
- view.setMetric(viewObject, {hostName: 'host1'});
- expect(viewObject.get('details')).to.eql({
- metricName: 'm1',
- metricValue: Em.I18n.t('charts.heatmap.unknown')
- });
- });
- it("metric name is 'Garbage Collection Time'", function () {
- view.set('controller.selectedMetric', Em.Object.create({
- name: 'Garbage Collection Time',
- hostToValueMap: {
- host1: 'val'
- }
- }));
- view.setMetric(viewObject, {hostName: 'host1'});
- expect(viewObject.get('details')).to.eql({
- metricName: 'Garbage Collection Time',
- metricValue: 'time'
- });
- });
- it("metric value is NaN", function () {
- view.set('controller.selectedMetric', Em.Object.create({
- name: 'm1',
- hostToValueMap: {
- host1: 'val'
- }
- }));
- view.setMetric(viewObject, {hostName: 'host1'});
- expect(viewObject.get('details')).to.eql({
- metricName: 'm1',
- metricValue: Em.I18n.t('charts.heatmap.unknown')
- });
- });
- it("metric value is number", function () {
- view.set('controller.selectedMetric', Em.Object.create({
- name: 'm1',
- hostToValueMap: {
- host1: 10
- },
- units: 'mb'
- }));
- view.setMetric(viewObject, {hostName: 'host1'});
- expect(viewObject.get('details')).to.eql({
- metricName: 'm1',
- metricValue: '10mb'
- });
- });
- });
- });
|