diff --git a/src/tests/frontend/specs/alphabet.js b/src/tests/frontend/specs/alphabet.js index 158bc734c..473d20299 100644 --- a/src/tests/frontend/specs/alphabet.js +++ b/src/tests/frontend/specs/alphabet.js @@ -4,9 +4,9 @@ describe('All the alphabet works n stuff', function () { const expectedString = 'abcdefghijklmnopqrstuvwxyz'; // create a new pad before each test run - beforeEach(function (cb) { - helper.newPad(cb); + beforeEach(async function () { this.timeout(60000); + await helper.aNewPad(); }); it('when you enter any char it appears right', function (done) { diff --git a/src/tests/frontend/specs/bold.js b/src/tests/frontend/specs/bold.js index 7aac2e36e..ce62b75a8 100644 --- a/src/tests/frontend/specs/bold.js +++ b/src/tests/frontend/specs/bold.js @@ -2,9 +2,9 @@ describe('bold button', function () { // create a new pad before each test run - beforeEach(function (cb) { - helper.newPad(cb); + beforeEach(async function () { this.timeout(60000); + await helper.aNewPad(); }); it('makes text bold on click', function (done) { diff --git a/src/tests/frontend/specs/change_user_color.js b/src/tests/frontend/specs/change_user_color.js index 1f41dcce2..aedf79b22 100644 --- a/src/tests/frontend/specs/change_user_color.js +++ b/src/tests/frontend/specs/change_user_color.js @@ -2,26 +2,26 @@ describe('change user color', function () { // create a new pad before each test run - beforeEach(function (cb) { - helper.newPad(cb); + beforeEach(async function () { this.timeout(60000); + await helper.aNewPad(); }); it('Color picker matches original color and remembers the user color' + - ' after a refresh', function (done) { + ' after a refresh', async function () { this.timeout(10000); - 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 $userSwatch = chrome$('#myswatch'); + let $userSwatch = chrome$('#myswatch'); $userSwatch.click(); const fb = chrome$.farbtastic('#colorpicker'); const $colorPickerSave = chrome$('#mycolorpickersave'); - const $colorPickerPreview = chrome$('#mycolorpickerpreview'); + let $colorPickerPreview = chrome$('#mycolorpickerpreview'); // Same color represented in two different ways const testColorHash = '#abcdef'; @@ -38,28 +38,25 @@ describe('change user color', function () { $colorPickerSave.click(); expect($userSwatch.css('background-color')).to.be(testColorRGB); - setTimeout(() => { // give it a second to save the color on the server side - helper.newPad({ // get a new pad, but don't clear the cookies - clearCookies: false, - cb() { - const chrome$ = helper.padChrome$; + // give it a second to save the color on the server side + await new Promise((resolve) => setTimeout(resolve, 1000)); - // click on the settings button to make settings visible - const $userButton = chrome$('.buttonicon-showusers'); - $userButton.click(); + // get a new pad, but don't clear the cookies + await helper.aNewPad({clearCookies: false}); - const $userSwatch = chrome$('#myswatch'); - $userSwatch.click(); + chrome$ = helper.padChrome$; - const $colorPickerPreview = chrome$('#mycolorpickerpreview'); + // click on the settings button to make settings visible + $userButton = chrome$('.buttonicon-showusers'); + $userButton.click(); - expect($colorPickerPreview.css('background-color')).to.be(testColorRGB); - expect($userSwatch.css('background-color')).to.be(testColorRGB); + $userSwatch = chrome$('#myswatch'); + $userSwatch.click(); - done(); - }, - }); - }, 1000); + $colorPickerPreview = chrome$('#mycolorpickerpreview'); + + expect($colorPickerPreview.css('background-color')).to.be(testColorRGB); + expect($userSwatch.css('background-color')).to.be(testColorRGB); }); it('Own user color is shown when you enter a chat', function (done) { diff --git a/src/tests/frontend/specs/change_user_name.js b/src/tests/frontend/specs/change_user_name.js index 8ba5e637a..166695db9 100644 --- a/src/tests/frontend/specs/change_user_name.js +++ b/src/tests/frontend/specs/change_user_name.js @@ -2,8 +2,8 @@ describe('change username value', function () { // create a new pad before each test run - beforeEach(function (cb) { - helper.newPad(cb); + beforeEach(async function () { + await helper.aNewPad(); }); it('Remembers the user name after a refresh', async function () { diff --git a/src/tests/frontend/specs/chat.js b/src/tests/frontend/specs/chat.js index be080755a..60bfe3d5a 100644 --- a/src/tests/frontend/specs/chat.js +++ b/src/tests/frontend/specs/chat.js @@ -2,8 +2,8 @@ describe('Chat messages and UI', function () { // create a new pad before each test run - beforeEach(function (cb) { - helper.newPad(cb); + beforeEach(async function () { + await helper.aNewPad(); }); it('opens chat, sends a message, makes sure it exists ' + @@ -86,34 +86,29 @@ describe('Chat messages and UI', function () { }); xit('Checks showChat=false URL Parameter hides chat then' + - ' when removed it shows chat', function (done) { + ' when removed it shows chat', async function () { this.timeout(60000); - setTimeout(() => { // give it a second to save the username on the server side - helper.newPad({ // get a new pad, but don't clear the cookies - clearCookies: false, - params: { - showChat: 'false', - }, cb() { - const chrome$ = helper.padChrome$; - const chaticon = chrome$('#chaticon'); - // chat should be hidden. - expect(chaticon.is(':visible')).to.be(false); + // give it a second to save the username on the server side + await new Promise((resolve) => setTimeout(resolve, 3000)); - setTimeout(() => { // give it a second to save the username on the server side - helper.newPad({ // get a new pad, but don't clear the cookies - clearCookies: false, - cb() { - const chrome$ = helper.padChrome$; - const chaticon = chrome$('#chaticon'); - // chat should be visible. - expect(chaticon.is(':visible')).to.be(true); - done(); - }, - }); - }, 1000); - }, - }); - }, 3000); + // get a new pad, but don't clear the cookies + await helper.aNewPad({clearCookies: false, params: {showChat: 'false'}}); + + let chrome$ = helper.padChrome$; + let chaticon = chrome$('#chaticon'); + // chat should be hidden. + expect(chaticon.is(':visible')).to.be(false); + + // give it a second to save the username on the server side + await new Promise((resolve) => setTimeout(resolve, 1000)); + + // get a new pad, but don't clear the cookies + await helper.aNewPad({clearCookies: false}); + + chrome$ = helper.padChrome$; + chaticon = chrome$('#chaticon'); + // chat should be visible. + expect(chaticon.is(':visible')).to.be(true); }); }); diff --git a/src/tests/frontend/specs/chat_load_messages.js b/src/tests/frontend/specs/chat_load_messages.js index 6b34e614b..f46c93170 100644 --- a/src/tests/frontend/specs/chat_load_messages.js +++ b/src/tests/frontend/specs/chat_load_messages.js @@ -3,9 +3,9 @@ describe('chat-load-messages', function () { let padName; - it('creates a pad', function (done) { - padName = helper.newPad(done); + it('creates a pad', async function () { this.timeout(60000); + padName = await helper.aNewPad(); }); it('adds a lot of messages', async function () { @@ -26,7 +26,7 @@ describe('chat-load-messages', function () { chatInput.sendkeys('{enter}'); await helper.waitForPromise(() => chatText.children('p').length === i); } - await new Promise((resolve) => helper.newPad(() => resolve(), padName)); + await helper.aNewPad({id: padName}); }); it('checks initial message count', function (done) { diff --git a/src/tests/frontend/specs/clear_authorship_colors.js b/src/tests/frontend/specs/clear_authorship_colors.js index ae5603949..8a8b5a32b 100644 --- a/src/tests/frontend/specs/clear_authorship_colors.js +++ b/src/tests/frontend/specs/clear_authorship_colors.js @@ -2,20 +2,18 @@ describe('clear authorship colors button', function () { // create a new pad before each test run - beforeEach(function (cb) { - helper.newPad(cb); + beforeEach(async function () { this.timeout(60000); + await helper.aNewPad(); }); - it('makes text clear authorship colors', function (done) { + it('makes text clear authorship colors', async function () { this.timeout(2500); const inner$ = helper.padInner$; const chrome$ = helper.padChrome$; // override the confirm dialogue functioon - helper.padChrome$.window.confirm = function () { - return true; - }; + helper.padChrome$.window.confirm = () => true; // get the first text element out of the inner iframe const $firstTextElement = inner$('div').first(); @@ -29,41 +27,31 @@ describe('clear authorship colors button', function () { $firstTextElement.sendkeys('{rightarrow}'); // wait until we have the full value available - helper.waitFor(() => inner$('div span').first().attr('class').indexOf('author') !== -1 - ).done(() => { - // IE hates you if you don't give focus to the inner frame bevore you do a clearAuthorship - inner$('div').first().focus(); + await helper.waitForPromise( + () => inner$('div span').first().attr('class').indexOf('author') !== -1); - // get the clear authorship colors button and click it - const $clearauthorshipcolorsButton = chrome$('.buttonicon-clearauthorship'); - $clearauthorshipcolorsButton.click(); + // IE hates you if you don't give focus to the inner frame bevore you do a clearAuthorship + inner$('div').first().focus(); - // does the first div include an author class? - const hasAuthorClass = inner$('div').first().attr('class').indexOf('author') !== -1; - expect(hasAuthorClass).to.be(false); + // get the clear authorship colors button and click it + const $clearauthorshipcolorsButton = chrome$('.buttonicon-clearauthorship'); + $clearauthorshipcolorsButton.click(); - helper.waitFor(() => { - const disconnectVisible = - chrome$('div.disconnected').attr('class').indexOf('visible') === -1; - return (disconnectVisible === true); - }); + // does the first div include an author class? + const hasAuthorClass = inner$('div').first().attr('class').indexOf('author') !== -1; + expect(hasAuthorClass).to.be(false); - const disconnectVisible = chrome$('div.disconnected').attr('class').indexOf('visible') === -1; - expect(disconnectVisible).to.be(true); - - done(); - }); + await helper.waitForPromise( + () => chrome$('div.disconnected').attr('class').indexOf('visible') === -1); }); - it("makes text clear authorship colors and checks it can't be undone", function (done) { + it("makes text clear authorship colors and checks it can't be undone", async function () { this.timeout(1500); const inner$ = helper.padInner$; const chrome$ = helper.padChrome$; // override the confirm dialogue functioon - helper.padChrome$.window.confirm = function () { - return true; - }; + helper.padChrome$.window.confirm = () => true; // get the first text element out of the inner iframe const $firstTextElement = inner$('div').first(); @@ -77,47 +65,38 @@ describe('clear authorship colors button', function () { $firstTextElement.sendkeys('{rightarrow}'); // wait until we have the full value available - helper.waitFor( - () => inner$('div span').first().attr('class').indexOf('author') !== -1 - ).done(() => { - // IE hates you if you don't give focus to the inner frame bevore you do a clearAuthorship - inner$('div').first().focus(); + await helper.waitForPromise( + () => inner$('div span').first().attr('class').indexOf('author') !== -1); - // get the clear authorship colors button and click it - const $clearauthorshipcolorsButton = chrome$('.buttonicon-clearauthorship'); - $clearauthorshipcolorsButton.click(); + // IE hates you if you don't give focus to the inner frame bevore you do a clearAuthorship + inner$('div').first().focus(); - // does the first div include an author class? - let hasAuthorClass = inner$('div').first().attr('class').indexOf('author') !== -1; - expect(hasAuthorClass).to.be(false); + // get the clear authorship colors button and click it + const $clearauthorshipcolorsButton = chrome$('.buttonicon-clearauthorship'); + $clearauthorshipcolorsButton.click(); - const e = new inner$.Event(helper.evtType); - e.ctrlKey = true; // Control key - e.which = 90; // z - inner$('#innerdocbody').trigger(e); // shouldn't od anything + // does the first div include an author class? + let hasAuthorClass = inner$('div').first().attr('class').indexOf('author') !== -1; + expect(hasAuthorClass).to.be(false); - // does the first div include an author class? - hasAuthorClass = inner$('div').first().attr('class').indexOf('author') !== -1; - expect(hasAuthorClass).to.be(false); + const e = new inner$.Event(helper.evtType); + e.ctrlKey = true; // Control key + e.which = 90; // z + inner$('#innerdocbody').trigger(e); // shouldn't od anything - // get undo and redo buttons - const $undoButton = chrome$('.buttonicon-undo'); + // does the first div include an author class? + hasAuthorClass = inner$('div').first().attr('class').indexOf('author') !== -1; + expect(hasAuthorClass).to.be(false); - // click the button - $undoButton.click(); // shouldn't do anything - hasAuthorClass = inner$('div').first().attr('class').indexOf('author') !== -1; - expect(hasAuthorClass).to.be(false); + // get undo and redo buttons + const $undoButton = chrome$('.buttonicon-undo'); - helper.waitFor(() => { - const disconnectVisible = - chrome$('div.disconnected').attr('class').indexOf('visible') === -1; - return (disconnectVisible === true); - }); + // click the button + $undoButton.click(); // shouldn't do anything + hasAuthorClass = inner$('div').first().attr('class').indexOf('author') !== -1; + expect(hasAuthorClass).to.be(false); - const disconnectVisible = chrome$('div.disconnected').attr('class').indexOf('visible') === -1; - expect(disconnectVisible).to.be(true); - - done(); - }); + await helper.waitForPromise( + () => chrome$('div.disconnected').attr('class').indexOf('visible') === -1); }); }); diff --git a/src/tests/frontend/specs/delete.js b/src/tests/frontend/specs/delete.js index 1ffbbd51c..869fc0775 100644 --- a/src/tests/frontend/specs/delete.js +++ b/src/tests/frontend/specs/delete.js @@ -2,12 +2,12 @@ describe('delete keystroke', function () { // create a new pad before each test run - beforeEach(function (cb) { - helper.newPad(cb); + beforeEach(async function () { this.timeout(60000); + await helper.aNewPad(); }); - it('makes text delete', function (done) { + it('makes text delete', async function () { this.timeout(50); const inner$ = helper.padInner$; @@ -28,7 +28,5 @@ describe('delete keystroke', function () { // expect it to be one char less in length expect(newElementLength).to.be((elementLength - 1)); - - done(); }); }); diff --git a/src/tests/frontend/specs/drag_and_drop.js b/src/tests/frontend/specs/drag_and_drop.js index 8937b375e..8f608d714 100644 --- a/src/tests/frontend/specs/drag_and_drop.js +++ b/src/tests/frontend/specs/drag_and_drop.js @@ -2,24 +2,23 @@ // WARNING: drag and drop is only simulated on these tests, manual testing might also be necessary describe('drag and drop', function () { - before(function (done) { - helper.newPad(() => { - createScriptWithSeveralLines(done); - }); + before(async function () { this.timeout(60000); + await helper.aNewPad(); + await createScriptWithSeveralLines(); }); context('when user drags part of one line and drops it far form its original place', function () { - before(function (done) { + before(async function () { selectPartOfSourceLine(); dragSelectedTextAndDropItIntoMiddleOfLine(TARGET_LINE); // make sure DnD was correctly simulated - helper.waitFor(() => { + await helper.waitForPromise(() => { const $targetLine = getLine(TARGET_LINE); const sourceWasMovedToTarget = $targetLine.text() === 'Target line [line 1]'; return sourceWasMovedToTarget; - }).done(done); + }); }); context('and user triggers UNDO', function () { @@ -30,7 +29,7 @@ describe('drag and drop', function () { await helper.waitForPromise(() => helper.padInner$('body').html() !== originalHTML); }); - it('moves text back to its original place', function (done) { + it('moves text back to its original place', async function () { this.timeout(50); // test text was removed from drop target const $targetLine = getLine(TARGET_LINE); @@ -41,23 +40,21 @@ describe('drag and drop', function () { const $lastSourceLine = getLine(FIRST_SOURCE_LINE + 1); expect($firstSourceLine.text()).to.be('Source line 1.'); expect($lastSourceLine.text()).to.be('Source line 2.'); - - done(); }); }); }); context('when user drags some lines far form its original place', function () { - before(function (done) { + before(async function () { selectMultipleSourceLines(); dragSelectedTextAndDropItIntoMiddleOfLine(TARGET_LINE); // make sure DnD was correctly simulated - helper.waitFor(() => { + await helper.waitForPromise(() => { const $lineAfterTarget = getLine(TARGET_LINE + 1); const sourceWasMovedToTarget = $lineAfterTarget.text() !== '...'; return sourceWasMovedToTarget; - }).done(done); + }); }); context('and user triggers UNDO', function () { @@ -68,7 +65,7 @@ describe('drag and drop', function () { await helper.waitForPromise(() => helper.padInner$('body').html() !== originalHTML); }); - it('moves text back to its original place', function (done) { + it('moves text back to its original place', async function () { this.timeout(50); // test text was removed from drop target const $targetLine = getLine(TARGET_LINE); @@ -79,8 +76,6 @@ describe('drag and drop', function () { const $lastSourceLine = getLine(FIRST_SOURCE_LINE + 1); expect($firstSourceLine.text()).to.be('Source line 1.'); expect($lastSourceLine.text()).to.be('Source line 2.'); - - done(); }); }); }); @@ -94,17 +89,17 @@ describe('drag and drop', function () { return $lines.slice(lineNumber, lineNumber + 1); }; - const createScriptWithSeveralLines = (done) => { + const createScriptWithSeveralLines = async () => { // create some lines to be used on the tests const $firstLine = helper.padInner$('div').first(); $firstLine.html('...
...
Target line []
...
...
' + 'Source line 1.
Source line 2.
'); // wait for lines to be split - helper.waitFor(() => { + await helper.waitForPromise(() => { const $lastSourceLine = getLine(FIRST_SOURCE_LINE + 1); return $lastSourceLine.text() === 'Source line 2.'; - }).done(done); + }); }; const selectPartOfSourceLine = () => { diff --git a/src/tests/frontend/specs/embed_value.js b/src/tests/frontend/specs/embed_value.js index 74c8d5ddc..388738358 100644 --- a/src/tests/frontend/specs/embed_value.js +++ b/src/tests/frontend/specs/embed_value.js @@ -50,13 +50,13 @@ describe('embed links', function () { describe('read and write', function () { // create a new pad before each test run - beforeEach(function (cb) { - helper.newPad(cb); + beforeEach(async function () { this.timeout(60000); + await helper.aNewPad(); }); describe('the share link', function () { - it('is the actual pad url', function (done) { + it('is the actual pad url', async function () { this.timeout(100); const chrome$ = helper.padChrome$; @@ -67,13 +67,11 @@ describe('embed links', function () { const shareLink = chrome$('#linkinput').val(); const padURL = chrome$.window.location.href; expect(shareLink).to.be(padURL); - - done(); }); }); describe('the embed as iframe code', function () { - it('is an iframe with the the correct url parameters and correct size', function (done) { + it('is an iframe with the the correct url parameters and correct size', async function () { this.timeout(50); const chrome$ = helper.padChrome$; @@ -84,20 +82,18 @@ describe('embed links', function () { const embedCode = chrome$('#embedinput').val(); checkiFrameCode(embedCode, false); - - done(); }); }); }); describe('when read only option is set', function () { - beforeEach(function (cb) { - helper.newPad(cb); + beforeEach(async function () { this.timeout(60000); + await helper.aNewPad(); }); describe('the share link', function () { - it('shows a read only url', function (done) { + it('shows a read only url', async function () { this.timeout(50); const chrome$ = helper.padChrome$; @@ -110,13 +106,11 @@ describe('embed links', function () { const shareLink = chrome$('#linkinput').val(); const containsReadOnlyLink = shareLink.indexOf('r.') > 0; expect(containsReadOnlyLink).to.be(true); - - done(); }); }); describe('the embed as iframe code', function () { - it('is an iframe with the the correct url parameters and correct size', function (done) { + it('is an iframe with the the correct url parameters and correct size', async function () { this.timeout(50); const chrome$ = helper.padChrome$; @@ -131,8 +125,6 @@ describe('embed links', function () { const embedCode = chrome$('#embedinput').val(); checkiFrameCode(embedCode, true); - - done(); }); }); }); diff --git a/src/tests/frontend/specs/enter.js b/src/tests/frontend/specs/enter.js index 69cd9d48a..070b45544 100644 --- a/src/tests/frontend/specs/enter.js +++ b/src/tests/frontend/specs/enter.js @@ -2,11 +2,12 @@ describe('enter keystroke', function () { // create a new pad before each test run - beforeEach(function (cb) { - helper.newPad(cb); + beforeEach(async function () { this.timeout(60000); + await helper.aNewPad(); }); - it('creates a new line & puts cursor onto a new line', function (done) { + + it('creates a new line & puts cursor onto a new line', async function () { this.timeout(2000); const inner$ = helper.padInner$; @@ -19,14 +20,13 @@ describe('enter keystroke', function () { // simulate key presses to enter content $firstTextElement.sendkeys('{enter}'); - helper.waitFor(() => inner$('div').first().text() === '').done(() => { - const $newSecondLine = inner$('div').first().next(); - const newFirstTextElementValue = inner$('div').first().text(); - expect(newFirstTextElementValue).to.be(''); // expect the first line to be blank - // expect the second line to be the same as the original first line. - expect($newSecondLine.text()).to.be(originalTextValue); - done(); - }); + await helper.waitForPromise(() => inner$('div').first().text() === ''); + + const $newSecondLine = inner$('div').first().next(); + const newFirstTextElementValue = inner$('div').first().text(); + expect(newFirstTextElementValue).to.be(''); // expect the first line to be blank + // expect the second line to be the same as the original first line. + expect($newSecondLine.text()).to.be(originalTextValue); }); it('enter is always visible after event', async function () { diff --git a/src/tests/frontend/specs/font_type.js b/src/tests/frontend/specs/font_type.js index 9790873b3..02d33db2e 100644 --- a/src/tests/frontend/specs/font_type.js +++ b/src/tests/frontend/specs/font_type.js @@ -2,12 +2,12 @@ describe('font select', function () { // create a new pad before each test run - beforeEach(function (cb) { - helper.newPad(cb); + beforeEach(async function () { this.timeout(60000); + await helper.aNewPad(); }); - it('makes text RobotoMono', function (done) { + it('makes text RobotoMono', async function () { this.timeout(100); const inner$ = helper.padInner$; const chrome$ = helper.padChrome$; @@ -29,7 +29,5 @@ describe('font select', function () { const fontFamily = inner$('body').css('font-family').toLowerCase(); const containsStr = fontFamily.indexOf('robotomono'); expect(containsStr).to.not.be(-1); - - done(); }); }); diff --git a/src/tests/frontend/specs/helper.js b/src/tests/frontend/specs/helper.js index d0a69c563..9dd2b05ce 100644 --- a/src/tests/frontend/specs/helper.js +++ b/src/tests/frontend/specs/helper.js @@ -2,23 +2,9 @@ describe('the test helper', function () { describe('the newPad method', function () { - xit("doesn't leak memory if you creates iframes over and over again", function (done) { + xit("doesn't leak memory if you creates iframes over and over again", async function () { this.timeout(100000); - - let times = 10; - - const loadPad = () => { - helper.newPad(() => { - times--; - if (times > 0) { - loadPad(); - } else { - done(); - } - }); - }; - - loadPad(); + for (let i = 0; i < 10; ++i) await helper.aNewPad(); }); it('gives me 3 jquery instances of chrome, outer and inner', async function () { @@ -252,20 +238,19 @@ describe('the test helper', function () { .replace(/\s/gi, ' '); }; - before(function (done) { - helper.newPad(() => { - // create some lines to be used on the tests - const $firstLine = helper.padInner$('div').first(); - $firstLine.sendkeys('{selectall}some{enter}short{enter}lines{enter}to test{enter}{enter}'); - - // wait for lines to be split - helper.waitFor(() => { - const $fourthLine = helper.padInner$('div').eq(3); - return $fourthLine.text() === 'to test'; - }).done(done); - }); - + before(async function () { this.timeout(60000); + await helper.aNewPad(); + + // create some lines to be used on the tests + const $firstLine = helper.padInner$('div').first(); + $firstLine.sendkeys('{selectall}some{enter}short{enter}lines{enter}to test{enter}{enter}'); + + // wait for lines to be split + await helper.waitForPromise(() => { + const $fourthLine = helper.padInner$('div').eq(3); + return $fourthLine.text() === 'to test'; + }); }); it('changes editor selection to be between startOffset of $startLine ' + @@ -322,7 +307,7 @@ describe('the test helper', function () { done(); }); - it('ends selection at beginning of $endLine when its offset is zero', function (done) { + it('ends selection at beginning of $endLine when its offset is zero', async function () { const inner$ = helper.padInner$; const startOffset = 2; @@ -344,8 +329,6 @@ describe('the test helper', function () { * how I'm covering it in this test. */ expect(cleanText(selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('ort lines '); - - done(); }); it('selects full line when offset is longer than line content', function (done) { @@ -376,7 +359,7 @@ describe('the test helper', function () { }); it('selects all text between beginning of $startLine and end of $endLine ' + - 'when no offset is provided', function (done) { + 'when no offset is provided', async function () { const inner$ = helper.padInner$; const $lines = inner$('div'); @@ -396,8 +379,6 @@ describe('the test helper', function () { */ expect(cleanText( selection.toString().replace(/(\r\n|\n|\r)/gm, ''))).to.be('short lines to test'); - - done(); }); }); diff --git a/src/tests/frontend/specs/importexport.js b/src/tests/frontend/specs/importexport.js index 73798eca9..954cd518b 100644 --- a/src/tests/frontend/specs/importexport.js +++ b/src/tests/frontend/specs/importexport.js @@ -500,8 +500,7 @@ describe('importexport.js', function () { let confirm; before(async function () { this.timeout(60000); - await new Promise( - (resolve, reject) => helper.newPad((err) => err != null ? reject(err) : resolve())); + await helper.aNewPad(); confirm = helper.padChrome$.window.confirm; helper.padChrome$.window.confirm = () => true; // As of 2021-02-22 a mutable FileList cannot be directly created so DataTransfer is used as a diff --git a/src/tests/frontend/specs/importindents.js b/src/tests/frontend/specs/importindents.js index eecbbce59..434c86b5f 100644 --- a/src/tests/frontend/specs/importindents.js +++ b/src/tests/frontend/specs/importindents.js @@ -1,20 +1,21 @@ 'use strict'; describe('import indents functionality', function () { - beforeEach(function (cb) { - helper.newPad(cb); // creates a new pad + beforeEach(async function () { this.timeout(60000); + await helper.aNewPad(); }); - function getinnertext() { + const getinnertext = () => { const inner = helper.padInner$; let newtext = ''; inner('div').each((line, el) => { newtext += `${el.innerHTML}\n`; }); return newtext; - } - function importrequest(data, importurl, type) { + }; + + const importrequest = (data, importurl, type) => { let error; const result = $.ajax({ url: importurl, @@ -42,8 +43,9 @@ describe('import indents functionality', function () { }); expect(error).to.be(undefined); return result; - } - function exportfunc(link) { + }; + + const exportfunc = (link) => { const exportresults = []; $.ajaxSetup({ async: false, @@ -58,51 +60,72 @@ describe('import indents functionality', function () { exportresults.push(['txt', data]); }); return exportresults; - } + }; - xit('import a pad with indents from html', function (done) { + xit('import a pad with indents from html', async function () { const importurl = `${helper.padChrome$.window.location.href}/import`; - /* eslint-disable-next-line max-len */ - const htmlWithIndents = ''; + const htmlWithIndents = + '' + + ''; importrequest(htmlWithIndents, importurl, 'html'); - helper.waitFor(() => expect(getinnertext()).to.be( + await helper.waitForPromise(() => getinnertext() === '\n' + '\n' + '\n' + '\n' + - '
\n')); + '
\n'); const results = exportfunc(helper.padChrome$.window.location.href); - /* eslint-disable-next-line max-len */ - expect(results[0][1]).to.be('
'); + expect(results[0][1]).to.be( + '
'); expect(results[1][1]) .to.be('\tindent line 1\n\tindent line 2\n\t\tindent2 line 1\n\t\tindent2 line 2\n\n'); - done(); }); - xit('import a pad with indented lists and newlines from html', function (done) { + xit('import a pad with indented lists and newlines from html', async function () { const importurl = `${helper.padChrome$.window.location.href}/import`; - /* eslint-disable-next-line max-len */ - const htmlWithIndents = '

'; + const htmlWithIndents = + '
' + + '
' + + ''; importrequest(htmlWithIndents, importurl, 'html'); - helper.waitFor(() => expect(getinnertext()).to.be( + await helper.waitForPromise(() => getinnertext() === '\n' + '
\n' + '\n' + '\n' + '
\n' + '\n' + - '
\n')); + '
\n'); const results = exportfunc(helper.padChrome$.window.location.href); - /* eslint-disable-next-line max-len */ - expect(results[0][1]).to.be('


'); - /* eslint-disable-next-line max-len */ - expect(results[1][1]).to.be('\tindent line 1\n\n\tindent 1 line 2\n\t\tindent 2 times line 1\n\n\t\tindent 2 times line 2\n\n'); - done(); + expect(results[0][1]).to.be( + '
' + + '
' + + '
'); + expect(results[1][1]).to.be( + '\tindent line 1\n\n\tindent 1 line 2\n\t\tindent 2 times line 1\n\n' + + '\t\tindent 2 times line 2\n\n'); }); - xit('import with 8 levels of indents and newlines and attributes from html', function (done) { + + xit('import with 8 levels of indents and newlines and attributes from html', async function () { const importurl = `${helper.padChrome$.window.location.href}/import`; - /* eslint-disable-next-line max-len */ - const htmlWithIndents = '