
* stable-3.0: Update git submodules Update git submodules Update git submodules Fix documentation of UI selection Set version to 2.16.12-SNAPSHOT Set version to 2.16.11 Update git submodules Revert "GerritServer: Silence non-critical logs from JGit's FileSnapshot" Revert "GerritServer: Silence non-critical logs from JGit's FS" Revert "Upgrade JGit to 5.1.10.201908230655-r" Revert "Stop using deprecated DirCacheEntry#setLastModified(long)" Update git submodules Update git submodules Update git submodules Update git submodules Update git submodules Update git submodules Set version to 2.15.17-SNAPSHOT Update git submodules Update git submodules Revert "Upgrade JGit to 5.3.4.201908231101-r" Set version to 2.15.16 Revert "CreateAccount: Fail early when invalid SSH key is given" Update git submodules tools/eclipse/project.py: Fix typo of bazelisk Set XSRF on '/' under PolyGerrit Migrate from old-style legacy .java provider to the new JavaInfo. Remove deleted rules for the new added section Support bazelisk or bazel in tools/eclipse/project.py Rework imports in project.py Update project.py to use argparse AccountIT: Test that account is not created with invalid email CreateAccount: Fail early when invalid SSH key is given Update git submodules GerritServer: Silence non-critical logs from JGit's FS GerritServer: Silence non-critical logs from JGit's FileSnapshot Stop using deprecated DirCacheEntry#setLastModified(long) ProjectState: Fix 'invalid type qualification' javadoc warning Upgrade JGit to 5.3.4.201908231101-r Documentation: refresh IntelliJ IDEA developer documentation Documentation: update external links to Bazel Use base url for commentlink Update git submodules Update git submodules Don't store LabelTypes in ProjectState Upgrade highlight.js to latest master revision Update git submodules Update git submodules Update git submodules StarredChangesUtil: Stop using deprecated RefDatabase.getRef Suppress warnings about deprecated BaseReceivePack DeleteRef: Stop using deprecated RefDatabase.getRef Upgrade elasticsearch-rest-client to 7.3.1 Add .gitreview file Remove vestigal GWT plugin loading hooks Upgrade JGit to 5.1.10.201908230655-r DeleteDraftComments: Don't update change modified timestamp ChangeIT: set submittableAfterLosingPermissions private Rebase: Don't swallow caught exception Output NoteDb migration progress to Flogger Update git submodules Remove AccountPatchReview data when change gets auto-abandoned DefaultChangeReportFormatter: Make constructor and urlFormatter visible StarredChangesUtil: Fix NPE when ref to be deleted doesn't exist StarredChangesUtil: Throw LockFailureException on LOCK_FAILURE Add test for creating a change on a non-existing base change Rebase: Do not fail with 500 ISE if non-existing change is given as base Fix detecting changes of parent trees when computing change kind for merge commit Remove duplicate descriptions of fields in Requirement JSON entity Allow to set content type in the plugin REST API interface InternalAccountQuery: Add back the oneByExternalId method Set version to 2.16.11-SNAPSHOT Revert "Migrate from old-style legacy .java provider to the new JavaInfo." Catch all exceptions for reporting on Schema_130 migration Update git submodules Migrate from old-style legacy .java provider to the new JavaInfo. Update git submodules Update git submodules AuthRequest: Fix Javadoc for return values ChangeApi: Add methods to get change comments/drafts as list Update git submodules ListChangeComments: Extend ListChangeDrafts Upgrade Go Bazel rules to the latest version detach -> detached Fix anchor tag for settings page Add support for Elasticsearch version 7.3.* PrologEnvironment: Reduce "setting reductionLimit" log spam ElasticContainer: Upgrade to 6.8.2 image for V6_8 tests Fix typo: program Fix email token routing Clarify usage of 'parent' option in list files API Remove unused Skylark patch file Files: Use Gerrit API to get revision parents Fix broken link for rest-api-projects.html#commentlink-info Add support for Elasticsearch version 6.8.x Upgrade elasticsearch-rest-client to 7.2.1 Add support for "Link Another Identity" in gr-identities Update git submodules CommitApi: Add method to get commit info Consolidate all CommitApi tests into a single class Files: Validate parent option to prevent internal server error RevisionIT: Assert that files(base) only works for patch set revisions Fix and expand documentation of REST API to get revision files RevisionIT#files: Simplify assertion Update git submodules Update git submodules Update git submodules Update git submodules Remove default bug tracker from _feedbackUrl PG: Add shortcuts for dashboard and watched changes PG: Allow empty label values Remove token param from getCapabilities Add an extension point to show a small banner next to the search bar Fix gr-group-audit-log to use tbody Change-Id: Iaf877b737f115d4fe95af74f8284eec19112a21d
647 lines
22 KiB
HTML
647 lines
22 KiB
HTML
<!DOCTYPE html>
|
|
<!--
|
|
@license
|
|
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-api-interface</title>
|
|
<script src="/test/common-test-setup.js"></script>
|
|
<script src="/bower_components/webcomponentsjs/custom-elements-es5-adapter.js"></script>
|
|
|
|
<script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
|
|
<script src="/bower_components/web-component-tester/browser.js"></script>
|
|
<link rel="import" href="../../../test/common-test-setup.html"/>
|
|
<link rel="import" href="gr-js-api-interface.html">
|
|
|
|
<script>void(0);</script>
|
|
|
|
<test-fixture id="basic">
|
|
<template>
|
|
<gr-js-api-interface></gr-js-api-interface>
|
|
</template>
|
|
</test-fixture>
|
|
|
|
<script>
|
|
suite('gr-js-api-interface tests', () => {
|
|
let element;
|
|
let plugin;
|
|
let errorStub;
|
|
let sandbox;
|
|
let getResponseObjectStub;
|
|
let sendStub;
|
|
|
|
const throwErrFn = function() {
|
|
throw Error('Unfortunately, this handler has stopped');
|
|
};
|
|
|
|
setup(() => {
|
|
sandbox = sinon.sandbox.create();
|
|
getResponseObjectStub = sandbox.stub().returns(Promise.resolve());
|
|
sendStub = sandbox.stub().returns(Promise.resolve({status: 200}));
|
|
stub('gr-rest-api-interface', {
|
|
getAccount() {
|
|
return Promise.resolve({name: 'Judy Hopps'});
|
|
},
|
|
getResponseObject: getResponseObjectStub,
|
|
send(...args) {
|
|
return sendStub(...args);
|
|
},
|
|
});
|
|
element = fixture('basic');
|
|
errorStub = sandbox.stub(console, 'error');
|
|
Gerrit.install(p => { plugin = p; }, '0.1',
|
|
'http://test.com/plugins/testplugin/static/test.js');
|
|
Gerrit._setPluginsPending([]);
|
|
});
|
|
|
|
teardown(() => {
|
|
sandbox.restore();
|
|
element._removeEventCallbacks();
|
|
plugin = null;
|
|
});
|
|
|
|
test('reuse plugin for install calls', () => {
|
|
let otherPlugin;
|
|
Gerrit.install(p => { otherPlugin = p; }, '0.1',
|
|
'http://test.com/plugins/testplugin/static/test.js');
|
|
assert.strictEqual(plugin, otherPlugin);
|
|
});
|
|
|
|
test('flushes preinstalls if provided', () => {
|
|
assert.doesNotThrow(() => {
|
|
Gerrit._flushPreinstalls();
|
|
});
|
|
window.Gerrit.flushPreinstalls = sandbox.stub();
|
|
Gerrit._flushPreinstalls();
|
|
assert.isTrue(window.Gerrit.flushPreinstalls.calledOnce);
|
|
delete window.Gerrit.flushPreinstalls;
|
|
});
|
|
|
|
test('url', () => {
|
|
assert.equal(plugin.url(), 'http://test.com/plugins/testplugin/');
|
|
assert.equal(plugin.url('/static/test.js'),
|
|
'http://test.com/plugins/testplugin/static/test.js');
|
|
});
|
|
|
|
test('_send on failure rejects with response text', () => {
|
|
sendStub.returns(Promise.resolve(
|
|
{status: 400, text() { return Promise.resolve('text'); }}));
|
|
return plugin._send().catch(r => {
|
|
assert.equal(r, 'text');
|
|
});
|
|
});
|
|
|
|
test('_send on failure without text rejects with code', () => {
|
|
sendStub.returns(Promise.resolve(
|
|
{status: 400, text() { return Promise.resolve(null); }}));
|
|
return plugin._send().catch(r => {
|
|
assert.equal(r, '400');
|
|
});
|
|
});
|
|
|
|
test('get', () => {
|
|
const response = {foo: 'foo'};
|
|
getResponseObjectStub.returns(Promise.resolve(response));
|
|
return plugin.get('/url', r => {
|
|
assert.isTrue(sendStub.calledWith(
|
|
'GET', 'http://test.com/plugins/testplugin/url'));
|
|
assert.strictEqual(r, response);
|
|
});
|
|
});
|
|
|
|
test('get using Promise', () => {
|
|
const response = {foo: 'foo'};
|
|
getResponseObjectStub.returns(Promise.resolve(response));
|
|
return plugin.get('/url', r => 'rubbish').then(r => {
|
|
assert.isTrue(sendStub.calledWith(
|
|
'GET', 'http://test.com/plugins/testplugin/url'));
|
|
assert.strictEqual(r, response);
|
|
});
|
|
});
|
|
|
|
test('post', () => {
|
|
const payload = {foo: 'foo'};
|
|
const response = {bar: 'bar'};
|
|
getResponseObjectStub.returns(Promise.resolve(response));
|
|
return plugin.post('/url', payload, r => {
|
|
assert.isTrue(sendStub.calledWith(
|
|
'POST', 'http://test.com/plugins/testplugin/url', payload));
|
|
assert.strictEqual(r, response);
|
|
});
|
|
});
|
|
|
|
test('put', () => {
|
|
const payload = {foo: 'foo'};
|
|
const response = {bar: 'bar'};
|
|
getResponseObjectStub.returns(Promise.resolve(response));
|
|
return plugin.put('/url', payload, r => {
|
|
assert.isTrue(sendStub.calledWith(
|
|
'PUT', 'http://test.com/plugins/testplugin/url', payload));
|
|
assert.strictEqual(r, response);
|
|
});
|
|
});
|
|
|
|
test('delete works', () => {
|
|
const response = {status: 204};
|
|
sendStub.returns(Promise.resolve(response));
|
|
return plugin.delete('/url', r => {
|
|
assert.isTrue(sendStub.calledWithExactly(
|
|
'DELETE', 'http://test.com/plugins/testplugin/url'));
|
|
assert.strictEqual(r, response);
|
|
});
|
|
});
|
|
|
|
test('delete fails', () => {
|
|
sendStub.returns(Promise.resolve(
|
|
{status: 400, text() { return Promise.resolve('text'); }}));
|
|
return plugin.delete('/url', r => {
|
|
throw new Error('Should not resolve');
|
|
}).catch(err => {
|
|
assert.isTrue(sendStub.calledWith(
|
|
'DELETE', 'http://test.com/plugins/testplugin/url'));
|
|
assert.equal('text', err);
|
|
});
|
|
});
|
|
|
|
test('history event', done => {
|
|
plugin.on(element.EventType.HISTORY, throwErrFn);
|
|
plugin.on(element.EventType.HISTORY, path => {
|
|
assert.equal(path, '/path/to/awesomesauce');
|
|
assert.isTrue(errorStub.calledOnce);
|
|
done();
|
|
});
|
|
element.handleEvent(element.EventType.HISTORY,
|
|
{path: '/path/to/awesomesauce'});
|
|
});
|
|
|
|
test('showchange event', done => {
|
|
const testChange = {
|
|
_number: 42,
|
|
revisions: {def: {_number: 2}, abc: {_number: 1}},
|
|
};
|
|
const expectedChange = Object.assign({mergeable: false}, testChange);
|
|
plugin.on(element.EventType.SHOW_CHANGE, throwErrFn);
|
|
plugin.on(element.EventType.SHOW_CHANGE, (change, revision, info) => {
|
|
assert.deepEqual(change, expectedChange);
|
|
assert.deepEqual(revision, testChange.revisions.abc);
|
|
assert.deepEqual(info, {mergeable: false});
|
|
assert.isTrue(errorStub.calledOnce);
|
|
done();
|
|
});
|
|
element.handleEvent(element.EventType.SHOW_CHANGE,
|
|
{change: testChange, patchNum: 1, info: {mergeable: false}});
|
|
});
|
|
|
|
test('handleEvent awaits plugins load', done => {
|
|
const testChange = {
|
|
_number: 42,
|
|
revisions: {def: {_number: 2}, abc: {_number: 1}},
|
|
};
|
|
const spy = sandbox.spy();
|
|
Gerrit._setPluginsCount(1);
|
|
plugin.on(element.EventType.SHOW_CHANGE, spy);
|
|
element.handleEvent(element.EventType.SHOW_CHANGE,
|
|
{change: testChange, patchNum: 1});
|
|
assert.isFalse(spy.called);
|
|
Gerrit._setPluginsCount(0);
|
|
flush(() => {
|
|
assert.isTrue(spy.called);
|
|
done();
|
|
});
|
|
});
|
|
|
|
test('comment event', done => {
|
|
const testCommentNode = {foo: 'bar'};
|
|
plugin.on(element.EventType.COMMENT, throwErrFn);
|
|
plugin.on(element.EventType.COMMENT, commentNode => {
|
|
assert.deepEqual(commentNode, testCommentNode);
|
|
assert.isTrue(errorStub.calledOnce);
|
|
done();
|
|
});
|
|
element.handleEvent(element.EventType.COMMENT, {node: testCommentNode});
|
|
});
|
|
|
|
test('revert event', () => {
|
|
function appendToRevertMsg(c, revertMsg, originalMsg) {
|
|
return revertMsg + '\n' + originalMsg.replace(/^/gm, '> ') + '\ninfo';
|
|
}
|
|
|
|
assert.equal(element.modifyRevertMsg(null, 'test', 'origTest'), 'test');
|
|
assert.equal(errorStub.callCount, 0);
|
|
|
|
plugin.on(element.EventType.REVERT, throwErrFn);
|
|
plugin.on(element.EventType.REVERT, appendToRevertMsg);
|
|
assert.equal(element.modifyRevertMsg(null, 'test', 'origTest'),
|
|
'test\n> origTest\ninfo');
|
|
assert.isTrue(errorStub.calledOnce);
|
|
|
|
plugin.on(element.EventType.REVERT, appendToRevertMsg);
|
|
assert.equal(element.modifyRevertMsg(null, 'test', 'origTest'),
|
|
'test\n> origTest\ninfo\n> origTest\ninfo');
|
|
assert.isTrue(errorStub.calledTwice);
|
|
});
|
|
|
|
test('postrevert event', () => {
|
|
function getLabels(c) {
|
|
return {'Code-Review': 1};
|
|
}
|
|
|
|
assert.deepEqual(element.getLabelValuesPostRevert(null), {});
|
|
assert.equal(errorStub.callCount, 0);
|
|
|
|
plugin.on(element.EventType.POST_REVERT, throwErrFn);
|
|
plugin.on(element.EventType.POST_REVERT, getLabels);
|
|
assert.deepEqual(
|
|
element.getLabelValuesPostRevert(null), {'Code-Review': 1});
|
|
assert.isTrue(errorStub.calledOnce);
|
|
});
|
|
|
|
test('commitmsgedit event', done => {
|
|
const testMsg = 'Test CL commit message';
|
|
plugin.on(element.EventType.COMMIT_MSG_EDIT, throwErrFn);
|
|
plugin.on(element.EventType.COMMIT_MSG_EDIT, (change, msg) => {
|
|
assert.deepEqual(msg, testMsg);
|
|
assert.isTrue(errorStub.calledOnce);
|
|
done();
|
|
});
|
|
element.handleCommitMessage(null, testMsg);
|
|
});
|
|
|
|
test('labelchange event', done => {
|
|
const testChange = {_number: 42};
|
|
plugin.on(element.EventType.LABEL_CHANGE, throwErrFn);
|
|
plugin.on(element.EventType.LABEL_CHANGE, change => {
|
|
assert.deepEqual(change, testChange);
|
|
assert.isTrue(errorStub.calledOnce);
|
|
done();
|
|
});
|
|
element.handleEvent(element.EventType.LABEL_CHANGE, {change: testChange});
|
|
});
|
|
|
|
test('submitchange', () => {
|
|
plugin.on(element.EventType.SUBMIT_CHANGE, throwErrFn);
|
|
plugin.on(element.EventType.SUBMIT_CHANGE, () => { return true; });
|
|
assert.isTrue(element.canSubmitChange());
|
|
assert.isTrue(errorStub.calledOnce);
|
|
plugin.on(element.EventType.SUBMIT_CHANGE, () => { return false; });
|
|
plugin.on(element.EventType.SUBMIT_CHANGE, () => { return true; });
|
|
assert.isFalse(element.canSubmitChange());
|
|
assert.isTrue(errorStub.calledTwice);
|
|
});
|
|
|
|
test('highlightjs-loaded event', done => {
|
|
const testHljs = {_number: 42};
|
|
plugin.on(element.EventType.HIGHLIGHTJS_LOADED, throwErrFn);
|
|
plugin.on(element.EventType.HIGHLIGHTJS_LOADED, hljs => {
|
|
assert.deepEqual(hljs, testHljs);
|
|
assert.isTrue(errorStub.calledOnce);
|
|
done();
|
|
});
|
|
element.handleEvent(element.EventType.HIGHLIGHTJS_LOADED, {hljs: testHljs});
|
|
});
|
|
|
|
test('versioning', () => {
|
|
const callback = sandbox.spy();
|
|
Gerrit.install(callback, '0.0pre-alpha');
|
|
assert(callback.notCalled);
|
|
});
|
|
|
|
test('getAccount', done => {
|
|
Gerrit.getLoggedIn().then(loggedIn => {
|
|
assert.isTrue(loggedIn);
|
|
done();
|
|
});
|
|
});
|
|
|
|
test('_setPluginsCount', done => {
|
|
stub('gr-reporting', {
|
|
pluginsLoaded() {
|
|
done();
|
|
},
|
|
});
|
|
Gerrit._setPluginsCount(0);
|
|
});
|
|
|
|
test('_arePluginsLoaded', () => {
|
|
assert.isTrue(Gerrit._arePluginsLoaded());
|
|
Gerrit._setPluginsCount(1);
|
|
assert.isFalse(Gerrit._arePluginsLoaded());
|
|
Gerrit._setPluginsCount(0);
|
|
assert.isTrue(Gerrit._arePluginsLoaded());
|
|
});
|
|
|
|
test('_pluginInstalled', () => {
|
|
const pluginsLoadedStub = sandbox.stub();
|
|
stub('gr-reporting', {
|
|
pluginsLoaded: (...args) => pluginsLoadedStub(...args),
|
|
});
|
|
const plugins = [
|
|
'http://test.com/plugins/foo/static/test.js',
|
|
'http://test.com/plugins/bar/static/test.js',
|
|
];
|
|
Gerrit._setPluginsPending(plugins);
|
|
Gerrit._pluginInstalled(plugins[0]);
|
|
Gerrit._pluginInstalled(plugins[1]);
|
|
assert.isTrue(pluginsLoadedStub.calledWithExactly(['foo', 'bar']));
|
|
});
|
|
|
|
test('install calls _pluginInstalled', () => {
|
|
sandbox.stub(Gerrit, '_pluginInstalled');
|
|
Gerrit.install(p => { plugin = p; }, '0.1',
|
|
'http://test.com/plugins/testplugin/static/test.js');
|
|
|
|
// testplugin has already been installed once (in setup).
|
|
assert.isFalse(Gerrit._pluginInstalled.called);
|
|
|
|
// testplugin2 plugin has not yet been installed.
|
|
Gerrit.install(p => { plugin = p; }, '0.1',
|
|
'http://test.com/plugins/testplugin2/static/test.js');
|
|
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
|
|
});
|
|
|
|
test('plugin install errors mark plugins as loaded', () => {
|
|
Gerrit._setPluginsCount(1);
|
|
Gerrit.install(() => {}, '0.0pre-alpha');
|
|
return Gerrit.awaitPluginsLoaded();
|
|
});
|
|
|
|
test('multiple ui plugins per java plugin', () => {
|
|
const file1 = 'http://test.com/plugins/qaz/static/foo.nocache.js';
|
|
const file2 = 'http://test.com/plugins/qaz/static/bar.js';
|
|
Gerrit._setPluginsPending([file1, file2]);
|
|
Gerrit.install(() => {}, '0.1', file1);
|
|
Gerrit.install(() => {}, '0.1', file2);
|
|
return Gerrit.awaitPluginsLoaded();
|
|
});
|
|
|
|
test('plugin install errors shows toasts', () => {
|
|
const alertStub = sandbox.stub();
|
|
document.addEventListener('show-alert', alertStub);
|
|
Gerrit._setPluginsCount(1);
|
|
Gerrit.install(() => {}, '0.0pre-alpha');
|
|
return Gerrit.awaitPluginsLoaded().then(() => {
|
|
assert.isTrue(alertStub.calledOnce);
|
|
});
|
|
});
|
|
|
|
test('attributeHelper', () => {
|
|
assert.isOk(plugin.attributeHelper());
|
|
});
|
|
|
|
test('deprecated.install', () => {
|
|
plugin.deprecated.install();
|
|
assert.strictEqual(plugin.popup, plugin.deprecated.popup);
|
|
assert.strictEqual(plugin.onAction, plugin.deprecated.onAction);
|
|
assert.notStrictEqual(plugin.install, plugin.deprecated.install);
|
|
});
|
|
|
|
test('getAdminMenuLinks', () => {
|
|
const links = [{text: 'a', url: 'b'}, {text: 'c', url: 'd'}];
|
|
const getCallbacksStub = sandbox.stub(element, '_getEventCallbacks')
|
|
.returns([
|
|
{getMenuLinks: () => [links[0]]},
|
|
{getMenuLinks: () => [links[1]]},
|
|
]);
|
|
const result = element.getAdminMenuLinks();
|
|
assert.deepEqual(result, links);
|
|
assert.isTrue(getCallbacksStub.calledOnce);
|
|
assert.equal(getCallbacksStub.lastCall.args[0],
|
|
element.EventType.ADMIN_MENU_LINKS);
|
|
});
|
|
|
|
test('Gerrit._isPluginPreloaded', () => {
|
|
Gerrit._preloadedPlugins = {baz: ()=>{}};
|
|
assert.isFalse(Gerrit._isPluginPreloaded('plugins/foo/bar'));
|
|
assert.isFalse(Gerrit._isPluginPreloaded('http://a.com/42'));
|
|
assert.isTrue(Gerrit._isPluginPreloaded('preloaded:baz'));
|
|
Gerrit._preloadedPlugins = null;
|
|
});
|
|
|
|
test('preloaded plugins are installed', () => {
|
|
const installStub = sandbox.stub();
|
|
Gerrit._preloadedPlugins = {foo: installStub};
|
|
Gerrit._installPreloadedPlugins();
|
|
assert.isTrue(installStub.called);
|
|
const pluginApi = installStub.lastCall.args[0];
|
|
assert.strictEqual(pluginApi.getPluginName(), 'foo');
|
|
});
|
|
|
|
test('installing preloaded plugin', () => {
|
|
let plugin;
|
|
window.ASSETS_PATH = 'http://blips.com/chitz';
|
|
Gerrit.install(p => { plugin = p; }, '0.1', 'preloaded:foo');
|
|
assert.strictEqual(plugin.getPluginName(), 'foo');
|
|
assert.strictEqual(plugin.url('/some/thing.html'),
|
|
'http://blips.com/chitz/plugins/foo/some/thing.html');
|
|
delete window.ASSETS_PATH;
|
|
});
|
|
|
|
suite('test plugin with base url', () => {
|
|
let baseUrlPlugin;
|
|
|
|
setup(() => {
|
|
sandbox.stub(Gerrit.BaseUrlBehavior, 'getBaseUrl').returns('/r');
|
|
|
|
Gerrit._setPluginsCount(1);
|
|
Gerrit.install(p => { baseUrlPlugin = p; }, '0.1',
|
|
'http://test.com/r/plugins/baseurlplugin/static/test.js');
|
|
});
|
|
|
|
test('url', () => {
|
|
assert.notEqual(baseUrlPlugin.url(),
|
|
'http://test.com/plugins/baseurlplugin/');
|
|
assert.equal(baseUrlPlugin.url(),
|
|
'http://test.com/r/plugins/baseurlplugin/');
|
|
assert.equal(baseUrlPlugin.url('/static/test.js'),
|
|
'http://test.com/r/plugins/baseurlplugin/static/test.js');
|
|
});
|
|
});
|
|
|
|
suite('popup', () => {
|
|
test('popup(element) is deprecated', () => {
|
|
plugin.popup(document.createElement('div'));
|
|
assert.isTrue(console.error.calledOnce);
|
|
});
|
|
|
|
test('popup(moduleName) creates popup with component', () => {
|
|
const openStub = sandbox.stub();
|
|
sandbox.stub(window, 'GrPopupInterface').returns({
|
|
open: openStub,
|
|
});
|
|
plugin.popup('some-name');
|
|
assert.isTrue(openStub.calledOnce);
|
|
assert.isTrue(GrPopupInterface.calledWith(plugin, 'some-name'));
|
|
});
|
|
|
|
test('deprecated.popup(element) creates popup with element', () => {
|
|
const el = document.createElement('div');
|
|
el.textContent = 'some text here';
|
|
const openStub = sandbox.stub(GrPopupInterface.prototype, 'open');
|
|
openStub.returns(Promise.resolve({
|
|
_getElement() {
|
|
return document.createElement('div');
|
|
}}));
|
|
plugin.deprecated.popup(el);
|
|
assert.isTrue(openStub.calledOnce);
|
|
});
|
|
});
|
|
|
|
suite('onAction', () => {
|
|
let change;
|
|
let revision;
|
|
let actionDetails;
|
|
|
|
setup(() => {
|
|
change = {};
|
|
revision = {};
|
|
actionDetails = {__key: 'some'};
|
|
sandbox.stub(plugin, 'on').callsArgWith(1, change, revision);
|
|
sandbox.stub(plugin, 'changeActions').returns({
|
|
addTapListener: sandbox.stub().callsArg(1),
|
|
getActionDetails: () => actionDetails,
|
|
});
|
|
});
|
|
|
|
test('returns GrPluginActionContext', () => {
|
|
const stub = sandbox.stub();
|
|
plugin.deprecated.onAction('change', 'foo', ctx => {
|
|
assert.isTrue(ctx instanceof GrPluginActionContext);
|
|
assert.strictEqual(ctx.change, change);
|
|
assert.strictEqual(ctx.revision, revision);
|
|
assert.strictEqual(ctx.action, actionDetails);
|
|
assert.strictEqual(ctx.plugin, plugin);
|
|
stub();
|
|
});
|
|
assert.isTrue(stub.called);
|
|
});
|
|
|
|
test('other actions', () => {
|
|
const stub = sandbox.stub();
|
|
plugin.deprecated.onAction('project', 'foo', stub);
|
|
plugin.deprecated.onAction('edit', 'foo', stub);
|
|
plugin.deprecated.onAction('branch', 'foo', stub);
|
|
assert.isFalse(stub.called);
|
|
});
|
|
});
|
|
|
|
suite('screen', () => {
|
|
test('screenUrl()', () => {
|
|
sandbox.stub(Gerrit.BaseUrlBehavior, 'getBaseUrl').returns('/base');
|
|
assert.equal(plugin.screenUrl(), 'http://test.com/base/x/testplugin');
|
|
assert.equal(
|
|
plugin.screenUrl('foo'), 'http://test.com/base/x/testplugin/foo');
|
|
});
|
|
|
|
test('deprecated works', () => {
|
|
const stub = sandbox.stub();
|
|
const hookStub = {onAttached: sandbox.stub()};
|
|
sandbox.stub(plugin, 'hook').returns(hookStub);
|
|
plugin.deprecated.screen('foo', stub);
|
|
assert.isTrue(plugin.hook.calledWith('testplugin-screen-foo'));
|
|
const fakeEl = {style: {display: ''}};
|
|
hookStub.onAttached.callArgWith(0, fakeEl);
|
|
assert.isTrue(stub.called);
|
|
assert.equal(fakeEl.style.display, 'none');
|
|
});
|
|
|
|
test('works', () => {
|
|
sandbox.stub(plugin, 'registerCustomComponent');
|
|
plugin.screen('foo', 'some-module');
|
|
assert.isTrue(plugin.registerCustomComponent.calledWith(
|
|
'testplugin-screen-foo', 'some-module'));
|
|
});
|
|
});
|
|
|
|
suite('panel', () => {
|
|
let fakeEl;
|
|
let emulateAttached;
|
|
|
|
setup(()=> {
|
|
fakeEl = {change: {}, revision: {}};
|
|
const hookStub = {onAttached: sandbox.stub()};
|
|
sandbox.stub(plugin, 'hook').returns(hookStub);
|
|
emulateAttached = () => hookStub.onAttached.callArgWith(0, fakeEl);
|
|
});
|
|
|
|
test('plugin.panel is deprecated', () => {
|
|
plugin.panel('rubbish');
|
|
assert.isTrue(console.error.called);
|
|
});
|
|
|
|
[
|
|
['CHANGE_SCREEN_BELOW_COMMIT_INFO_BLOCK', 'change-view-integration'],
|
|
['CHANGE_SCREEN_BELOW_CHANGE_INFO_BLOCK', 'change-metadata-item'],
|
|
].forEach(([panelName, endpointName]) => {
|
|
test(`deprecated.panel works for ${panelName}`, () => {
|
|
const callback = sandbox.stub();
|
|
plugin.deprecated.panel(panelName, callback);
|
|
assert.isTrue(plugin.hook.calledWith(endpointName));
|
|
emulateAttached();
|
|
assert.isTrue(callback.called);
|
|
const args = callback.args[0][0];
|
|
assert.strictEqual(args.body, fakeEl);
|
|
assert.strictEqual(args.p.CHANGE_INFO, fakeEl.change);
|
|
assert.strictEqual(args.p.REVISION_INFO, fakeEl.revision);
|
|
});
|
|
});
|
|
});
|
|
|
|
suite('settingsScreen', () => {
|
|
test('plugin.settingsScreen is deprecated', () => {
|
|
plugin.settingsScreen('rubbish');
|
|
assert.isTrue(console.error.called);
|
|
});
|
|
|
|
test('plugin.settings() returns GrSettingsApi', () => {
|
|
assert.isOk(plugin.settings());
|
|
assert.isTrue(plugin.settings() instanceof GrSettingsApi);
|
|
});
|
|
|
|
test('plugin.deprecated.settingsScreen() works', () => {
|
|
const hookStub = {onAttached: sandbox.stub()};
|
|
sandbox.stub(plugin, 'hook').returns(hookStub);
|
|
const fakeSettings = {};
|
|
fakeSettings.title = sandbox.stub().returns(fakeSettings);
|
|
fakeSettings.token = sandbox.stub().returns(fakeSettings);
|
|
fakeSettings.module = sandbox.stub().returns(fakeSettings);
|
|
fakeSettings.build = sandbox.stub().returns(hookStub);
|
|
sandbox.stub(plugin, 'settings').returns(fakeSettings);
|
|
const callback = sandbox.stub();
|
|
|
|
plugin.deprecated.settingsScreen('path', 'menu', callback);
|
|
assert.isTrue(fakeSettings.title.calledWith('menu'));
|
|
assert.isTrue(fakeSettings.token.calledWith('path'));
|
|
assert.isTrue(fakeSettings.module.calledWith('div'));
|
|
assert.equal(fakeSettings.build.callCount, 1);
|
|
|
|
const fakeBody = {};
|
|
const fakeEl = {
|
|
style: {
|
|
display: '',
|
|
},
|
|
querySelector: sandbox.stub().returns(fakeBody),
|
|
};
|
|
// Emulate settings screen attached
|
|
hookStub.onAttached.callArgWith(0, fakeEl);
|
|
assert.isTrue(callback.called);
|
|
const args = callback.args[0][0];
|
|
assert.strictEqual(args.body, fakeBody);
|
|
assert.equal(fakeEl.style.display, 'none');
|
|
});
|
|
});
|
|
});
|
|
</script>
|