浏览代码

AMBARI-2707. Fix JS Unit tests after merge 1.4.0 to trunk. (Oleg Nechiporenko via yusaku)

Yusaku Sako 12 年之前
父节点
当前提交
a5502753be

+ 0 - 1
ambari-web/app/assets/test/tests.js

@@ -62,6 +62,5 @@ require('test/utils/config_test');
 require('test/utils/string_utils_test');
 require('test/views/common/chart/linear_time_test');
 require('test/views/common/filter_view_test');
-require('test/models/host_component_test');
 require('test/models/host_test');
 require('test/models/rack_test');

+ 0 - 9
ambari-web/app/controllers/wizard/step3_controller.js

@@ -353,15 +353,6 @@ App.WizardStep3Controller = Em.Controller.extend({
     }
   },
 
-  /*
-   stopBootstrap: function () {
-   console.log('stopBootstrap() called');
-   Ember.run.later(this, function () {
-   this.startRegistration();
-   }, 1000);
-   },
-   */
-
   startRegistration: function () {
     if (this.get('registrationStartedAt') == null) {
       this.set('registrationStartedAt', new Date().getTime());

+ 2 - 2
ambari-web/app/controllers/wizard/step6_controller.js

@@ -146,8 +146,8 @@ App.WizardStep6Controller = Em.Controller.extend({
    * @return {*}
    */
   isServiceSelected: function (name) {
-    return this.get('content.services').findProperty('serviceName', name) &&
-      this.get('content.services').findProperty('serviceName', name).get('isSelected');
+    return !!(this.get('content.services').findProperty('serviceName', name) &&
+      this.get('content.services').findProperty('serviceName', name).get('isSelected'));
   },
 
   /**

+ 2 - 73
ambari-web/app/utils/date.js

@@ -37,24 +37,6 @@ module.exports = {
     var days = this.dateDays;
     return days[date.getDay()] + ', ' + months[date.getMonth()] + ' ' + this.dateFormatZeroFirst(date.getDate()) + ', ' + date.getFullYear() + ' ' + this.dateFormatZeroFirst(date.getHours()) + ':' + this.dateFormatZeroFirst(date.getMinutes());
   },
-  /**
-   * Convert date-string 'DAY_OF_THE_WEEK, MONTH DAY, YEAR HOURS:MINUTES' to timestamp
-   * @param date_string
-   * @return {String}
-   */
-  dateUnformat: function(date_string) {
-    var date = date_string.substring(4);
-    var month = date.substring(1, 4);
-    var day = date.substring(5, 7);
-    var year = date.substring(9, 13);
-    var hours = date.substring(14, 16);
-    var minutes = date.substring(17, 19);
-
-    var months = this.dateMonths;
-    month = months.indexOf(month) + 1;
-    if (month < 10) month = '0' + month;
-    return year + month + day + hours + minutes;
-  },
   /**
    * Convert timestamp to date-string 'DAY_OF_THE_WEEK MONTH DAY YEAR'
    * @param timestamp
@@ -70,60 +52,6 @@ module.exports = {
     }
     return date.toDateString();
   },
-  /**
-   * Convert date-string 'DAY_OF_THE_WEEK MONTH DAY YEAR' to the timestamp
-   * @param date_string
-   * @return {Number}
-   */
-  dateUnformatShort: function(date_string) {
-    var date = new Date(date_string);
-    return date.getTime();
-  },
-  /**
-   * Convert time in mseconds to 'HOURS:MINUTES:SECONDS'
-   * @param ms_interval
-   * @return string formatted date
-   */
-  dateFormatInterval:function (ms_interval) {
-    if (!validator.isValidInt(ms_interval)) return ms_interval;
-    var hours = Math.floor(ms_interval / (60 * 60000));
-    var divisor_for_minutes = ms_interval % (60 * 60000);
-    var minutes = Math.floor(divisor_for_minutes / 60000);
-    var divisor_for_seconds = divisor_for_minutes % 60000;
-    var seconds = (divisor_for_seconds / 1000).toFixed(2);
-
-    return (hours < 10 ? '0' : '') + hours + ':' + (minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
-  },
-  /**
-   * Convert 'HOURS:MINUTES:SECONDS' to time in mseconds
-   * @param formattedDate date string
-   * @return time in mseconds
-   */
-  dateUnformatInterval: function(formattedDate) {
-    var formattedDateArray = formattedDate.split(' ');
-
-    if (Object.prototype.toString.call( formattedDateArray ) === '[object Array]' && formattedDateArray.length == 2) {
-      var oneMinMs = 60000;
-      var oneHourMs = 3600000;
-      var oneDayMs = 86400000;
-
-      if (formattedDateArray['1'] == 'ms') {
-        return formattedDateArray['0'];
-      } else if (formattedDateArray['1'] == 'secs') {
-        return formattedDateArray['0'] * 1000;
-      } else if (formattedDateArray['1'] == 'mins') {
-        return formattedDateArray['0'] * oneMinMs;
-      } else if (formattedDateArray['1'] == 'hours') {
-        return formattedDateArray['0'] * oneHourMs;
-      } else if (formattedDateArray['1'] == 'days') {
-        return formattedDateArray['0'] * oneDayMs;
-      } else {
-        console.warn('function dateUnformatInterval: Undefined format');
-      }
-    } else {
-      console.warn('function dateUnformatInterval: formattedDateArray');
-    }
-  },
   /**
    * Convert time in mseconds to
    * 30 ms = 30 ms
@@ -141,6 +69,7 @@ module.exports = {
    */
   timingFormat:function (time) {
     var intTime  = parseInt(time);
+    if (!intTime) return null;
     var timeStr = intTime.toString();
     var lengthOfNumber = timeStr.length;
     var oneMinMs = 60000;
@@ -163,4 +92,4 @@ module.exports = {
       return time + ' days';
     }
   }
-}
+}

+ 3 - 9
ambari-web/app/utils/helper.js

@@ -203,6 +203,8 @@ Number.prototype.long2ip = function () {
  * @param {String} testUrl  URL to be used if app is not in test mode (!App.testMode)
  * @return {String} Formatted URL
  */
+App = require('app');
+
 App.formatUrl = function (urlTemplate, substitutes, testUrl) {
   var formatted = urlTemplate;
   if (urlTemplate) {
@@ -371,12 +373,4 @@ App.format = {
   taskStatus:function (_taskStatus) {
     return _taskStatus.toLowerCase();
   }
-};
-
-Array.prototype.removeAll = function(array){
-  var temp = array;
-  for(var i = 0 ; i < array.length ; i++ ){
-    temp = temp.without(array[i]);
-  }
-  return temp;
-};
+};

+ 0 - 2
ambari-web/test/controllers/main/admin/security/add/step3_test.js

@@ -19,8 +19,6 @@
 
 var App = require('app');
 
-require('utils/string_utils');
-require('utils/helper');
 require('controllers/main/admin/security/add/step3');
 require('models/host_component');
 require('models/host');

+ 0 - 48
ambari-web/test/controllers/main/app_contoller_test.js

@@ -62,42 +62,6 @@ describe('MainAppsController', function () {
      })
    });
 
-   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();
@@ -144,10 +108,6 @@ describe('MainAppsController', function () {
        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");
@@ -164,10 +124,6 @@ describe('MainAppsController', function () {
            "&sSearch_3=admin" +
            "&minJobs=1" +
            "&maxJobs=2" +
-           "&minInputBytes=2000" +
-           "&maxInputBytes=3000" +
-           "&minOutputBytes=1500" +
-           "&maxOutputBytes=2000" +
            "&minDuration=1000" +
            "&maxDuration=2000" +
            "&minStartTime=999" +
@@ -187,10 +143,6 @@ describe('MainAppsController', function () {
        mainAppsController.set("filterObject.sSearch_3", "");
        mainAppsController.set("filterObject.minJobs", "");
        mainAppsController.set("filterObject.maxJobs", "");
-       mainAppsController.set("filterObject.minInputBytes", "");
-       mainAppsController.set("filterObject.maxInputBytes", "");
-       mainAppsController.set("filterObject.minOutputBytes", "");
-       mainAppsController.set("filterObject.maxOutputBytes", "");
        mainAppsController.set("filterObject.minDuration", "");
        mainAppsController.set("filterObject.maxDuration", "");
        mainAppsController.set("filterObject.minStartTime", "");

+ 1 - 0
ambari-web/test/installer/step2_test.js

@@ -20,6 +20,7 @@ var App = require('app');
 var Ember = require('ember');
 require('controllers/wizard/step2_controller');
 require('models/host');
+require('models/host_component');
 require('messages');
 
 describe('App.WizardStep2Controller', function () {

+ 2 - 0
ambari-web/test/installer/step5_test.js

@@ -19,9 +19,11 @@
 var Ember = require('ember');
 var App = require('app');
 require('controllers/wizard/step5_controller');
+var components = require('data/service_components');
 
 describe('App.WizardStep5Controller', function () {
   var controller = App.WizardStep5Controller.create();
+  controller.set('content', {});
   var cpu = 2, memory = 4;
   var schemes = [
     {'description': 'empty condition'},

+ 0 - 79
ambari-web/test/models/host_component_test.js

@@ -1,79 +0,0 @@
-/**
- * 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('models/host_component');
-require('models/host');
-require('router');
-require('models/service/hdfs');
-require('controllers/main/service');
-
-
-describe('App.HostComponent', function () {
-
-
-  var hostComponentData = [
-    {
-      id: 'component1',
-      component_name: 'DATANODE',
-      host_id: 'host1'
-    },
-    {
-      id: 'component2',
-      component_name: 'DATANODE',
-      host_id: 'host3'
-    },
-    {
-      id: 'component3',
-      component_name: 'TASKTRACKER',
-      host_id: 'host2'
-    }
-  ];
-
-  var hdfsData = {
-    id: 'HDFS',
-    service_name: 'HDFS',
-    decommission_data_nodes: ['host1', 'host2']
-  };
-
-
-  //3 hosts are loaded to the model (host1, host2, host3) in models/host_test
-  App.store.load(App.HDFSService, hdfsData);
-  App.store.loadMany(App.HostComponent, hostComponentData);
-
-
-
-  describe('#isDecommissioning', function () {
-
-    it('component1 is DATANODE and on decommissioned host', function () {
-      var hostComponent = App.HostComponent.find().findProperty('id', 'component1');
-      expect(hostComponent.get('isDecommissioning')).to.equal(true);
-    });
-    it('component2 is DATANODE but not on decommissioned host', function () {
-      var hostComponent = App.HostComponent.find().findProperty('id', 'component2');
-      expect(hostComponent.get('isDecommissioning')).to.equal(false);
-    });
-    it('component3 isn\'t DATANODE', function () {
-      var hostComponent = App.HostComponent.find().findProperty('id', 'component3');
-      expect(hostComponent.get('isDecommissioning')).to.equal(false);
-    });
-  });
-
-
-});