ep_comments_page 0.1.98 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,66 +1,83 @@
1
1
  'use strict';
2
2
 
3
- describe('ep_comments_page - Comment Suggestion', function () {
4
- // create a new pad before each test run
5
- beforeEach(function (cb) {
6
- helper.newPad(cb);
7
- this.timeout(60000);
8
- });
3
+ const utils = require('../utils');
9
4
 
10
- it('Fills suggestion Change From field when adding a comment with suggestion', async function () {
11
- const chrome$ = helper.padChrome$;
5
+ // create a new pad before each test run
6
+ beforeEach(async function () {
7
+ this.timeout(60000);
8
+ await utils.aNewPad();
9
+ });
12
10
 
13
- // As in the function openCommentFormWithSuggestion we send all the text and call 'selectall',
14
- // we select the beginning of line as well. This situation does not happen in the browser, it's
15
- // not possible to select the beginning of first line of a selection. To fix this we add a first
16
- // text without line attribute, in this case a <span>, to avoid select a '*'
17
- const targetText = '<span>A</span><ul><li> text with</li><li> line attributes</li></ul>';
11
+ it('Fills suggestion Change From field when adding a comment with suggestion', async function () {
12
+ const chrome$ = helper.padChrome$;
18
13
 
19
- await openCommentFormWithSuggestion(targetText);
20
- const $suggestionFrom = chrome$('.from-value');
21
- expect($suggestionFrom.text()).to.be('A\n text with\n line attributes');
22
- });
14
+ // As in the function openCommentFormWithSuggestion we send all the text and call 'selectall',
15
+ // we select the beginning of line as well. This situation does not happen in the browser, it's
16
+ // not possible to select the beginning of first line of a selection. To fix this we add a first
17
+ // text without line attribute, in this case a <span>, to avoid select a '*'
18
+ const targetText = '<span>A</span><ul><li> text with</li><li> line attributes</li></ul>';
19
+
20
+ await openCommentFormWithSuggestion(targetText);
21
+ const $suggestionFrom = chrome$('.from-value');
22
+ expect($suggestionFrom.text()).to.be('A\n text with\n line attributes');
23
+ });
24
+
25
+ it('Cancel suggestion and try again fills suggestion Change From field', async function () {
26
+ const outer$ = helper.padOuter$;
27
+ const chrome$ = helper.padChrome$;
23
28
 
24
- it('Cancel suggestion and try again fills suggestion Change From field', async function () {
25
- const outer$ = helper.padOuter$;
26
- const chrome$ = helper.padChrome$;
29
+ await openCommentFormWithSuggestion('This content will receive a comment');
27
30
 
28
- await openCommentFormWithSuggestion('This content will receive a comment');
31
+ // cancel
32
+ const $cancelButton = chrome$('#comment-reset');
33
+ $cancelButton.click();
29
34
 
30
- // cancel
31
- const $cancelButton = chrome$('#comment-reset');
32
- $cancelButton.click();
35
+ // wait for comment form to close
36
+ await helper.waitForPromise(() => outer$('#newComments.active').length === 0);
37
+ await openCommentFormWithSuggestion('New target for comment');
33
38
 
34
- // wait for comment form to close
35
- await helper.waitForPromise(() => outer$('#newComments.active').length === 0);
36
- await openCommentFormWithSuggestion('New target for comment');
39
+ const $suggestionFrom = chrome$('.from-value');
40
+ expect($suggestionFrom.text()).to.be('New target for comment');
41
+ });
42
+
43
+ it('Fills suggestion Change From field, adds sugestion', async function () {
44
+ const outer$ = helper.padOuter$;
45
+ const inner$ = helper.padInner$;
46
+ const chrome$ = helper.padChrome$;
47
+ const origText = 'This content will receive a comment';
48
+ const suggestedText = 'amp: & dq: " sq: \' lt: < gt: > bs: \\ end';
49
+ await openCommentFormWithSuggestion(origText);
37
50
 
38
- const $suggestionFrom = chrome$('.from-value');
39
- expect($suggestionFrom.text()).to.be('New target for comment');
51
+ await helper.waitForPromise(() => chrome$('#newComment.popup-show').is(':visible'));
52
+ chrome$('#newComment').find('textarea.comment-content').val('A new comment text');
53
+ chrome$('#newComment').find('suggestion-checkbox').click();
54
+ let newCommentSuggestion;
55
+ await helper.waitForPromise(() => {
56
+ newCommentSuggestion = chrome$('#newComment').find('textarea.to-value');
57
+ return newCommentSuggestion.length > 0 && newCommentSuggestion.is(':visible');
40
58
  });
59
+ newCommentSuggestion.val(suggestedText);
60
+ chrome$('#comment-create-btn').click();
41
61
 
42
- it('Fills suggestion Change From field, adds sugestion', async function () {
43
- const outer$ = helper.padOuter$;
44
- const inner$ = helper.padInner$;
45
- const chrome$ = helper.padChrome$;
46
- const suggestedText = 'A new suggested text';
47
- await openCommentFormWithSuggestion('This content will receive a comment');
48
-
49
- await helper.waitForPromise(() => chrome$('#newComment.popup-show').is(':visible'));
50
- chrome$('#newComment').find('textarea.comment-content').val('A new comment text');
51
- chrome$('#newComment').find('textarea.to-value').val(suggestedText);
52
- chrome$('#comment-create-btn').click();
53
- await helper.waitForPromise(() => inner$('div').first().find('.comment').length);
54
- let comment$ = inner$('div').first().find('.comment');
55
- comment$.click();
56
- await helper.waitForPromise(() => {
57
- outer$('.approve-suggestion-btn:visible').click();
58
- return true;
59
- });
60
- comment$ = inner$('div').first().find('.comment');
61
- await helper.waitForPromise(() => comment$.text() === suggestedText);
62
- expect(comment$.text()).to.be(suggestedText);
62
+ let commentedText$;
63
+ await helper.waitForPromise(() => {
64
+ commentedText$ = inner$('div').first().find('.comment');
65
+ return commentedText$.length > 0;
63
66
  });
67
+ commentedText$.click();
68
+ let comment$;
69
+ await helper.waitForPromise(() => {
70
+ comment$ = outer$('.comment-container');
71
+ const fd$ = comment$.find('.full-display-content');
72
+ return comment$.length > 0 && fd$.length > 0 && fd$.is(':visible');
73
+ });
74
+ await helper.waitForPromise(
75
+ () => comment$.find('.comment-title-wrapper .from-label').text().includes(suggestedText));
76
+
77
+ outer$('.approve-suggestion-btn:visible').click();
78
+ commentedText$ = inner$('div').first().find('.comment');
79
+ await helper.waitForPromise(
80
+ () => inner$('div').first().find('.comment').text() === suggestedText);
64
81
  });
65
82
 
66
83
  const openCommentFormWithSuggestion = async (targetText) => {
@@ -1,137 +1,137 @@
1
1
  'use strict';
2
2
 
3
- describe('ep_comments_page - Comment Localization', function () {
4
- // create a new pad with comment before each test run
5
- beforeEach(function (cb) {
6
- helper.newPad(() => {
7
- createComment(() => {
8
- // ensure we start on the default language
9
- changeEtherpadLanguageTo('en', cb);
10
- });
11
- });
12
- this.timeout(60000);
13
- });
14
-
15
- // ensure we go back to English to avoid breaking other tests:
16
- after(function (cb) {
17
- changeEtherpadLanguageTo('en', cb);
18
- });
19
-
20
- it('uses default values when language was not localized yet', function (done) {
21
- changeEtherpadLanguageTo('oc', () => {
22
- const outer$ = helper.padOuter$;
23
-
24
- // get the title of the comment
25
- const $changeToLabel = outer$('.comment-suggest').first();
26
- expect($changeToLabel.text()).to.be(
27
- ' Include suggested change ');
28
-
29
- done();
30
- });
31
- });
32
-
33
- it('localizes comment when Etherpad language is changed', function (done) {
34
- changeEtherpadLanguageTo('pt-br', () => {
35
- const outer$ = helper.padOuter$;
36
- const commentId = getCommentId();
37
-
38
- // get the 'Suggested Change' label
39
- const $changeToLabel = outer$(`#${commentId} .from-label`).first();
40
- expect($changeToLabel.text()).to.be('Sugerir alteração de');
41
-
42
- done();
43
- });
44
- });
45
-
46
- it("localizes 'new comment' form when Etherpad language is changed", function (done) {
47
- // make sure form was created before changing the language
48
- const inner$ = helper.padInner$;
49
- const outer$ = helper.padOuter$;
50
- const chrome$ = helper.padChrome$;
51
-
52
- // get the first text element out of the inner iframe
53
- const $firstTextElement = inner$('div').first();
54
-
55
- // get the comment button and click it
56
- $firstTextElement.sendkeys('{selectall}'); // needs to select content to add comment to
57
- const $commentButton = chrome$('.addComment');
58
- $commentButton.click();
59
-
60
- changeEtherpadLanguageTo('pt-br', () => {
61
- // get the 'Include suggested change' label
62
- const $changeToLabel = outer$('.new-comment label.label-suggestion-checkbox').first();
63
- expect($changeToLabel.text()).to.be('Incluir alteração sugerida');
64
-
65
- done();
66
- });
67
- });
68
-
69
- /* ********** Helper functions ********** */
70
-
71
- const createComment = (callback) => {
72
- const inner$ = helper.padInner$;
73
- const outer$ = helper.padOuter$;
74
- const chrome$ = helper.padChrome$;
75
-
76
- // get the first text element out of the inner iframe
77
- const $firstTextElement = inner$('div').first();
78
-
79
- // simulate key presses to delete content
80
- $firstTextElement.sendkeys('{selectall}'); // select all
81
- $firstTextElement.sendkeys('{del}'); // clear the first line
82
- $firstTextElement.sendkeys('This content will receive a comment'); // insert text
83
-
84
- // get the comment button and click it
85
- $firstTextElement.sendkeys('{selectall}'); // needs to select content to add comment to
86
- const $commentButton = chrome$('.addComment');
87
- $commentButton.click();
88
-
89
- // fill the comment form and submit it
90
- const $commentField = chrome$('textarea.comment-content');
91
- $commentField.val('My comment');
92
- const $hasSuggestion = outer$('.suggestion-checkbox');
93
- $hasSuggestion.click();
94
- const $suggestionField = outer$('textarea.to-value');
95
- $suggestionField.val('Change to this suggestion');
96
- const $submittButton = chrome$('.comment-buttons input[type=submit]');
97
- $submittButton.click();
98
-
99
- // wait until comment is created and comment id is set
100
- helper.waitFor(() => getCommentId() != null)
101
- .done(callback);
102
- };
3
+ const utils = require('../utils');
103
4
 
104
- const changeEtherpadLanguageTo = (lang, callback) => {
105
- const boldTitles = {
106
- 'en': 'Bold (Ctrl+B)',
107
- 'pt-br': 'Negrito (Ctrl-B)',
108
- 'oc': 'Gras (Ctrl-B)',
109
- };
110
- const chrome$ = helper.padChrome$;
5
+ const commentedText = 'This content will receive a comment';
6
+ const suggestedText = 'Change to this suggestion';
111
7
 
112
- // click on the settings button to make settings visible
113
- const $settingsButton = chrome$('.buttonicon-settings');
114
- $settingsButton.click();
8
+ // create a new pad with comment before each test run
9
+ beforeEach(async function () {
10
+ this.timeout(60000);
11
+ await utils.aNewPad();
12
+ await createComment();
13
+ await changeEtherpadLanguageTo('en');
14
+ });
115
15
 
116
- // select the language
117
- const $language = chrome$('#languagemenu');
118
- $language.val(lang);
119
- $language.change();
16
+ // ensure we go back to English to avoid breaking other tests:
17
+ after(async function () {
18
+ await changeEtherpadLanguageTo('en');
19
+ });
120
20
 
121
- // hide settings again
122
- $settingsButton.click();
21
+ it('uses default values when language was not localized yet', async function () {
22
+ await changeEtherpadLanguageTo('oc');
23
+ const outer$ = helper.padOuter$;
123
24
 
124
- helper.waitFor(() => chrome$('.buttonicon-bold').parent()[0].title === boldTitles[lang])
125
- .done(callback);
126
- };
25
+ // get the title of the comment
26
+ const $changeToLabel = outer$('.comment-suggest').first();
27
+ expect($changeToLabel.text()).to.be(
28
+ ' Include suggested change ');
29
+ });
127
30
 
128
- const getCommentId = () => {
129
- const inner$ = helper.padInner$;
130
- const comment = inner$('.comment').first();
131
- const cls = comment.attr('class');
132
- const classCommentId = /(?:^| )(c-[A-Za-z0-9]*)/.exec(cls);
133
- const commentId = (classCommentId) ? classCommentId[1] : null;
31
+ it('localizes comment when Etherpad language is changed', async function () {
32
+ await changeEtherpadLanguageTo('pt-br');
33
+ const outer$ = helper.padOuter$;
34
+ const commentId = getCommentId();
134
35
 
135
- return commentId;
136
- };
36
+ // get the 'Suggested Change' label
37
+ const $changeToLabel = outer$(`#${commentId} .from-label`).first();
38
+ expect($changeToLabel.text())
39
+ .to.be(`Alteração sugerida de "${commentedText}" para "${suggestedText}"`);
137
40
  });
41
+
42
+ it("localizes 'new comment' form when Etherpad language is changed", async function () {
43
+ // make sure form was created before changing the language
44
+ const inner$ = helper.padInner$;
45
+ const outer$ = helper.padOuter$;
46
+ const chrome$ = helper.padChrome$;
47
+
48
+ // get the first text element out of the inner iframe
49
+ const $firstTextElement = inner$('div').first();
50
+
51
+ // get the comment button and click it
52
+ $firstTextElement.sendkeys('{selectall}'); // needs to select content to add comment to
53
+ const $commentButton = chrome$('.addComment');
54
+ $commentButton.click();
55
+
56
+ await changeEtherpadLanguageTo('pt-br');
57
+ // get the 'Include suggested change' label
58
+ const $changeToLabel = outer$('.new-comment label.label-suggestion-checkbox').first();
59
+ expect($changeToLabel.text()).to.be('Incluir alteração sugerida');
60
+ });
61
+
62
+ /* ********** Helper functions ********** */
63
+
64
+ const createComment = async () => {
65
+ const inner$ = helper.padInner$;
66
+ const chrome$ = helper.padChrome$;
67
+
68
+ // Returns the first line div. Must be a function because Etherpad might replace the div with a
69
+ // new div if the content changes.
70
+ const $firstTextElement = () => {
71
+ const $div = inner$('div').first();
72
+ expect($div.length).to.be(1);
73
+ return $div;
74
+ };
75
+
76
+ // simulate key presses to delete content
77
+ $firstTextElement().sendkeys('{selectall}'); // select all
78
+ $firstTextElement().sendkeys('{del}'); // clear the first line
79
+ $firstTextElement().sendkeys(commentedText); // insert text
80
+
81
+ // get the comment button and click it
82
+ $firstTextElement().sendkeys('{selectall}'); // needs to select content to add comment to
83
+ const $commentButton = chrome$('.addComment');
84
+ expect($commentButton.length).to.be(1);
85
+ $commentButton.click();
86
+
87
+ // fill the comment form and submit it
88
+ const $commentField = chrome$('textarea.comment-content');
89
+ expect($commentField.length).to.be(1);
90
+ $commentField.val('My comment');
91
+ const $hasSuggestion = chrome$('#newComment .suggestion-checkbox');
92
+ expect($hasSuggestion.length).to.be(1);
93
+ $hasSuggestion.click();
94
+ const $suggestionField = chrome$('textarea.to-value');
95
+ expect($suggestionField.length).to.be(1);
96
+ $suggestionField.val(suggestedText);
97
+ const $submittButton = chrome$('.comment-buttons input[type=submit]');
98
+ expect($submittButton.length).to.be(1);
99
+ $submittButton.click();
100
+
101
+ // wait until comment is created and comment id is set
102
+ await helper.waitForPromise(() => getCommentId() != null);
103
+ };
104
+
105
+ const changeEtherpadLanguageTo = async (lang) => {
106
+ const boldTitles = {
107
+ 'en': 'Bold (Ctrl+B)',
108
+ 'pt-br': 'Negrito (Ctrl-B)',
109
+ 'oc': 'Gras (Ctrl-B)',
110
+ };
111
+ const chrome$ = helper.padChrome$;
112
+
113
+ // click on the settings button to make settings visible
114
+ const $settingsButton = chrome$('.buttonicon-settings');
115
+ $settingsButton.click();
116
+
117
+ // select the language
118
+ const $language = chrome$('#languagemenu');
119
+ $language.val(lang);
120
+ $language.change();
121
+
122
+ // hide settings again
123
+ $settingsButton.click();
124
+
125
+ await helper.waitForPromise(
126
+ () => chrome$('.buttonicon-bold').parent()[0].title === boldTitles[lang]);
127
+ };
128
+
129
+ const getCommentId = () => {
130
+ const inner$ = helper.padInner$;
131
+ const comment = inner$('.comment');
132
+ if (comment.length === 0) return null;
133
+ for (const cls of comment[0].classList) {
134
+ if (cls.startsWith('c-')) return cls;
135
+ }
136
+ return null;
137
+ };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const utils = require('../utils');
4
+
5
+ before(async function () {
6
+ await utils.aNewPad();
7
+ helper.padInner$('div').first()
8
+ .sendkeys('{selectall}')
9
+ .sendkeys('{del}')
10
+ .text('commented text')
11
+ .sendkeys('{selectall}');
12
+ });
13
+
14
+ it('new comment button focuses on comment textarea', async function () {
15
+ helper.padChrome$('.addComment').click();
16
+ expect(helper.padChrome$.document.activeElement)
17
+ .to.be(helper.padChrome$('#newComment').find('.comment-content')[0]);
18
+ });