diff options
Diffstat (limited to 'polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html')
-rw-r--r-- | polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html | 528 |
1 files changed, 361 insertions, 167 deletions
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html index b188acad2e..81fe54ef65 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html @@ -1,5 +1,6 @@ <!DOCTYPE html> <!-- +@license Copyright (C) 2016 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); @@ -79,12 +80,16 @@ limitations under the License. return Promise.reject('bad url'); }, + getProjectConfig() { return Promise.resolve({}); }, }); + sandbox = sinon.sandbox.create(); + sandbox.stub(Gerrit, 'awaitPluginsLoaded').returns(Promise.resolve()); + element = fixture('basic'); element.change = {}; element.changeNum = '42'; - element.patchNum = '2'; + element.latestPatchNum = '2'; element.actions = { '/': { method: 'DELETE', @@ -93,7 +98,10 @@ limitations under the License. enabled: true, }, }; - sandbox = sinon.sandbox.create(); + sandbox.stub(element.$.confirmCherrypick.$.restAPI, + 'getRepoBranches').returns(Promise.resolve([])); + sandbox.stub(element.$.confirmMove.$.restAPI, + 'getRepoBranches').returns(Promise.resolve([])); return element.reload(); }); @@ -102,13 +110,21 @@ limitations under the License. sandbox.restore(); }); + test('primary and secondary actions split properly', () => { + // Submit should be the only primary action. + assert.equal(element._topLevelPrimaryActions.length, 1); + assert.equal(element._topLevelPrimaryActions[0].label, 'Submit'); + assert.equal(element._topLevelSecondaryActions.length, + element._topLevelActions.length - 1); + }); + test('_shouldHideActions', () => { assert.isTrue(element._shouldHideActions(undefined, true)); assert.isTrue(element._shouldHideActions({base: {}}, false)); assert.isFalse(element._shouldHideActions({base: ['test']}, false)); }); - test('plugin revision actions', () => { + test('plugin revision actions', done => { sandbox.stub(element.$.restAPI, 'getChangeActionURL').returns( Promise.resolve('the-url')); element.revisionActions = { @@ -117,12 +133,13 @@ limitations under the License. assert.isOk(element.revisionActions['plugin~action']); flush(() => { assert.isTrue(element.$.restAPI.getChangeActionURL.calledWith( - element.changeNum, element.patchNum, '/plugin~action')); + element.changeNum, element.latestPatchNum, '/plugin~action')); assert.equal(element.revisionActions['plugin~action'].__url, 'the-url'); + done(); }); }); - test('plugin change actions', () => { + test('plugin change actions', done => { sandbox.stub(element.$.restAPI, 'getChangeActionURL').returns( Promise.resolve('the-url')); element.actions = { @@ -132,16 +149,15 @@ limitations under the License. flush(() => { assert.isTrue(element.$.restAPI.getChangeActionURL.calledWith( element.changeNum, null, '/plugin~action')); - assert.equal(element.revisionActions['plugin~action'].__url, 'the-url'); + assert.equal(element.actions['plugin~action'].__url, 'the-url'); + done(); }); }); test('not supported actions are filtered out', () => { - element.revisionActions = { - followup: { - }, - }; - assert.equal(element.querySelectorAll('section gr-button').length, 0); + element.revisionActions = {followup: {}}; + assert.equal(element.querySelectorAll( + 'section gr-button[data-action-type="revision"]').length, 0); }); test('getActionDetails', () => { @@ -188,7 +204,11 @@ limitations under the License. const buttonEls = Polymer.dom(element.root) .querySelectorAll('gr-button'); const menuItems = element.$.moreActions.items; - assert.equal(buttonEls.length + menuItems.length, 6); + + // Total button number is one greater than the number of total actions + // due to the existence of the overflow menu trigger. + assert.equal(buttonEls.length + menuItems.length, + element._allActionValues.length + 1); assert.isFalse(element.hidden); done(); }); @@ -201,9 +221,7 @@ limitations under the License. }); assert.equal(deleteItems.length, 1); assert.notEqual(deleteItems[0].name); - assert.isTrue( - deleteItems[0].name === 'Delete Change' - ); + assert.equal(deleteItems[0].name, 'Delete change'); done(); }); }); @@ -234,29 +252,64 @@ limitations under the License. assert.deepEqual(result, actions); }); - test('submit change', done => { + test('submit change', () => { + const showSpy = sandbox.spy(element, '_showActionDialog'); sandbox.stub(element.$.restAPI, 'getFromProjectLookup') .returns(Promise.resolve('test')); - sandbox.stub(element, 'fetchIsLatestKnown', - () => { return Promise.resolve(true); }); + sandbox.stub(element, 'fetchChangeUpdates', + () => { return Promise.resolve({isLatest: true}); }); + sandbox.stub(element.$.overlay, 'open').returns(Promise.resolve()); element.change = { revisions: { rev1: {_number: 1}, rev2: {_number: 2}, }, }; - element.patchNum = '2'; + element.latestPatchNum = '2'; - flush(() => { - const submitButton = element.$$('gr-button[data-action-key="submit"]'); - assert.ok(submitButton); - MockInteractions.tap(submitButton); + const 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', () => { - done(); - }); - }); + flushAsynchronousOperations(); + assert.isTrue(showSpy.calledWith(element.$.confirmSubmitDialog)); + }); + + test('submit change, tap on icon', done => { + sandbox.stub(element.$.confirmSubmitDialog, 'resetFocus', done); + sandbox.stub(element.$.restAPI, 'getFromProjectLookup') + .returns(Promise.resolve('test')); + sandbox.stub(element, 'fetchChangeUpdates', + () => { return Promise.resolve({isLatest: true}); }); + sandbox.stub(element.$.overlay, 'open').returns(Promise.resolve()); + element.change = { + revisions: { + rev1: {_number: 1}, + rev2: {_number: 2}, + }, + }; + element.latestPatchNum = '2'; + + const submitIcon = + element.$$('gr-button[data-action-key="submit"] iron-icon'); + assert.ok(submitIcon); + MockInteractions.tap(submitIcon); + }); + + test('_handleSubmitConfirm', () => { + const fireStub = sandbox.stub(element, '_fireAction'); + sandbox.stub(element, '_canSubmitChange').returns(true); + element._handleSubmitConfirm(); + assert.isTrue(fireStub.calledOnce); + assert.deepEqual(fireStub.lastCall.args, + ['/submit', element.revisionActions.submit, true]); + }); + + test('_handleSubmitConfirm when not able to submit', () => { + const fireStub = sandbox.stub(element, '_fireAction'); + sandbox.stub(element, '_canSubmitChange').returns(false); + element._handleSubmitConfirm(); + assert.isFalse(fireStub.called); }); test('submit change with plugin hook', done => { @@ -302,6 +355,9 @@ limitations under the License. test('rebase change', done => { const fireActionStub = sandbox.stub(element, '_fireAction'); + const fetchChangesStub = sandbox.stub(element.$.confirmRebase, + 'fetchRecentChanges').returns(Promise.resolve([])); + element._hasKnownChainState = true; flush(() => { const rebaseButton = element.$$('gr-button[data-action-key="rebase"]'); MockInteractions.tap(rebaseButton); @@ -314,24 +370,26 @@ limitations under the License. method: 'POST', title: 'Rebase onto tip of branch or parent change', }; - // rebase on other - element.$.confirmRebase.base = '1234'; - element._handleRebaseConfirm(); + assert.isTrue(fetchChangesStub.called); + element._handleRebaseConfirm({detail: {base: '1234'}}); assert.deepEqual(fireActionStub.lastCall.args, ['/rebase', rebaseAction, true, {base: '1234'}]); + done(); + }); + }); - // 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: ''}]); + test(`rebase dialog gets recent changes each time it's opened`, done => { + const fetchChangesStub = sandbox.stub(element.$.confirmRebase, + 'fetchRecentChanges').returns(Promise.resolve([])); + element._hasKnownChainState = true; + const rebaseButton = element.$$('gr-button[data-action-key="rebase"]'); + MockInteractions.tap(rebaseButton); + assert.isTrue(fetchChangesStub.calledOnce); + flush(() => { + element.$.confirmRebase.fire('cancel'); + MockInteractions.tap(rebaseButton); + assert.isTrue(fetchChangesStub.calledTwice); done(); }); }); @@ -367,134 +425,133 @@ limitations under the License. assert.isFalse(element.$.mainContent.classList.contains('overlayOpen')); }); - suite('change edits', () => { - let fireActionStub; - const deleteEditAction = { - enabled: true, - label: 'Delete Edit', - title: 'Delete change edit', - __key: 'deleteEdit', - __primary: false, - __type: 'change', - method: 'DELETE', - }; - const publishEditAction = { - enabled: true, - label: 'Publish Edit', - title: 'Publish change edit', - __key: 'publishEdit', - __primary: false, - __type: 'change', - method: 'POST', - }; - const rebaseEditAction = { - enabled: true, - label: 'Rebase Edit', - title: 'Rebase change edit', - __key: 'rebaseEdit', - __primary: false, - __type: 'change', - method: 'POST', - }; - - setup(() => { - fireActionStub = sandbox.stub(element, '_fireAction'); - element.patchNum = 'edit'; - element.editLoaded = true; + test('_setLabelValuesOnRevert', () => { + const labels = {'Foo': 1, 'Bar-Baz': -2}; + const changeId = 1234; + sandbox.stub(element.$.jsAPI, 'getLabelValuesPostRevert').returns(labels); + const saveStub = sandbox.stub(element.$.restAPI, 'saveChangeReview') + .returns(Promise.resolve()); + return element._setLabelValuesOnRevert(changeId).then(() => { + assert.isTrue(saveStub.calledOnce); + assert.equal(saveStub.lastCall.args[0], changeId); + assert.deepEqual(saveStub.lastCall.args[2], {labels}); }); + }); - test('does not delete edit on action', () => { - element._handleDeleteEditTap(); - assert.isFalse(fireActionStub.called); + suite('change edits', () => { + test('disableEdit', () => { + element.set('editMode', false); + element.set('editPatchsetLoaded', false); + element.change = {status: 'NEW'}; + element.set('disableEdit', true); + flushAsynchronousOperations(); + + assert.isNotOk(element.$$('gr-button[data-action-key="publishEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="rebaseEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="deleteEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="edit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="stopEdit"]')); }); test('shows confirm dialog for delete edit', () => { + element.set('editMode', true); + element.set('editPatchsetLoaded', true); + + const fireActionStub = sandbox.stub(element, '_fireAction'); element._handleDeleteEditTap(); - assert.isFalse(element.$$('#confirmDeleteEditDialog').hidden); - assert.ok(element.$$('gr-button[data-action-key="deleteEdit"]')); + assert.isFalse(element.$.confirmDeleteEditDialog.hidden); MockInteractions.tap( element.$$('#confirmDeleteEditDialog').$$('gr-button[primary]')); flushAsynchronousOperations(); - assert.isTrue( - fireActionStub.calledWith('/edit', deleteEditAction, false)); + + assert.equal(fireActionStub.lastCall.args[0], '/edit'); }); - test('show publish edit but rebaseEdit is hidden', () => { - element.change = { - status: 'NEW', - }; - const rebaseEditButton = - element.$$('gr-button[data-action-key="rebaseEdit"]'); - assert.isNotOk(rebaseEditButton); - - const publishEditButton = - element.$$('gr-button[data-action-key="publishEdit"]'); - assert.ok(publishEditButton); - MockInteractions.tap(publishEditButton); - element._handlePublishEditTap(); + test('hide publishEdit and rebaseEdit if change is not open', () => { + element.set('editMode', true); + element.set('editPatchsetLoaded', true); + element.change = {status: 'MERGED'}; flushAsynchronousOperations(); - assert.isTrue( - fireActionStub.calledWith('/edit:publish', publishEditAction, false)); + assert.isNotOk(element.$$('gr-button[data-action-key="publishEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="rebaseEdit"]')); + assert.isOk(element.$$('gr-button[data-action-key="deleteEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="edit"]')); }); - test('show rebase edit but publishEdit is hidden', () => { - element.change = { - status: 'NEW', - }; + test('edit patchset is loaded, needs rebase', () => { + element.set('editMode', true); + element.set('editPatchsetLoaded', true); + element.change = {status: 'NEW'}; element.editBasedOnCurrentPatchSet = false; + flushAsynchronousOperations(); - const publishEditButton = - element.$$('gr-button[data-action-key="publishEdit"]'); - assert.isNotOk(publishEditButton); + assert.isNotOk(element.$$('gr-button[data-action-key="publishEdit"]')); + assert.isOk(element.$$('gr-button[data-action-key="rebaseEdit"]')); + assert.isOk(element.$$('gr-button[data-action-key="deleteEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="edit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="stopEdit"]')); + }); - const rebaseEditButton = - element.$$('gr-button[data-action-key="rebaseEdit"]'); - assert.ok(rebaseEditButton); - MockInteractions.tap(rebaseEditButton); - element._handleRebaseEditTap(); + test('edit patchset is loaded, does not need rebase', () => { + element.set('editMode', true); + element.set('editPatchsetLoaded', true); + element.change = {status: 'NEW'}; + element.editBasedOnCurrentPatchSet = true; flushAsynchronousOperations(); - assert.isTrue( - fireActionStub.calledWith('/edit:rebase', rebaseEditAction, false)); + assert.isOk(element.$$('gr-button[data-action-key="publishEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="rebaseEdit"]')); + assert.isOk(element.$$('gr-button[data-action-key="deleteEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="edit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="stopEdit"]')); }); - test('hide publishEdit and rebaseEdit if change is not open', () => { - element.change = { - status: 'MERGED', - }; + test('edit mode is loaded, no edit patchset', () => { + element.set('editMode', true); + element.set('editPatchsetLoaded', false); + element.change = {status: 'NEW'}; flushAsynchronousOperations(); - const publishEditButton = - element.$$('gr-button[data-action-key="publishEdit"]'); - assert.isNotOk(publishEditButton); + assert.isNotOk(element.$$('gr-button[data-action-key="publishEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="rebaseEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="deleteEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="edit"]')); + assert.isOk(element.$$('gr-button[data-action-key="stopEdit"]')); + }); - const rebaseEditButton = - element.$$('gr-button[data-action-key="rebaseEdit"]'); - assert.isNotOk(rebaseEditButton); + test('normal patch set', () => { + element.set('editMode', false); + element.set('editPatchsetLoaded', false); + element.change = {status: 'NEW'}; + flushAsynchronousOperations(); - const deleteEditButton = - element.$$('gr-button[data-action-key="deleteEdit"]'); - assert.ok(deleteEditButton); + assert.isNotOk(element.$$('gr-button[data-action-key="publishEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="rebaseEdit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="deleteEdit"]')); + assert.isOk(element.$$('gr-button[data-action-key="edit"]')); + assert.isNotOk(element.$$('gr-button[data-action-key="stopEdit"]')); }); - test('do not show delete edit on a non change edit', () => { - element.editLoaded = false; + test('edit action', done => { + element.addEventListener('edit-tap', () => { done(); }); + element.set('editMode', true); + element.change = {status: 'NEW'}; flushAsynchronousOperations(); - const deleteEditButton = - element.$$('gr-button[data-action-key="deleteEdit"]'); - assert.isNotOk(deleteEditButton); - }); - test('do not show publish edit on a non change edit', () => { - element.change = { - status: 'NEW', - }; - element.editLoaded = false; + assert.isNotOk(element.$$('gr-button[data-action-key="edit"]')); + assert.isOk(element.$$('gr-button[data-action-key="stopEdit"]')); + element.change = {status: 'MERGED'}; flushAsynchronousOperations(); - const publishEditButton = - element.$$('gr-button[data-action-key="publishEdit"]'); - assert.isNotOk(publishEditButton); + + assert.isNotOk(element.$$('gr-button[data-action-key="edit"]')); + element.change = {status: 'NEW'}; + element.set('editMode', false); + flushAsynchronousOperations(); + + const editButton = element.$$('gr-button[data-action-key="edit"]'); + assert.isOk(editButton); + MockInteractions.tap(editButton); }); }); @@ -513,7 +570,7 @@ limitations under the License. __type: 'revision', __primary: false, enabled: true, - label: 'Cherry Pick', + label: 'Cherry pick', method: 'POST', title: 'Cherry pick change to a different branch', }; @@ -538,7 +595,40 @@ limitations under the License. assert.deepEqual(fireActionStub.lastCall.args, [ '/cherrypick', action, true, { destination: 'master', + base: null, message: 'foo message', + allow_conflicts: false, + }, + ]); + }); + + test('cherry pick even with conflicts', () => { + element._handleCherrypickTap(); + const action = { + __key: 'cherrypick', + __type: 'revision', + __primary: false, + enabled: true, + label: 'Cherry pick', + method: 'POST', + title: 'Cherry pick change to a different branch', + }; + + element.$.confirmCherrypick.branch = 'master'; + + // Add attributes that are used to determine the message. + element.$.confirmCherrypick.commitMessage = 'foo message'; + element.$.confirmCherrypick.changeStatus = 'OPEN'; + element.$.confirmCherrypick.commitNum = '123'; + + element._handleCherrypickConflictConfirm(); + + assert.deepEqual(fireActionStub.lastCall.args, [ + '/cherrypick', action, true, { + destination: 'master', + base: null, + message: 'foo message', + allow_conflicts: true, }, ]); }); @@ -620,7 +710,7 @@ limitations under the License. const key = 'cherrypick'; const type = 'revision'; const cleanup = element._setLoadingOnButtonWithKey(type, key); - assert.equal(element._actionLoadingMessage, 'Cherry-Picking...'); + assert.equal(element._actionLoadingMessage, 'Cherry-picking...'); assert.include(element._disabledMenuActions, 'cherrypick'); assert.isFunction(cleanup); @@ -630,6 +720,74 @@ limitations under the License. assert.notInclude(element._disabledMenuActions, 'cherrypick'); }); + suite('abandon change', () => { + let alertStub; + let fireActionStub; + + setup(() => { + fireActionStub = sandbox.stub(element, '_fireAction'); + alertStub = sandbox.stub(window, 'alert'); + element.actions = { + abandon: { + method: 'POST', + label: 'Abandon', + title: 'Abandon the change', + enabled: true, + }, + }; + return element.reload(); + }); + + test('abandon change with message', done => { + const newAbandonMsg = 'Test Abandon Message'; + element.$.confirmAbandonDialog.message = newAbandonMsg; + flush(() => { + const abandonButton = + element.$$('gr-button[data-action-key="abandon"]'); + MockInteractions.tap(abandonButton); + + assert.equal(element.$.confirmAbandonDialog.message, newAbandonMsg); + done(); + }); + }); + + test('abandon change with no message', done => { + flush(() => { + const abandonButton = + element.$$('gr-button[data-action-key="abandon"]'); + MockInteractions.tap(abandonButton); + + assert.isUndefined(element.$.confirmAbandonDialog.message); + done(); + }); + }); + + test('works', () => { + element.$.confirmAbandonDialog.message = 'original message'; + const restoreButton = + element.$$('gr-button[data-action-key="abandon"]'); + MockInteractions.tap(restoreButton); + + element.$.confirmAbandonDialog.message = 'foo message'; + element._handleAbandonDialogConfirm(); + assert.notOk(alertStub.called); + + const action = { + __key: 'abandon', + __type: 'change', + __primary: false, + enabled: true, + label: 'Abandon', + method: 'POST', + title: 'Abandon the change', + }; + assert.deepEqual(fireActionStub.lastCall.args, [ + '/abandon', action, false, { + message: 'foo message', + }]); + }); + }); + suite('revert change', () => { let alertStub; let fireActionStub; @@ -715,7 +873,7 @@ limitations under the License. element.change.is_private = false; element.changeNum = '2'; - element.patchNum = '2'; + element.latestPatchNum = '2'; return element.reload(); }); @@ -761,7 +919,7 @@ limitations under the License. element.change.is_private = true; element.changeNum = '2'; - element.patchNum = '2'; + element.latestPatchNum = '2'; return element.reload(); }); @@ -853,7 +1011,7 @@ limitations under the License. }; element.changeNum = '2'; - element.patchNum = '2'; + element.latestPatchNum = '2'; element.reload().then(() => { flush(done); }); }); @@ -892,7 +1050,7 @@ limitations under the License. }; element.changeNum = '2'; - element.patchNum = '2'; + element.latestPatchNum = '2'; element.reload().then(() => { flush(done); }); }); @@ -932,7 +1090,7 @@ limitations under the License. }; element.changeNum = '2'; - element.patchNum = '2'; + element.latestPatchNum = '2'; element.reload().then(() => { flush(done); }); }); @@ -972,7 +1130,7 @@ limitations under the License. }; element.changeNum = '2'; - element.patchNum = '2'; + element.latestPatchNum = '2'; element.reload().then(() => { flush(done); }); }); @@ -1022,8 +1180,24 @@ limitations under the License. assert.isNotNull(approveButton); }); - test('is first in list of actions', () => { - const approveButton = element.$$('gr-button'); + test('hide quick approve', () => { + const approveButton = + element.$$('gr-button[data-action-key=\'review\']'); + assert.isNotNull(approveButton); + assert.isFalse(element._hideQuickApproveAction); + + // Assert approve button gets removed from list of buttons. + element.hideQuickApproveAction(); + flushAsynchronousOperations(); + const approveButtonUpdated = + element.$$('gr-button[data-action-key=\'review\']'); + assert.isNull(approveButtonUpdated); + assert.isTrue(element._hideQuickApproveAction); + }); + + test('is first in list of secondary actions', () => { + const approveButton = element.$.secondaryActions + .querySelector('gr-button'); assert.equal(approveButton.getAttribute('data-label'), 'foo+1'); }); @@ -1175,10 +1349,18 @@ limitations under the License. const reloadStub = sandbox.stub(element, 'reload'); element.changeNum = 123; assert.isFalse(reloadStub.called); - element.patchNum = 456; + element.latestPatchNum = 456; assert.isFalse(reloadStub.called); }); + test('_toSentenceCase', () => { + assert.equal(element._toSentenceCase('blah blah'), 'Blah blah'); + assert.equal(element._toSentenceCase('BLAH BLAH'), 'Blah blah'); + assert.equal(element._toSentenceCase('b'), 'B'); + assert.equal(element._toSentenceCase(''), ''); + assert.equal(element._toSentenceCase('!@#$%^&*()'), '!@#$%^&*()'); + }); + suite('setActionOverflow', () => { test('move action from overflow', () => { assert.isNotOk(element.$$('[data-action-key="cherrypick"]')); @@ -1235,14 +1417,17 @@ limitations under the License. suite('_send', () => { let cleanup; let payload; + let onShowError; let onShowAlert; setup(() => { cleanup = sinon.stub(); element.changeNum = 42; - element.patchNum = 12; + element.latestPatchNum = 12; payload = {foo: 'bar'}; + onShowError = sinon.stub(); + element.addEventListener('show-error', onShowError); onShowAlert = sinon.stub(); element.addEventListener('show-alert', onShowAlert); }); @@ -1251,53 +1436,54 @@ limitations under the License. let sendStub; setup(() => { - sandbox.stub(element, 'fetchIsLatestKnown') - .returns(Promise.resolve(true)); - sendStub = sandbox.stub(element.$.restAPI, 'getChangeURLAndSend') + sandbox.stub(element, 'fetchChangeUpdates') + .returns(Promise.resolve({isLatest: true})); + sendStub = sandbox.stub(element.$.restAPI, 'executeChangeAction') .returns(Promise.resolve({})); }); test('change action', () => { return element._send('DELETE', payload, '/endpoint', false, cleanup) .then(() => { - assert.isFalse(onShowAlert.called); + assert.isFalse(onShowError.called); assert.isTrue(cleanup.calledOnce); - assert.isTrue(sendStub.calledWith(42, 'DELETE', null, - '/endpoint', payload)); + assert.isTrue(sendStub.calledWith(42, 'DELETE', '/endpoint', + null, payload)); }); }); test('revision action', () => { return element._send('DELETE', payload, '/endpoint', true, cleanup) .then(() => { - assert.isFalse(onShowAlert.called); + assert.isFalse(onShowError.called); assert.isTrue(cleanup.calledOnce); - assert.isTrue(sendStub.calledWith(42, 'DELETE', 12, '/endpoint', - payload)); + assert.isTrue(sendStub.calledWith(42, 'DELETE', '/endpoint', + 12, payload)); }); }); }); suite('failure modes', () => { test('non-latest', () => { - sandbox.stub(element, 'fetchIsLatestKnown') - .returns(Promise.resolve(false)); + sandbox.stub(element, 'fetchChangeUpdates') + .returns(Promise.resolve({isLatest: false})); const sendStub = sandbox.stub(element.$.restAPI, - 'getChangeURLAndSend'); + 'executeChangeAction'); return element._send('DELETE', payload, '/endpoint', true, cleanup) .then(() => { assert.isTrue(onShowAlert.calledOnce); + assert.isFalse(onShowError.called); assert.isTrue(cleanup.calledOnce); assert.isFalse(sendStub.called); }); }); test('send fails', () => { - sandbox.stub(element, 'fetchIsLatestKnown') - .returns(Promise.resolve(true)); + sandbox.stub(element, 'fetchChangeUpdates') + .returns(Promise.resolve({isLatest: true})); const sendStub = sandbox.stub(element.$.restAPI, - 'getChangeURLAndSend', + 'executeChangeAction', (num, method, patchNum, endpoint, payload, onErr) => { onErr(); return Promise.resolve(null); @@ -1306,7 +1492,7 @@ limitations under the License. return element._send('DELETE', payload, '/endpoint', true, cleanup) .then(() => { - assert.isFalse(onShowAlert.called); + assert.isFalse(onShowError.called); assert.isTrue(cleanup.called); assert.isTrue(sendStub.calledOnce); assert.isTrue(handleErrorStub.called); @@ -1314,5 +1500,13 @@ limitations under the License. }); }); }); + + test('_handleAction reports', () => { + sandbox.stub(element, '_fireAction'); + const reportStub = sandbox.stub(element.$.reporting, 'reportInteraction'); + element._handleAction('type', 'key'); + assert.isTrue(reportStub.called); + assert.equal(reportStub.lastCall.args[0], 'type-key'); + }); }); </script> |