Repository: ambari Updated Branches: refs/heads/trunk 6e762a04d -> 1067a831f
AMBARI-17060. Visual explain unit tests (pallavkul) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1067a831 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1067a831 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1067a831 Branch: refs/heads/trunk Commit: 1067a831f9ce1932d848d4125214451e04f7a66a Parents: 6e762a0 Author: Pallav Kulshreshtha <[email protected]> Authored: Wed Jun 8 15:43:27 2016 +0530 Committer: Pallav Kulshreshtha <[email protected]> Committed: Wed Jun 8 15:43:27 2016 +0530 ---------------------------------------------------------------------- .../ui/hive-web/app/templates/databases.hbs | 4 +- .../ui/hive-web/tests/helpers/api-mock.js | 13 ++ .../ui/hive-web/tests/helpers/dbclick.js | 26 ++++ .../hive-web/tests/integration/database-test.js | 27 ++++ .../tests/integration/query-editor-test.js | 20 +++ .../tests/integration/saved-queries-test.js | 30 ++++- .../ui/hive-web/tests/integration/udfs-test.js | 18 +++ .../tests/unit/components/udf-tr-view-test.js | 122 +++++++++++++++++++ .../tests/unit/controllers/udfs-test.js | 26 +++- 9 files changed, 280 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/1067a831/contrib/views/hive/src/main/resources/ui/hive-web/app/templates/databases.hbs ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/templates/databases.hbs b/contrib/views/hive/src/main/resources/ui/hive-web/app/templates/databases.hbs index 290cdac..3997ea8 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/templates/databases.hbs +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/templates/databases.hbs @@ -29,7 +29,7 @@ <hr /> {{#if selectedDatabase}} - {{extended-input class="form-control input-sm mozBoxSizeFix" + {{extended-input class="form-control input-sm mozBoxSizeFix input-sm search-tables-text" placeholderTranslation="placeholders.search.tables" valueSearched="searchTables" value=tableSearchTerm}} @@ -39,7 +39,7 @@ {{#if tableSearchResults.tables}} - {{extended-input class="form-control input-sm mozBoxSizeFix" + {{extended-input class="form-control input-sm mozBoxSizeFix search-columns-text" placeholderTranslation="placeholders.search.columns" valueSearched="searchColumns" value=columnSearchTerm}} http://git-wip-us.apache.org/repos/asf/ambari/blob/1067a831/contrib/views/hive/src/main/resources/ui/hive-web/tests/helpers/api-mock.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/tests/helpers/api-mock.js b/contrib/views/hive/src/main/resources/ui/hive-web/tests/helpers/api-mock.js index ed4822d..5bf41e6 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/tests/helpers/api-mock.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/tests/helpers/api-mock.js @@ -246,6 +246,15 @@ export default function() { return [200, {"Content-Type": "application/json"}, JSON.stringify(files)]; }); + this.delete(baseUrl + '/fileResources/1', function (req) { + return [200, {"Content-Type": "application/json"}, JSON.stringify({})]; + }); + + this.put(baseUrl + '/udfs/1', function (req) { + return [200, {"Content-Type": "application/json"}, JSON.stringify({})]; + }); + + this.get(baseUrl + '/fileResources/1', function (req) { var files = { "fileResources": [ @@ -274,6 +283,10 @@ export default function() { return [200, {"Content-Type": "application/json"}, JSON.stringify(data)]; }); + this.delete(baseUrl + '/savedQueries/1', function (req) { + return [200, {"Content-Type": "application/json"}, JSON.stringify({})]; + }); + this.get(baseUrl + '/api/v1/views/TEZ/versions/1', function (req) { var data = { instances: [ http://git-wip-us.apache.org/repos/asf/ambari/blob/1067a831/contrib/views/hive/src/main/resources/ui/hive-web/tests/helpers/dbclick.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/tests/helpers/dbclick.js b/contrib/views/hive/src/main/resources/ui/hive-web/tests/helpers/dbclick.js new file mode 100644 index 0000000..e6dfe83 --- /dev/null +++ b/contrib/views/hive/src/main/resources/ui/hive-web/tests/helpers/dbclick.js @@ -0,0 +1,26 @@ +/** + * 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. + */ + +Ember.Test.registerAsyncHelper('dblclick', + function (app, selector, context) { + var $el = findWithAssert(selector, context); + Ember.run(function () { + $el.dblclick(); + }); + } +); http://git-wip-us.apache.org/repos/asf/ambari/blob/1067a831/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/database-test.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/database-test.js b/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/database-test.js index 52cda77..1af72c8 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/database-test.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/database-test.js @@ -101,3 +101,30 @@ test('Searching for a table will display table results and column search field', }); }); }); + + +test('Users can search tables', function (assert) { + assert.expect(4); + + visit('/'); + + andThen(function () { + fillIn(find('.database-explorer .search-tables-text'), 'not_found'); + keyEvent(find('.database-explorer .search-tables-text'), 'keyup', 13); + }); + + andThen(function () { + assert.ok(find('.alert-warning .database-explorer-alert'), 'Alert is show when a table is not found'); + }); + + andThen(function () { + fillIn(find('.database-explorer .search-tables-text'), 'table'); + keyEvent(find('.database-explorer .search-tables-text'), 'keyup', 13); + }); + + andThen(function () { + assert.ok(find('.database-explorer .nav-tabs li:last').hasClass('active'), 'Search results tab is active'); + assert.ok(find('.database-explorer .databases .fa-database').length, 'Found databases are shown'); + assert.ok(find('.database-explorer .databases .tables').length, 'Found tables are shown'); + }); +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/1067a831/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/query-editor-test.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/query-editor-test.js b/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/query-editor-test.js index b409e12..3073013 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/query-editor-test.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/query-editor-test.js @@ -20,6 +20,7 @@ import Ember from 'ember'; import { test } from 'ember-qunit'; import startApp from '../helpers/start-app'; import api from '../helpers/api-mock'; +import '../helpers/dbclick'; var App; var server; @@ -104,3 +105,22 @@ test('Can save query', function() { click('.modal-footer .btn-danger'); }); + +test('Can change tab title', function (assert) { + assert.expect(1); + + visit('/'); + + andThen(function () { + dblclick('.query-editor-panel tabs li:first a'); + + andThen(function () { + fillIn('.modal-body input', 'WS'); + click('.modal-footer .btn-success'); + + andThen(function () { + assert.equal(find('.query-editor-panel tabs li:first a').text().trim(), 'WS', 'Tab renamed'); + }); + }); + }); +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/1067a831/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/saved-queries-test.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/saved-queries-test.js b/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/saved-queries-test.js index c444523..fdbcd4e 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/saved-queries-test.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/saved-queries-test.js @@ -117,10 +117,36 @@ test('Saved Query options menu', function() { expect(2); visit("/queries"); - click('.fa-gear'); + click('.fa-gear:first'); andThen(function() { equal(find('.dropdown-menu:visible').length, 1, 'Query menu is visible'); equal(find('.dropdown-menu:visible li').length, 2, 'Query menu has 2 options'); }); -}); \ No newline at end of file +}); + +test('User is able to see history for a query', function (assert) { + assert.expect(2); + + visit("/queries"); + click('.fa-gear:first'); + click('.dropdown-menu:visible li:first'); + + andThen(function () { + assert.equal(currentURL(), "/history", 'User is redirected to history'); + assert.equal(find('#content .table tbody tr').length, 1, 'Queries are filtered'); + }); +}); + +test('User is able to delete a query', function (assert) { + assert.expect(1); + + visit("/queries"); + click('.fa-gear:first'); + click('.dropdown-menu:visible li:last'); + click('.modal-footer .btn-success'); + + andThen(function () { + equal(find('#content .table tbody tr').length, 1, 'Query deleted'); + }); +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/1067a831/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/udfs-test.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/udfs-test.js b/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/udfs-test.js index 95a0043..526efc0 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/udfs-test.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/tests/integration/udfs-test.js @@ -89,3 +89,21 @@ test('User is able to add udf', function() { equal(find('#content .table tbody tr').length, 3); }); }); + + +test('Can delete file resource', function (assert) { + assert.expect(1); + + visit('/udfs'); + click('.fa-gear:first'); + click('.dropdown-menu li:first'); + click('.dropdown-toggle:first'); + click('.fa-remove:first'); + + andThen(function () { + click('.modal-footer .btn-success'); + click('tr.ember-view:first .btn-success'); + }); + + assert.equal($('tr.ember-view:first td:first').text().trim().length, 0, 'File Resource Deleted'); +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/1067a831/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/components/udf-tr-view-test.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/components/udf-tr-view-test.js b/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/components/udf-tr-view-test.js new file mode 100644 index 0000000..18916de --- /dev/null +++ b/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/components/udf-tr-view-test.js @@ -0,0 +1,122 @@ +/** + * 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. + */ + +import Ember from 'ember'; +import { moduleForComponent, test } from 'ember-qunit'; + +moduleForComponent('udf-tr-view', 'UdfTrViewComponent', { + unit: true, + needs: ['component:select-widget'] +}); + +test('Can send actions', function (assert) { + assert.expect(6); + + var targetObject = { + onDeleteUdf: function () { + assert.ok(true, 'onDeleteUdf called'); + }, + onAddFileResource: function () { + assert.ok(true, 'onAddFileResource called'); + }, + onDeleteFileResource: function () { + assert.ok(true, 'onDeleteFileResource called'); + }, + onSaveUdf: function () { + assert.ok(true, 'onSaveUdf called'); + }, + }; + + var component = this.subject({ + onDeleteUdf: 'onDeleteUdf', + onAddFileResource: 'onAddFileResource', + onDeleteFileResource: 'onDeleteFileResource', + onSaveUdf: 'onSaveUdf', + + targetObject: targetObject, + + udf: Ember.Object.create() + }); + + Ember.run(function () { + component.send('deleteUdf'); + component.send('addFileResource'); + component.send('deleteFileResource'); + component.send('save'); + + component.send('editUdf'); + component.send('editFileResource', {}); + }); + + assert.ok(component.get('udf.isEditing'), 'Can edit udf'); + assert.ok(component.get('udf.isEditingResource'), 'Can edit resource'); +}); + +test('It sets isEditing to true if udf.isNew', function (assert) { + assert.expect(1); + + var component = this.subject({ + udf: Ember.Object.create({ + isNew: true, + isEditing: false + }) + }); + + var $component = this.render(); + assert.ok(component.get('udf.isEditing'), 'isEditing set to true'); +}); + +test('Cancel edit whould rollback changes', function (assert) { + assert.expect(5); + + var backup = 'fileResource backup'; + var file = Ember.Object.create({ + rollback: function () { + assert.ok(true, 'file.rollback() called'); + } + }); + + var udf = Ember.Object.create({ + isEditing: true, + isEditingResource: true, + get: function () { + var defer = new Ember.RSVP.defer; + defer.resolve(file); + + return defer.promise; + }, + rollback: function () { + assert.ok(true, 'udf.rollback() called'); + } + }); + + var component = this.subject({ + file: file, + udf: udf, + fileBackup: backup + }); + + Ember.run(function () { + component.send('cancel'); + }); + + assert.ok(!component.get('udf.isEditing'), 'isEditing set to false'); + assert.ok(!component.get('udf.isEditingResource'), 'isEditingResource set to false'); + + assert.equal(component.get('udf.fileResource'), backup, 'backup is set as file resource'); +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/1067a831/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/controllers/udfs-test.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/controllers/udfs-test.js b/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/controllers/udfs-test.js index 5bd369e..2568d4a 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/controllers/udfs-test.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/tests/unit/controllers/udfs-test.js @@ -19,7 +19,11 @@ import Ember from 'ember'; import { moduleFor, test } from 'ember-qunit'; -moduleFor('controller:udfs', 'UdfsController', {}); +moduleFor('controller:udfs', 'UdfsController', { + needs: [ + 'model:file-resource' + ] +}); test('controller is initialized', function() { expect(3); @@ -57,4 +61,22 @@ test('add', function() { Ember.run(function () { component.send('add'); }); -}); \ No newline at end of file +}); + +test('handleAddFileResource', function (assert) { + assert.expect(2); + + var udf = Ember.Object.create({ + isEditingResource: false, + fileResource: null + }); + + var controller = this.subject(); + + Ember.run(function () { + controller.send('handleAddFileResource', udf); + }); + + assert.ok(udf.get('fileResource'), 'File Resource created'); + assert.ok(udf.get('isEditingResource'), 'Editing mode in enabled'); +});
