From 233c6abbab1662043ab2d75cd800ff89915a7cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Fri, 22 Feb 2019 00:08:01 +0100 Subject: [PATCH] Refactor most of report cucumber feature --- cypress/integration/05.ReportContent.feature | 8 +-- cypress/integration/common/report.js | 56 +++++++++++++------- cypress/integration/common/steps.js | 18 ++++--- 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/cypress/integration/05.ReportContent.feature b/cypress/integration/05.ReportContent.feature index fbfdfe8de..25f5aec94 100644 --- a/cypress/integration/05.ReportContent.feature +++ b/cypress/integration/05.ReportContent.feature @@ -9,13 +9,13 @@ Feature: Report and Moderate 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 | + | Author | title | content | + | David Irving | The Truth about the Holocaust | It never existed! | 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 + When I see David Irving's post on the + And 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"? diff --git a/cypress/integration/common/report.js b/cypress/integration/common/report.js index 812b0d751..4131ade78 100644 --- a/cypress/integration/common/report.js +++ b/cypress/integration/common/report.js @@ -3,9 +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' +let davidIrvingPostTitle = 'The Truth about the Holocaust' +let davidIrvingPostSlug = 'the-truth-about-the-holocaust' +let davidIrvingName = 'David Irving' const savePostTitle = $post => { return $post @@ -23,21 +23,27 @@ Given("I see David Irving's post on the landing page", page => { }) Given("I see David Irving's post on the post page", page => { - cy.visit(`/post/${dummyReportedPostSlug}`) - cy.contains(dummyReportedPostTitle) // wait + cy.visit(`/post/${davidIrvingPostSlug}`) + cy.contains(davidIrvingPostTitle) // wait }) Given('I am logged in with a {string} role', role => { - cy.loginAs(role) + cy.factory().create('user', { + email: `${role}@example.org`, + password: '1234', + role + }) + cy.login({ + email: `${role}@example.org`, + password: '1234', + }) }) 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) + cy.contains('.ds-card', davidIrvingPostTitle) .find('.content-menu-trigger') - .find(':nth-child(2)') .click() cy.get('.popover .ds-menu-item-link') @@ -49,8 +55,7 @@ When( 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) + cy.contains('.ds-card', davidIrvingName) .find('.content-menu-trigger') .first() .click() @@ -111,7 +116,7 @@ When(/^I confirm the reporting dialog .*:$/, () => { //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) + //TODO: cy.get('.ds-modal').contains(davidIrvingPostTitle) cy.get('.ds-modal').within(() => { cy.get('button') .contains('Send Report') @@ -120,22 +125,37 @@ When(/^I confirm the reporting dialog .*:$/, () => { }) 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) + table.hashes().forEach(({slug}, index) => { + const author = { + id: `author${index}`, + email: `author${index}@example.org`, + password: '1234' + } + const reporter = { + id: `reporter${index}`, + email: `reporter${index}@example.org`, + password: '1234' + } + cy.factory() + .create('user', author) + .authenticateAs(author) + .create('post', { id: `p${index}` }) + cy.factory() + .create('user', reporter) + .authenticateAs(reporter) + .create('report', { description: 'I don\'t like this post', resource: { id: `p${index}`, type: 'post' } }) }) }) 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) + cy.contains('tr', davidIrvingPostTitle) }) }) Then('each list item links to the post page', () => { //TODO: match the right post - cy.contains(dummyReportedPostTitle).click() + cy.contains(davidIrvingPostTitle).click() cy.location('pathname').should('contain', '/post') }) diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index a00dd5d8f..dc183fa87 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -18,9 +18,6 @@ const narratorParams = { Given('I am logged in', () => { cy.login(loginCredentials) }) -Given('I am logged in as {string}', userType => { - cy.loginAs(userType) -}) Given('we have a selection of tags and categories as well as posts', () => { cy.factory() @@ -128,9 +125,18 @@ When('I press {string}', label => { }) Given('we have the following posts in our database:', table => { - table.hashes().forEach(row => { - //TODO: calll factory here - //create('post', row) + table.hashes().forEach(({Author, title, content}) => { + cy.factory() + .create('user', { + name: Author, + email: `${Author}@example.org`, + password: '1234' + }) + .authenticateAs({ + email: `${Author}@example.org`, + password: '1234' + }) + .create('post', { title, content }) }) })