From 10570ca3ac6f9497ae0c7506a094d2ce9d4e88a5 Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Mon, 11 Mar 2024 20:22:42 +0100 Subject: [PATCH] Fixed failing tests. Moved another test. --- .../frontend-new/specs/indentation.spec.ts | 2 +- src/tests/frontend-new/specs/language.spec.ts | 15 +- .../frontend-new/specs/ordered_list.spec.ts | 109 ++++++++ .../frontend-new/specs/strikethrough.spec.ts | 30 +++ src/tests/frontend-new/specs/undo.spec.ts | 1 + src/tests/frontend/specs/ordered_list.js | 233 ------------------ src/tests/frontend/specs/strikethrough.js | 35 --- 7 files changed, 150 insertions(+), 275 deletions(-) create mode 100644 src/tests/frontend-new/specs/ordered_list.spec.ts create mode 100644 src/tests/frontend-new/specs/strikethrough.spec.ts delete mode 100644 src/tests/frontend/specs/ordered_list.js delete mode 100644 src/tests/frontend/specs/strikethrough.js diff --git a/src/tests/frontend-new/specs/indentation.spec.ts b/src/tests/frontend-new/specs/indentation.spec.ts index 269a67011..3e94dbad3 100644 --- a/src/tests/frontend-new/specs/indentation.spec.ts +++ b/src/tests/frontend-new/specs/indentation.spec.ts @@ -25,7 +25,7 @@ test.describe('indentation button', function () { const padBody = await getPadBody(page); await page.locator('.buttonicon-indent').click() - const uls = padBody.locator('div').first().locator('ul li') + const uls = padBody.locator('div').first().locator('ul') await expect(uls).toHaveCount(1); }); diff --git a/src/tests/frontend-new/specs/language.spec.ts b/src/tests/frontend-new/specs/language.spec.ts index 79acb5412..87da86b13 100644 --- a/src/tests/frontend-new/specs/language.spec.ts +++ b/src/tests/frontend-new/specs/language.spec.ts @@ -18,10 +18,11 @@ test.describe('Language select and change', function () { await showSettings(page) // click the language button - await page.locator('.nice-select').nth(1).locator('.current').click() + const languageDropDown = page.locator('.nice-select').nth(1) + + await languageDropDown.click() await page.locator('.nice-select').locator('[data-value=de]').click() - //const $language = chrome$('#languagemenu'); - //const $languageoption = $language.find('[value=de]'); + await expect(languageDropDown.locator('.current')).toHaveText('Deutsch') // select german await page.locator('.buttonicon-bold').evaluate((el) => el.parentElement!.title === 'Fett (Strg-B)'); @@ -70,10 +71,12 @@ test.describe('Language select and change', function () { test('changes direction when picking an ltr lang', async function ({page}) { await showSettings(page) - // change to english - await page.locator('.nice-select').nth(1).locator('.current').click() - await page.locator('.nice-select').locator('[data-value=en]').click() + const languageDropDown = page.locator('.nice-select').nth(1) + await languageDropDown.locator('.current').click() + await languageDropDown.locator('[data-value=en]').click() + + await expect(languageDropDown.locator('.current')).toHaveText('English') // check if the language is now English await page.locator('.buttonicon-bold').evaluate((el) => el.parentElement!.title !== 'Fett (Strg-B)'); diff --git a/src/tests/frontend-new/specs/ordered_list.spec.ts b/src/tests/frontend-new/specs/ordered_list.spec.ts new file mode 100644 index 000000000..04e996e66 --- /dev/null +++ b/src/tests/frontend-new/specs/ordered_list.spec.ts @@ -0,0 +1,109 @@ +import {expect, test} from "@playwright/test"; +import {clearPadContent, getPadBody, goToNewPad, writeToPad} from "../helper/padHelper"; + +test.beforeEach(async ({ page })=>{ + await goToNewPad(page); +}) + + +test.describe('ordered_list.js', function () { + + test('issue #4748 keeps numbers increment on OL', async function ({page}) { + const padBody = await getPadBody(page); + await clearPadContent(page) + await writeToPad(page, 'Line 1') + await page.keyboard.press('Enter') + await writeToPad(page, 'Line 2') + + const $insertorderedlistButton = page.locator('.buttonicon-insertorderedlist') + await padBody.locator('div').first().selectText() + await $insertorderedlistButton.first().click(); + + const secondLine = padBody.locator('div').nth(1) + + await secondLine.selectText() + await $insertorderedlistButton.click(); + + expect(await secondLine.locator('ol').getAttribute('start')).toEqual('2'); + }); + + test('issue #1125 keeps the numbered list on enter for the new line', async function ({page}) { + // EMULATES PASTING INTO A PAD + const padBody = await getPadBody(page); + await clearPadContent(page) + await expect(padBody.locator('div')).toHaveCount(1) + const $insertorderedlistButton = page.locator('.buttonicon-insertorderedlist') + await $insertorderedlistButton.click(); + + // type a bit, make a line break and type again + const firstTextElement = padBody.locator('div').first() + await firstTextElement.click() + await writeToPad(page, 'line 1') + await page.keyboard.press('Enter') + await writeToPad(page, 'line 2') + await page.keyboard.press('Enter') + + await expect(padBody.locator('div span').nth(1)).toHaveText('line 2'); + + const $newSecondLine = padBody.locator('div').nth(1) + expect(await $newSecondLine.locator('ol li').count()).toEqual(1); + await expect($newSecondLine.locator('ol li').nth(0)).toHaveText('line 2'); + const hasLineNumber = await $newSecondLine.locator('ol').getAttribute('start'); + // This doesn't work because pasting in content doesn't work + expect(Number(hasLineNumber)).toBe(2); + }); + }); + + test.describe('Pressing Tab in an OL increases and decreases indentation', function () { + + test('indent and de-indent list item with keypress', async function ({page}) { + const padBody = await getPadBody(page); + + // get the first text element out of the inner iframe + const $firstTextElement = padBody.locator('div').first(); + + // select this text element + await $firstTextElement.selectText() + + const $insertorderedlistButton = page.locator('.buttonicon-insertorderedlist') + await $insertorderedlistButton.click() + + await page.keyboard.press('Tab') + + await expect(padBody.locator('div').first().locator('.list-number2')).toHaveCount(1) + + await page.keyboard.press('Shift+Tab') + + + await expect(padBody.locator('div').first().locator('.list-number1')).toHaveCount(1) + }); + }); + + + test.describe('Pressing indent/outdent button in an OL increases and ' + + 'decreases indentation and bullet / ol formatting', function () { + + test('indent and de-indent list item with indent button', async function ({page}) { + const padBody = await getPadBody(page); + + // get the first text element out of the inner iframe + const $firstTextElement = padBody.locator('div').first(); + + // select this text element + await $firstTextElement.selectText() + + const $insertorderedlistButton = page.locator('.buttonicon-insertorderedlist') + await $insertorderedlistButton.click() + + const $indentButton = page.locator('.buttonicon-indent') + await $indentButton.dblclick() // make it indented twice + + const outdentButton = page.locator('.buttonicon-outdent') + + await expect(padBody.locator('div').first().locator('.list-number3')).toHaveCount(1) + + await outdentButton.click(); // make it deindented to 1 + + await expect(padBody.locator('div').first().locator('.list-number2')).toHaveCount(1) + }); + }); diff --git a/src/tests/frontend-new/specs/strikethrough.spec.ts b/src/tests/frontend-new/specs/strikethrough.spec.ts new file mode 100644 index 000000000..a4f68b4a7 --- /dev/null +++ b/src/tests/frontend-new/specs/strikethrough.spec.ts @@ -0,0 +1,30 @@ +import {expect, test} from "@playwright/test"; +import {clearPadContent, getPadBody, goToNewPad, writeToPad} from "../helper/padHelper"; + +test.beforeEach(async ({ page })=>{ + await goToNewPad(page); +}) + +test.describe('strikethrough button', function () { + + test('makes text strikethrough', async function ({page}) { + const padBody = await getPadBody(page); + + // get the first text element out of the inner iframe + const $firstTextElement = padBody.locator('div').first(); + + // select this text element + await $firstTextElement.selectText() + + // get the strikethrough button and click it + await page.locator('.buttonicon-strikethrough').click(); + + // ace creates a new dom element when you press a button, just get the first text element again + + // is there a element now? + await expect($firstTextElement.locator('s')).toHaveCount(1); + + // make sure the text hasn't changed + expect(await $firstTextElement.textContent()).toEqual(await $firstTextElement.textContent()); + }); +}); diff --git a/src/tests/frontend-new/specs/undo.spec.ts b/src/tests/frontend-new/specs/undo.spec.ts index 197458401..cdbc12083 100644 --- a/src/tests/frontend-new/specs/undo.spec.ts +++ b/src/tests/frontend-new/specs/undo.spec.ts @@ -49,6 +49,7 @@ test.describe('undo button', function () { // undo the change await page.keyboard.press('Control+Z'); + await page.waitForTimeout(1000) await expect(firstTextElement).toHaveText(originalValue!); }); diff --git a/src/tests/frontend/specs/ordered_list.js b/src/tests/frontend/specs/ordered_list.js deleted file mode 100644 index 33e7f5c90..000000000 --- a/src/tests/frontend/specs/ordered_list.js +++ /dev/null @@ -1,233 +0,0 @@ -'use strict'; - -describe('ordered_list.js', function () { - describe('assign ordered list', function () { - // create a new pad before each test run - beforeEach(async function () { - await helper.aNewPad(); - }); - - it('inserts ordered list text', async function () { - const inner$ = helper.padInner$; - const chrome$ = helper.padChrome$; - - const $insertorderedlistButton = chrome$('.buttonicon-insertorderedlist'); - $insertorderedlistButton.trigger('click'); - - await helper.waitForPromise(() => inner$('div').first().find('ol li').length === 1); - }); - - context('when user presses Ctrl+Shift+N', function () { - context('and pad shortcut is enabled', function () { - beforeEach(async function () { - const originalHTML = helper.padInner$('body').html(); - makeSureShortcutIsEnabled('cmdShiftN'); - triggerCtrlShiftShortcut('N'); - await helper.waitForPromise(() => helper.padInner$('body').html() !== originalHTML); - }); - - it('inserts unordered list', async function () { - await helper.waitForPromise( - () => helper.padInner$('div').first().find('ol li').length === 1); - }); - }); - - context('and pad shortcut is disabled', function () { - beforeEach(async function () { - const originalHTML = helper.padInner$('body').html(); - makeSureShortcutIsDisabled('cmdShiftN'); - triggerCtrlShiftShortcut('N'); - try { - // The HTML should not change. Briefly wait for it to change and fail if it does change. - await helper.waitForPromise( - () => helper.padInner$('body').html() !== originalHTML, 500); - } catch (err) { - // We want the test to pass if the above wait timed out. (If it timed out that - // means the HTML never changed, which is a good thing.) - // TODO: Re-throw non-"condition never became true" errors to avoid false positives. - } - // This will fail if the above `waitForPromise()` succeeded. - expect(helper.padInner$('body').html()).to.be(originalHTML); - }); - - it('does not insert unordered list', async function () { - this.timeout(3000); - try { - await helper.waitForPromise( - () => helper.padInner$('div').first().find('ol li').length === 1); - } catch (err) { - return; - } - expect().fail('Unordered list inserted, should ignore shortcut'); - }); - }); - }); - - context('when user presses Ctrl+Shift+1', function () { - context('and pad shortcut is enabled', function () { - beforeEach(async function () { - const originalHTML = helper.padInner$('body').html(); - makeSureShortcutIsEnabled('cmdShift1'); - triggerCtrlShiftShortcut('1'); - await helper.waitForPromise(() => helper.padInner$('body').html() !== originalHTML); - }); - - it('inserts unordered list', async function () { - helper.waitForPromise(() => helper.padInner$('div').first().find('ol li').length === 1); - }); - }); - - context('and pad shortcut is disabled', function () { - beforeEach(async function () { - const originalHTML = helper.padInner$('body').html(); - makeSureShortcutIsDisabled('cmdShift1'); - triggerCtrlShiftShortcut('1'); - try { - // The HTML should not change. Briefly wait for it to change and fail if it does change. - await helper.waitForPromise( - () => helper.padInner$('body').html() !== originalHTML, 500); - } catch (err) { - // We want the test to pass if the above wait timed out. (If it timed out that - // means the HTML never changed, which is a good thing.) - // TODO: Re-throw non-"condition never became true" errors to avoid false positives. - } - // This will fail if the above `waitForPromise()` succeeded. - expect(helper.padInner$('body').html()).to.be(originalHTML); - }); - - it('does not insert unordered list', async function () { - this.timeout(3000); - try { - await helper.waitForPromise( - () => helper.padInner$('div').first().find('ol li').length === 1); - } catch (err) { - return; - } - expect().fail('Unordered list inserted, should ignore shortcut'); - }); - }); - }); - - it('issue #4748 keeps numbers increment on OL', async function () { - this.timeout(5000); - const inner$ = helper.padInner$; - const chrome$ = helper.padChrome$; - const $insertorderedlistButton = chrome$('.buttonicon-insertorderedlist'); - const $firstLine = inner$('div').first(); - $firstLine.sendkeys('{selectall}'); - $insertorderedlistButton.trigger('click'); - const $secondLine = inner$('div').first().next(); - $secondLine.sendkeys('{selectall}'); - $insertorderedlistButton.trigger('click'); - expect($secondLine.find('ol').attr('start') === 2); - }); - - xit('issue #1125 keeps the numbered list on enter for the new line', async function () { - // EMULATES PASTING INTO A PAD - const inner$ = helper.padInner$; - const chrome$ = helper.padChrome$; - - const $insertorderedlistButton = chrome$('.buttonicon-insertorderedlist'); - $insertorderedlistButton.trigger('click'); - - // type a bit, make a line break and type again - const $firstTextElement = inner$('div span').first(); - $firstTextElement.sendkeys('line 1'); - $firstTextElement.sendkeys('{enter}'); - $firstTextElement.sendkeys('line 2'); - $firstTextElement.sendkeys('{enter}'); - - await helper.waitForPromise(() => inner$('div span').first().text().indexOf('line 2') === -1); - - const $newSecondLine = inner$('div').first().next(); - const hasOLElement = $newSecondLine.find('ol li').length === 1; - expect(hasOLElement).to.be(true); - expect($newSecondLine.text()).to.be('line 2'); - const hasLineNumber = $newSecondLine.find('ol').attr('start') === 2; - // This doesn't work because pasting in content doesn't work - expect(hasLineNumber).to.be(true); - }); - - const triggerCtrlShiftShortcut = (shortcutChar) => { - const inner$ = helper.padInner$; - const e = new inner$.Event(helper.evtType); - e.ctrlKey = true; - e.shiftKey = true; - e.which = shortcutChar.toString().charCodeAt(0); - inner$('#innerdocbody').trigger(e); - }; - - const makeSureShortcutIsDisabled = (shortcut) => { - helper.padChrome$.window.clientVars.padShortcutEnabled[shortcut] = false; - }; - const makeSureShortcutIsEnabled = (shortcut) => { - helper.padChrome$.window.clientVars.padShortcutEnabled[shortcut] = true; - }; - }); - - describe('Pressing Tab in an OL increases and decreases indentation', function () { - // create a new pad before each test run - beforeEach(async function () { - await helper.aNewPad(); - }); - - it('indent and de-indent list item with keypress', async function () { - const inner$ = helper.padInner$; - const chrome$ = helper.padChrome$; - - // get the first text element out of the inner iframe - const $firstTextElement = inner$('div').first(); - - // select this text element - $firstTextElement.sendkeys('{selectall}'); - - const $insertorderedlistButton = chrome$('.buttonicon-insertorderedlist'); - $insertorderedlistButton.trigger('click'); - - const e = new inner$.Event(helper.evtType); - e.keyCode = 9; // tab - inner$('#innerdocbody').trigger(e); - - expect(inner$('div').first().find('.list-number2').length === 1).to.be(true); - e.shiftKey = true; // shift - e.keyCode = 9; // tab - inner$('#innerdocbody').trigger(e); - - await helper.waitForPromise(() => inner$('div').first().find('.list-number1').length === 1); - }); - }); - - - describe('Pressing indent/outdent button in an OL increases and ' + - 'decreases indentation and bullet / ol formatting', function () { - // create a new pad before each test run - beforeEach(async function () { - await helper.aNewPad(); - }); - - it('indent and de-indent list item with indent button', async function () { - this.timeout(1000); - const inner$ = helper.padInner$; - const chrome$ = helper.padChrome$; - - // get the first text element out of the inner iframe - const $firstTextElement = inner$('div').first(); - - // select this text element - $firstTextElement.sendkeys('{selectall}'); - - const $insertorderedlistButton = chrome$('.buttonicon-insertorderedlist'); - $insertorderedlistButton.trigger('click'); - - const $indentButton = chrome$('.buttonicon-indent'); - $indentButton.trigger('click'); // make it indented twice - - expect(inner$('div').first().find('.list-number2').length === 1).to.be(true); - - const $outdentButton = chrome$('.buttonicon-outdent'); - $outdentButton.trigger('click'); // make it deindented to 1 - - await helper.waitForPromise(() => inner$('div').first().find('.list-number1').length === 1); - }); - }); -}); diff --git a/src/tests/frontend/specs/strikethrough.js b/src/tests/frontend/specs/strikethrough.js deleted file mode 100644 index 8385d676e..000000000 --- a/src/tests/frontend/specs/strikethrough.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; - -describe('strikethrough button', function () { - // create a new pad before each test run - beforeEach(async function () { - await helper.aNewPad(); - }); - - it('makes text strikethrough', async function () { - const inner$ = helper.padInner$; - const chrome$ = helper.padChrome$; - - // get the first text element out of the inner iframe - const $firstTextElement = inner$('div').first(); - - // select this text element - $firstTextElement.sendkeys('{selectall}'); - - // get the strikethrough button and click it - const $strikethroughButton = chrome$('.buttonicon-strikethrough'); - $strikethroughButton.trigger('click'); - - // ace creates a new dom element when you press a button, just get the first text element again - const $newFirstTextElement = inner$('div').first(); - - // is there a element now? - const isstrikethrough = $newFirstTextElement.find('s').length === 1; - - // expect it to be strikethrough - expect(isstrikethrough).to.be(true); - - // make sure the text hasn't changed - expect($newFirstTextElement.text()).to.eql($firstTextElement.text()); - }); -});