Added: incubator/ambari/trunk/ambari-web/test/main/app/app_contoller_test.js URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/main/app/app_contoller_test.js?rev=1454639&view=auto ============================================================================== --- incubator/ambari/trunk/ambari-web/test/main/app/app_contoller_test.js (added) +++ incubator/ambari/trunk/ambari-web/test/main/app/app_contoller_test.js Sat Mar 9 02:03:51 2013 @@ -0,0 +1,188 @@ +/** + * 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'); + require('controllers/main/apps_controller'); +/* require('models/cluster'); + require('models/service'); + require('models/pagination'); + require('controllers/main/host');*/ + + describe('MainAppsController', function () { + + + describe('#iTotalDisplayRecordsObserver()', function () { + it('should set number of filtered jobs when switching to all jobs', function () { + var mainAppsController = App.MainAppsController.create(); + mainAppsController.set("paginationObject.iTotalDisplayRecords", 5); + expect(mainAppsController.get('filterObject.filteredDisplayRecords')).to.equal(5); + }) + }); + + + describe('#filterObject.onRunTypeChange()', function () { + it('should set sSearch_2 of filterObject when changing value of filterObject.runType', function () { + var mainAppsController = App.MainAppsController.create(); + mainAppsController.set("filterObject.runType", "MapReduce"); + expect(mainAppsController.get('filterObject.sSearch_2')).to.equal("mr"); + mainAppsController.set("filterObject.runType", "Hive"); + expect(mainAppsController.get('filterObject.sSearch_2')).to.equal("hive"); + mainAppsController.set("filterObject.runType", "Pig"); + expect(mainAppsController.get('filterObject.sSearch_2')).to.equal("pig"); + }) + }); + + describe('#filterObject.onJobsChange()', function () { + it('should set minJobs,maxJobs of filterObject when changing value of filterObject.jobs', function () { + var mainAppsController = App.MainAppsController.create(); + mainAppsController.set("filterObject.jobs", ">3"); + expect(mainAppsController.get('filterObject.minJobs')).to.equal("3"); + expect(mainAppsController.get('filterObject.maxJobs')).to.equal(""); + mainAppsController.set("filterObject.jobs", "<3"); + expect(mainAppsController.get('filterObject.minJobs')).to.equal(""); + expect(mainAppsController.get('filterObject.maxJobs')).to.equal("3"); + mainAppsController.set("filterObject.jobs", "3"); + expect(mainAppsController.get('filterObject.minJobs')).to.equal("3"); + expect(mainAppsController.get('filterObject.maxJobs')).to.equal("3"); + mainAppsController.set("filterObject.jobs", "=3"); + expect(mainAppsController.get('filterObject.minJobs')).to.equal("3"); + expect(mainAppsController.get('filterObject.maxJobs')).to.equal("3"); + }) + }); + + describe('#filterObject.onInputChange()', function () { + it('should set minInputBytes,maxInputBytes of filterObject when changing value of filterObject.input', function () { + var mainAppsController = App.MainAppsController.create(); + mainAppsController.set("filterObject.input", ">3gb"); + expect(mainAppsController.get('filterObject.minInputBytes')).to.equal(3215856763); + expect(mainAppsController.get('filterObject.maxInputBytes')).to.equal(""); + mainAppsController.set("filterObject.input", "<6m"); + expect(mainAppsController.get('filterObject.minInputBytes')).to.equal(""); + expect(mainAppsController.get('filterObject.maxInputBytes')).to.equal(6343884); + mainAppsController.set("filterObject.input", "10kb"); + expect(mainAppsController.get('filterObject.minInputBytes')).to.equal(10189); + expect(mainAppsController.get('filterObject.maxInputBytes')).to.equal(10291); + mainAppsController.set("filterObject.input", "1"); + expect(mainAppsController.get('filterObject.minInputBytes')).to.equal(1024); + expect(mainAppsController.get('filterObject.maxInputBytes')).to.equal(1075); + }) + }); + + describe('#filterObject.onOutputChange()', function () { + it('should set minOutputBytes,maxOutputBytes of filterObject when changing value of filterObject.output', function () { + var mainAppsController = App.MainAppsController.create(); + mainAppsController.set("filterObject.output", ">3gb"); + expect(mainAppsController.get('filterObject.minOutputBytes')).to.equal(3215856763); + expect(mainAppsController.get('filterObject.maxOutputBytes')).to.equal(""); + mainAppsController.set("filterObject.output", "<6m"); + expect(mainAppsController.get('filterObject.minOutputBytes')).to.equal(""); + expect(mainAppsController.get('filterObject.maxOutputBytes')).to.equal(6343884); + mainAppsController.set("filterObject.output", "10kb"); + expect(mainAppsController.get('filterObject.minOutputBytes')).to.equal(10189); + expect(mainAppsController.get('filterObject.maxOutputBytes')).to.equal(10291); + mainAppsController.set("filterObject.output", "1"); + expect(mainAppsController.get('filterObject.minOutputBytes')).to.equal(1024); + expect(mainAppsController.get('filterObject.maxOutputBytes')).to.equal(1075); + }) + }); + + describe('#filterObject.onDurationChange()', function () { + it('should set minDuration,maxDuration of filterObject when changing value of filterObject.duration', function () { + var mainAppsController = App.MainAppsController.create(); + mainAppsController.set("filterObject.duration", ">3h"); + expect(mainAppsController.get('filterObject.minDuration')).to.equal(10799640); + expect(mainAppsController.get('filterObject.maxDuration')).to.equal(""); + mainAppsController.set("filterObject.duration", "<6m"); + expect(mainAppsController.get('filterObject.minDuration')).to.equal(""); + expect(mainAppsController.get('filterObject.maxDuration')).to.equal(360060); + mainAppsController.set("filterObject.duration", "10s"); + expect(mainAppsController.get('filterObject.minDuration')).to.equal(9990); + expect(mainAppsController.get('filterObject.maxDuration')).to.equal(10010); + mainAppsController.set("filterObject.duration", "1"); + expect(mainAppsController.get('filterObject.minDuration')).to.equal(990); + expect(mainAppsController.get('filterObject.maxDuration')).to.equal(1010); + }) + }); + + describe('#filterObject.onRunDateChange()', function () { + it('should set minStartTime,maxStartTime of filterObject when changing value of filterObject.runDate', function () { + var mainAppsController = App.MainAppsController.create(); + mainAppsController.set("filterObject.runDate", "Any"); + expect(mainAppsController.get('filterObject.minStartTime')).to.equal(""); + mainAppsController.set("filterObject.runDate", "Past 1 Day"); + expect(mainAppsController.get('filterObject.minStartTime')).to.be.within(((new Date().getTime())-86400000)-10,((new Date().getTime())-86400000)+10); + mainAppsController.set("filterObject.runDate", "Past 2 Days"); + expect(mainAppsController.get('filterObject.minStartTime')).to.be.within(((new Date().getTime())-172800000)-10,((new Date().getTime())-172800000)+10); + mainAppsController.set("filterObject.runDate", "Past 7 Days"); + expect(mainAppsController.get('filterObject.minStartTime')).to.be.within(((new Date().getTime())-604800000)-10,((new Date().getTime())-604800000)+10); + mainAppsController.set("filterObject.runDate", "Past 14 Days"); + expect(mainAppsController.get('filterObject.minStartTime')).to.be.within(((new Date().getTime())-1209600000)-10,((new Date().getTime())-1209600000)+10); + mainAppsController.set("filterObject.runDate", "Past 30 Days"); + expect(mainAppsController.get('filterObject.minStartTime')).to.be.within(((new Date().getTime())-2592000000)-10,((new Date().getTime())-2592000000)+10); + }) + }); + + describe('#filterObject.createAppLink(), #filterObject.valueObserver()', function () { + it('should set runUrl of filterObject when changing value for any filter', function () { + var mainAppsController = App.MainAppsController.create(); + mainAppsController.set("filterObject.sSearch_0", "0"); + mainAppsController.set("filterObject.sSearch_1", "workflowName"); + mainAppsController.set("filterObject.sSearch_2", "pig"); + mainAppsController.set("filterObject.sSearch_3", "admin"); + mainAppsController.set("filterObject.minJobs", "1"); + mainAppsController.set("filterObject.maxJobs", "2"); + mainAppsController.set("filterObject.minInputBytes", "2000"); + mainAppsController.set("filterObject.maxInputBytes", "3000"); + mainAppsController.set("filterObject.minOutputBytes", "1500"); + mainAppsController.set("filterObject.maxOutputBytes", "2000"); + mainAppsController.set("filterObject.minDuration", "1000"); + mainAppsController.set("filterObject.maxDuration", "2000"); + mainAppsController.set("filterObject.minStartTime", "999"); + mainAppsController.set("filterObject.maxStartTime", "1000"); + mainAppsController.set("filterObject.sSearch", "searchTerm"); + mainAppsController.set("filterObject.iDisplayLength", "10"); + mainAppsController.set("filterObject.iDisplayStart", "10"); + mainAppsController.set("filterObject.iSortCol_0", "1"); + mainAppsController.set("filterObject.sSortDir_0", "ASC"); + expect(mainAppsController.get('runUrl')).to.equal("/jobhistory/datatable?" + + "sSearch_0=0" + + "&sSearch_1=workflowName" + + "&sSearch_2=pig" + + "&sSearch_3=admin" + + "&minJobs=1" + + "&maxJobs=2" + + "&minInputBytes=2000" + + "&maxInputBytes=3000" + + "&minOutputBytes=1500" + + "&maxOutputBytes=2000" + + "&minDuration=1000" + + "&maxDuration=2000" + + "&minStartTime=999" + + "&maxStartTime=1000" + + "&sSearch=searchTerm" + + "&iDisplayLength=10" + + "&iDisplayStart=10" + + "&iSortCol_0=1" + + "&sSortDir_0=ASC"); + }) + }); + + + }); +
Modified: incubator/ambari/trunk/ambari-web/test/test-helpers.coffee URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/test-helpers.coffee?rev=1454639&r1=1454638&r2=1454639&view=diff ============================================================================== --- incubator/ambari/trunk/ambari-web/test/test-helpers.coffee (original) +++ incubator/ambari/trunk/ambari-web/test/test-helpers.coffee Sat Mar 9 02:03:51 2013 @@ -20,7 +20,10 @@ chai = require 'chai' sinonChai = require 'sinon-chai' chai.use sinonChai +xmlhttprequest = require 'xmlhttprequest' module.exports = expect: chai.expect sinon: require 'sinon' + testHost: 'localhost:3333' + xmlhttprequest: xmlhttprequest Added: incubator/ambari/trunk/ambari-web/test/utils/ajax_test.js URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/utils/ajax_test.js?rev=1454639&view=auto ============================================================================== --- incubator/ambari/trunk/ambari-web/test/utils/ajax_test.js (added) +++ incubator/ambari/trunk/ambari-web/test/utils/ajax_test.js Sat Mar 9 02:03:51 2013 @@ -0,0 +1,42 @@ +/** + * 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. + */ + +/** + * Here is fix for ajax support + * @type {*} + */ +var XMLHttpRequest = xmlhttprequest.XMLHttpRequest; +var $ = window.$; + +$.support.cors = true; +$.ajaxSettings.xhr = function () { + return new XMLHttpRequest(); +} + +$.mocho = true; +$.hostName = testHost; + +/*sinon.stub2 = function(object, property, value){ + var origin = object[property]; + var count = 0; + var newValue = function(){ + count++; + return value.call(this, arguments, origin, count); + } + sinon.stub(object, property, newValue); +}*/ Added: incubator/ambari/trunk/ambari-web/test/utils/misc_test.js URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/utils/misc_test.js?rev=1454639&view=auto ============================================================================== --- incubator/ambari/trunk/ambari-web/test/utils/misc_test.js (added) +++ incubator/ambari/trunk/ambari-web/test/utils/misc_test.js Sat Mar 9 02:03:51 2013 @@ -0,0 +1,44 @@ +/** + * 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 misc = require('utils/misc'); + +describe('misc', function () { + + describe('#formatBandwidth', function () { + var tests = [ + {m:'undefined to undefined',i:undefined,e:undefined}, + {m:'0 to <1KB',i:'0',e:'<1KB'}, + {m:'1000 to <1KB',i:'1000',e:'<1KB'}, + {m:'1024 to 1.0KB',i:'1024',e:'1.0KB'}, + {m:'2048 to 2.0KB',i:'2048',e:'2.0KB'}, + {m:'1048576 to 1.0MB',i:'1048576',e:'1.0MB'}, + {m:'1782579 to 1.7MB',i:'1782579',e:'1.7MB'}, + {m:'1546188226 to 1.44GB',i:'1546188226',e:'1.44GB'} + ]; + tests.forEach(function(test) { + it(test.m + ' ', function () { + expect(misc.formatBandwidth(test.i)).to.equal(test.e); + }); + }); + it('NaN to NaN' + ' ', function () { + expect(isNaN(misc.formatBandwidth(NaN))).to.equal(true); + }); + }); + +}); Modified: incubator/ambari/trunk/ambari-web/test/utils/validator_test.js URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/utils/validator_test.js?rev=1454639&r1=1454638&r2=1454639&view=diff ============================================================================== --- incubator/ambari/trunk/ambari-web/test/utils/validator_test.js (original) +++ incubator/ambari/trunk/ambari-web/test/utils/validator_test.js Sat Mar 9 02:03:51 2013 @@ -197,6 +197,24 @@ describe('validator', function () { it('"55454" - invalid Domain Name', function () { expect(validator.isDomainName('55454')).to.equal(false); }) + }), + describe('#isValidUserName(value)', function() { + var tests = [ + {m:'"" - invalid',i:'',e:false}, + {m:'"abc123" - valid',i:'abc123',e:true}, + {m:'"1abc123" - invalid',i:'1abc123',e:false}, + {m:'"abc123$" - valid',i:'abc123$',e:true}, + {m:'"~1abc123" - invalid',i: '~1abc123',e:false}, + {m:'"abc12345679abc1234567890abc1234567890$" - invalid',i:'abc12345679abc1234567890abc1234567890$',e:false}, + {m:'"1abc123$$" - invalid',i:'1abc123$$',e:false}, + {m:'"a" - valid',i:'a',e:true}, + {m:'"!" - invalid',i:'!',e:false} + ]; + tests.forEach(function(test) { + it(test.m + ' ', function () { + expect(validator.isValidUserName(test.i)).to.equal(test.e); + }) + }); }) }) \ No newline at end of file Added: incubator/ambari/trunk/ambari-web/test/views/common/chart/linear_time_test.js URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/views/common/chart/linear_time_test.js?rev=1454639&view=auto ============================================================================== --- incubator/ambari/trunk/ambari-web/test/views/common/chart/linear_time_test.js (added) +++ incubator/ambari/trunk/ambari-web/test/views/common/chart/linear_time_test.js Sat Mar 9 02:03:51 2013 @@ -0,0 +1,131 @@ +/** + * 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'); +require('views/common/chart/linear_time'); + +describe('App.ChartLinearTimeView', function () { + + var chartLinearTimeView = App.ChartLinearTimeView.create({}); + + describe('#transformData ([[1, 2], [2, 3], [3, 4]], "abc")', function () { + + var data = [[1, 2], [2, 3], [3, 4]]; + var name = 'abc'; + var result = chartLinearTimeView.transformData(data, name); + it('"name" should be "abc" ', function () { + expect(result.name).to.equal('abc'); + }) + it('data size should be 3 ', function () { + expect(result.data.length).to.equal(3); + }) + it('data[0].x should be 2 ', function () { + expect(result.data[0].x).to.equal(2); + }) + it('data[0].y should be 1 ', function () { + expect(result.data[0].y).to.equal(1); + }) + }), + describe('#yAxisFormatter', function() { + var tests = [ + {m:'undefined to 0',i:undefined,e:0}, + {m:'NaN to 0',i:NaN,e:0}, + {m:'0 to 0',i:'0',e:'0'}, + {m:'1000 to 1K',i:'1000',e:'1K'}, + {m:'1000000 to 1M',i:'1000000',e:'1M'}, + {m:'1000000000 to 1B',i:'1000000000',e:'1B'}, + {m:'1000000000000 to 1T',i:'1000000000000',e:'1T'}, + {m:'1048576 to 1.049M',i:'1048576',e:'1.049M'}, + {m:'1073741824 to 1.074B',i:'1073741824',e:'1.074B'} + ]; + tests.forEach(function(test) { + it(test.m + ' ', function () { + expect(chartLinearTimeView.yAxisFormatter(test.i)).to.equal(test.e); + }); + }); + }), + describe('#checkSeries', function() { + var tests = [ + {m:'undefined - false',i:undefined,e:false}, + {m:'NaN - false',i:NaN,e:false}, + {m:'object without data property - false',i:[{}],e:false}, + {m:'object with empty data property - false',i:[{data:[]}],e:false}, + {m:'object with invalid data property - false',i:[{data:[1]}],e:false}, + {m:'object with valid data property - true',i:[{data:[{x:1,y:1},{x:2,y:2}]}],e:true} + ]; + tests.forEach(function(test) { + it(test.m + ' ', function () { + expect(chartLinearTimeView.checkSeries(test.i)).to.equal(test.e); + }); + }); + }), + describe('#BytesFormatter', function() { + var tests = [ + {m:'undefined to "0 B"',i:undefined,e:'0 B'}, + {m:'NaN to "0 B"',i:NaN,e:'0 B'}, + {m:'0 to "0 B"',i:0,e:'0 B'}, + {m:'124 to "124 B"',i:124,e:'124 B'}, + {m:'1024 to "1 KB"',i:1024,e:'1 KB'}, + {m:'1536 to "1 KB"',i:1536,e:'1.5 KB'}, + {m:'1048576 to "1 MB"',i:1048576,e:'1 MB'}, + {m:'1073741824 to "1 GB"',i:1073741824,e:'1 GB'}, + {m:'1610612736 to "1.5 GB"',i:1610612736,e:'1.5 GB'} + ]; + + tests.forEach(function(test) { + it(test.m + ' ', function () { + + expect(App.ChartLinearTimeView.BytesFormatter(test.i)).to.equal(test.e); + }); + }); + }), + describe('#PercentageFormatter', function() { + var tests = [ + {m:'undefined to "0 %"',i:undefined,e:'0 %'}, + {m:'NaN to "0 %"',i:NaN,e:'0 %'}, + {m:'0 to "0 %"',i:0,e:'0 %'}, + {m:'1 to "1%"',i:1,e:'1%'}, + {m:'1.12341234 to "1.123%"',i:1.12341234,e:'1.123%'}, + {m:'-11 to "-11%"',i:-11,e:'-11%'}, + {m:'-11.12341234 to "-11.123%"',i:-11.12341234,e:'-11.123%'} + ]; + tests.forEach(function(test) { + it(test.m + ' ', function () { + expect(App.ChartLinearTimeView.PercentageFormatter(test.i)).to.equal(test.e); + }); + }); + }), + describe('#TimeElapsedFormatter', function() { + var tests = [ + {m:'undefined to "0 ms"',i:undefined,e:'0 ms'}, + {m:'NaN to "0 ms"',i:NaN,e:'0 ms'}, + {m:'0 to "0 ms"',i:0,e:'0 ms'}, + {m:'1000 to "1000 ms"',i:1000,e:'1000 ms'}, + {m:'120000 to "2 m"',i:120000,e:'2 m'}, + {m:'3600000 to "60 m"',i:3600000,e:'60 m'}, + {m:'5000000 to "1 hr"',i:5000000,e:'1 hr'}, + {m:'7200000 to "2 hr"',i:7200000,e:'2 hr'}, + {m:'90000000 to "1 d"',i:90000000,e:'1 d'} + ]; + tests.forEach(function(test) { + it(test.m + ' ', function () { + expect(App.ChartLinearTimeView.TimeElapsedFormatter(test.i)).to.equal(test.e); + }); + }); + }) +}) Modified: incubator/ambari/trunk/ambari-web/vendor/scripts/jquery.ui.custom-effects.js URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/vendor/scripts/jquery.ui.custom-effects.js?rev=1454639&r1=1454638&r2=1454639&view=diff ============================================================================== --- incubator/ambari/trunk/ambari-web/vendor/scripts/jquery.ui.custom-effects.js (original) +++ incubator/ambari/trunk/ambari-web/vendor/scripts/jquery.ui.custom-effects.js Sat Mar 9 02:03:51 2013 @@ -148,7 +148,7 @@ $.effects = { // determine rgba support immediately supportElem.style.cssText = "background-color:rgba(1,1,1,.5)"; -support.rgba = supportElem.style.backgroundColor.indexOf( "rgba" ) > -1; +support.rgba = (supportElem.style.backgroundColor || supportElem.style['background-color']).indexOf( "rgba" ) > -1; // define cache name and alpha properties // for rgba and hsla spaces @@ -1726,7 +1726,7 @@ $.effects.effect.highlight = function( o } $.effects.save( elem, props ); - + elem .show() .css({
