From 90e4682cf68acbd3d534d1e8edbcd3ac94bc0771 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Fri, 25 May 2018 22:49:35 +0200 Subject: [PATCH] Take karma into account when doing e2e --- .../src/components/ApproveButton.js | 3 +- .../src/components/RejectButton.js | 3 +- .../Moderation/components/ModerationMenu.js | 1 + .../Moderation/components/ModerationQueue.js | 10 +++- test/e2e/globals.js | 3 -- test/e2e/page_objects/admin.js | 23 ++++++++- test/e2e/specs/03_embedStream.js | 10 ++-- test/e2e/specs/05_banUser.js | 49 +++++++++++++++++++ test/e2e/specs/06_suspendUser.js | 19 +++---- 9 files changed, 98 insertions(+), 23 deletions(-) diff --git a/client/coral-admin/src/components/ApproveButton.js b/client/coral-admin/src/components/ApproveButton.js index 884ac3da5..96dbdd375 100644 --- a/client/coral-admin/src/components/ApproveButton.js +++ b/client/coral-admin/src/components/ApproveButton.js @@ -14,7 +14,8 @@ const ApproveButton = ({ active, minimal, onClick, className, disabled }) => { className={cn( styles.root, { [styles.minimal]: minimal, [styles.active]: active }, - className + className, + 'talk-admin-approve-button' )} onClick={onClick} disabled={disabled || active} diff --git a/client/coral-admin/src/components/RejectButton.js b/client/coral-admin/src/components/RejectButton.js index 69e1047e6..2aabff007 100644 --- a/client/coral-admin/src/components/RejectButton.js +++ b/client/coral-admin/src/components/RejectButton.js @@ -14,7 +14,8 @@ const RejectButton = ({ active, minimal, onClick, className, disabled }) => { className={cn( styles.root, { [styles.minimal]: minimal, [styles.active]: active }, - className + className, + 'talk-admin-reject-button' )} onClick={onClick} disabled={disabled || active} diff --git a/client/coral-admin/src/routes/Moderation/components/ModerationMenu.js b/client/coral-admin/src/routes/Moderation/components/ModerationMenu.js index 27394c6c9..5300ce3eb 100644 --- a/client/coral-admin/src/routes/Moderation/components/ModerationMenu.js +++ b/client/coral-admin/src/routes/Moderation/components/ModerationMenu.js @@ -24,6 +24,7 @@ const ModerationMenu = ({ asset = {}, items, getModPath, activeTab }) => { > {items.map(queue => ( nodes.some(node => node.id === id); @@ -380,6 +381,11 @@ class ModerationQueue extends React.Component { ...props } = this.props; + const rootClassName = cn( + styles.root, + `talk-admin-moderate-queue-${this.props.activeTab}` + ); + if (comments.length === 0) { return (
@@ -401,7 +407,7 @@ class ModerationQueue extends React.Component { const comment = comments[index]; return ( -
+
+
this.viewNewComments()} count={comments.length - view.length} diff --git a/test/e2e/globals.js b/test/e2e/globals.js index aeecd204e..6a7eb07fb 100644 --- a/test/e2e/globals.js +++ b/test/e2e/globals.js @@ -23,9 +23,6 @@ module.exports = { username: 'user', password: 'testtest', }, - comment: { - body: 'This is a test comment', - }, organizationName: 'Coral', organizationContactEmail: 'coral@coralproject.net', }, diff --git a/test/e2e/page_objects/admin.js b/test/e2e/page_objects/admin.js index 8e319e499..64d22c97b 100644 --- a/test/e2e/page_objects/admin.js +++ b/test/e2e/page_objects/admin.js @@ -70,9 +70,28 @@ module.exports = { }, moderate: { selector: '.talk-admin-moderation-container', + commands: [ + { + url: function() { + return `${this.api.launchUrl}/admin/moderate`; + }, + ready() { + return this.waitForElementVisible('body'); + }, + goToQueue(queue) { + this.click(`#talk-admin-moderate-tab-${queue}`).expect.section( + `.talk-admin-moderate-queue-${queue}` + ).to.be.visible; + return this; + }, + }, + ], elements: { - comment: '.talk-admin-moderate-comment', - commentUsername: '.talk-admin-moderate-comment-username', + firstComment: '.talk-admin-moderate-comment', + firstCommentUsername: '.talk-admin-moderate-comment-username', + firstCommentContent: '.talk-admin-comment', + firstCommentApprove: '.talk-admin-approve-button', + firstCommentReject: '.talk-admin-reject-button', }, }, stories: { diff --git a/test/e2e/specs/03_embedStream.js b/test/e2e/specs/03_embedStream.js index 4b6831271..9eca7a736 100644 --- a/test/e2e/specs/03_embedStream.js +++ b/test/e2e/specs/03_embedStream.js @@ -1,3 +1,5 @@ +const commentBody = 'Embed Stream Test'; + module.exports = { '@tags': ['embedStream', 'login'], @@ -40,28 +42,26 @@ module.exports = { }, 'user posts a comment': client => { const comments = client.page.embedStream().section.comments; - const { testData: { comment } } = client.globals; comments .waitForElementVisible('@commentBoxTextarea') - .setValue('@commentBoxTextarea', comment.body) + .setValue('@commentBoxTextarea', commentBody) .waitForElementVisible('@commentBoxPostButton') .click('@commentBoxPostButton') .waitForElementVisible('@firstCommentContent') .getText('@firstCommentContent', result => { - comments.assert.equal(result.value, comment.body); + comments.assert.equal(result.value, commentBody); }); }, 'signed in user sees comment history': client => { const profile = client.page.embedStream().goToProfileSection(); - const { testData: { comment } } = client.globals; profile .waitForElementVisible('@myCommentHistory') .waitForElementVisible('@myCommentHistoryComment') .getText('@myCommentHistoryComment', result => { - profile.assert.equal(result.value, comment.body); + profile.assert.equal(result.value, commentBody); }); }, 'user sees replies and reactions to comments': client => { diff --git a/test/e2e/specs/05_banUser.js b/test/e2e/specs/05_banUser.js index 45ab0c347..51055a180 100644 --- a/test/e2e/specs/05_banUser.js +++ b/test/e2e/specs/05_banUser.js @@ -1,3 +1,5 @@ +const commentBody = 'Ban User Test'; + module.exports = { before: client => { client.setWindowPosition(0, 0); @@ -109,4 +111,51 @@ module.exports = { .waitForElementVisible('@commentBoxTextarea') .waitForElementVisible('@commentBoxPostButton'); }, + 'user posts comment, karma should stop it from happening': client => { + const comments = client.page.embedStream().section.comments; + + comments + .waitForElementVisible('@commentBoxTextarea') + .setValue('@commentBoxTextarea', commentBody) + .waitForElementVisible('@commentBoxPostButton') + .click('@commentBoxPostButton'); + + client.pause(2000); + + comments.waitForElementNotPresent('@firstCommentContent'); + }, + 'user logs out 3': client => { + const embedStream = client.page.embedStream(); + const comments = embedStream.section.comments; + + comments.logout(); + }, + 'admin logs in (3)': client => { + const adminPage = client.page.admin(); + const { testData: { admin } } = client.globals; + + adminPage.navigateAndLogin(admin); + }, + 'admin goes to moderation queue reported': client => { + const adminPage = client.page.admin(); + + adminPage.goToModerate().goToQueue('reported'); + }, + 'comment should be in reported queue': client => { + const moderate = client.page.admin().section.moderate; + + moderate + .waitForElementVisible('@firstComment') + .getText('@firstCommentContent', result => { + moderate.assert.equal(result.value, commentBody); + }); + }, + 'approve comment to restore karma': client => { + const moderate = client.page.admin().section.moderate; + + moderate.click('@firstCommentApprove'); + + // TODO: check why this fails. + // .waitForElementNotPresent('@firstComment'); + }, }; diff --git a/test/e2e/specs/06_suspendUser.js b/test/e2e/specs/06_suspendUser.js index 81fde3781..e02f21db9 100644 --- a/test/e2e/specs/06_suspendUser.js +++ b/test/e2e/specs/06_suspendUser.js @@ -1,3 +1,5 @@ +const commentBody = 'Suspend User Test'; + module.exports = { before: client => { client.setWindowPosition(0, 0); @@ -25,16 +27,15 @@ module.exports = { }, 'user posts comment': client => { const comments = client.page.embedStream().section.comments; - const { testData: { comment } } = client.globals; comments .waitForElementVisible('@commentBoxTextarea') - .setValue('@commentBoxTextarea', comment.body) + .setValue('@commentBoxTextarea', commentBody) .waitForElementVisible('@commentBoxPostButton') .click('@commentBoxPostButton') .waitForElementVisible('@firstCommentContent') .getText('@firstCommentContent', result => { - comments.assert.equal(result.value, comment.body); + comments.assert.equal(result.value, commentBody); }); }, 'user logs out': client => { @@ -84,9 +85,9 @@ module.exports = { .goToModerate(); moderate - .waitForElementVisible('@comment') - .waitForElementVisible('@commentUsername') - .click('@commentUsername'); + .waitForElementVisible('@firstComment') + .waitForElementVisible('@firstCommentUsername') + .click('@firstCommentUsername'); userDetailDrawer .waitForElementVisible('@actionsMenu') @@ -112,9 +113,9 @@ module.exports = { const { moderate, userDetailDrawer } = adminPage.section; moderate - .waitForElementVisible('@comment') - .waitForElementVisible('@commentUsername') - .click('@commentUsername'); + .waitForElementVisible('@firstComment') + .waitForElementVisible('@firstCommentUsername') + .click('@firstCommentUsername'); userDetailDrawer .waitForElementVisible('@tabBar')