Added report content tests

This commit is contained in:
Grzegorz Leoniec 2019-01-17 22:22:10 +01:00
parent 453ceae726
commit a87c9e4f4a
No known key found for this signature in database
GPG Key ID: 3AA43686D4EB1377
6 changed files with 138 additions and 22 deletions

View File

@ -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"
}
}

View File

@ -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"

View File

@ -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))
})
})

View File

@ -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 => {

View File

@ -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

View File

@ -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
}
}
}