<!DOCTYPE html>
<!--
Copyright (C) 2016 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-actions</title>

<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<script src="../../../scripts/util.js"></script>

<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-change-actions.html">

<test-fixture id="basic">
  <template>
    <gr-change-actions></gr-change-actions>
  </template>
</test-fixture>

<script>
  suite('gr-change-actions tests', function() {
    var element;
    setup(function() {
      stub('gr-rest-api-interface', {
        getChangeRevisionActions: function() {
          return Promise.resolve({
            '/': {
              method: 'DELETE',
              label: 'Delete',
              title: 'Delete draft revision 2',
              enabled: true,
            },
            cherrypick: {
              method: 'POST',
              label: 'Cherry Pick',
              title: 'Cherry pick change to a different branch',
              enabled: true,
            },
            rebase: {
              method: 'POST',
              label: 'Rebase',
              title: 'Rebase onto tip of branch or parent change',
              enabled: true,
            },
            submit: {
              method: 'POST',
              label: 'Submit',
              title: 'Submit patch set 2 into master',
              enabled: true,
            },
          });
        },
        send: function(method, url, payload) {
          if (method !== 'POST') { return Promise.reject('bad method'); }

          if (url === '/changes/42/revisions/2/submit') {
            return Promise.resolve({
              ok: true,
              text: function() { return Promise.resolve(')]}\'\n{}'); },
            });
          } else if (url === '/changes/42/revisions/2/rebase') {
            return Promise.resolve({
              ok: true,
              text: function() { return Promise.resolve(')]}\'\n{}'); },
            });
          }

          return Promise.reject('bad url');
        },
      });

      element = fixture('basic');
      element.change = {};
      element.changeNum = '42';
      element.patchNum = '2';
      element.actions = {
        '/': {
          method: 'DELETE',
          label: 'Delete',
          title: 'Delete draft change 42',
          enabled: true,
        },
      };
      return element.reload();
    });

    test('_shouldHideActions', function() {
      assert.isTrue(element._shouldHideActions(undefined, true));
      assert.isTrue(element._shouldHideActions({base: {}}, false));
      assert.isFalse(element._shouldHideActions({base: ['test']}, false));
    });

    test('hide revision action', function(done) {
      flush(function() {
        var buttonEl = element.$$('[data-action-key="submit"]');
        assert.isOk(buttonEl);
        assert.throws(element.setActionHidden.bind(element, 'invalid type'));
        element.setActionHidden(element.ActionType.REVISION,
            element.RevisionActions.SUBMIT, true);
        assert.lengthOf(element._hiddenActions, 1);
        element.setActionHidden(element.ActionType.REVISION,
            element.RevisionActions.SUBMIT, true);
        assert.lengthOf(element._hiddenActions, 1);
        flush(function() {
          var buttonEl = element.$$('[data-action-key="submit"]');
          assert.isNotOk(buttonEl);

          element.setActionHidden(element.ActionType.REVISION,
            element.RevisionActions.SUBMIT, false);
          flush(function() {
            var buttonEl = element.$$('[data-action-key="submit"]');
            assert.isOk(buttonEl);
            assert.isFalse(buttonEl.hasAttribute('hidden'));
            done();
          });
        });
      });
    });

    test('hide menu action', function(done) {
      flush(function() {
        var buttonEl = element.$.moreActions.$$('span[data-id="delete"]');
        assert.isOk(buttonEl);
        assert.throws(element.setActionHidden.bind(element, 'invalid type'));
        element.setActionHidden(element.ActionType.CHANGE,
            element.ChangeActions.DELETE, true);
        assert.lengthOf(element._hiddenActions, 1);
        element.setActionHidden(element.ActionType.CHANGE,
            element.ChangeActions.DELETE, true);
        assert.lengthOf(element._hiddenActions, 1);
        flush(function() {
          var buttonEl = element.$.moreActions.$$('span[data-id="delete"]');
          assert.isNotOk(buttonEl);

          element.setActionHidden(element.ActionType.CHANGE,
            element.RevisionActions.DELETE, false);
          flush(function() {
            var buttonEl = element.$.moreActions.$$('span[data-id="delete"]');
            assert.isOk(buttonEl);
            done();
          });
        });
      });
    });

    test('buttons exist', function(done) {
      element._loading = false;
      flush(function() {
        var buttonEls = Polymer.dom(element.root)
            .querySelectorAll('gr-button');
        var menuItems = element.$.moreActions.items;
        assert.equal(buttonEls.length + menuItems.length, 6);
        assert.isFalse(element.hidden);
        done();
      });
    });

    test('delete buttons have explicit labels', function(done) {
      flush(function() {
        var deleteItems = element.$.moreActions.items.filter(function(item) {
          return item.id === 'delete';
        });
        assert.equal(deleteItems.length, 2);
        assert.notEqual(deleteItems[0].name, deleteItems[1].name);
        assert.isTrue(
            deleteItems[0].name === 'Delete Revision' ||
            deleteItems[0].name === 'Delete Change'
        );
        assert.isTrue(
            deleteItems[1].name === 'Delete Revision' ||
            deleteItems[1].name === 'Delete Change'
        );
        done();
      });
    });

    test('get revision object from change', function() {
      var revObj = {_number: 2, foo: 'bar'};
      var change = {
        revisions: {
          rev1: {_number: 1},
          rev2: revObj,
        },
      };
      assert.deepEqual(element._getRevision(change, '2'), revObj);
    });

    test('_actionComparator sort order', function() {
      var actions = [
        {label: '123', __type: 'change', __key: 'review'},
        {label: 'abc', __type: 'revision'},
        {label: 'abc', __type: 'change'},
        {label: 'def', __type: 'change'},
        {label: 'def', __type: 'change', __primary: true},
      ];

      var result = actions.slice();
      result.reverse();
      result.sort(element._actionComparator);

      assert.deepEqual(result, actions);
    });

    test('submit change', function(done) {
      element.change = {
        revisions: {
          rev1: {_number: 1},
          rev2: {_number: 2},
        },
      };
      element.patchNum = '2';

      flush(function() {
        var submitButton = element.$$('gr-button[data-action-key="submit"]');
        assert.ok(submitButton);
        MockInteractions.tap(submitButton);

        // Upon success it should fire the reload-change event.
        element.addEventListener('reload-change', function(e) {
          done();
        });
      });
    });

    test('submit change with plugin hook', function(done) {
      var canSubmitStub = sinon.stub(element, '_canSubmitChange',
          function() { return false; });
      var fireActionStub = sinon.stub(element, '_fireAction');
      flush(function() {
        var submitButton = element.$$('gr-button[data-action-key="submit"]');
        assert.ok(submitButton);
        MockInteractions.tap(submitButton);
        assert.equal(fireActionStub.callCount, 0);

        canSubmitStub.restore();
        fireActionStub.restore();
        done();
      });
    });

    test('chain state', function() {
      assert.equal(element._hasKnownChainState, false);
      element.hasParent = true;
      assert.equal(element._hasKnownChainState, true);
      element.hasParent = false;
    });

    test('_calculateDisabled', function() {
      var hasKnownChainState = false;
      var action = {__key: 'rebase', enabled: true};
      assert.equal(
          element._calculateDisabled(action, hasKnownChainState), true);

      action.__key = 'delete';
      assert.equal(
          element._calculateDisabled(action, hasKnownChainState), false);

      action.__key = 'rebase';
      hasKnownChainState = true;
      assert.equal(
          element._calculateDisabled(action, hasKnownChainState), false);

      action.enabled = false;
      assert.equal(
          element._calculateDisabled(action, hasKnownChainState), true);
    });

    test('rebase change', function(done) {
      var fireActionStub = sinon.stub(element, '_fireAction');
      flush(function() {
        var rebaseButton = element.$$('gr-button[data-action-key="rebase"]');
        MockInteractions.tap(rebaseButton);
        var rebaseAction = {
          __key: 'rebase',
          __type: 'revision',
          __primary: false,
          enabled: true,
          label: 'Rebase',
          method: 'POST',
          title: 'Rebase onto tip of branch or parent change',
        };
        // rebase on other
        element.$.confirmRebase.base = '1234';
        element._handleRebaseConfirm();
        assert.deepEqual(fireActionStub.lastCall.args,
          ['/rebase', rebaseAction, true, {base: '1234'}]);

        // rebase on parent
        element.$.confirmRebase.base = null;
        element._handleRebaseConfirm();
        assert.deepEqual(fireActionStub.lastCall.args,
          ['/rebase', rebaseAction, true, {base: null}]);

        // rebase on tip
        element.$.confirmRebase.base = '';
        element._handleRebaseConfirm();
        assert.deepEqual(fireActionStub.lastCall.args,
          ['/rebase', rebaseAction, true, {base: ''}]);

        fireActionStub.restore();
        done();
      });
    });

    test('two dialogs are not shown at the same time', function(done) {
      element._hasKnownChainState = true;
      flush(function() {
        var rebaseButton = element.$$('gr-button[data-action-key="rebase"]');
        assert.ok(rebaseButton);
        MockInteractions.tap(rebaseButton);
        flushAsynchronousOperations();
        assert.isFalse(element.$.confirmRebase.hidden);

        element._handleCherrypickTap();
        flushAsynchronousOperations();
        assert.isTrue(element.$.confirmRebase.hidden);
        assert.isFalse(element.$.confirmCherrypick.hidden);
        done();
      });
    });

    suite('cherry-pick', function() {
      var fireActionStub;
      var alertStub;

      setup(function() {
        fireActionStub = sinon.stub(element, '_fireAction');
        alertStub = sinon.stub(window, 'alert');
      });

      teardown(function() {
        alertStub.restore();
        fireActionStub.restore();
      });

      test('works', function() {
        element._handleCherrypickTap();
        var action = {
          __key: 'cherrypick',
          __type: 'revision',
          __primary: false,
          enabled: true,
          label: 'Cherry Pick',
          method: 'POST',
          title: 'Cherry pick change to a different branch',
        };

        element._handleCherrypickConfirm();
        assert.equal(fireActionStub.callCount, 0);

        element.$.confirmCherrypick.branch = 'master';
        element._handleCherrypickConfirm();
        assert.equal(fireActionStub.callCount, 0);  // Still needs a message.

        // Add attributes that are used to determine the message.
        element.$.confirmCherrypick.commitMessage = 'foo message';
        element.$.confirmCherrypick.changeStatus = 'OPEN';
        element.$.confirmCherrypick.commitNum = '123';

        element._handleCherrypickConfirm();

        assert.equal(element.$.confirmCherrypick.$.messageInput.value,
            'foo message');

        assert.deepEqual(fireActionStub.lastCall.args, [
          '/cherrypick', action, true, {
            destination: 'master',
            message: 'foo message',
          },
        ]);
      });

      test('branch name cleared when re-open cherrypick', function() {
        var emptyBranchName = '';
        element.$.confirmCherrypick.branch = 'master';

        element._handleCherrypickTap();
        assert.equal(element.$.confirmCherrypick.branch, emptyBranchName);
      });
    });

    test('custom actions', function(done) {
      // Add a button with the same key as a server-based one to ensure
      // collisions are taken care of.
      var key = element.addActionButton(element.ActionType.REVISION, 'Bork!');
      element.addEventListener(key + '-tap', function(e) {
        assert.equal(e.detail.node.getAttribute('data-action-key'), key);
        element.removeActionButton(key);
        flush(function() {
          assert.notOk(element.$$('[data-action-key="' + key + '"]'));
          done();
        });
      });
      flush(function() {
        MockInteractions.tap(element.$$('[data-action-key="' + key + '"]'));
      });
    });

    test('_setLoadingOnButtonWithKey top-level', function() {
      var key = 'rebase';
      var cleanup = element._setLoadingOnButtonWithKey(key);
      assert.equal(element._actionLoadingMessage, 'Rebasing...');

      var button = element.$$('[data-action-key="' + key + '"]');
      assert.isTrue(button.hasAttribute('loading'));
      assert.isTrue(button.disabled);

      assert.isOk(cleanup);
      assert.isFunction(cleanup);
      cleanup();

      assert.isFalse(button.hasAttribute('loading'));
      assert.isFalse(button.disabled);
      assert.isNotOk(element._actionLoadingMessage);
    });

    test('_setLoadingOnButtonWithKey overflow menu', function() {
      var key = 'cherrypick';
      var cleanup = element._setLoadingOnButtonWithKey(key);
      assert.equal(element._actionLoadingMessage, 'Cherry-Picking...');
      assert.include(element._disabledMenuActions, 'cherrypick');
      assert.isFunction(cleanup);

      cleanup();

      assert.notOk(element._actionLoadingMessage);
      assert.notInclude(element._disabledMenuActions, 'cherrypick');
    });

    suite('revert change', function() {
      var alertStub;
      var fireActionStub;

      setup(function() {
        fireActionStub = sinon.stub(element, '_fireAction');
        alertStub = sinon.stub(window, 'alert');
        element.actions = {
          revert: {
            method: 'POST',
            label: 'Revert',
            title: 'Revert the change',
            enabled: true,
          },
        };
        return element.reload();
      });

      teardown(function() {
        alertStub.restore();
        fireActionStub.restore();
      });

      test('revert change with plugin hook', function(done) {
        element.change = {
          current_revision: 'abc1234',
        };
        var newRevertMsg = 'Modified revert msg';
        var modifyRevertMsgStub = sinon.stub(element, '_modifyRevertMsg',
            function() { return newRevertMsg; });
        var populateRevertMsgStub = sinon.stub(
            element.$.confirmRevertDialog, 'populateRevertMessage',
            function() { return 'original msg'; });
        flush(function() {
          var revertButton = element.$$('gr-button[data-action-key="revert"]');
          MockInteractions.tap(revertButton);

          assert.equal(element.$.confirmRevertDialog.message, newRevertMsg);

          populateRevertMsgStub.restore();
          modifyRevertMsgStub.restore();
          done();
        });
      });

      test('works', function() {
        element.change = {
          current_revision: 'abc1234',
        };
        var populateRevertMsgStub = sinon.stub(
            element.$.confirmRevertDialog, 'populateRevertMessage',
            function() { return 'original msg'; });
        var revertButton = element.$$('gr-button[data-action-key="revert"]');
        MockInteractions.tap(revertButton);

        element.$.confirmRevertDialog.message = 'foo message';
        element._handleRevertDialogConfirm();
        assert.notOk(alertStub.called);

        var action = {
          __key: 'revert',
          __type: 'change',
          __primary: false,
          enabled: true,
          label: 'Revert',
          method: 'POST',
          title: 'Revert the change',
        };
        assert.deepEqual(fireActionStub.lastCall.args, [
          '/revert', action, false, {
            message: 'foo message',
          }]);
        populateRevertMsgStub.restore();
      });
    });

    suite('delete change', function() {
      var fireActionStub;
      var deleteAction;

      setup(function() {
        fireActionStub = sinon.stub(element, '_fireAction');
        element.change = {
          current_revision: 'abc1234',
        };
        deleteAction = {
          method: 'DELETE',
          label: 'Delete Change',
          title: 'Delete change X_X',
          enabled: true,
        };
        element.actions = {
          '/': deleteAction,
        };
      });

      teardown(function() {
        fireActionStub.restore();
      });

      test('does not delete on action', function() {
        element._handleDeleteTap();
        assert.isFalse(fireActionStub.called);
      });

      test('shows confirm dialog', function() {
        element._handleDeleteTap();
        assert.isFalse(element.$$('#confirmDeleteDialog').hidden);
        MockInteractions.tap(
            element.$$('#confirmDeleteDialog').$$('gr-button[primary]'));
        flushAsynchronousOperations();
        assert.isTrue(fireActionStub.calledWith('/', deleteAction, false));
      });

      test('hides delete confirm on cancel', function() {
        element._handleDeleteTap();
        MockInteractions.tap(
            element.$$('#confirmDeleteDialog').$$('gr-button:not([primary])'));
        flushAsynchronousOperations();
        assert.isTrue(element.$$('#confirmDeleteDialog').hidden);
        assert.isFalse(fireActionStub.called);
      });
    });

    suite('quick approve', function() {
      setup(function() {
        element.change = {
          current_revision: 'abc1234',
        };
        element.change = {
          current_revision: 'abc1234',
          labels: {
            foo: {
              values: {
                '-1': '',
                ' 0': '',
                '+1': '',
              },
            },
          },
          permitted_labels: {
            foo: ['-1', ' 0', '+1'],
          },
        };
        flushAsynchronousOperations();
      });

      test('added when can approve', function() {
        var approveButton = element.$$('gr-button[data-action-key=\'review\']');
        assert.isNotNull(approveButton);
      });

      test('is first in list of actions', function() {
        var approveButton = element.$$('gr-button');
        assert.equal(approveButton.getAttribute('data-label'), 'foo+1');
      });

      test('not added when already approved', function() {
        element.change = {
          current_revision: 'abc1234',
          labels: {
            foo: {
              approved: {},
              values: {},
            },
          },
          permitted_labels: {
            foo: [' 0', '+1'],
          },
        };
        flushAsynchronousOperations();
        var approveButton = element.$$('gr-button[data-action-key=\'review\']');
        assert.isNull(approveButton);
      });

      test('not added when label not permitted', function() {
        element.change = {
          current_revision: 'abc1234',
          labels: {
            foo: {values: {}},
          },
          permitted_labels: {
            bar: [],
          },
        };
        flushAsynchronousOperations();
        var approveButton = element.$$('gr-button[data-action-key=\'review\']');
        assert.isNull(approveButton);
      });

      test('approves when taped', function() {
        var fireActionStub = sinon.stub(element, '_fireAction');
        MockInteractions.tap(
            element.$$('gr-button[data-action-key=\'review\']'));
        flushAsynchronousOperations();
        assert.isTrue(fireActionStub.called);
        assert.isTrue(fireActionStub.calledWith('/review'));
        var payload = fireActionStub.lastCall.args[3];
        assert.deepEqual(payload.labels, {foo: '+1'});
        fireActionStub.restore();
      });

      test('not added when multiple labels are required', function() {
        element.change = {
          current_revision: 'abc1234',
          labels: {
            foo: {values: {}},
            bar: {values: {}},
          },
          permitted_labels: {
            foo: [' 0', '+1'],
            bar: [' 0', '+1', '+2'],
          },
        };
        flushAsynchronousOperations();
        var approveButton = element.$$('gr-button[data-action-key=\'review\']');
        assert.isNull(approveButton);
      });

      test('button label for missing approval', function() {
        element.change = {
          current_revision: 'abc1234',
          labels: {
            foo: {
              values: {
                ' 0': '',
                '+1': '',
              },
            },
            bar: {approved: {}, values: {}},
          },
          permitted_labels: {
            foo: [' 0', '+1'],
            bar: [' 0', '+1', '+2'],
          },
        };
        flushAsynchronousOperations();
        var approveButton = element.$$('gr-button[data-action-key=\'review\']');
        assert.equal(approveButton.getAttribute('data-label'), 'foo+1');
      });

      test('no quick approve if score is not maximal for a label', function() {
        element.change = {
          current_revision: 'abc1234',
          labels: {
            bar: {
              value: 1,
              values: {
                ' 0': '',
                '+1': '',
                '+2': '',
              },
            },
          },
          permitted_labels: {
            bar: [' 0', '+1'],
          },
        };
        flushAsynchronousOperations();
        var approveButton = element.$$('gr-button[data-action-key=\'review\']');
        assert.isNull(approveButton);
      });

      test('approving label with a non-max score', function() {
        element.change = {
          current_revision: 'abc1234',
          labels: {
            bar: {
              value: 1,
              values: {
                ' 0': '',
                '+1': '',
                '+2': '',
              },
            },
          },
          permitted_labels: {
            bar: [' 0', '+1', '+2'],
          },
        };
        flushAsynchronousOperations();
        var approveButton = element.$$('gr-button[data-action-key=\'review\']');
        assert.equal(approveButton.getAttribute('data-label'), 'bar+2');
      });
    });
  });
</script>
