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

Jest test for bold and italic command #543

Merged
merged 8 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ before_script:
- grunt build
script:
- grunt jasmine --force
- npm run test-ui
- npm run test-ui
2 changes: 1 addition & 1 deletion dist/PublicLab.Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20479,7 +20479,7 @@ PL.MapModule = require('./modules/PublicLab.MapModule.js');

$(document).ready(function() {
PL.Util.preventModalScrollToTop();
PL.Util.enableRichTextModeKeyboardShortcut();
PL.Util.enableTextModeKeyboardShortcut();
PL.Util.preventUploadedImagesDragging();
});

Expand Down
2 changes: 1 addition & 1 deletion src/PublicLab.Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PL.MapModule = require('./modules/PublicLab.MapModule.js');

$(document).ready(function() {
PL.Util.preventModalScrollToTop();
PL.Util.enableRichTextModeKeyboardShortcut();
PL.Util.enableTextModeKeyboardShortcut();
PL.Util.preventUploadedImagesDragging();
});

Expand Down
43 changes: 43 additions & 0 deletions test/ui-testing/bold.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const timeout = process.env.SLOWMO ? 60000 : 10000;
const fs = require('fs');
beforeAll(async () => {
path = fs.realpathSync('file://../examples/index.html');
await page.goto('file://' + path, {waitUntil: 'domcontentloaded'});
});

describe('Bold Text', () => {
test('Adds strong text in rich text mode', async () => {
// clicks on bold button and checks if 'strong text' is added in the editor
await page.waitForSelector('.ple-module-body');
await page.click('.woofmark-command-bold');
const stringIsIncluded = await page.evaluate(() => document.querySelector('.wk-wysiwyg').textContent.includes('strong text'));
expect(stringIsIncluded).toBe(true);

// resets the changes by removing the added text
await page.keyboard.press("Backspace");

}, timeout);

test('Adds strong text in markdown mode', async () => {
// clicks on bold button and checks if '**strong text**' is added in the editor
await page.waitForSelector('.woofmark-mode-markdown');
await page.click('.woofmark-mode-markdown');
await page.evaluate(() => document.querySelector('.ple-textarea').value += ' ');
await page.click('.woofmark-command-bold');
let stringIsIncluded = await page.evaluate(() => document.querySelector('.ple-textarea').value.includes('**strong text**'));
expect(stringIsIncluded).toBe(true);

// clicks bold button again to un-bolden the text but retains the text value 'strong text'
await page.click('.woofmark-command-bold');
stringIsIncluded = await page.evaluate(() => document.querySelector('.ple-textarea').value.includes('strong text'));
expect(stringIsIncluded).toBe(true);
stringIsIncluded = await page.evaluate(() => document.querySelector('.ple-textarea').value.includes('**strong text**'));
expect(stringIsIncluded).toBe(false);

// resets changes by removing the added text and changes back to wysiwyg mode
await page.keyboard.press("Backspace");
await page.click('.woofmark-mode-wysiwyg');

}, timeout);

});
43 changes: 43 additions & 0 deletions test/ui-testing/italic.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const timeout = process.env.SLOWMO ? 60000 : 10000;
const fs = require('fs');
beforeAll(async () => {
path = fs.realpathSync('file://../examples/index.html');
await page.goto('file://' + path, {waitUntil: 'domcontentloaded'});
});

describe('Italic Text', () => {
test('Adds emphasized text in rich text mode', async () => {
// clicks on italic button and checks if 'emphasized text' is added in the editor
await page.waitForSelector('.ple-module-body');
await page.click('.woofmark-command-italic');
const stringIsIncluded = await page.evaluate(() => document.querySelector('.wk-wysiwyg').textContent.includes('emphasized text'));
expect(stringIsIncluded).toBe(true);

// resets the changes by removing the added text
await page.keyboard.press("Backspace");

}, timeout);

test('Adds emphasized text in markdown mode', async () => {
// clicks on italic button and checks if '*emphasized text*' is added in the editor
await page.waitForSelector('.woofmark-mode-markdown');
await page.click('.woofmark-mode-markdown');
await page.evaluate(() => document.querySelector('.ple-textarea').value += ' ');
await page.click('.woofmark-command-italic');
let stringIsIncluded = await page.evaluate(() => document.querySelector('.ple-textarea').value.includes('*emphasized text*'));
expect(stringIsIncluded).toBe(true);

// clicks italic button again to un-emphasize the text but retains the text value 'emphasized text'
await page.click('.woofmark-command-italic');
stringIsIncluded = await page.evaluate(() => document.querySelector('.ple-textarea').value.includes('emphasized text'));
expect(stringIsIncluded).toBe(true);
stringIsIncluded = await page.evaluate(() => document.querySelector('.ple-textarea').value.includes('*emphasized text*'));
expect(stringIsIncluded).toBe(false);

// resets changes by removing the added text and changes back to wysiwyg mode
await page.keyboard.press("Backspace");
await page.click('.woofmark-mode-wysiwyg');

}, timeout);

});