tests: frontend tests for admin UI

admin-tests
John McLear 2021-02-06 20:13:35 +00:00
parent 21cc298d6d
commit c639e743d7
4 changed files with 274 additions and 0 deletions

View File

@ -0,0 +1,119 @@
'use strict';
describe('Plugins page', function () {
function timeout(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
before(async function () {
let success = false;
$.ajax({
url: `${location.protocol}//admin:changeme@${location.hostname}:${location.port}/admin`,
type: 'GET',
success: () => success = true,
});
await helper.waitForPromise(() => success === true);
});
// create a new pad before each test run
beforeEach(async function () {
helper.newAdmin('plugins');
await helper.waitForPromise(
() => helper.admin$ && helper.admin$('.menu').find('li').length >= 3);
});
it('Lists some plugins', async function () {
await helper.waitForPromise(() => helper.admin$('.results').children().length > 50);
});
it('Searches for plugin', async function () {
helper.admin$('#search-query').val('ep_font_color');
await helper.waitForPromise(() => helper.admin$('.results').children().length < 300, 5000);
await helper.waitForPromise(() => helper.admin$('.results').children().length > 0, 5000);
});
it('Attempt to Update a plugin', async function () {
// !IMPORTANT! We only run admin tests in one browser!
if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) this.skip();
this.timeout(120000);
if (helper.admin$('.ep_align').length === 0) this.skip();
await helper.waitForPromise(
() => helper.admin$('.ep_align .version').text().split('.').length >= 2);
const minorVersionBefore =
parseInt(helper.admin$('.ep_align .version').text().split('.')[1]);
if (!minorVersionBefore) {
throw new Error('Unable to get minor number of plugin, is the plugin installed?');
}
if (minorVersionBefore !== 2) this.skip();
helper.waitForPromise(
() => helper.admin$('.ep_align .do-update').length === 1);
await timeout(500); // HACK! Please submit better fix..
const $doUpdateButton = helper.admin$('.ep_align .do-update');
$doUpdateButton.click();
// ensure its showing as Updating
await helper.waitForPromise(
() => helper.admin$('.ep_align .message').text() === 'Updating');
// Ensure it's a higher minor version IE 0.3.x as 0.2.x was installed
// Coverage for https://github.com/ether/etherpad-lite/issues/4536
await helper.waitForPromise(() => parseInt(helper.admin$(
'.ep_align .version'
)
.text()
.split('.')[1]) > minorVersionBefore, 60000, 1000);
// allow 50 seconds, check every 1 second.
});
it('Attempt to Install a plugin', async function () {
// !IMPORTANT! We only run admin tests in one browser!
if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) this.skip();
this.timeout(240000);
helper.admin$('#search-query').val('ep_activepads');
await helper.waitForPromise(() => helper.admin$('.results').children().length < 300, 6000);
await helper.waitForPromise(() => helper.admin$('.results').children().length > 0, 6000);
// skip if we already have ep_activepads installed..
if (helper.admin$('.ep_activepads .do-install').is(':visible') === false) this.skip();
helper.admin$('.ep_activepads .do-install').click();
// ensure install has attempted to be started
await helper.waitForPromise(
() => helper.admin$('.ep_activepads .do-install').length !== 0, 120000);
// ensure its not showing installing any more
await helper.waitForPromise(
() => helper.admin$('.ep_activepads .message').text() === '', 180000);
// ensure uninstall button is visible
await helper.waitForPromise(
() => helper.admin$('.ep_activepads .do-uninstall').length !== 0, 120000);
});
it('Attempt to Uninstall a plugin', async function () {
// !IMPORTANT! We only run admin tests in one browser!
if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) this.skip();
this.timeout(360000);
await helper.waitForPromise(
() => helper.admin$('.ep_activepads .do-uninstall').length !== 0, 120000);
helper.admin$('.ep_activepads .do-uninstall').click();
// ensure its showing uninstalling
await helper.waitForPromise(
() => helper.admin$('.ep_activepads .message')
.text() === 'Uninstalling', 120000);
// ensure its gone
await helper.waitForPromise(
() => helper.admin$('.ep_activepads').length === 0, 240000);
helper.admin$('#search-query').val('ep_headings2');
await helper.waitForPromise(() => helper.admin$('.results').children().length < 300, 6000);
await helper.waitForPromise(() => helper.admin$('.results').children().length > 0, 6000);
});
});

View File

@ -0,0 +1,29 @@
'use strict';
describe('Admin page', function () {
before(async function () {
let success = false;
$.ajax({
url: `${location.protocol}//admin:changeme@${location.hostname}:${location.port}/admin/`,
type: 'GET',
success: () => success = true,
});
await helper.waitForPromise(() => success === true);
});
beforeEach(async function () {
helper.newAdmin('');
await helper.waitForPromise(
() => helper.admin$ && helper.admin$('.menu').find('li').length >= 3);
});
it('Shows Plugin Manager Link', async function () {
helper.admin$('a[data-l10n-id="admin_plugins"]').is(':visible');
});
it('Shows Troubleshooting Info Link', async function () {
helper.admin$('a[data-l10n-id="admin_plugins_info"]').is(':visible');
});
it('Shows Settings Link', async function () {
helper.admin$('a[data-l10n-id="admin_settings"]').is(':visible');
});
});

View File

@ -0,0 +1,79 @@
'use strict';
describe('Admin > Settings', function () {
this.timeout(360000);
before(async function () {
let success = false;
$.ajax({
url: `${location.protocol}//admin:changeme@${location.hostname}:${location.port}/admin/`,
type: 'GET',
success: () => success = true,
});
await helper.waitForPromise(() => success === true);
});
beforeEach(async function () {
helper.newAdmin('settings');
// needed, because the load event is fired to early
await helper.waitForPromise(() => helper.admin$ && helper.admin$('.settings').val().length > 0);
});
it('Are Settings visible, populated, does save work', async function () {
// !IMPORTANT! We only run admin tests in one browser!
if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) this.skip();
// save old value
const settings = helper.admin$('.settings').val();
const settingsLength = settings.length;
// set new value
helper.admin$('.settings').val((_, text) => `/* test */\n${text}`);
await helper.waitForPromise(
() => settingsLength + 11 === helper.admin$('.settings').val().length);
// saves
helper.admin$('#saveSettings').click();
await helper.waitForPromise(() => helper.admin$('#response').is(':visible'));
// new value for settings.json should now be saved
// reset it to the old value
helper.newAdmin('settings');
await helper.waitForPromise(() => helper.admin$ && helper.admin$('.settings').val().length > 0);
// replace the test value with a line break
helper.admin$('.settings').val((_, text) => text.replace('/* test */\n', ''));
await helper.waitForPromise(() => settingsLength === helper.admin$('.settings').val().length);
helper.admin$('#saveSettings').click(); // saves
await helper.waitForPromise(() => helper.admin$('#response').is(':visible'));
// settings should have the old value
helper.newAdmin('settings');
await helper.waitForPromise(
() => helper.admin$ && helper.admin$('.settings').val().length > 0, 18000);
expect(settings).to.be(helper.admin$('.settings').val());
});
function timeout(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
it('restart works', async function () {
// !IMPORTANT! We only run admin tests in one browser!
if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) this.skip();
// restarts
helper.admin$('#restartEtherpad').click();
// Hacky... Other suggestions welcome..
await timeout(50000);
let success = false;
$.ajax({
url: `${location.protocol}//admin:changeme@${location.hostname}:${location.port}/admin`,
type: 'GET',
success: () => success = true,
});
await helper.waitForPromise(() => success === true);
});
});

View File

@ -0,0 +1,47 @@
'use strict';
describe('Admin Troupbleshooting page', function () {
before(async function () {
let success = false;
$.ajax({
url: `${location.protocol}//admin:changeme@${location.hostname}:${location.port}/admin`,
type: 'GET',
success: () => success = true,
});
await helper.waitForPromise(() => success === true);
});
// create a new pad before each test run
beforeEach(async function () {
helper.newAdmin('plugins/info');
await helper.waitForPromise(
() => helper.admin$ && helper.admin$('.menu').find('li').length >= 3);
});
it('Shows Troubleshooting page Manager', async function () {
helper.admin$('a[data-l10n-id="admin_plugins_info"]')[0].click();
});
it('Shows a version number', async function () {
const content = helper.admin$('span[data-l10n-id="admin_plugins_info.version_number"]')
.parent().text();
const version = content.split(': ')[1].split('.');
if (version.length !== 3) {
throw new Error('Not displaying a semver version number');
}
});
it('Lists installed parts', async function () {
const parts = helper.admin$('pre')[1];
if (parts.textContent.indexOf('ep_etherpad-lite/adminsettings') === -1) {
throw new Error('No admin setting part being displayed...');
}
});
it('Lists installed hooks', async function () {
const parts = helper.admin$('dt');
if (parts.length <= 20) {
throw new Error('Not enough hooks being displayed...');
}
});
});