You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by on...@apache.org on 2015/12/10 15:14:14 UTC

[3/5] ambari git commit: AMBARI-14296. Add common tests for Em.computed macros (onechiporenko)

http://git-wip-us.apache.org/repos/asf/ambari/blob/240a27a5/ambari-web/test/init_computed_aliases.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/init_computed_aliases.js b/ambari-web/test/init_computed_aliases.js
new file mode 100644
index 0000000..030480d
--- /dev/null
+++ b/ambari-web/test/init_computed_aliases.js
@@ -0,0 +1,169 @@
+/**
+ * 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.
+ */
+
+/**
+ *
+ *
+ * @class App.TestAliases
+ */
+App.TestAliases = {
+  helpers: {
+
+    /**
+     * Get needed value (basing on <code>key</code>) from <code>self</code> or <code>App</code>
+     *
+     * @param {Ember.Object} self
+     * @param {string} key
+     * @returns {*}
+     */
+    smartGet: function (self, key) {
+      var isApp = key.startsWith('App.');
+      var name = isApp ? key.replace('App.', '') : key;
+      return isApp ? App.get(name) : self.get(name);
+    },
+
+    /**
+     * Stub <code>get</code> for <code>App</code> or <code>self</code>
+     *
+     * @param {Ember.Object} self
+     * @returns {App.TestAliases}
+     */
+    smartStubGet: function (self) {
+      var args = [].slice.call(arguments);
+      if (args.length === 3) {
+        return this._stubOneKey.apply(this, args);
+      }
+      return this._stubManyKeys.apply(this, args)
+
+    },
+
+    /**
+     * Trigger recalculation of the needed property in the <code>self</code>
+     * or in the <code>App</code> (depends on <code>propertyName</code>)
+     *
+     * @param {Ember.Object} self
+     * @param {string} propertyName
+     * @returns {App.TestAliases}
+     */
+    propertyDidChange: function (self, propertyName) {
+      var isApp = propertyName.startsWith('App.');
+      var name = isApp ? propertyName.replace('App.', '') : propertyName;
+      var context = isApp ? App : self;
+      Em.propertyDidChange(context, name);
+      return this;
+    },
+
+    /**
+     * Try to restore (@see sinon.restore) <code>get</code> for <code>App</code> and <code>context</code>
+     *
+     * @param {Ember.Object} context
+     * @returns {App.TestAliases}
+     */
+    smartRestoreGet: function(context) {
+      Em.tryInvoke(context.get, 'restore');
+      Em.tryInvoke(App.get, 'restore');
+      return this;
+    },
+
+    /**
+     * Stub <code>get</code>-method for <code>App</code> or <code>self</code> (depends on <code>dependentKey</code>)
+     * to return <code>value</code> if <code>dependentKey</code> is get
+     *
+     * @param {Ember.Object} self
+     * @param {string} dependentKey
+     * @param {*} value
+     * @returns {App.TestAliases}
+     * @private
+     */
+    _stubOneKey: function (self,dependentKey, value) {
+      var isApp = dependentKey.startsWith('App.');
+      var name = isApp ? dependentKey.replace('App.', '') : dependentKey;
+      var context = isApp ? App : self;
+      sinon.stub(context, 'get', function (k) {
+        return k === name ? value : Em.get(context, k);
+      });
+      return this;
+    },
+
+    /**
+     * Stub <code>get</code>-method for <code>App</code> or <code>self</code> (depends on </code>hash</code>-keys)
+     * If some key is starts with 'App.' it will be used in the App-stub,
+     * otherwise it will be used in thw self-stub
+     *
+     * @param {Ember.Object} self
+     * @param {object} hash
+     * @returns {App.TestAliases}
+     * @private
+     */
+    _stubManyKeys: function (self, hash) {
+      var hashForApp = {}; // used in the App-stub
+      var hashForSelf = {}; // used in the self-stub
+      Object.keys(hash).forEach(function(key) {
+        var isApp = key.startsWith('App.');
+        var name = isApp ? key.replace('App.', '') : key;
+        if(isApp) {
+          hashForApp[name] = hash[key];
+        }
+        else {
+          hashForSelf[name] = hash[key];
+        }
+      });
+      sinon.stub(App, 'get', function (k) {
+        if (hashForApp.hasOwnProperty(k)) {
+          return hashForApp[k];
+        }
+        return Em.get(App, k);
+      });
+      sinon.stub(self, 'get', function (k) {
+        if (hashForSelf.hasOwnProperty(k)) {
+          return hashForSelf[k];
+        }
+        return Em.get(self, k);
+      });
+      return this;
+    }
+
+  }
+};
+
+require('test/aliases/computed/equal');
+require('test/aliases/computed/notEqual');
+require('test/aliases/computed/equalProperties');
+require('test/aliases/computed/notEqualProperties');
+require('test/aliases/computed/ifThenElse');
+require('test/aliases/computed/sumProperties');
+require('test/aliases/computed/countBasedMessage');
+require('test/aliases/computed/firstNotBlank');
+require('test/aliases/computed/percents');
+require('test/aliases/computed/existsIn');
+require('test/aliases/computed/notExistsIn');
+require('test/aliases/computed/alias');
+require('test/aliases/computed/gte');
+require('test/aliases/computed/gt');
+require('test/aliases/computed/gteProperties');
+require('test/aliases/computed/gtProperties');
+require('test/aliases/computed/lte');
+require('test/aliases/computed/lt');
+require('test/aliases/computed/lteProperties');
+require('test/aliases/computed/ltProperties');
+require('test/aliases/computed/someBy');
+require('test/aliases/computed/everyBy');
+require('test/aliases/computed/mapBy');
+require('test/aliases/computed/filterBy');
+require('test/aliases/computed/findBy');
+require('test/aliases/computed/sumBy');
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/240a27a5/ambari-web/test/models/alerts/alert_group_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/alerts/alert_group_test.js b/ambari-web/test/models/alerts/alert_group_test.js
new file mode 100644
index 0000000..036a32d
--- /dev/null
+++ b/ambari-web/test/models/alerts/alert_group_test.js
@@ -0,0 +1,29 @@
+/**
+ * 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');
+
+function getModel() {
+  return App.AlertGroup.createRecord();
+}
+
+describe('App.AlertGroup', function() {
+
+  App.TestAliases.testAsComputedAlias(getModel(), 'isAddDefinitionsDisabled', 'default', 'boolean');
+
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/240a27a5/ambari-web/test/models/configs/theme/tab_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/configs/theme/tab_test.js b/ambari-web/test/models/configs/theme/tab_test.js
new file mode 100644
index 0000000..813d997
--- /dev/null
+++ b/ambari-web/test/models/configs/theme/tab_test.js
@@ -0,0 +1,36 @@
+/**
+ * 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 model;
+
+function getModel() {
+  return App.Tab.createRecord();
+}
+
+describe('App.Tab', function () {
+
+  beforeEach(function () {
+    model = getModel();
+  });
+
+  App.TestAliases.testAsComputedSumBy(getModel(), 'errorsCount', 'sections', 'errorsCount');
+
+  App.TestAliases.testAsComputedIfThenElse(getModel(), 'tooltipMsg', 'isHiddenByFilter', Em.I18n.t('services.service.config.nothing.to.display') , '');
+
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/240a27a5/ambari-web/test/models/stack_version/repository_version_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/stack_version/repository_version_test.js b/ambari-web/test/models/stack_version/repository_version_test.js
new file mode 100644
index 0000000..9122d87
--- /dev/null
+++ b/ambari-web/test/models/stack_version/repository_version_test.js
@@ -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.
+ */
+
+var App = require('app');
+var model;
+
+function getModel() {
+  return App.RepositoryVersion.createRecord();
+}
+
+describe('App.RepositoryVersion', function () {
+
+  beforeEach(function () {
+    model = getModel();
+  });
+
+  App.TestAliases.testAsComputedFirstNotBlank(getModel(), 'status', ['stackVersion.state', 'defaultStatus']);
+
+  App.TestAliases.testAsComputedFirstNotBlank(getModel(), 'notInstalledHosts', ['stackVersion.notInstalledHosts', 'App.allHostNames']);
+
+  App.TestAliases.testAsComputedIfThenElse(getModel(), 'noInitHostsTooltip', 'noInitHosts', Em.I18n.t('admin.stackVersions.version.emptyHostsTooltip'), Em.I18n.t('admin.stackVersions.version.hostsTooltip'));
+
+  App.TestAliases.testAsComputedIfThenElse(getModel(), 'noCurrentHostsTooltip', 'noCurrentHosts', Em.I18n.t('admin.stackVersions.version.emptyHostsTooltip'), Em.I18n.t('admin.stackVersions.version.hostsTooltip'));
+
+  App.TestAliases.testAsComputedIfThenElse(getModel(), 'noInstalledHostsTooltip', 'noInstalledHosts', Em.I18n.t('admin.stackVersions.version.emptyHostsTooltip'), Em.I18n.t('admin.stackVersions.version.hostsTooltip'));
+
+});