From b48b93dd0d2dc03fc2342fe3c8c7fbb2a8e5fbc5 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Mon, 27 Jan 2020 15:07:32 +0100 Subject: [PATCH] Set up cypress test for direct reply to comment --- backend/src/models/Post.js | 10 ++++++++++ backend/src/seed/factories/posts.js | 11 +++++++++++ cypress/integration/common/post.js | 11 +++++++++++ cypress/integration/post/Comment.feature | 13 +++++++++---- cypress/support/commands.js | 1 - 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/backend/src/models/Post.js b/backend/src/models/Post.js index fd1e5b2ac..70b0d8793 100644 --- a/backend/src/models/Post.js +++ b/backend/src/models/Post.js @@ -41,4 +41,14 @@ export default { language: { type: 'string', allow: [null] }, imageBlurred: { type: 'boolean', default: false }, imageAspectRatio: { type: 'float', default: 1.0 }, + comments: { + type: 'relationship', + relationship: 'COMMENTS', + target: 'Comment', + direction: 'in', + properties: { + createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, + updatedAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, + }, + }, } diff --git a/backend/src/seed/factories/posts.js b/backend/src/seed/factories/posts.js index 55f4f95fb..e93941c88 100644 --- a/backend/src/seed/factories/posts.js +++ b/backend/src/seed/factories/posts.js @@ -52,7 +52,18 @@ export default function create() { author = author || (await factoryInstance.create('User')) const post = await neodeInstance.create('Post', args) + + let { comment, commentContent } = args + delete args.comment + delete args.commentContent + if (comment && commentContent) throw new Error('You provided both comment and commentContent') + if (commentContent) comment = await neodeInstance.find('Comment', commentContent) + comment = + comment || + (await factoryInstance.create('Comment', { content: commentContent, post, author })) + await post.relateTo(author, 'author') + await post.relateTo(comment, 'comments') await Promise.all(categories.map(c => c.relateTo(post, 'post'))) await Promise.all(tags.map(t => t.relateTo(post, 'post'))) return post diff --git a/cypress/integration/common/post.js b/cypress/integration/common/post.js index 4d1856bcc..02c50ab64 100644 --- a/cypress/integration/common/post.js +++ b/cypress/integration/common/post.js @@ -17,6 +17,11 @@ Then("I click on the {string} button", text => { .click(); }); +Then("I click on the reply button", () => { + cy.get(".reply-button") + .click(); +}); + Then("my comment should be successfully created", () => { cy.get(".iziToast-message").contains("Comment Submitted"); }); @@ -44,3 +49,9 @@ Then("I should see an abreviated version of my comment", () => { Then("the editor should be cleared", () => { cy.get(".ProseMirror p").should("have.class", "is-empty"); }); + +Then("it should create a mention in the CommentForm", () => { + cy.get(".ProseMirror a") + .should('have.class', 'mention') + .should('contain', '@peter-pan') +}) \ No newline at end of file diff --git a/cypress/integration/post/Comment.feature b/cypress/integration/post/Comment.feature index 50284d6f5..66cf7a6d7 100644 --- a/cypress/integration/post/Comment.feature +++ b/cypress/integration/post/Comment.feature @@ -4,10 +4,10 @@ Feature: Post Comment To be able to express my thoughts and emotions about these, discuss, and add give further information. Background: - Given we have the following posts in our database: - | id | title | slug | - | bWBjpkTKZp | 101 Essays that will change the way you think | 101-essays | - And I have a user account + Given I have a user account + And we have the following posts in our database: + | id | title | slug | authorId | commentContent | + | bWBjpkTKZp | 101 Essays that will change the way you think | 101-essays | id-of-peter-pan | @peter-pan reply to me | And I am logged in Scenario: Comment creation @@ -36,3 +36,8 @@ Feature: Post Comment Then my comment should be successfully created And I should see an abreviated version of my comment And the editor should be cleared + + Scenario: Direct reply to Comment + Given I visit "post/bWBjpkTKZp/101-essays" + And I click on the reply button + Then it should create a mention in the CommentForm diff --git a/cypress/support/commands.js b/cypress/support/commands.js index c9a2e213a..16ac43a19 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -15,7 +15,6 @@ /* globals Cypress cy */ import "cypress-file-upload"; import helpers from "./helpers"; -import users from "../fixtures/users.json"; import { GraphQLClient, request } from 'graphql-request' import { gql } from '../../backend/src/helpers/jest' import config from '../../backend/src/config'