From a87c9e4f4aedcee294c8b3c01e58ddffd4c199e9 Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Thu, 17 Jan 2019 22:22:10 +0100 Subject: [PATCH] Added report content tests --- cypress/fixtures/users.json | 17 +++++ cypress/integration/05.ReportContent.feature | 34 +++++++++ cypress/integration/common/report.js | 73 ++++++++++++++++++++ cypress/integration/common/steps.js | 13 ++-- cypress/support/commands.js | 7 ++ cypress/support/config.js | 16 ----- 6 files changed, 138 insertions(+), 22 deletions(-) create mode 100644 cypress/fixtures/users.json create mode 100644 cypress/integration/05.ReportContent.feature create mode 100644 cypress/integration/common/report.js delete mode 100644 cypress/support/config.js diff --git a/cypress/fixtures/users.json b/cypress/fixtures/users.json new file mode 100644 index 000000000..339866774 --- /dev/null +++ b/cypress/fixtures/users.json @@ -0,0 +1,17 @@ +{ + "admin": { + "email": "admin@example.org", + "password": "1234", + "name": "Peter Lustig" + }, + "moderator": { + "email": "moderator@example.org", + "password": "1234", + "name": "Bob der Bausmeister" + }, + "user": { + "email": "user@example.org", + "password": "1234", + "name": "Jenny Rostock" + } +} diff --git a/cypress/integration/05.ReportContent.feature b/cypress/integration/05.ReportContent.feature new file mode 100644 index 000000000..d9b9e46fe --- /dev/null +++ b/cypress/integration/05.ReportContent.feature @@ -0,0 +1,34 @@ +Feature: Report content + As a user + I would like to report content that viloates the community guidlines + So the moderators can take action on it + + As a moderator + 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 + + 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: Normal user can't see the moderation page + #Given I am logged in as "user" diff --git a/cypress/integration/common/report.js b/cypress/integration/common/report.js new file mode 100644 index 000000000..e202bfad2 --- /dev/null +++ b/cypress/integration/common/report.js @@ -0,0 +1,73 @@ +import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps' + +/* global cy */ + +let lastPostTitle + +const savePostTitle = $post => { + return $post + .first() + .find('.ds-heading') + .first() + .invoke('text') + .then(title => { + lastPostTitle = title + }) +} +const invokeReportOnElement = selector => { + cy.get(selector) + .first() + .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)') + .click() + .wait(200) + 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 a Post menu and select the report option', () => { + invokeReportOnElement('.post-card') +}) + +When('I click on send in the confirmation dialog', () => { + cy.get('button') + .contains('Send') + .click() +}) + +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-child()').contains(lastPostTitle.slice(0, 20)) + }) +}) diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index ee9a364f7..a7c88d74d 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -1,11 +1,9 @@ import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps' import { getLangByName } from '../../support/helpers' -import find from 'lodash/find' +import users from '../../fixtures/users.json' /* global cy */ -const username = 'Peter Lustig' - const openPage = page => { if (page === 'landing') { page = '' @@ -14,7 +12,10 @@ const openPage = page => { } Given('I am logged in', () => { - cy.login('admin@example.org', 1234) + cy.loginAs('admin') +}) +Given('I am logged in as {string}', userType => { + cy.loginAs(userType) }) Given('we have a selection of tags and categories as well as posts', () => { @@ -59,7 +60,7 @@ Then('I can click on my profile picture in the top right corner', () => { }) Then('I can see my name {string} in the dropdown menu', () => { - cy.get('.avatar-menu-popover').should('contain', username) + cy.get('.avatar-menu-popover').should('contain', users.admin.name) }) Then('I see the login screen again', () => { @@ -68,7 +69,7 @@ Then('I see the login screen again', () => { Then('I am still logged in', () => { cy.get('.avatar-menu').click() - cy.get('.avatar-menu-popover').contains(username) + cy.get('.avatar-menu-popover').contains(users.admin.name) }) When('I select {string} in the language menu', name => { diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 77c75c7d5..a747644de 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -15,6 +15,7 @@ /* globals Cypress cy */ import { getLangByName } from './helpers' +import users from '../fixtures/users.json' const switchLang = name => { cy.get('.locale-menu').click() @@ -54,6 +55,12 @@ Cypress.Commands.add('login', (email, password) => { .click() 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('logout', (email, password) => { cy.visit(`/logout`) cy.location('pathname').should('contain', '/login') // we're out diff --git a/cypress/support/config.js b/cypress/support/config.js deleted file mode 100644 index af96ad615..000000000 --- a/cypress/support/config.js +++ /dev/null @@ -1,16 +0,0 @@ -export default { - users: { - admin: { - email: 'admin@example.org', - password: 1234 - }, - moderator: { - email: 'moderator@example.org', - password: 1234 - }, - user: { - email: 'user@example.org', - password: 1234 - } - } -}