Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converted history jasmine test to jest #815

Merged
merged 5 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 0 additions & 108 deletions spec/javascripts/history_spec.js

This file was deleted.

105 changes: 101 additions & 4 deletions test/ui-testing/history.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,109 @@
const timeout = process.env.SLOWMO ? 60000 : 15000;
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', () => {
test('something we are testing described here', () => {
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();

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);
}
});
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("<div id='history'></div>"));

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);
}
expect(await page.evaluate(() => $('#history p.day').length)).toBe(1);
});
}, timeout);
}, timeout);