Przeglądaj źródła

AMBARI-9843. Slider View. Add App Wizard. No validation for Frequency field (alexantonenko)

Alex Antonenko 10 lat temu
rodzic
commit
709e17a883

+ 31 - 2
contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step1_controller.js

@@ -52,6 +52,18 @@ App.CreateAppWizardStep1Controller = Ember.Controller.extend(App.AjaxErrorHandle
    */
   nameErrorMessage: '',
 
+  /**
+   * Define if <code>frequency</code> value is valid
+   * @type {Boolean}
+   */
+  isFrequencyError: false,
+
+  /**
+   * Error message describing frequency validation error
+   * @type {String}
+   */
+  frequencyErrorMessage: '',
+
   /**
    * Determines if request for validating new App name is sent
    * If true - "Next" button should be disabled
@@ -81,8 +93,9 @@ App.CreateAppWizardStep1Controller = Ember.Controller.extend(App.AjaxErrorHandle
    * @type {bool}
    */
   isSubmitDisabled: function () {
-    return this.get('validateAppNameRequestExecuting') || !this.get('newApp.name') || this.get('isNameError') || this.get('isAppTypesError');
-  }.property('newApp.name', 'isNameError', 'isAppTypesError', 'validateAppNameRequestExecuting'),
+    return this.get('validateAppNameRequestExecuting') || !this.get('newApp.name') || this.get('isNameError') ||
+      this.get('isFrequencyError') || this.get('isAppTypesError');
+  }.property('newApp.name', 'isNameError', 'isAppTypesError', 'validateAppNameRequestExecuting', 'isFrequencyError'),
 
   /**
    * Initialize new App and set it to <code>newApp</code>
@@ -144,6 +157,22 @@ App.CreateAppWizardStep1Controller = Ember.Controller.extend(App.AjaxErrorHandle
     return true;
   }.observes('newApp.name'),
 
+  /**
+   * Validate <code>frequency</code> value
+   * It should be numeric
+   * @method frequencyValidator
+   * @return {Boolean}
+   */
+  frequencyValidator: function () {
+    var frequency = this.get('newApp.frequency');
+    var isFrequencyError = frequency && /\D/.test(frequency);
+    this.setProperties({
+      isFrequencyError: isFrequencyError,
+      frequencyErrorMessage: isFrequencyError ? Em.I18n.t('wizard.step1.frequencyError') : ''
+    });
+    return !isFrequencyError;
+  }.observes('newApp.frequency'),
+
   /**
    * Proceed if app name has passed server validation
    * @method {validateAppNameSuccessCallback}

+ 8 - 1
contrib/views/slider/src/main/resources/ui/app/templates/createAppWizard/step1.hbs

@@ -151,7 +151,7 @@
       </div>
     </div>
     <div class="row">
-      <div class="col-xs-3">
+      <div class="col-xs-3" {{bind-attr class=":col-xs-3 controller.isFrequencyError:error"}}>
         <label class="control-label">{{t common.frequency}}</label>
       </div>
       <div class="col-xs-7">
@@ -161,6 +161,13 @@
         </div>
       </div>
     </div>
+    {{#if controller.isFrequencyError}}
+      <div class="row">
+        <div class="col-xs-12 alert alert-danger">
+          {{controller.frequencyErrorMessage}}
+        </div>
+      </div>
+    {{/if}}
     <!-- Log Aggregation end -->
     <div class="btn-area">
       <button

+ 1 - 0
contrib/views/slider/src/main/resources/ui/app/translations.js

@@ -143,6 +143,7 @@ Em.I18n.translations = {
   'wizard.step1.nameRepeatError': 'App with entered Name already exists.',
   'wizard.step1.validateAppNameError': 'Application with name \'{0}\' already exists',
   'wizard.step1.noAppTypesError': 'No Slider Application packages have been installed on this server. Please contact your Ambari server administrator to install Slider Application packages into /var/lib/ambari-server/resources/apps/ folder and restart Ambari server.',
+  'wizard.step1.frequencyError': 'Frequency value should be numeric',
   'wizard.step2.name': 'Allocate Resources',
   'wizard.step2.header': ' application requires resources to be allocated on the cluster. Provide resource allocation requests for each component of the application below.',
   'wizard.step2.table.instances': 'Instances',

+ 1 - 1
contrib/views/slider/src/main/resources/ui/test/integration/processes/create_new_app_test.js

@@ -88,7 +88,7 @@ var selectors = {
     type: 'HBASE',
     includeFilePatterns: 'includeFilePatterns1',
     excludeFilePatterns: 'excludeFilePatterns1',
-    frequency: 'frequency1',
+    frequency: '1',
     queueName: 'queueName1',
     specialLabel: 'specialLabel1',
     selectedYarnLabel: 'selectedYarnLabel1',

+ 92 - 12
contrib/views/slider/src/main/resources/ui/test/unit/controllers/createAppWizard/step1_controller_test.js

@@ -106,23 +106,103 @@ test('validateAppNameSuccessCallback', function () {
 
 test('isSubmitDisabled', function () {
 
+  expect(6);
+
   var controller = this.subject({
-    availableTypes: {
-      content: [
-        {}
-      ]
-    },
-    isNameError: false,
-    newApp: {
-      name: 'some'
-    }
-  });
+      availableTypes: {
+        content: [
+          {}
+        ]
+      },
+      isNameError: false,
+      newApp: {
+        name: 'some'
+      }
+    }),
+    cases = [
+      {
+        key: 'validateAppNameRequestExecuting',
+        title: 'request is executing'
+      },
+      {
+        key: 'isNameError',
+        title: 'app name is invalid'
+      },
+      {
+        key: 'no app types are available',
+        title: 'request is executing'
+      },
+      {
+        key: 'isFrequencyError',
+        title: 'frequency value is invalid'
+      }
+    ],
+    keys = cases.mapProperty('key'),
+    failTitle = 'submit button is disabled when {0}';
 
   equal(controller.get('isSubmitDisabled'), false);
+
+  cases.forEach(function (item) {
+    Em.run(function () {
+      keys.forEach(function (key) {
+        controller.set(key, item.key != key);
+      });
+    });
+    equal(controller.get('isSubmitDisabled'), true, failTitle.format(item.title));
+  });
+
   Em.run(function () {
-    controller.set('validateAppNameRequestExecuting', true);
+    keys.forEach(function (key) {
+      controller.set(key, true);
+    });
+    controller.set('newApp.name', '');
   });
+  equal(controller.get('isSubmitDisabled'), true, failTitle.format('no app name is specified'));
 
-  equal(controller.get('isSubmitDisabled'), true, 'button disabled when request executing');
+});
+
+test('frequencyValidator', function () {
+
+  expect(8);
+
+  var controller = this.subject(),
+    cases = [
+      {
+        value: '123',
+        isFrequencyError: false,
+        frequencyErrorMessage: '',
+        title: 'numeric value'
+      },
+      {
+        value: '123a',
+        isFrequencyError: true,
+        frequencyErrorMessage: Em.I18n.t('wizard.step1.frequencyError'),
+        title: 'value contains letter'
+      },
+      {
+        value: '123-',
+        isFrequencyError: true,
+        frequencyErrorMessage: Em.I18n.t('wizard.step1.frequencyError'),
+        title: 'value contains special symbol'
+      },
+      {
+        value: '123 ',
+        isFrequencyError: true,
+        frequencyErrorMessage: Em.I18n.t('wizard.step1.frequencyError'),
+        title: 'value contains space'
+      }
+    ],
+    errorTitle = '{0}: isFrequencyError is set correctly',
+    messageTitle = '{0}: error message is set correctly';
+
+  cases.forEach(function (item) {
+    Em.run(function () {
+      controller.set('newApp', {
+        frequency: item.value
+      });
+    });
+    equal(controller.get('isFrequencyError'), item.isFrequencyError, errorTitle.format(item.title));
+    equal(controller.get('frequencyErrorMessage'), item.frequencyErrorMessage, messageTitle.format(item.title));
+  });
 
 });