Skip to content

Commit 44597de

Browse files
authored
New: Add basic UI tests for point & highlight comment annotations (#182)
- Create/Cancel/Reply/Delete a highlight comment annotation - Create/Cancel/Reply/Delete a point annotation - Enter/Exit point annotation mode - Move common validation/actions into helper methods - Combine multiple scenarios to speed up functional tests
1 parent f1c584a commit 44597de

File tree

9 files changed

+359
-29
lines changed

9 files changed

+359
-29
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* eslint-disable prefer-arrow-callback, no-var, func-names */
2+
const {
3+
SELECTOR_ANNOTATION_DIALOG,
4+
SELECTOR_ANNOTATION_BUTTON_POST,
5+
SELECTOR_ANNOTATION_BUTTON_CANCEL,
6+
SELECTOR_ANNOTATION_COMMENT,
7+
SELECTOR_DELETE_COMMENT_BTN,
8+
SELECTOR_REPLY_TEXTAREA,
9+
SELECTOR_REPLY_CONTAINER
10+
} = require('../helpers/constants');
11+
const { validateReply, validateDeleteConfirmation } = require('./validation');
12+
13+
function replyToThread(I) {
14+
I.say('Reply to highlight comment annotation');
15+
I.fillField(SELECTOR_REPLY_TEXTAREA, 'Sample reply');
16+
I.click(`${SELECTOR_REPLY_CONTAINER} ${SELECTOR_ANNOTATION_BUTTON_POST}`);
17+
validateReply(I, SELECTOR_ANNOTATION_DIALOG);
18+
I.waitNumberOfVisibleElements(SELECTOR_ANNOTATION_COMMENT, 2);
19+
20+
I.say('Cancel a reply to a highlight comment annotation');
21+
I.fillField(SELECTOR_REPLY_TEXTAREA, 'Sample canceled reply');
22+
I.click(`${SELECTOR_REPLY_CONTAINER} ${SELECTOR_ANNOTATION_BUTTON_CANCEL}`);
23+
I.waitNumberOfVisibleElements(SELECTOR_ANNOTATION_COMMENT, 2);
24+
}
25+
26+
function deleteAnnotation(I, annotationCount) {
27+
I.waitNumberOfVisibleElements(SELECTOR_ANNOTATION_COMMENT, annotationCount);
28+
29+
I.say('Delete the annotation');
30+
I.click(SELECTOR_DELETE_COMMENT_BTN);
31+
validateDeleteConfirmation(I);
32+
33+
I.say('Annotation should be deleted');
34+
if (annotationCount > 1) {
35+
I.waitNumberOfVisibleElements(SELECTOR_ANNOTATION_COMMENT, annotationCount - 1);
36+
I.waitForVisible(SELECTOR_ANNOTATION_DIALOG);
37+
} else {
38+
I.waitForDetached(SELECTOR_ANNOTATION_DIALOG, 1);
39+
}
40+
}
41+
42+
exports.replyToThread = replyToThread;
43+
exports.deleteAnnotation = deleteAnnotation;

functional-tests/helpers/constants.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
exports.SELECTOR_TEXT_LAYER = '.textLayer';
2-
31
// Preview CSS constants
42
const CLASS_ACTIVE = 'bp-is-active';
53
exports.SELECTOR_ACTIVE = `.${CLASS_ACTIVE}`;
@@ -32,6 +30,8 @@ const CLASS_BOX_PREVIEW = 'bp';
3230
exports.SELECTOR_BOX_PREVIEW = `.${CLASS_BOX_PREVIEW}`;
3331
const CLASS_PREVIEW_PRESENTATION = 'bp-doc-presentation';
3432
exports.SELECTOR_PREVIEW_PRESENTATION = `.${CLASS_PREVIEW_PRESENTATION}`;
33+
const CLASS_TEXT_LAYER = 'textLayer';
34+
exports.SELECTOR_TEXT_LAYER = `.${CLASS_TEXT_LAYER}`;
3535

3636
// Annotation CSS constants
3737
const CLASS_ANNOTATED_ELEMENT = 'annotated-element';
@@ -68,11 +68,18 @@ const CLASS_ANNOTATION_BUTTON_POST = 'post-annotation-btn';
6868
exports.SELECTOR_ANNOTATION_BUTTON_POST = `.${CLASS_ANNOTATION_BUTTON_POST}`;
6969
const CLASS_DELETE_COMMENT_BTN = 'delete-comment-btn';
7070
exports.SELECTOR_DELETE_COMMENT_BTN = `.${CLASS_DELETE_COMMENT_BTN}`;
71+
7172
const CLASS_DELETE_CONFIRM_MESSAGE = 'delete-confirmation-message';
7273
exports.SELECTOR_DELETE_CONFIRM_MESSAGE = `.${CLASS_DELETE_CONFIRM_MESSAGE}`;
74+
const CLASS_CANCEL_DELETE_BTN = 'cancel-delete-btn';
75+
exports.SELECTOR_CANCEL_DELETE_BTN = `.${CLASS_CANCEL_DELETE_BTN}`;
76+
const CLASS_CONFIRM_DELETE_BTN = 'confirm-delete-btn';
77+
exports.SELECTOR_CONFIRM_DELETE_BTN = `.${CLASS_CONFIRM_DELETE_BTN}`;
7378

7479
const CLASS_ANNOTATION_CONTAINER = 'annotation-container';
7580
exports.SELECTOR_ANNOTATION_CONTAINER = `.${CLASS_ANNOTATION_CONTAINER}`;
81+
const CLASS_ANNOTATION_COMMENT = 'annotation-comment';
82+
exports.SELECTOR_ANNOTATION_COMMENT = `.${CLASS_ANNOTATION_COMMENT}`;
7683
const CLASS_ANNOTATION_COMMENT_TEXT = 'ba-annotation-comment-text';
7784
exports.SELECTOR_ANNOTATION_COMMENT_TEXT = `.${CLASS_ANNOTATION_COMMENT_TEXT}`;
7885
const CLASS_PROFILE_CONTAINER = 'profile-container';
@@ -84,6 +91,11 @@ exports.SELECTOR_USER_NAME = `.${CLASS_USER_NAME}`;
8491
const CLASS_COMMENT_DATE = 'comment-date';
8592
exports.SELECTOR_COMMENT_DATE = `.${CLASS_COMMENT_DATE}`;
8693

94+
const CLASS_REPLY_CONTAINER = 'reply-container';
95+
exports.SELECTOR_REPLY_CONTAINER = `.${CLASS_REPLY_CONTAINER}`;
96+
const CLASS_REPLY_TEXTAREA = 'reply-textarea';
97+
exports.SELECTOR_REPLY_TEXTAREA = `.${CLASS_REPLY_TEXTAREA}`;
98+
8799
const CLASS_CREATE_COMMENT = 'ba-create-comment';
88100
exports.SELECTOR_CREATE_COMMENT = `.${CLASS_CREATE_COMMENT}`;
89101

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* eslint-disable prefer-arrow-callback, no-var, func-names */
2+
const {
3+
SELECTOR_ANNOTATION_DIALOG,
4+
SELECTOR_ACTIVE,
5+
SELECTOR_ANNOTATION_BUTTON_POST,
6+
SELECTOR_INVALID_INPUT,
7+
SELECTOR_ANNOTATION_BUTTON_CANCEL,
8+
SELECTOR_USER_NAME,
9+
SELECTOR_ANNOTATION_CONTAINER,
10+
SELECTOR_ANNOTATION_COMMENT,
11+
SELECTOR_DELETE_COMMENT_BTN,
12+
SELECTOR_PROFILE_IMG_CONTAINER,
13+
SELECTOR_REPLY_TEXTAREA,
14+
SELECTOR_DELETE_CONFIRM_MESSAGE,
15+
SELECTOR_CONFIRM_DELETE_BTN,
16+
SELECTOR_CANCEL_DELETE_BTN,
17+
SELECTOR_REPLY_CONTAINER
18+
} = require('../helpers/constants');
19+
const { expect } = require('chai');
20+
21+
async function validateIconColor(I, selector, color) {
22+
I.waitForElement(selector);
23+
const clr = await I.grabCssPropertyFrom(`${selector} svg`, 'fill');
24+
expect(clr).to.equal(color);
25+
}
26+
27+
function* validateTextarea(I, containerSel, textareaSel) {
28+
I.say(`Validate ${containerSel} ${textareaSel}`);
29+
I.waitForVisible(`${containerSel} ${textareaSel}${SELECTOR_ACTIVE}`);
30+
I.waitForVisible(`${containerSel} ${SELECTOR_ANNOTATION_BUTTON_CANCEL}`);
31+
I.waitForVisible(`${containerSel} ${SELECTOR_ANNOTATION_BUTTON_POST}`);
32+
expect(yield I.grabValueFrom(`${containerSel} ${textareaSel}`)).to.equal('');
33+
34+
const message = textareaSel === SELECTOR_REPLY_CONTAINER ? 'Post a reply...' : 'Add a comment here...';
35+
expect(yield I.grabAttributeFrom(`${containerSel} ${textareaSel}`, 'placeholder')).to.equal(message);
36+
37+
I.click(`${containerSel} ${SELECTOR_ANNOTATION_BUTTON_POST}`);
38+
I.waitForVisible(`${containerSel} ${textareaSel}${SELECTOR_INVALID_INPUT}`);
39+
I.waitForVisible(SELECTOR_ANNOTATION_DIALOG);
40+
}
41+
42+
function validateAnnotation(I) {
43+
I.say('Dialog should contain new annotation');
44+
I.waitForVisible(SELECTOR_ANNOTATION_DIALOG);
45+
I.see('Posting...', SELECTOR_USER_NAME);
46+
I.waitForVisible(SELECTOR_ANNOTATION_CONTAINER);
47+
I.waitNumberOfVisibleElements(SELECTOR_ANNOTATION_COMMENT, 1);
48+
I.waitForEnabled(SELECTOR_DELETE_COMMENT_BTN);
49+
I.waitForVisible(SELECTOR_PROFILE_IMG_CONTAINER);
50+
I.waitForText('Kanye West', 10, SELECTOR_USER_NAME);
51+
52+
validateTextarea(I, SELECTOR_REPLY_CONTAINER, SELECTOR_REPLY_TEXTAREA);
53+
}
54+
55+
function validateReply(I) {
56+
I.say('Reply should be added to dialog');
57+
I.waitForVisible(SELECTOR_ANNOTATION_DIALOG);
58+
I.waitForVisible(SELECTOR_ANNOTATION_CONTAINER);
59+
I.waitNumberOfVisibleElements(SELECTOR_ANNOTATION_COMMENT, 2);
60+
I.waitForEnabled(SELECTOR_DELETE_COMMENT_BTN);
61+
I.waitForVisible(SELECTOR_PROFILE_IMG_CONTAINER);
62+
I.waitForText('Kanye West', 10, SELECTOR_USER_NAME);
63+
64+
validateTextarea(I, SELECTOR_REPLY_CONTAINER, SELECTOR_REPLY_TEXTAREA);
65+
}
66+
67+
function validateDeleteConfirmation(I) {
68+
I.say('Validate delete confirmation');
69+
I.waitForText('Delete this annotation?', 10, SELECTOR_DELETE_CONFIRM_MESSAGE);
70+
I.waitForVisible(SELECTOR_CONFIRM_DELETE_BTN);
71+
I.waitForVisible(SELECTOR_CANCEL_DELETE_BTN);
72+
73+
// Cancel annotation delete
74+
I.click(SELECTOR_CANCEL_DELETE_BTN);
75+
I.waitForInvisible(SELECTOR_DELETE_CONFIRM_MESSAGE);
76+
77+
// Delete the annotation
78+
I.click(SELECTOR_DELETE_COMMENT_BTN);
79+
80+
// Delete confirmation should appear
81+
I.waitForVisible(SELECTOR_CONFIRM_DELETE_BTN);
82+
I.click(SELECTOR_CONFIRM_DELETE_BTN);
83+
}
84+
85+
exports.validateIconColor = validateIconColor;
86+
exports.validateAnnotation = validateAnnotation;
87+
exports.validateDeleteConfirmation = validateDeleteConfirmation;
88+
exports.validateReply = validateReply;
89+
exports.validateTextarea = validateTextarea;

functional-tests/tests/draw.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable prefer-arrow-callback, no-var, func-names */
12
const {
23
SELECTOR_TEXT_LAYER,
34
SELECTOR_DISABLED,
@@ -19,11 +20,14 @@ const { draw, clickAtLocation } = require('../helpers/mouseEvents');
1920

2021
Feature('Draw Annotation Sanity');
2122

22-
Before((I) => {
23+
Before(function(I) {
2324
I.amOnPage('/');
2425
});
2526

26-
Scenario('Can enter/exit drawing mode properly @desktop', (I) => {
27+
Scenario('Create/Delete drawing @desktop', function(I) {
28+
/*
29+
* Can enter/exit drawing mode properly @desktop
30+
*/
2731
I.waitForVisible(SELECTOR_ANNOTATIONS_LOADED);
2832
I.waitForVisible(SELECTOR_ANNOTATION_BUTTON_DRAW);
2933

@@ -42,12 +46,10 @@ Scenario('Can enter/exit drawing mode properly @desktop', (I) => {
4246
I.click(SELECTOR_ANNOTATION_BUTTON_DRAW_CANCEL);
4347
I.dontSeeElement(SELECTOR_ANNNOTATION_MODE_BACKGROUND);
4448
I.waitForVisible(SELECTOR_ANNOTATION_BUTTON_DRAW);
45-
});
46-
47-
Scenario('Cancel a new drawing annotation @desktop', (I) => {
48-
I.waitForVisible(SELECTOR_ANNOTATIONS_LOADED);
49-
I.waitForVisible(SELECTOR_ANNOTATION_BUTTON_DRAW);
5049

50+
/*
51+
* Cancel a new drawing annotation
52+
*/
5153
I.say('Enter draw annotation mode');
5254
I.click(SELECTOR_ANNOTATION_BUTTON_DRAW);
5355
I.click(SELECTOR_TEXT_LAYER);
@@ -63,16 +65,10 @@ Scenario('Cancel a new drawing annotation @desktop', (I) => {
6365
I.say('Cancel drawing');
6466
I.click(SELECTOR_DELETE_DRAWING_BTN);
6567
I.waitForInvisible(SELECTOR_ANNOTATION_DRAWING_DIALOG);
66-
});
67-
68-
Scenario('Create/Delete a drawing annotation w/ drawing dialog @desktop', (I) => {
69-
I.waitForVisible(SELECTOR_ANNOTATIONS_LOADED);
70-
I.waitForVisible(SELECTOR_ANNOTATION_BUTTON_DRAW);
71-
72-
I.say('Enter draw annotation mode');
73-
I.click(SELECTOR_ANNOTATION_BUTTON_DRAW);
74-
I.click(SELECTOR_TEXT_LAYER);
7568

69+
/*
70+
* Create/Delete a drawing annotation w/ drawing dialog
71+
*/
7672
draw(I, SELECTOR_TEXT_LAYER, 100);
7773
I.waitForVisible(SELECTOR_ANNOTATION_LAYER_DRAW_IN_PROGRESS);
7874
I.waitForVisible(SELECTOR_ANNOTATION_DRAWING_DIALOG);
@@ -104,7 +100,7 @@ Scenario('Create/Delete a drawing annotation w/ drawing dialog @desktop', (I) =>
104100
I.waitForInvisible(SELECTOR_ANNOTATION_DRAWING_DIALOG);
105101
});
106102

107-
Scenario('Create a drawing annotation by exiting mode @desktop', (I) => {
103+
Scenario('Create/Delete a drawing by exiting mode @desktop', function(I) {
108104
I.waitForVisible(SELECTOR_ANNOTATIONS_LOADED);
109105
I.waitForVisible(SELECTOR_ANNOTATION_BUTTON_DRAW);
110106

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* eslint-disable prefer-arrow-callback, no-var, func-names */
2+
const {
3+
SELECTOR_TEXT_LAYER,
4+
SELECTOR_ANNOTATIONS_LOADED,
5+
SELECTOR_ANNOTATION_HIGHLIGHT_DIALOG,
6+
SELECTOR_ADD_HIGHLIGHT_BTN,
7+
SELECTOR_ADD_HIGHLIGHT_COMMENT_BTN,
8+
SELECTOR_CREATE_DIALOG,
9+
SELECTOR_CREATE_COMMENT,
10+
SELECTOR_ANNOTATION_TEXTAREA,
11+
SELECTOR_ANNOTATION_BUTTON_POST,
12+
SELECTOR_ANNOTATION_BUTTON_CANCEL,
13+
SELECTOR_ANNOTATION_DIALOG,
14+
SELECTOR_DELETE_COMMENT_BTN,
15+
SELECTOR_ANNOTATION_COMMENT
16+
} = require('../helpers/constants');
17+
18+
const { selectText } = require('../helpers/mouseEvents');
19+
const { validateTextarea, validateAnnotation } = require('../helpers/validation');
20+
const { replyToThread, deleteAnnotation } = require('../helpers/actions');
21+
22+
Feature('Highlight Comment Annotation Sanity');
23+
24+
Before(function(I) {
25+
I.amOnPage('/');
26+
});
27+
28+
Scenario('Create/Reply/Delete a new highlight comment annotation @desktop', function(I) {
29+
I.waitForVisible(SELECTOR_ANNOTATIONS_LOADED);
30+
31+
I.say('Highlight dialog should appear after selecting text');
32+
selectText(I, SELECTOR_TEXT_LAYER);
33+
I.waitForVisible(SELECTOR_ANNOTATION_HIGHLIGHT_DIALOG);
34+
I.waitForVisible(SELECTOR_ADD_HIGHLIGHT_BTN);
35+
I.waitForVisible(SELECTOR_ADD_HIGHLIGHT_COMMENT_BTN);
36+
37+
I.say('Create highlight comment annotation');
38+
I.click(SELECTOR_ADD_HIGHLIGHT_COMMENT_BTN);
39+
I.waitForVisible(SELECTOR_CREATE_DIALOG);
40+
validateTextarea(I, SELECTOR_CREATE_COMMENT, SELECTOR_ANNOTATION_TEXTAREA);
41+
42+
I.say('Cancel highlight comment annotation');
43+
I.click(SELECTOR_ANNOTATION_BUTTON_CANCEL);
44+
I.waitForInvisible(SELECTOR_CREATE_COMMENT, 1);
45+
I.waitForVisible(SELECTOR_ADD_HIGHLIGHT_BTN);
46+
I.waitForVisible(SELECTOR_ADD_HIGHLIGHT_COMMENT_BTN);
47+
48+
/*
49+
* Create/reply to a new highlight comment annotation
50+
*/
51+
I.say('Highlight dialog should appear after selecting text');
52+
selectText(I, SELECTOR_TEXT_LAYER);
53+
I.waitForVisible(SELECTOR_ANNOTATION_HIGHLIGHT_DIALOG);
54+
I.waitForVisible(SELECTOR_ADD_HIGHLIGHT_BTN);
55+
I.waitForVisible(SELECTOR_ADD_HIGHLIGHT_COMMENT_BTN);
56+
57+
I.say('Create highlight comment annotation');
58+
I.click(SELECTOR_ADD_HIGHLIGHT_COMMENT_BTN);
59+
I.waitForVisible(SELECTOR_CREATE_DIALOG);
60+
validateTextarea(I, SELECTOR_CREATE_COMMENT, SELECTOR_ANNOTATION_TEXTAREA);
61+
62+
I.say('Post highlight comment annotation');
63+
I.fillField(SELECTOR_ANNOTATION_TEXTAREA, 'Sample comment');
64+
I.click(SELECTOR_ANNOTATION_BUTTON_POST);
65+
validateAnnotation(I);
66+
I.waitNumberOfVisibleElements(SELECTOR_ANNOTATION_COMMENT, 1);
67+
68+
replyToThread(I);
69+
70+
/*
71+
* Delete the highlight comment annotation and reply
72+
*/
73+
I.waitForVisible(SELECTOR_ANNOTATIONS_LOADED);
74+
75+
I.say('Highlight dialog should appear on click');
76+
I.click(`${SELECTOR_TEXT_LAYER} div`);
77+
I.waitForVisible(SELECTOR_ANNOTATION_DIALOG);
78+
I.waitForEnabled(SELECTOR_DELETE_COMMENT_BTN);
79+
80+
deleteAnnotation(I, 2);
81+
deleteAnnotation(I, 1);
82+
});

functional-tests/tests/plain_highlight.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
/* eslint-disable prefer-arrow-callback, no-var, func-names */
12
const {
3+
SELECTOR_ACTIVE,
24
SELECTOR_TEXT_LAYER,
35
SELECTOR_ANNOTATIONS_LOADED,
46
SELECTOR_ANNOTATION_HIGHLIGHT_DIALOG,
@@ -8,16 +10,20 @@ const {
810
} = require('../helpers/constants');
911

1012
const { selectText } = require('../helpers/mouseEvents');
13+
const { validateIconColor } = require('../helpers/validation');
1114

1215
Feature('Plain Highlight Annotation Sanity');
1316

14-
Before((I) => {
17+
Before(function(I) {
1518
I.amOnPage('/');
1619
});
1720

18-
Scenario('Create a new plain highlight annotation @desktop', (I) => {
21+
Scenario('Create/Delete a new plain highlight annotation @desktop', function(I) {
1922
I.waitForVisible(SELECTOR_ANNOTATIONS_LOADED);
2023

24+
/*
25+
* Create plain highlight annotation
26+
*/
2127
I.say('Highlight dialog should appear after selecting text');
2228
selectText(I, SELECTOR_TEXT_LAYER);
2329
I.waitForVisible(SELECTOR_ANNOTATION_HIGHLIGHT_DIALOG);
@@ -29,11 +35,12 @@ Scenario('Create a new plain highlight annotation @desktop', (I) => {
2935
I.waitForVisible(SELECTOR_ANNOTATION_DIALOG);
3036
I.waitForText('Kanye West highlighted', 9, SELECTOR_HIGHLIGHT_LABEL);
3137
I.waitForEnabled(SELECTOR_ADD_HIGHLIGHT_BTN);
32-
});
3338

34-
Scenario('Delete the plain highlight annotation @desktop', (I) => {
35-
I.waitForVisible(SELECTOR_ANNOTATIONS_LOADED);
39+
validateIconColor(I, `${SELECTOR_ADD_HIGHLIGHT_BTN}${SELECTOR_ACTIVE}`, 'rgb(255, 201, 0)');
3640

41+
/*
42+
* Delete plain highlight annotation
43+
*/
3744
I.say('Highlight dialog should appear on click');
3845
I.click(`${SELECTOR_TEXT_LAYER} div`);
3946
I.waitForVisible(SELECTOR_ANNOTATION_HIGHLIGHT_DIALOG);

0 commit comments

Comments
 (0)