| <!DOCTYPE html> |
| <!-- |
| Copyright (C) 2015 The Android Open Source Project |
| |
| Licensed 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. |
| --> |
| |
| <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> |
| <title>gr-change-metadata</title> |
| |
| <script src="../../../bower_components/webcomponentsjs/webcomponents.min.js"></script> |
| <script src="../../../bower_components/web-component-tester/browser.js"></script> |
| |
| <link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html"> |
| <link rel="import" href="gr-change-metadata.html"> |
| |
| <test-fixture id="basic"> |
| <template> |
| <gr-change-metadata></gr-change-metadata> |
| </template> |
| </test-fixture> |
| |
| <script> |
| suite('gr-change-metadata tests', function() { |
| var element; |
| var sandbox; |
| |
| setup(function() { |
| sandbox = sinon.sandbox.create(); |
| stub('gr-rest-api-interface', { |
| getConfig: function() { return Promise.resolve({}); }, |
| getLoggedIn: function() { return Promise.resolve(false); }, |
| }); |
| |
| element = fixture('basic'); |
| }); |
| |
| teardown(function() { |
| sandbox.restore(); |
| }); |
| |
| test('computed fields', function() { |
| assert.isFalse(element._computeHideStrategy({status: 'NEW'})); |
| assert.isFalse(element._computeHideStrategy({status: 'DRAFT'})); |
| assert.isTrue(element._computeHideStrategy({status: 'MERGED'})); |
| assert.isTrue(element._computeHideStrategy({status: 'ABANDONED'})); |
| assert.equal(element._computeStrategy({submit_type: 'CHERRY_PICK'}), |
| 'Cherry Pick'); |
| }); |
| |
| test('show strategy for open change', function() { |
| element.change = {status: 'NEW', submit_type: 'CHERRY_PICK', labels: {}}; |
| flushAsynchronousOperations(); |
| var strategy = element.$$('.strategy'); |
| assert.ok(strategy); |
| assert.isFalse(strategy.hasAttribute('hidden')); |
| assert.equal(strategy.children[1].innerHTML, 'Cherry Pick'); |
| }); |
| |
| test('hide strategy for closed change', function() { |
| element.change = {status: 'MERGED', labels: {}}; |
| flushAsynchronousOperations(); |
| assert.isTrue(element.$$('.strategy').hasAttribute('hidden')); |
| }); |
| |
| test('show CC section when NoteDb enabled', function() { |
| function hasCc() { |
| return element._showReviewersByState; |
| } |
| |
| element.serverConfig = {}; |
| assert.isFalse(hasCc()); |
| |
| element.serverConfig = {note_db_enabled: true}; |
| assert.isTrue(hasCc()); |
| }); |
| |
| test('computes submit status', function() { |
| var labels = {}; |
| assert.equal(element._computeSubmitStatus(labels), 'Ready to submit'); |
| labels = {test: {}}; |
| assert.equal(element._computeSubmitStatus(labels), 'Needs test label'); |
| labels.test.approved = true; |
| assert.equal(element._computeSubmitStatus(labels), 'Ready to submit'); |
| labels.test.approved = false; |
| labels.test.optional = true; |
| assert.equal(element._computeSubmitStatus(labels), 'Ready to submit'); |
| labels.test.optional = false; |
| labels.test2 = {}; |
| assert.equal(element._computeSubmitStatus(labels), |
| 'Needs test and test2 labels'); |
| }); |
| |
| test('weblinks hidden when no weblinks', function() { |
| element.commitInfo = {}; |
| flushAsynchronousOperations(); |
| var webLinks = element.$.webLinks; |
| assert.isTrue(webLinks.hasAttribute('hidden')); |
| }); |
| |
| test('weblinks hidden when only gitiles weblink', function() { |
| element.commitInfo = {web_links: [{name: 'gitiles', url: '#'}]}; |
| flushAsynchronousOperations(); |
| var webLinks = element.$.webLinks; |
| assert.isTrue(webLinks.hasAttribute('hidden')); |
| assert.equal(element._computeWebLinks(element.commitInfo), null); |
| }); |
| |
| test('weblinks are visible when other weblinks', function() { |
| element.commitInfo = {web_links: [{name: 'test', url: '#'}]}; |
| flushAsynchronousOperations(); |
| var webLinks = element.$.webLinks; |
| assert.isFalse(webLinks.hasAttribute('hidden')); |
| assert.equal(element._computeWebLinks(element.commitInfo).length, 1); |
| // With two non-gitiles weblinks, there are two returned. |
| element.commitInfo = { |
| web_links: [{name: 'test', url: '#'}, {name: 'test2', url: '#'}]}; |
| assert.equal(element._computeWebLinks(element.commitInfo).length, 2); |
| }); |
| |
| test('weblinks are visible when gitiles and other weblinks', function() { |
| element.commitInfo = { |
| web_links: [{name: 'test', url: '#'}, {name: 'gitiles', url: '#'}]}; |
| flushAsynchronousOperations(); |
| var webLinks = element.$.webLinks; |
| assert.isFalse(webLinks.hasAttribute('hidden')); |
| // Only the non-gitiles weblink is returned. |
| assert.equal(element._computeWebLinks(element.commitInfo).length, 1); |
| }); |
| |
| suite('Topic removal', function() { |
| var change; |
| setup(function() { |
| change = { |
| _number: 'the number', |
| actions: { |
| topic: {enabled: false}, |
| }, |
| change_id: 'the id', |
| topic: 'the topic', |
| status: 'NEW', |
| submit_type: 'CHERRY_PICK', |
| labels: { |
| test: { |
| all: [{_account_id: 1, name: 'bojack', value: 1}], |
| default_value: 0, |
| values: [], |
| }, |
| }, |
| removable_reviewers: [], |
| }; |
| }); |
| |
| test('_computeTopicReadOnly', function() { |
| var mutable = false; |
| assert.isTrue(element._computeTopicReadOnly(mutable, change)); |
| mutable = true; |
| assert.isTrue(element._computeTopicReadOnly(mutable, change)); |
| change.actions.topic.enabled = true; |
| assert.isFalse(element._computeTopicReadOnly(mutable, change)); |
| mutable = false; |
| assert.isTrue(element._computeTopicReadOnly(mutable, change)); |
| }); |
| |
| test('topic read only hides delete button', function() { |
| element.mutable = false; |
| element.change = change; |
| flushAsynchronousOperations(); |
| var button = element.$$('gr-linked-chip').$$('gr-button'); |
| assert.isTrue(button.hasAttribute('hidden')); |
| }); |
| |
| test('topic not read only does not hide delete button', function() { |
| element.mutable = true; |
| change.actions.topic.enabled = true; |
| element.change = change; |
| flushAsynchronousOperations(); |
| var button = element.$$('gr-linked-chip').$$('gr-button'); |
| assert.isFalse(button.hasAttribute('hidden')); |
| }); |
| }); |
| |
| suite('remove reviewer votes', function() { |
| setup(function() { |
| sandbox.stub(element, '_computeValueTooltip').returns(''); |
| sandbox.stub(element, '_computeTopicReadOnly').returns(true); |
| element.change = { |
| _number: 'the number', |
| change_id: 'the id', |
| topic: 'the topic', |
| status: 'NEW', |
| submit_type: 'CHERRY_PICK', |
| labels: { |
| test: { |
| all: [{_account_id: 1, name: 'bojack', value: 1}], |
| default_value: 0, |
| values: [], |
| }, |
| }, |
| removable_reviewers: [], |
| }; |
| }); |
| |
| test('_computeCanDeleteVote hides delete button', function() { |
| flushAsynchronousOperations(); |
| var button = element.$$('gr-account-chip').$$('gr-button'); |
| assert.isTrue(button.hasAttribute('hidden')); |
| element.mutable = true; |
| assert.isTrue(button.hasAttribute('hidden')); |
| }); |
| |
| test('_computeCanDeleteVote shows delete button', function() { |
| element.change.removable_reviewers = [ |
| { |
| _account_id: 1, |
| name: 'bojack', |
| } |
| ]; |
| element.mutable = true; |
| flushAsynchronousOperations(); |
| var button = element.$$('gr-account-chip').$$('gr-button'); |
| assert.isFalse(button.hasAttribute('hidden')); |
| }); |
| |
| test('deletes votes', function(done) { |
| sandbox.stub(element.$.restAPI, 'deleteVote') |
| .returns(Promise.resolve({'ok': true})); |
| element.change.removable_reviewers = [ |
| { |
| _account_id: 1, |
| name: 'bojack', |
| } |
| ]; |
| element.mutable = true; |
| flushAsynchronousOperations(); |
| var button = element.$$('gr-account-chip').$$('gr-button'); |
| MockInteractions.tap(button); |
| flushAsynchronousOperations(); |
| var spliceStub = sinon.stub(element, 'splice', |
| function(path, index, length) { |
| assert.deepEqual(path, ['change.labels', 'test', 'all']); |
| assert.equal(index, 0); |
| assert.equal(length, 1); |
| spliceStub.restore(); |
| done(); |
| }); |
| }); |
| |
| test('changing topic calls setChangeTopic', function() { |
| var topicStub = sandbox.stub(element.$.restAPI, 'setChangeTopic', |
| function() {}); |
| element._handleTopicChanged({}, 'the new topic'); |
| assert.isTrue(topicStub.calledWith('the number', 'the new topic')); |
| }); |
| |
| test('topic href has quotes', function() { |
| var hrefArr = element._computeTopicHref('test') |
| .split('%2522'); // Double-escaped quote. |
| assert.equal(hrefArr[1], 'test'); |
| }); |
| |
| test('clicking x on topic chip removes topic', function() { |
| var topicStub = sandbox.stub(element.$.restAPI, 'setChangeTopic'); |
| flushAsynchronousOperations(); |
| var remove = element.$$('gr-linked-chip').$.remove; |
| MockInteractions.tap(remove); |
| assert.equal(element.change.topic, ''); |
| assert.isTrue(topicStub.called); |
| }); |
| |
| suite('assignee field', function() { |
| var dummyAccount = { |
| _account_id: 1, |
| name: 'bojack', |
| }; |
| var deleteStub; |
| var setStub; |
| setup(function() { |
| deleteStub = sandbox.stub(element.$.restAPI, 'deleteAssignee'); |
| setStub = sandbox.stub(element.$.restAPI, 'setAssignee'); |
| }); |
| |
| test('changing change recomputes _assignee', function() { |
| assert.isFalse(!!element._assignee.length); |
| var change = element.change; |
| change.assignee = dummyAccount; |
| element._changeChanged(change); |
| assert.deepEqual(element._assignee[0], dummyAccount); |
| }); |
| |
| test('modifying _assignee calls API', function() { |
| assert.isFalse(!!element._assignee.length); |
| element.set('_assignee', [dummyAccount]); |
| assert.isTrue(setStub.calledOnce); |
| assert.deepEqual(element.change.assignee, dummyAccount); |
| element.set('_assignee', [dummyAccount]); |
| assert.isTrue(setStub.calledOnce); |
| element.set('_assignee', []); |
| assert.isTrue(deleteStub.calledOnce); |
| assert.equal(element.change.assignee, undefined); |
| element.set('_assignee', []); |
| assert.isTrue(deleteStub.calledOnce); |
| }); |
| }); |
| }); |
| }); |
| </script> |