Set up cypress test for direct reply to comment

This commit is contained in:
mattwr18 2020-01-27 15:07:32 +01:00
parent 36130d9d7c
commit b48b93dd0d
5 changed files with 41 additions and 5 deletions

View File

@ -41,4 +41,14 @@ export default {
language: { type: 'string', allow: [null] }, language: { type: 'string', allow: [null] },
imageBlurred: { type: 'boolean', default: false }, imageBlurred: { type: 'boolean', default: false },
imageAspectRatio: { type: 'float', default: 1.0 }, 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() },
},
},
} }

View File

@ -52,7 +52,18 @@ export default function create() {
author = author || (await factoryInstance.create('User')) author = author || (await factoryInstance.create('User'))
const post = await neodeInstance.create('Post', args) 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(author, 'author')
await post.relateTo(comment, 'comments')
await Promise.all(categories.map(c => c.relateTo(post, 'post'))) await Promise.all(categories.map(c => c.relateTo(post, 'post')))
await Promise.all(tags.map(t => t.relateTo(post, 'post'))) await Promise.all(tags.map(t => t.relateTo(post, 'post')))
return post return post

View File

@ -17,6 +17,11 @@ Then("I click on the {string} button", text => {
.click(); .click();
}); });
Then("I click on the reply button", () => {
cy.get(".reply-button")
.click();
});
Then("my comment should be successfully created", () => { Then("my comment should be successfully created", () => {
cy.get(".iziToast-message").contains("Comment Submitted"); 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", () => { Then("the editor should be cleared", () => {
cy.get(".ProseMirror p").should("have.class", "is-empty"); 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')
})

View File

@ -4,10 +4,10 @@ Feature: Post Comment
To be able to express my thoughts and emotions about these, discuss, and add give further information. To be able to express my thoughts and emotions about these, discuss, and add give further information.
Background: Background:
Given we have the following posts in our database: Given I have a user account
| id | title | slug | And we have the following posts in our database:
| bWBjpkTKZp | 101 Essays that will change the way you think | 101-essays | | id | title | slug | authorId | commentContent |
And I have a user account | 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 And I am logged in
Scenario: Comment creation Scenario: Comment creation
@ -36,3 +36,8 @@ Feature: Post Comment
Then my comment should be successfully created Then my comment should be successfully created
And I should see an abreviated version of my comment And I should see an abreviated version of my comment
And the editor should be cleared 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

View File

@ -15,7 +15,6 @@
/* globals Cypress cy */ /* globals Cypress cy */
import "cypress-file-upload"; import "cypress-file-upload";
import helpers from "./helpers"; import helpers from "./helpers";
import users from "../fixtures/users.json";
import { GraphQLClient, request } from 'graphql-request' import { GraphQLClient, request } from 'graphql-request'
import { gql } from '../../backend/src/helpers/jest' import { gql } from '../../backend/src/helpers/jest'
import config from '../../backend/src/config' import config from '../../backend/src/config'