-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: Add plain highlight functional tests (#168)
- Move more CSS selectors to consts
- Loading branch information
Showing
7 changed files
with
134 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Selects text on the document | ||
* | ||
* @param {Object} I - the codeceptjs I | ||
* @param {string} selector - the selector to use | ||
* | ||
* @return {void} | ||
*/ | ||
function selectText(I, selector) { | ||
I.waitForElement(selector); | ||
|
||
I.executeScript( | ||
/* eslint-disable prefer-arrow-callback, no-var, func-names */ | ||
function (sel) { | ||
const preview = document.querySelector('.bp-doc'); | ||
const selectionEl = document.querySelector(sel); | ||
const start = selectionEl.firstElementChild; | ||
const end = selectionEl.lastElementChild; | ||
|
||
const selection = window.getSelection(); | ||
selection.removeAllRanges(); | ||
|
||
/** | ||
* Cross browser event creation | ||
* @param {string} eventName the event name | ||
* @param {HTMLElement} el - the DOM element to use | ||
* @return {Event} the event | ||
*/ | ||
function createNewEvent(eventName, el) { | ||
const x = el.offsetLeft + 2; | ||
const y = el.offsetTop + 2; | ||
|
||
let event; | ||
if (typeof MouseEvent === 'function') { | ||
event = new MouseEvent(eventName, { | ||
bubbles: true, | ||
clientX: x, | ||
clientY: y | ||
}); | ||
} | ||
|
||
return event; | ||
} | ||
|
||
preview.dispatchEvent(createNewEvent('mousedown', start)); | ||
preview.dispatchEvent(createNewEvent('mousemove', end)); | ||
selection.setBaseAndExtent(start, 0, end, 0); | ||
preview.dispatchEvent(createNewEvent('mouseup', end)); | ||
}, | ||
selector | ||
); | ||
} | ||
|
||
exports.selectText = selectText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const { | ||
SELECTOR_ANNOTATIONS_LOADED, | ||
SELECTOR_ANNOTATION_HIGHLIGHT_DIALOG, | ||
SELECTOR_ANNOTATION_DIALOG, | ||
SELECTOR_ADD_HIGHLIGHT_BTN, | ||
SELECTOR_HIGHLIGHT_LABEL | ||
} = require('../helpers/constants'); | ||
|
||
const { selectText } = require('../helpers/mouseEvents'); | ||
|
||
Feature('Plain Highlight Annotation Sanity'); | ||
|
||
Before((I) => { | ||
I.amOnPage('/'); | ||
}); | ||
|
||
Scenario('Create a new plain highlight annotation @desktop @enabled', (I) => { | ||
I.waitForVisible(SELECTOR_ANNOTATIONS_LOADED); | ||
|
||
I.say('Highlight dialog should appear after selecting text'); | ||
selectText(I, '.textLayer'); | ||
I.waitForVisible(SELECTOR_ANNOTATION_HIGHLIGHT_DIALOG); | ||
|
||
I.say('Highlight selected text'); | ||
I.click(SELECTOR_ADD_HIGHLIGHT_BTN); | ||
|
||
I.say('Highlight should be created and dialog should appear'); | ||
I.waitForVisible(SELECTOR_ANNOTATION_DIALOG); | ||
I.waitForText('Kanye West highlighted', 5, SELECTOR_HIGHLIGHT_LABEL); | ||
I.waitForEnabled(SELECTOR_ADD_HIGHLIGHT_BTN); | ||
}); | ||
|
||
Scenario('Delete the plain highlight annotation @desktop @enabled', (I) => { | ||
I.waitForVisible(SELECTOR_ANNOTATIONS_LOADED); | ||
|
||
I.say('Highlight dialog should appear on click'); | ||
I.click('.textLayer div'); | ||
I.waitForVisible(SELECTOR_ANNOTATION_HIGHLIGHT_DIALOG); | ||
|
||
I.say('Delete the highlight annotation'); | ||
I.click(SELECTOR_ADD_HIGHLIGHT_BTN); | ||
|
||
I.say('Highlight should be deleted'); | ||
I.waitForDetached(SELECTOR_ANNOTATION_DIALOG, 5); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters