Repository: ambari Updated Branches: refs/heads/trunk 109682544 -> 221ae2f23
AMBARI-5805. Unit test for steps sub-views. (onechiporenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/221ae2f2 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/221ae2f2 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/221ae2f2 Branch: refs/heads/trunk Commit: 221ae2f2350e275521837ed76e2e5edb51e6b467 Parents: 1096825 Author: Oleg Nechiporenko <[email protected]> Authored: Mon May 19 15:07:10 2014 +0300 Committer: Oleg Nechiporenko <[email protected]> Committed: Mon May 19 15:07:10 2014 +0300 ---------------------------------------------------------------------- ambari-web/app/assets/test/tests.js | 1 + .../views/wizard/step3/hostLogPopupBody_view.js | 20 +- .../wizard/step3/hostWarningPopupBody_view.js | 3 +- .../views/wizard/step9/hostLogPopupBody_view.js | 2 +- .../test/controllers/wizard/step8_test.js | 2 +- .../wizard/step3/hostLogPopupBody_view_test.js | 18 ++ .../step3/hostWarningPopupBody_view_test.js | 199 +++++++++++++++++++ .../wizard/step9/hostLogPopupBody_view_test.js | 114 +++++++++++ 8 files changed, 348 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/221ae2f2/ambari-web/app/assets/test/tests.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js index d079252..ec8650e 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -157,6 +157,7 @@ require('test/views/main/charts/heatmap/heatmap_rack_test'); require('test/views/main/service/info/config_test'); require('test/views/common/configs/services_config_test'); require('test/views/wizard/step3/hostLogPopupBody_view_test'); +require('test/views/wizard/step3/hostWarningPopupBody_view_test'); require('test/views/wizard/step3/hostWarningPopupFooter_view_test'); require('test/views/wizard/step0_view_test'); require('test/views/wizard/step1_view_test'); http://git-wip-us.apache.org/repos/asf/ambari/blob/221ae2f2/ambari-web/app/views/wizard/step3/hostLogPopupBody_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/wizard/step3/hostLogPopupBody_view.js b/ambari-web/app/views/wizard/step3/hostLogPopupBody_view.js index 0cca32d..c3e0bed 100644 --- a/ambari-web/app/views/wizard/step3/hostLogPopupBody_view.js +++ b/ambari-web/app/views/wizard/step3/hostLogPopupBody_view.js @@ -43,11 +43,12 @@ App.WizardStep3HostLogPopupBody = Em.View.extend({ textArea: Em.TextArea.extend({ didInsertElement: function () { - var element = $(this.get('element')); - element.width($(this.get('parentView').get('element')).width() - 10); - element.height($(this.get('parentView').get('element')).height()); - element.select(); - element.css('resize', 'none'); + /* istanbul ignore next: simple DOM manipulations */ + $(this.get('element')) + .width($(this.get('parentView').get('element')).width() - 10) + .height($(this.get('parentView').get('element')).height()) + .select() + .css('resize', 'none'); }, /** @@ -73,15 +74,18 @@ App.WizardStep3HostLogPopupBody = Em.View.extend({ $(this).text(self.get('isTextArea') ? Em.I18n.t('installer.step3.hostLogPopup.highlight') : Em.I18n.t('installer.step3.hostLogPopup.copy')); self.set('isTextArea', !self.get('isTextArea')); }); - $(this.get('element')).find('.content-area').mouseenter( + /* istanbul ignore next: difficult to test */ + $(this.get('element')).find('.content-area') + .mouseenter( function () { $(this).css('border', '1px solid #dcdcdc'); button.css('visibility', 'visible'); - }).mouseleave( + }) + .mouseleave( function () { $(this).css('border', 'none'); button.css('visibility', 'hidden'); - }) + }); } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/221ae2f2/ambari-web/app/views/wizard/step3/hostWarningPopupBody_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/wizard/step3/hostWarningPopupBody_view.js b/ambari-web/app/views/wizard/step3/hostWarningPopupBody_view.js index d28fcf4..9b42cfe 100644 --- a/ambari-web/app/views/wizard/step3/hostWarningPopupBody_view.js +++ b/ambari-web/app/views/wizard/step3/hostWarningPopupBody_view.js @@ -319,10 +319,11 @@ App.WizardStep3HostWarningPopupBody = Em.View.extend({ * Show popup with selected hostnames * @param {object} hosts * @method showHostsPopup + * @return {App.ModalPopup} */ showHostsPopup: function (hosts) { $('.tooltip').hide(); - App.ModalPopup.show({ + return App.ModalPopup.show({ header: Em.I18n.t('installer.step3.hostWarningsPopup.allHosts'), bodyClass: Em.View.extend({ hosts: hosts.context, http://git-wip-us.apache.org/repos/asf/ambari/blob/221ae2f2/ambari-web/app/views/wizard/step9/hostLogPopupBody_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/wizard/step9/hostLogPopupBody_view.js b/ambari-web/app/views/wizard/step9/hostLogPopupBody_view.js index dd05b59..f0c0785 100644 --- a/ambari-web/app/views/wizard/step9/hostLogPopupBody_view.js +++ b/ambari-web/app/views/wizard/step9/hostLogPopupBody_view.js @@ -148,7 +148,7 @@ App.WizardStep9HostLogPopupBodyView = Em.View.extend({ } else if (taskInfo.get('status') == 'in_progress') { taskInfo.set('icon', 'icon-cogs'); } else if (taskInfo.get('status') == 'completed') { - taskInfo.set('icon', ' icon-ok'); + taskInfo.set('icon', 'icon-ok'); } else if (taskInfo.get('status') == 'failed') { taskInfo.set('icon', 'icon-exclamation-sign'); } else if (taskInfo.get('status') == 'aborted') { http://git-wip-us.apache.org/repos/asf/ambari/blob/221ae2f2/ambari-web/test/controllers/wizard/step8_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/wizard/step8_test.js b/ambari-web/test/controllers/wizard/step8_test.js index 057c69b..c2eea7a 100644 --- a/ambari-web/test/controllers/wizard/step8_test.js +++ b/ambari-web/test/controllers/wizard/step8_test.js @@ -518,7 +518,7 @@ describe('App.WizardStep8Controller', function () { ], removed: Em.A(['hive_ambari_host', 'hive_ambari_database', 'hive_existing_oracle_host', 'hive_existing_oracle_database', 'hive_existing_mysql_host', 'hive_existing_mysql_database']), - hive_database_type: 'postgresql', + hive_database_type: 'postgres', m: 'hive_database: Existing PostgreSQL Database', host: 'h1' }, http://git-wip-us.apache.org/repos/asf/ambari/blob/221ae2f2/ambari-web/test/views/wizard/step3/hostLogPopupBody_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/wizard/step3/hostLogPopupBody_view_test.js b/ambari-web/test/views/wizard/step3/hostLogPopupBody_view_test.js index 934c3f8..2275a6c 100644 --- a/ambari-web/test/views/wizard/step3/hostLogPopupBody_view_test.js +++ b/ambari-web/test/views/wizard/step3/hostLogPopupBody_view_test.js @@ -29,6 +29,24 @@ describe('App.WizardStep3HostLogPopupBody', function() { }); }); + describe('#textArea', function() { + + var v; + + beforeEach(function() { + v = view.get('textArea').create(); + }); + + describe('#value', function() { + it('should be equal to content', function() { + var c = 'Relax, you are doing fine'; + v.set('content', c); + expect(v.get('value')).to.equal(c); + }); + }); + + }); + describe('#bootLog', function() { it('should be equal to parentView.host.bootLog', function() { var log = 'i wanna play a game'; http://git-wip-us.apache.org/repos/asf/ambari/blob/221ae2f2/ambari-web/test/views/wizard/step3/hostWarningPopupBody_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/wizard/step3/hostWarningPopupBody_view_test.js b/ambari-web/test/views/wizard/step3/hostWarningPopupBody_view_test.js new file mode 100644 index 0000000..840ce97 --- /dev/null +++ b/ambari-web/test/views/wizard/step3/hostWarningPopupBody_view_test.js @@ -0,0 +1,199 @@ +/** + * 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 lazyloading = require('utils/lazy_loading'); +require('views/wizard/step3/hostWarningPopupBody_view'); +var view; + +describe('App.WizardStep3HostWarningPopupBody', function() { + + beforeEach(function() { + view = App.WizardStep3HostWarningPopupBody.create({ + didInsertElement: Em.K, + $: function() { + return Em.Object.create({ + toggle: Em.K + }) + } + }); + }); + + describe('#onToggleBlock', function() { + it('should toggle', function() { + var context = Em.Object.create({isCollapsed: false}); + view.onToggleBlock({context: context}); + expect(context.get('isCollapsed')).to.equal(true); + view.onToggleBlock({context: context}); + expect(context.get('isCollapsed')).to.equal(false); + }); + }); + + describe('#showHostsPopup', function() { + it('should call App.ModalPopup.show', function() { + sinon.stub(App.ModalPopup, 'show', Em.K); + view.showHostsPopup({context: []}); + expect(App.ModalPopup.show.calledOnce).to.equal(true); + App.ModalPopup.show.restore(); + }); + }); + + describe('#categoryWarnings', function() { + it('should return empty array', function() { + var warningsByHost = null; + view.reopen({warningsByHost: warningsByHost}); + expect(view.get('categoryWarnings')).to.eql([]); + }); + it('should return filtered warnings', function() { + var warningsByHost = [ + {name: 'c', warnings: [{}, {}, {}]}, + {name: 'd', warnings: [{}]} + ]; + view.reopen({warningsByHost: warningsByHost, category: 'c'}); + expect(view.get('categoryWarnings.length')).to.equal(3); + }); + }); + + describe('#warningHostsNamesCount', function() { + it('should parse warnings', function() { + view.set('bodyController', Em.Object.create({ + repoCategoryWarnings: [ + {hostsNames: ['h1', 'h4']} + ], + diskCategoryWarnings: [ + {hostsNames: ['h2', 'h5']} + ], + warningsByHost: [ + {}, + { name: 'h1', warnings: [{}, {}, {}] }, + { name: 'h2', warnings: [{}, {}, {}] }, + { name: 'h3', warnings: [] } + ] + })); + expect(view.warningHostsNamesCount()).to.equal(4); + }); + }); + + describe('#hostSelectView', function() { + + var v; + + beforeEach(function() { + v = view.get('hostSelectView').create(); + }); + + describe('#click', function() { + Em.A([ + { + isLoaded: false, + isLazyLoading: true, + e: true + }, + { + isLoaded: true, + isLazyLoading: true, + e: false + }, + { + isLoaded: false, + isLazyLoading: false, + e: false + }, + { + isLoaded: true, + isLazyLoading: false, + e: false + } + ]).forEach(function (test) { + it('isLoaded: ' + test.isLoaded.toString() + ', isLazyLoading: ' + test.isLazyLoading.toString(), function () { + v.reopen({ + isLoaded: test.isLoaded, + isLazyLoading: test.isLazyLoading + }); + sinon.spy(lazyloading, 'run'); + v.click(); + if (test.e) { + expect(lazyloading.run.calledOnce).to.equal(true); + } + else { + expect(lazyloading.run.called).to.equal(false); + } + lazyloading.run.restore(); + }); + }); + }); + + }); + + describe('#contentInDetails', function() { + var content = [ + {category: 'firewall', warnings: [{name: 'n1'}, {name: 'n2'}, {name: 'n3'}]}, + {category: 'fileFolders', warnings: [{name: 'n4'}, {name: 'n5'}, {name: 'n6'}]}, + { + category: 'process', + warnings: [ + {name: 'n7', hosts:['h1', 'h2'], user: 'u1', pid: 'pid1'}, + {name: 'n8', hosts:['h2'], user: 'u2', pid: 'pid2'}, + {name: 'n9', hosts:['h3'], user: 'u1', pid: 'pid3'} + ] + }, + {category: 'package', warnings: [{name: 'n10'}, {name: 'n11'}, {name: 'n12'}]}, + {category: 'service', warnings: [{name: 'n13'}, {name: 'n14'}, {name: 'n15'}]}, + {category: 'user', warnings: [{name: 'n16'}, {name: 'n17'}, {name: 'n18'}]} + ], warningsByHost = [ + {}, + {name: 'c', warnings: [{}, {}, {}]}, + {name: 'd', warnings: [{}]} + ]; + beforeEach(function() { + view.reopen({content: content, warningsByHost: warningsByHost}); + }); + it('should map hosts', function() { + var newContent = view.get('contentInDetails'); + expect(newContent.contains('c d')).to.equal(true); + }); + it('should map firewall warnings', function() { + var newContent = view.get('contentInDetails'); + expect(newContent.contains('n1<br>n2<br>n3')).to.equal(true); + }); + it('should map fileFolders warnings', function() { + var newContent = view.get('contentInDetails'); + expect(newContent.contains('n4 n5 n6')).to.equal(true); + }); + it('should map process warnings', function() { + var newContent = view.get('contentInDetails'); + expect(newContent.contains('(h1,u1,pid1)')).to.equal(true); + expect(newContent.contains('(h2,u1,pid1)')).to.equal(true); + expect(newContent.contains('(h2,u2,pid2)')).to.equal(true); + expect(newContent.contains('(h3,u1,pid3)')).to.equal(true); + }); + it('should map package warnings', function() { + var newContent = view.get('contentInDetails'); + expect(newContent.contains('n10 n11 n12')).to.equal(true); + }); + it('should map service warnings', function() { + var newContent = view.get('contentInDetails'); + expect(newContent.contains('n13 n14 n15')).to.equal(true); + }); + it('should map user warnings', function() { + var newContent = view.get('contentInDetails'); + expect(newContent.contains('n16 n17 n18')).to.equal(true); + }); + }); + +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/221ae2f2/ambari-web/test/views/wizard/step9/hostLogPopupBody_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/wizard/step9/hostLogPopupBody_view_test.js b/ambari-web/test/views/wizard/step9/hostLogPopupBody_view_test.js index 918d3d9..530727c 100644 --- a/ambari-web/test/views/wizard/step9/hostLogPopupBody_view_test.js +++ b/ambari-web/test/views/wizard/step9/hostLogPopupBody_view_test.js @@ -142,4 +142,118 @@ describe('App.WizardStep9HostLogPopupBodyView', function() { }); }); + describe('#tasks', function() { + var testTask = { + Tasks: { + status: 'init', + id: 1, + request_id: 2, + role: 'PIG', + stderr: 'stderr', + stdout: 'stdout', + host_name: 'host1', + command: 'Cmd' + } + }; + + it('should map tasks', function() { + view.set('parentView.host.logTasks', [testTask]); + var t = view.get('tasks'); + expect(t.length).to.equal(1); + var first = t[0]; + expect(first.get('id')).to.equal(1); + expect(first.get('requestId')).to.equal(2); + expect(first.get('command')).to.equal('cmd'); + expect(first.get('role')).to.equal('Pig'); + expect(first.get('stderr')).to.equal('stderr'); + expect(first.get('stdout')).to.equal('stdout'); + expect(first.get('isVisible')).to.equal(true); + expect(first.get('hostName')).to.equal('host1'); + }); + + it('should set cog icon', function() { + var t = Em.copy(testTask); + t.Tasks.status = 'pending'; + view.set('parentView.host.logTasks', [t]); + var first = view.get('tasks')[0]; + expect(first.get('icon')).to.equal('icon-cog'); + }); + + it('should set cog icon (2)', function() { + var t = Em.copy(testTask); + t.Tasks.status = 'queued'; + view.set('parentView.host.logTasks', [t]); + var first = view.get('tasks')[0]; + expect(first.get('icon')).to.equal('icon-cog'); + }); + + it('should set cogs icon', function() { + var t = Em.copy(testTask); + t.Tasks.status = 'in_progress'; + view.set('parentView.host.logTasks', [t]); + var first = view.get('tasks')[0]; + expect(first.get('icon')).to.equal('icon-cogs'); + }); + + it('should set ok icon', function() { + var t = Em.copy(testTask); + t.Tasks.status = 'completed'; + view.set('parentView.host.logTasks', [t]); + var first = view.get('tasks')[0]; + expect(first.get('icon')).to.equal('icon-ok'); + }); + + it('should set icon-exclamation-sign icon', function() { + var t = Em.copy(testTask); + t.Tasks.status = 'failed'; + view.set('parentView.host.logTasks', [t]); + var first = view.get('tasks')[0]; + expect(first.get('icon')).to.equal('icon-exclamation-sign'); + }); + + it('should set minus icon', function() { + var t = Em.copy(testTask); + t.Tasks.status = 'aborted'; + view.set('parentView.host.logTasks', [t]); + var first = view.get('tasks')[0]; + expect(first.get('icon')).to.equal('icon-minus'); + }); + + it('should set time icon', function() { + var t = Em.copy(testTask); + t.Tasks.status = 'timedout'; + view.set('parentView.host.logTasks', [t]); + var first = view.get('tasks')[0]; + expect(first.get('icon')).to.equal('icon-time'); + }); + + }); + + describe('#toggleTaskLog', function() { + it('isLogWrapHidden is true', function() { + var taskInfo = { + id: 1, + requestId: 2 + }; + view.set('isLogWrapHidden', true); + view.set('parentView.c', Em.Object.create({loadCurrentTaskLog: Em.K})); + sinon.spy(view.get('parentView.c'), 'loadCurrentTaskLog'); + view.toggleTaskLog({context: taskInfo}); + expect(view.get('isLogWrapHidden')).to.equal(false); + expect(view.get('parentView.c.currentOpenTaskId')).to.equal(taskInfo.id); + expect(view.get('parentView.c.currentOpenTaskRequestId')).to.equal(taskInfo.requestId); + expect(view.get('parentView.c').loadCurrentTaskLog.calledOnce).to.equal(true); + view.get('parentView.c').loadCurrentTaskLog.restore(); + }); + it('isLogWrapHidden is false', function() { + var taskInfo = {}; + view.set('isLogWrapHidden', false); + view.set('parentView.c', Em.Object.create({loadCurrentTaskLog: Em.K})); + view.toggleTaskLog({context: taskInfo}); + expect(view.get('isLogWrapHidden')).to.equal(true); + expect(view.get('parentView.c.currentOpenTaskId')).to.equal(0); + expect(view.get('parentView.c.currentOpenTaskRequestId')).to.equal(0); + }); + }); + }); \ No newline at end of file
