diff --git a/cypress/integration/03.TagsAndCategories.feature b/cypress/integration/03.TagsAndCategories.feature index 050fb3643..8f27a36cf 100644 --- a/cypress/integration/03.TagsAndCategories.feature +++ b/cypress/integration/03.TagsAndCategories.feature @@ -22,20 +22,19 @@ Feature: Tags and Categories When I navigate to the administration dashboard And I click on "Categories" Then I can see a list of categories ordered by post count: - | Icon | Name | Post Count | - | | Just For Fun | 5 | - | | Happyness & Values | 2 | - | | Health & Wellbeing | 1 | + | Icon | Name | Posts | + | | Just For Fun | 2 | + | | Happyness & Values | 1 | + | | Health & Wellbeing | 0 | Scenario: See an overview of tags When I navigate to the administration dashboard And I click on "Tags" - Then I can see a list of tags ordered by user and post count: - | # | Name | Nutzer | Beiträge | - | 1 | Naturschutz | 2 | 2 | - | 2 | Freiheit | 2 | 2 | - | 3 | Umwelt | 1 | 1 | - | 4 | Demokratie | 1 | 1 | + Then I can see a list of tags ordered by user count: + | # | Name | Users | Posts | + | 1 | Democracy | 2 | 3 | + | 2 | Ecology | 1 | 1 | + | 3 | Nature | 1 | 2 | diff --git a/cypress/integration/common/admin.js b/cypress/integration/common/admin.js index 9162667b4..b0bc60c16 100644 --- a/cypress/integration/common/admin.js +++ b/cypress/integration/common/admin.js @@ -2,18 +2,6 @@ import { When, Then } from 'cypress-cucumber-preprocessor/steps' /* global cy */ -const lastColumnIsSortedInDescendingOrder = () => { - cy.get('tbody') - .find('tr td:last-child') - .then(lastColumn => { - cy.wrap(lastColumn) - const values = lastColumn - .map((i, td) => parseInt(td.textContent)) - .toArray() - const orderedDescending = values.slice(0).sort((a, b) => b - a) - return cy.wrap(values).should('deep.eq', orderedDescending) - }) -} When('I navigate to the administration dashboard', () => { cy.get('.avatar-menu').click() @@ -27,13 +15,25 @@ Then('I can see a list of categories ordered by post count:', table => { cy.get('thead') .find('tr th') .should('have.length', 3) - lastColumnIsSortedInDescendingOrder() + table.hashes().forEach(({Name, Posts}, index) => { + cy.get(`tbody > :nth-child(${index + 1}) > :nth-child(2)`) + .should('contain', Name) + cy.get(`tbody > :nth-child(${index + 1}) > :nth-child(3)`) + .should('contain', Posts) + }) }) -Then('I can see a list of tags ordered by user and post count:', table => { +Then('I can see a list of tags ordered by user count:', table => { // TODO: match the table in the feature with the html table cy.get('thead') .find('tr th') .should('have.length', 4) - lastColumnIsSortedInDescendingOrder() + table.hashes().forEach(({Name, Users, Posts}, index) => { + cy.get(`tbody > :nth-child(${index + 1}) > :nth-child(2)`) + .should('contain', Name) + cy.get(`tbody > :nth-child(${index + 1}) > :nth-child(3)`) + .should('contain', Users) + cy.get(`tbody > :nth-child(${index + 1}) > :nth-child(4)`) + .should('contain', Posts) + }) }) diff --git a/cypress/integration/common/report.js b/cypress/integration/common/report.js index f9b232d29..380d51034 100644 --- a/cypress/integration/common/report.js +++ b/cypress/integration/common/report.js @@ -28,7 +28,7 @@ Given("I see David Irving's post on the post page", page => { }) Given('I am logged in with a {string} role', role => { - cy.factory().create('user', { + cy.factory().create('User', { email: `${role}@example.org`, password: '1234', role @@ -131,9 +131,9 @@ Given('somebody reported the following posts:', table => { password: '1234' } cy.factory() - .create('user', reporter) + .create('User', reporter) .authenticateAs(reporter) - .create('report', { + .create('Report', { description: "I don't like this post", resource: { id, type: 'contribution' } }) diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index 5e816c5ce..c17c2729b 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -21,52 +21,64 @@ Given('I am logged in', () => { Given('we have a selection of tags and categories as well as posts', () => { cy.factory() .authenticateAs(loginCredentials) - .create('category', { + .create('Category', { id: 'cat1', name: 'Just For Fun', slug: 'justforfun', icon: 'smile' }) - .create('category', { + .create('Category', { id: 'cat2', name: 'Happyness & Values', slug: 'happyness-values', icon: 'heart-o' }) - .create('category', { + .create('Category', { id: 'cat3', name: 'Health & Wellbeing', slug: 'health-wellbeing', icon: 'medkit' }) - .create('tag', { id: 't1', name: 'Ecology' }) - .create('tag', { id: 't2', name: 'Nature' }) - .create('tag', { id: 't3', name: 'Democracy' }) - .create('post', { id: 'p0' }) - .create('post', { id: 'p1' }) - .create('post', { id: 'p2' }) - .relate('post', 'Categories', { from: 'p0', to: 'cat1' }) - .relate('post', 'Categories', { from: 'p1', to: 'cat2' }) - .relate('post', 'Categories', { from: 'p2', to: 'cat3' }) - .relate('post', 'Tags', { from: 'p0', to: 't1' }) - .relate('post', 'Tags', { from: 'p0', to: 't2' }) - .relate('post', 'Tags', { from: 'p0', to: 't3' }) - .relate('post', 'Tags', { from: 'p1', to: 't1' }) - .relate('post', 'Tags', { from: 'p1', to: 't2' }) + .create('Tag', { id: 't1', name: 'Ecology' }) + .create('Tag', { id: 't2', name: 'Nature' }) + .create('Tag', { id: 't3', name: 'Democracy' }) + + const someAuthor = { + id: 'authorId', + email: 'author@example.org', + password: '1234' + } + cy.factory() + .create('User', someAuthor) + .authenticateAs(someAuthor) + .create('Post', { id: 'p0' }) + .create('Post', { id: 'p1' }) + cy.factory() + .authenticateAs(loginCredentials) + .create('Post', { id: 'p2' }) + .relate('Post', 'Categories', { from: 'p0', to: 'cat1' }) + .relate('Post', 'Categories', { from: 'p1', to: 'cat2' }) + .relate('Post', 'Categories', { from: 'p2', to: 'cat1' }) + .relate('Post', 'Tags', { from: 'p0', to: 't1' }) + .relate('Post', 'Tags', { from: 'p0', to: 't2' }) + .relate('Post', 'Tags', { from: 'p0', to: 't3' }) + .relate('Post', 'Tags', { from: 'p1', to: 't2' }) + .relate('Post', 'Tags', { from: 'p1', to: 't3' }) + .relate('Post', 'Tags', { from: 'p2', to: 't3' }) }) Given('we have the following user accounts:', table => { table.hashes().forEach(params => { - cy.factory().create('user', params) + cy.factory().create('User', params) }) }) Given('I have a user account', () => { - cy.factory().create('user', narratorParams) + cy.factory().create('User', narratorParams) }) Given('my user account has the role {string}', role => { - cy.factory().create('user', { + cy.factory().create('User', { role, ...loginCredentials }) @@ -141,7 +153,7 @@ When('I press {string}', label => { Given('we have the following posts in our database:', table => { table.hashes().forEach(({ Author, id, title, content }) => { cy.factory() - .create('user', { + .create('User', { name: Author, email: `${Author}@example.org`, password: '1234' @@ -150,7 +162,7 @@ Given('we have the following posts in our database:', table => { email: `${Author}@example.org`, password: '1234' }) - .create('post', { id, title, content }) + .create('Post', { id, title, content }) }) }) @@ -172,7 +184,7 @@ When( Given('I previously created a post', () => { cy.factory() .authenticateAs(loginCredentials) - .create('post', lastPost) + .create('Post', lastPost) }) When('I choose {string} as the title of the post', title => {