Files
gerrit/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api_test.html
Becky Siegel 61ecc0cf10 Update gr-confirm-rebase-dialog with tailored options
The three rebase options are
1. Rebase on parent change
2. Rebase on top of the <branch name> branch
3. Rebase on a specific change or ref

Scenarios:

Has parent, can rebase on parent
- Show all 3 options. Second two options show "breaks relation chain"
  message.

Has parent, can't rebase on parent
- Instead of option 1, show message that is up to date with parent.
- Show second two options with "breaks relation chain" message.

Has no parent, can rebase on parent (tip of branch)
- Do not show option 1, nor dipslay message in its place.
- Show second two options without "breaks relation chain" message.

Has no parent, can't rebase on parent (tip of branch)
- Do not show option 1, nor dipslay message in its place.
- Instead of option, show message that change is up to date with tip of
  branch already
- Show option 3  without "breaks relation chain" message.

Because 'hasParent' isn't immediately known when change actions are
displayed, the rebase button will also remain disabled until this
becomes known.

Bug: Issue 5447
Change-Id: I45ef8241a75c1f5d197ed64e51b19c5ce74d0227
2017-02-22 22:32:39 +00:00

142 lines
4.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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-js-api</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">
<!--
This must refer to the element this interface is wrapping around. Otherwise
breaking changes to gr-change-actions wont be noticed.
-->
<link rel="import" href="../../change/gr-change-actions/gr-change-actions.html">
<test-fixture id="basic">
<template>
<gr-change-actions></gr-change-actions>
</template>
</test-fixture>
<script>
suite('gr-js-api-interface tests', function() {
var element;
var changeActions;
// Because deepEqual doesnt behave in Safari.
function assertArraysEqual(actual, expected) {
assert.equal(actual.length, expected.length);
for (var i = 0; i < actual.length; i++) {
assert.equal(actual[i], expected[i]);
}
}
setup(function() {
element = fixture('basic');
element.change = {};
element._hasKnownChainState = false;
var plugin;
Gerrit.install(function(p) { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
changeActions = plugin.changeActions();
});
teardown(function() {
changeActions = null;
});
test('property existence', function() {
[
'ActionType',
'ChangeActions',
'RevisionActions',
].forEach(function(p) {
assertArraysEqual(changeActions[p], element[p]);
});
});
test('add/remove primary action keys', function() {
element.primaryActionKeys = [];
changeActions.addPrimaryActionKey('foo');
assertArraysEqual(element.primaryActionKeys, ['foo']);
changeActions.addPrimaryActionKey('foo');
assertArraysEqual(element.primaryActionKeys, ['foo']);
changeActions.addPrimaryActionKey('bar');
assertArraysEqual(element.primaryActionKeys, ['foo', 'bar']);
changeActions.removePrimaryActionKey('foo');
assertArraysEqual(element.primaryActionKeys, ['bar']);
changeActions.removePrimaryActionKey('baz');
assertArraysEqual(element.primaryActionKeys, ['bar']);
changeActions.removePrimaryActionKey('bar');
assertArraysEqual(element.primaryActionKeys, []);
});
test('action buttons', function(done) {
var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
var handler = sinon.spy();
changeActions.addTapListener(key, handler);
flush(function() {
MockInteractions.tap(element.$$('[data-action-key="' + key + '"]'));
assert(handler.calledOnce);
changeActions.removeTapListener(key, handler);
MockInteractions.tap(element.$$('[data-action-key="' + key + '"]'));
assert(handler.calledOnce);
changeActions.remove(key);
flush(function() {
assert.isNull(element.$$('[data-action-key="' + key + '"]'));
done();
});
});
});
test('action button properties', function(done) {
var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
flush(function() {
var button = element.$$('[data-action-key="' + key + '"]');
assert.isOk(button);
assert.equal(button.getAttribute('data-label'), 'Bork!');
assert.isNotOk(button.disabled);
changeActions.setLabel(key, 'Yo');
changeActions.setEnabled(key, false);
flush(function() {
assert.equal(button.getAttribute('data-label'), 'Yo');
assert.isTrue(button.disabled);
done();
});
});
});
test('hide action buttons', function(done) {
var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
flush(function() {
var button = element.$$('[data-action-key="' + key + '"]');
assert.isOk(button);
assert.isFalse(button.hasAttribute('hidden'));
changeActions.setActionHidden(changeActions.ActionType.REVISION, key,
true);
flush(function() {
var button = element.$$('[data-action-key="' + key + '"]');
assert.isNotOk(button);
done();
});
});
});
});
</script>