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