diff --git a/cypress/integration/05.ReportContent.feature b/cypress/integration/05.ReportContent.feature index 29509fdcd..fbfdfe8de 100644 --- a/cypress/integration/05.ReportContent.feature +++ b/cypress/integration/05.ReportContent.feature @@ -7,40 +7,53 @@ Feature: Report and Moderate I would like to see all reported content So I can look into it and decide what to do - Scenario: Report a Post from landingpage - Given I am logged in as "user" - And I am on the "landing" page + Background: + Given we have the following posts in our database: + | Author | Title | Content | Slug | + | David Irving | The Truth about the Holocaust | It never existed! | the-truth-about-the-holocaust | - When I click on a Post menu and select the report option - And I click on send in the confirmation dialog - Then I get a success message - - Scenario: See reported content - Given I am logged in as "moderator" - And I previously reported a post - - When I am on the "moderation" page - Then I see my reported post - - Scenario: Report while reading Post - Given I am logged in as "admin" - And I am viewing a post - - When I report the current post - And I visit the "moderation" page - Then I see my reported post + Scenario Outline: Report a post from various pages + Given I am logged in with a "user" role + And I see David Irving's post on the + When I click on "Report Contribution" from the triple dot menu of the post + And I confirm the reporting dialog because it is a criminal act under German law: + """ + Do you really want to report the contribution "The Truth about the Holocaust"? + """ + Then I see a success message: + """ + Thanks for reporting! + """ + Examples: + | Page | + | landing page | + | post page | Scenario: Report user - Given I am logged in as "admin" - And I am viewing a post - + Given I am logged in with a "user" role + And I see David Irving's post on the post page When I click on the author - And I report the author - And I visit the "moderation" page - Then I see my reported user + And I click on "Report User" from the triple dot menu in the user info box + And I confirm the reporting dialog because he is a holocaust denier: + """ + Do you really want to report the user "David Irving"? + """ + Then I see a success message: + """ + Thanks for reporting! + """ + + Scenario: Review reported content + Given somebody reported the following posts: + | Slug | + | the-truth-about-the-holocaust | + And I am logged in with a "moderator" role + When I click on the avatar menu in the top right corner + And I click on "Moderation" + Then I see all the reported posts including the one from above + And each list item links to the post page Scenario: Normal user can't see the moderation page - Given I am logged in as "user" - - When I can click on my profile picture in the top right corner + Given I am logged in with a "user" role + When I click on the avatar menu in the top right corner Then I can't see the moderation menu item diff --git a/cypress/integration/common/report.js b/cypress/integration/common/report.js index bbe2916c6..144b18630 100644 --- a/cypress/integration/common/report.js +++ b/cypress/integration/common/report.js @@ -3,6 +3,9 @@ import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps' /* global cy */ let lastReportTitle +let dummyReportedPostTitle = "Hacker, Freaks und Funktionäre" +let dummyReportedPostSlug = 'hacker-freaks-und-funktionareder-ccc' +let dummyAuthorName = "Jenny Rostock" const savePostTitle = $post => { return $post @@ -14,46 +17,42 @@ const savePostTitle = $post => { lastReportTitle = title }) } -const invokeReportOnElement = selector => { - cy.get(selector) - .first() + +Given('I see David Irving\'s post on the landing page', (page) => { + cy.openPage('landing') +}) + +Given('I see David Irving\'s post on the post page', (page) => { + cy.visit(`/post/${dummyReportedPostSlug}`) + cy.contains(dummyReportedPostTitle) // wait +}) + +Given('I am logged in with a {string} role', role => { + cy.loginAs(role) +}) + +When('I click on "Report Contribution" from the triple dot menu of the post', () => { + //TODO: match the created post title, not a dummy post title + cy.contains('.ds-card', dummyReportedPostTitle) .find('.content-menu-trigger') .first() .click() - return savePostTitle(cy.get(selector)).then(() => { - cy.get('.popover .ds-menu-item-link') - .contains('Report') - .click() - }) -} - -Given('I am logged in as {string}', userType => { - cy.loginAs(userType) -}) - -Given('I previously reported a post', () => { - invokeReportOnElement('.post-card') -}) - -Given('I am viewing a post', () => { - cy.visit('/') - cy.get('.post-card:nth(2)') + cy.get('.popover .ds-menu-item-link') + .contains('Report Contribution') .click() - .wait(300) - cy.location('pathname').should('contain', '/post') }) -When('I report the current post', () => { - invokeReportOnElement('.post-card').then(() => { - cy.get('button') - .contains('Send') - .click() - }) -}) +When('I click on "Report User" from the triple dot menu in the user info box', () => { + //TODO: match the created post author, not a dummy author + cy.contains('.ds-card', dummyAuthorName) + .find('.content-menu-trigger') + .first() + .click() -When('I click on a Post menu and select the report option', () => { - invokeReportOnElement('.post-card') + cy.get('.popover .ds-menu-item-link') + .contains('Report User') + .click() }) When('I click on the author', () => { @@ -83,13 +82,6 @@ Then('I get a success message', () => { cy.get('.iziToast-message').contains('Thanks') }) -Then('I see my reported post', () => { - cy.get('table').then(() => { - cy.get('tbody tr') - .first() - .contains(lastReportTitle.trim().slice(0, 20)) - }) -}) Then('I see my reported user', () => { cy.get('table').then(() => { cy.get('tbody tr') @@ -99,8 +91,45 @@ Then('I see my reported user', () => { }) Then(`I can't see the moderation menu item`, () => { - cy.get('.avatar-menu').click() cy.get('.avatar-menu-popover') - .find('a[href="/moderation"]') - .should('have.length', 0) + .find('a[href="/settings"]', 'Settings') + .should('exist') // OK, the dropdown is actually open + + cy.get('.avatar-menu-popover') + .find('a[href="/moderation"]', 'Moderation') + .should('not.exist') +}) + +When(/^I confirm the reporting dialog .*:$/, () => { + //TODO: take message from method argument + //TODO: match the right post + const message = 'Do you really want to report the' + cy.contains(message) // wait for element to become visible + //TODO: cy.get('.ds-modal').contains(dummyReportedPostTitle) + cy.get('.ds-modal').within(() => { + cy.get('button') + .contains('Send Report') + .click() + }) +}) + +Given('somebody reported the following posts:', table => { + table.hashes().forEach((row) => { + //TODO: calll factory here + // const options = Object.assign({}, row, { reported: true }) + //create('post', options) + }) +}) + +Then('I see all the reported posts including the one from above', () => { + //TODO: match the right post + cy.get('table tbody').within(() => { + cy.contains('tr', dummyReportedPostTitle) + }) +}) + +Then('each list item links to the post page', () => { + //TODO: match the right post + cy.contains(dummyReportedPostTitle).click() + cy.location('pathname').should('contain', '/post') }) diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index a7c88d74d..6d370a75a 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -4,13 +4,6 @@ import users from '../../fixtures/users.json' /* global cy */ -const openPage = page => { - if (page === 'landing') { - page = '' - } - cy.visit(`/${page}`) -} - Given('I am logged in', () => { cy.loginAs('admin') }) @@ -33,10 +26,11 @@ Given('my user account has the role {string}', role => { When('I log out', cy.logout) When('I visit the {string} page', page => { - openPage(page) + cy.openPage(page) }) + Given('I am on the {string} page', page => { - openPage(page) + cy.openPage(page) }) When('I fill in my email and password combination and click submit', () => { @@ -54,11 +48,6 @@ When('I log out through the menu in the top right corner', () => { .click() }) -Then('I can click on my profile picture in the top right corner', () => { - cy.get('.avatar-menu').click() - cy.get('.avatar-menu-popover') -}) - Then('I can see my name {string} in the dropdown menu', () => { cy.get('.avatar-menu-popover').should('contain', users.admin.name) }) @@ -94,3 +83,19 @@ When(`I click on {string}`, linkOrButton => { When('I press {string}', label => { cy.contains(label).click() }) + +Given('we have the following posts in our database:', table => { + table.hashes().forEach((row) => { + //TODO: calll factory here + //create('post', row) + }) +}) + + +Then('I see a success message:', (message) => { + cy.contains(message) +}) + +When('I click on the avatar menu in the top right corner', () => { + cy.get('.avatar-menu').click() +}) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index a747644de..3d91979bd 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -56,9 +56,9 @@ Cypress.Commands.add('login', (email, password) => { cy.location('pathname').should('eq', '/') // we're in! }) -Cypress.Commands.add('loginAs', userType => { - userType = userType || 'admin' - cy.login(users[userType].email, users[userType].password) +Cypress.Commands.add('loginAs', role => { + role = role || 'admin' + cy.login(users[role].email, users[role].password) }) Cypress.Commands.add('logout', (email, password) => { @@ -66,6 +66,14 @@ Cypress.Commands.add('logout', (email, password) => { cy.location('pathname').should('contain', '/login') // we're out }) +Cypress.Commands.add('openPage', (page) => { + if (page === 'landing') { + page = '' + } + cy.visit(`/${page}`) +}) + + // // // -- This is a child command --