From 412a185567939877c34479c8ff96fbcb5ccc9ac7 Mon Sep 17 00:00:00 2001 From: Paul Ibeabuchi C Date: Thu, 27 Jan 2022 17:13:31 +0100 Subject: [PATCH 1/3] converted history jasmine test to jest --- test/ui-testing/history.test.js | 103 +++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 2 deletions(-) diff --git a/test/ui-testing/history.test.js b/test/ui-testing/history.test.js index 3ab4e65b..e7bff8dc 100644 --- a/test/ui-testing/history.test.js +++ b/test/ui-testing/history.test.js @@ -1,14 +1,113 @@ const timeout = process.env.SLOWMO ? 60000 : 10000; const fs = require('fs'); +let editor; beforeAll(async () => { path = fs.realpathSync('file://../examples/index.html'); await page.goto('file://' + path, {waitUntil: 'domcontentloaded'}); + await page.evaluate(() => { + editor = new PL.Editor({ + textarea: document.querySelector('.ple-textarea') + }); + }); }); -describe('History functions', () => { +describe('History', () => { + test('has log, key, interval and id', async () => { + expect( await page.evaluate(() => editor.history.log) ).toBeDefined(); + expect( await page.evaluate(() => editor.history.key) ).toBeDefined(); + expect( await page.evaluate(() => editor.history.options) ).toBeDefined(); + expect( await page.evaluate(() => editor.history.options.interval) ).toBeDefined(); + expect( await page.evaluate(() => editor.history.options.id) ).toBeDefined(); + }); + + test('can be flushed', async () => { + expect( await page.evaluate(() => editor.history.fetch()) ).not.toEqual([]); + expect( await page.evaluate(() => editor.history.last()) ).not.toBe(null); + + await page.evaluate(() => editor.history.flush()); + + expect( await page.evaluate(() => editor.history.fetch()) ).toEqual([]); + expect( await page.evaluate(() => editor.history.last()) ).toBe(null); + }); + + test('adds, fetches and stores', async () => { + await page.evaluate(() => editor.history.flush()); + expect( await page.evaluate(() => editor.history.fetch()) ).toEqual([]); + expect( await page.evaluate(() => editor.history.last()) ).toBe(null); + + expect( await page.evaluate(() => document.querySelector('.ple-history-saving').style.display) ).toBe('none'); + await page.evaluate(() => editor.history.add('some text')); + expect( await page.evaluate(() => editor.history.last().text) ).toBe('some text'); + expect( await page.evaluate(() => editor.history.last().timestamp) ).toBeDefined(); - test('something we are testing described here', () => { + expect( await page.evaluate(() => editor.history.fetch().length) ).toEqual(1); + expect( await page.evaluate( () => editor.history.last().text) ).toBe('some text'); + + await page.evaluate(() => editor.history.add('some more text')); + expect( await page.evaluate( () => editor.history.last().text) ).toBe('some more text'); + expect( await page.evaluate(() => editor.history.last().timestamp) ).toBeDefined(); + expect( await page.evaluate(() => editor.history.fetch().length) ).toEqual(2); + }); + test('creates new log entry when value() set', async () => { + expect( await page.evaluate(() => editor.richTextModule.options.textarea.value.length) ).toBeGreaterThan(0); + expect( await page.evaluate(() => editor.richTextModule.options.textarea) ).toBeDefined(); + await page.evaluate(() => editor.richTextModule.value("changed textarea text")); + await page.evaluate(() => editor.history.check()); + expect(await page.evaluate(() => editor.history.last().text)).toBe("changed textarea text"); }); + test('stores only 20 items until we optimize it', async () => { + await page.evaluate(() => editor.history.flush()); + await page.evaluate(() => { + for (let i = 0; i < 10; i++) { + editor.history.add("some text " + i); + } + }); + expect( await page.evaluate(() => editor.history.log.length) ).toBe(10); + + await page.evaluate(() => { + for (let i = 10; i < 20; i++) { + editor.history.add("some text " + i); + // checked for the length instead of individual value in the loop, hence the below test wasn't added + // expect( await page.evaluate(() => editor.history.log[editor.history.log.length - 1].text) ).toBe("some text " + i); + } + }); + expect(await page.evaluate(() => editor.history.log.length)).toBe(20); + + await page.evaluate(() => { + for (var i = 20; i < 30; i++) { + editor.history.add("some text " + i); + } + }); + expect(await page.evaluate(() => editor.history.log.length)).toBe(20); + + await page.evaluate(() => editor.history.fetch()); + expect(await page.evaluate(() => editor.history.log.length)).toBe(20); + expect(await page.evaluate(() => editor.history.log[0].text)).toBe('some text 10'); + }); + + test('writes out history to a DOM element', async () => { + await page.evaluate(() => $('body').append("
")); + + await page.evaluate(() => editor.history.display($('#history')[0])); + + expect(await page.evaluate(() => editor.history.log.length)).not.toBe(0); + expect(await page.evaluate(() => $('#history').html())).not.toBe(''); + expect(await page.evaluate(() => $('#history p.log').length)).toBe(20); + expect(await page.evaluate(() => $('#history p.day').length)).toBe(1); + + // start over and build DOM, checking as we go: + await page.evaluate(() => editor.history.log = []); + for (let i = 0; i < 10; i++) { + await page.evaluate(() => { + editor.history.add("some text " + i); + editor.history.display($('#history')[0]); + }); + expect(await page.evaluate(() => $('#history p.log').length)).toBe(1 + i); + // commented out this line because the value of i available to it is 0 which is inconsistent + // expect(await page.evaluate(() => $('#history p.log:last .preview').html())).toBe("some text " + i + "..."); + } + expect(await page.evaluate(() => $('#history p.day').length)).toBe(1); + }); }, timeout); From 38fabe166ea344457c880f1d6cfb49bf9ac0f80b Mon Sep 17 00:00:00 2001 From: Paul Ibeabuchi C Date: Thu, 27 Jan 2022 22:59:53 +0100 Subject: [PATCH 2/3] removed equivalent jasmine test file --- spec/javascripts/history_spec.js | 108 ------------------------------- 1 file changed, 108 deletions(-) delete mode 100644 spec/javascripts/history_spec.js diff --git a/spec/javascripts/history_spec.js b/spec/javascripts/history_spec.js deleted file mode 100644 index 4547c309..00000000 --- a/spec/javascripts/history_spec.js +++ /dev/null @@ -1,108 +0,0 @@ -var editor; - -describe("History", function() { - beforeAll(function() { - fixture = loadFixtures('index.html'); - - editor = new PL.Editor({ - textarea: $('.ple-textarea')[0] - }); - }); - - - it("has log, key, interval, and id", function() { - expect(editor.history.log).not.toBeUndefined(); - expect(editor.history.key).not.toBeUndefined(); - expect(editor.history.options).not.toBeUndefined(); - expect(editor.history.options.interval).not.toBeUndefined(); - expect(editor.history.options.id).not.toBeUndefined(); - }); - - - it("can be flushed", function() { - expect(editor.history.fetch()).not.toEqual([]); - expect(editor.history.last()).not.toBe(null); - - editor.history.flush(); - - expect(editor.history.fetch()).toEqual([]); - expect(editor.history.last()).toBe(null); - }); - - - it("adds, fetches, and stores", function() { - editor.history.flush(); - expect(editor.history.fetch()).toEqual([]); - expect(editor.history.last()).toBe(null); - - expect($('.ple-history-saving').is(':visible')).toBe(false); - editor.history.add("some text"); - expect(editor.history.last().text).toBe("some text"); - expect(editor.history.last().timestamp).not.toBeUndefined(); - - expect(editor.history.fetch().length).toEqual(1); - expect(editor.history.last().text).toBe("some text"); - - editor.history.add("some more text"); - expect(editor.history.last().text).toBe("some more text"); - expect(editor.history.last().timestamp).not.toBeUndefined(); - - expect(editor.history.fetch().length).toEqual(2); - expect(editor.history.last().text).toBe("some more text"); - }); - - - it("creates new log entry when value() set", function() { - expect($(editor.richTextModule.options.textarea).length).toBeGreaterThan(0); - editor.richTextModule.value("changed textarea text"); - editor.history.check(); - expect(editor.history.last().text).toBe("changed textarea text"); - }); - - - it("stores only 20 items until we optimize it", function() { - editor.history.flush(); - for (var i = 0; i < 10; i++) { - editor.history.add("some text " + i); - } - expect(editor.history.log.length).toBe(10); - - for (var i = 10; i < 20; i++) { - editor.history.add("some text " + i); - expect(editor.history.log[editor.history.log.length - 1].text).toBe("some text " + i); - } - expect(editor.history.log.length).toBe(20); - - for (var i = 20; i < 30; i++) { - editor.history.add("some text " + i); - } - expect(editor.history.log.length).toBe(20); - - editor.history.fetch(); - expect(editor.history.log.length).toBe(20); - expect(editor.history.log[0].text).toBe('some text 10'); - }); - - - it("writes out history to a DOM element", function() { - $('body').append("
"); - - editor.history.display($('#history')[0]); - - expect(editor.history.log.length).not.toBe(0); - expect($('#history').html()).not.toBe(''); - expect($('#history p.log').length).toBe(20); - expect($('#history p.day').length).toBe(1); - - // start over and build DOM, checking as we go: - editor.history.log = []; - - for (var i = 0; i < 10; i++) { - editor.history.add("some text " + i); - editor.history.display($('#history')[0]); - expect($('#history p.log').length).toBe(1 + i); - expect($('#history p.log:last .preview').html()).toBe("some text " + i + "..."); - } - expect($('#history p.day').length).toBe(1); - }); -}); From ce0df4e86b2f09a2d769e7eefacc768eca3b63ba Mon Sep 17 00:00:00 2001 From: Paul Ibeabuchi C Date: Thu, 27 Jan 2022 23:00:58 +0100 Subject: [PATCH 3/3] removed unwanted comments --- test/ui-testing/history.test.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/ui-testing/history.test.js b/test/ui-testing/history.test.js index e7bff8dc..5314d6e3 100644 --- a/test/ui-testing/history.test.js +++ b/test/ui-testing/history.test.js @@ -69,8 +69,6 @@ describe('History', () => { await page.evaluate(() => { for (let i = 10; i < 20; i++) { editor.history.add("some text " + i); - // checked for the length instead of individual value in the loop, hence the below test wasn't added - // expect( await page.evaluate(() => editor.history.log[editor.history.log.length - 1].text) ).toBe("some text " + i); } }); expect(await page.evaluate(() => editor.history.log.length)).toBe(20); @@ -105,8 +103,6 @@ describe('History', () => { editor.history.display($('#history')[0]); }); expect(await page.evaluate(() => $('#history p.log').length)).toBe(1 + i); - // commented out this line because the value of i available to it is 0 which is inconsistent - // expect(await page.evaluate(() => $('#history p.log:last .preview').html())).toBe("some text " + i + "..."); } expect(await page.evaluate(() => $('#history p.day').length)).toBe(1); });