tests: Promisify some of the helper.js tests

This commit is contained in:
Richard Hansen 2021-03-31 00:08:35 -04:00 committed by webzwo0i
parent 701a40ac13
commit 63e6e163b7

View file

@ -21,23 +21,19 @@ describe('the test helper', function () {
loadPad();
});
it('gives me 3 jquery instances of chrome, outer and inner', function (done) {
it('gives me 3 jquery instances of chrome, outer and inner', async function () {
this.timeout(10000);
helper.newPad(() => {
await helper.aNewPad();
// check if the jquery selectors have the desired elements
expect(helper.padChrome$('#editbar').length).to.be(1);
expect(helper.padOuter$('#outerdocbody').length).to.be(1);
expect(helper.padInner$('#innerdocbody').length).to.be(1);
// check if the document object was set correctly
expect(helper.padChrome$.window.document).to.be(helper.padChrome$.document);
expect(helper.padOuter$.window.document).to.be(helper.padOuter$.document);
expect(helper.padInner$.window.document).to.be(helper.padInner$.document);
});
done();
});
});
// Make sure the cookies are cleared, and make sure that the cookie
// clearing has taken effect at this point in the code. It has been
// observed that the former can happen without the latter if there
@ -45,7 +41,7 @@ describe('the test helper', function () {
// However this doesn't seem to always be easily replicated, so this
// timeout may or may end up in the code. None the less, we test here
// to catch it if the bug comes up again.
it('clears cookies', function (done) {
it('clears cookies', async function () {
this.timeout(60000);
// set cookies far into the future to make sure they're not expired yet
@ -55,20 +51,21 @@ describe('the test helper', function () {
expect(window.document.cookie).to.contain('token=foo');
expect(window.document.cookie).to.contain('language=bar');
helper.newPad(() => {
await helper.aNewPad();
// helper function seems to have cleared cookies
// NOTE: this doesn't yet mean it's proven to have taken effect by this point in execution
const firstCookie = window.document.cookie;
expect(firstCookie).to.not.contain('token=foo');
expect(firstCookie).to.not.contain('language=bar');
const chrome$ = helper.padChrome$;
let chrome$ = helper.padChrome$;
// click on the settings button to make settings visible
const $userButton = chrome$('.buttonicon-showusers');
let $userButton = chrome$('.buttonicon-showusers');
$userButton.click();
const $usernameInput = chrome$('#myusernameedit');
let $usernameInput = chrome$('#myusernameedit');
$usernameInput.click();
$usernameInput.val('John McLear');
@ -87,9 +84,11 @@ describe('the test helper', function () {
// window.document.cookie. Let's just be sure.
expect(window.document.cookie).to.not.contain('prefsHtml=baz');
setTimeout(() => { // give it a second to save the username on the server side
helper.newPad(() => { // get a new pad, let it clear the cookies
const chrome$ = helper.padChrome$;
// give it a second to save the username on the server side
await new Promise((resolve) => setTimeout(resolve, 1000));
await helper.aNewPad(); // get a new pad, let it clear the cookies
chrome$ = helper.padChrome$;
// helper function seems to have cleared cookies
// NOTE: this doesn't yet mean cookies were cleared effectively.
@ -102,31 +101,20 @@ describe('the test helper', function () {
expect(window.document.cookie).to.not.be(firstCookie);
// click on the settings button to make settings visible
const $userButton = chrome$('.buttonicon-showusers');
$userButton = chrome$('.buttonicon-showusers');
$userButton.click();
// confirm that the session was actually cleared
const $usernameInput = chrome$('#myusernameedit');
$usernameInput = chrome$('#myusernameedit');
expect($usernameInput.val()).to.be('');
done();
});
}, 1000);
});
});
it('sets pad prefs cookie', function (done) {
it('sets pad prefs cookie', async function () {
this.timeout(60000);
helper.newPad({
padPrefs: {foo: 'bar'},
cb() {
await helper.aNewPad({padPrefs: {foo: 'bar'}});
const chrome$ = helper.padChrome$;
expect(chrome$.document.cookie).to.contain('prefsHttp=%7B%22');
expect(chrome$.document.cookie).to.contain('foo%22%3A%22bar');
done();
},
});
});
});
@ -416,10 +404,8 @@ describe('the test helper', function () {
});
describe('helper', function () {
before(function (cb) {
helper.newPad(() => {
cb();
});
before(async function () {
await helper.aNewPad();
});
it('.textLines() returns the text of the pad as strings', async function () {