From ccb6f347ae87f3b85eba70d5fc74a5cb5bb6c203 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 27 Sep 2018 17:48:10 +0200 Subject: [PATCH] test: use baseComment and baseAsset in fixtures --- .../__snapshots__/editComment.spec.tsx.snap | 42 +-- .../__snapshots__/loadMore.spec.tsx.snap | 18 +- .../__snapshots__/postComment.spec.tsx.snap | 18 +- .../__snapshots__/postReply.spec.tsx.snap | 24 +- .../__snapshots__/renderReplies.spec.tsx.snap | 18 +- .../__snapshots__/renderStream.spec.tsx.snap | 6 +- .../showAllReplies.spec.tsx.snap | 18 +- .../stream/test/comments/postComment.spec.tsx | 16 +- .../test/comments/postLocalReply.spec.tsx | 24 +- .../stream/test/comments/postReply.spec.tsx | 19 +- src/core/client/stream/test/fixtures.ts | 263 +++++++----------- 11 files changed, 191 insertions(+), 275 deletions(-) diff --git a/src/core/client/stream/test/comments/__snapshots__/editComment.spec.tsx.snap b/src/core/client/stream/test/comments/__snapshots__/editComment.spec.tsx.snap index 3d4a0fb0d..ce0e2467f 100644 --- a/src/core/client/stream/test/comments/__snapshots__/editComment.spec.tsx.snap +++ b/src/core/client/stream/test/comments/__snapshots__/editComment.spec.tsx.snap @@ -315,10 +315,10 @@ exports[`cancel edit: edit canceled 1`] = ` > @@ -754,10 +754,10 @@ exports[`edit a comment: edit form 1`] = ` > @@ -1193,10 +1193,10 @@ exports[`edit a comment: optimistic response 1`] = ` > @@ -1568,10 +1568,10 @@ exports[`edit a comment: render stream 1`] = ` > @@ -1952,10 +1952,10 @@ exports[`edit a comment: server response 1`] = ` > @@ -2327,10 +2327,10 @@ exports[`shows expiry message: edit form closed 1`] = ` > @@ -2743,10 +2743,10 @@ exports[`shows expiry message: edit time expired 1`] = ` > diff --git a/src/core/client/stream/test/comments/__snapshots__/loadMore.spec.tsx.snap b/src/core/client/stream/test/comments/__snapshots__/loadMore.spec.tsx.snap index 7a6a13b76..704cfcf74 100644 --- a/src/core/client/stream/test/comments/__snapshots__/loadMore.spec.tsx.snap +++ b/src/core/client/stream/test/comments/__snapshots__/loadMore.spec.tsx.snap @@ -245,10 +245,10 @@ exports[`loads more comments 1`] = ` > @@ -315,10 +315,10 @@ exports[`loads more comments 1`] = ` > @@ -605,10 +605,10 @@ exports[`renders comment stream 1`] = ` > diff --git a/src/core/client/stream/test/comments/__snapshots__/postComment.spec.tsx.snap b/src/core/client/stream/test/comments/__snapshots__/postComment.spec.tsx.snap index fa033c7d5..e4936901c 100644 --- a/src/core/client/stream/test/comments/__snapshots__/postComment.spec.tsx.snap +++ b/src/core/client/stream/test/comments/__snapshots__/postComment.spec.tsx.snap @@ -394,10 +394,10 @@ exports[`post a comment: optimistic response 1`] = ` > @@ -838,10 +838,10 @@ exports[`post a comment: server response 1`] = ` > @@ -1197,10 +1197,10 @@ exports[`renders comment stream 1`] = ` > diff --git a/src/core/client/stream/test/comments/__snapshots__/postReply.spec.tsx.snap b/src/core/client/stream/test/comments/__snapshots__/postReply.spec.tsx.snap index 8dd6ae3f6..74de69a57 100644 --- a/src/core/client/stream/test/comments/__snapshots__/postReply.spec.tsx.snap +++ b/src/core/client/stream/test/comments/__snapshots__/postReply.spec.tsx.snap @@ -426,10 +426,10 @@ exports[`post a reply: open reply form 1`] = ` > @@ -1013,10 +1013,10 @@ exports[`post a reply: optimistic response 1`] = ` > @@ -1463,10 +1463,10 @@ exports[`post a reply: server response 1`] = ` > @@ -1822,10 +1822,10 @@ exports[`renders comment stream 1`] = ` > diff --git a/src/core/client/stream/test/comments/__snapshots__/renderReplies.spec.tsx.snap b/src/core/client/stream/test/comments/__snapshots__/renderReplies.spec.tsx.snap index 2266711cd..0c70f8956 100644 --- a/src/core/client/stream/test/comments/__snapshots__/renderReplies.spec.tsx.snap +++ b/src/core/client/stream/test/comments/__snapshots__/renderReplies.spec.tsx.snap @@ -393,10 +393,10 @@ exports[`renders comment stream 1`] = ` > @@ -463,10 +463,10 @@ exports[`renders comment stream 1`] = ` > @@ -535,10 +535,10 @@ exports[`renders comment stream 1`] = ` > diff --git a/src/core/client/stream/test/comments/__snapshots__/renderStream.spec.tsx.snap b/src/core/client/stream/test/comments/__snapshots__/renderStream.spec.tsx.snap index bfe500ef4..cce33a64d 100644 --- a/src/core/client/stream/test/comments/__snapshots__/renderStream.spec.tsx.snap +++ b/src/core/client/stream/test/comments/__snapshots__/renderStream.spec.tsx.snap @@ -245,10 +245,10 @@ exports[`renders comment stream 1`] = ` > diff --git a/src/core/client/stream/test/comments/__snapshots__/showAllReplies.spec.tsx.snap b/src/core/client/stream/test/comments/__snapshots__/showAllReplies.spec.tsx.snap index 27fc4c77a..5fe47021f 100644 --- a/src/core/client/stream/test/comments/__snapshots__/showAllReplies.spec.tsx.snap +++ b/src/core/client/stream/test/comments/__snapshots__/showAllReplies.spec.tsx.snap @@ -249,10 +249,10 @@ exports[`renders comment stream 1`] = ` > @@ -569,10 +569,10 @@ exports[`show all replies 1`] = ` > @@ -639,10 +639,10 @@ exports[`show all replies 1`] = ` > diff --git a/src/core/client/stream/test/comments/postComment.spec.tsx b/src/core/client/stream/test/comments/postComment.spec.tsx index f4594c4dd..35ce4c4f2 100644 --- a/src/core/client/stream/test/comments/postComment.spec.tsx +++ b/src/core/client/stream/test/comments/postComment.spec.tsx @@ -5,7 +5,7 @@ import timekeeper from "timekeeper"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assets, settings, users } from "../fixtures"; +import { assets, baseComment, settings, users } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; @@ -39,20 +39,10 @@ beforeEach(() => { edge: { cursor: null, node: { + ...baseComment, id: "comment-x", author: users[0], body: "Hello world! (from server)", - createdAt: "2018-07-06T18:24:00.000Z", - editing: { - edited: false, - editableUntil: "2018-07-06T18:24:30.000Z", - }, - replies: { edges: [], pageInfo: {} }, - actionCounts: { - reaction: { - total: 0, - }, - }, }, }, clientMutationId: "0", @@ -84,7 +74,7 @@ it("post a comment", async () => { .findByProps({ inputId: "comments-postCommentForm-field" }) .props.onChange({ html: "Hello world!" }); - timekeeper.freeze(new Date("2018-07-06T18:24:00.000Z")); + timekeeper.freeze(new Date(baseComment.createdAt)); testRenderer.root .findByProps({ id: "comments-postCommentForm-form" }) diff --git a/src/core/client/stream/test/comments/postLocalReply.spec.tsx b/src/core/client/stream/test/comments/postLocalReply.spec.tsx index ac69ce5ae..3e665cf80 100644 --- a/src/core/client/stream/test/comments/postLocalReply.spec.tsx +++ b/src/core/client/stream/test/comments/postLocalReply.spec.tsx @@ -5,7 +5,12 @@ import timekeeper from "timekeeper"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assetWithDeepestReplies, settings, users } from "../fixtures"; +import { + assetWithDeepestReplies, + baseComment, + settings, + users, +} from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; @@ -39,23 +44,10 @@ beforeEach(() => { edge: { cursor: null, node: { + ...baseComment, id: "comment-x", author: users[0], body: "Hello world! (from server)", - createdAt: "2018-07-06T18:24:00.000Z", - replies: { - edges: [], - pageInfo: { endCursor: null, hasNextPage: false }, - }, - editing: { - edited: false, - editableUntil: "2018-07-06T18:24:30.000Z", - }, - actionCounts: { - reaction: { - total: 0, - }, - }, }, }, clientMutationId: "0", @@ -102,7 +94,7 @@ it("post a reply", async () => { }) .props.onChange({ html: "Hello world!" }); - timekeeper.freeze(new Date("2018-07-06T18:24:00.000Z")); + timekeeper.freeze(new Date(baseComment.createdAt)); testRenderer.root .findByProps({ id: "comments-replyCommentForm-form-comment-with-deepest-replies-5", diff --git a/src/core/client/stream/test/comments/postReply.spec.tsx b/src/core/client/stream/test/comments/postReply.spec.tsx index ad96fe03c..ee7b34566 100644 --- a/src/core/client/stream/test/comments/postReply.spec.tsx +++ b/src/core/client/stream/test/comments/postReply.spec.tsx @@ -5,7 +5,7 @@ import timekeeper from "timekeeper"; import { timeout } from "talk-common/utils"; import { createSinonStub } from "talk-framework/testHelpers"; -import { assets, settings, users } from "../fixtures"; +import { assets, baseComment, settings, users } from "../fixtures"; import create from "./create"; let testRenderer: ReactTestRenderer; @@ -39,23 +39,10 @@ beforeEach(() => { edge: { cursor: null, node: { + ...baseComment, id: "comment-x", author: users[0], body: "Hello world! (from server)", - createdAt: "2018-07-06T18:24:00.000Z", - replies: { - edges: [], - pageInfo: { endCursor: null, hasNextPage: false }, - }, - editing: { - edited: false, - editableUntil: "2018-07-06T18:24:30.000Z", - }, - actionCounts: { - reaction: { - total: 0, - }, - }, }, }, clientMutationId: "0", @@ -97,7 +84,7 @@ it("post a reply", async () => { .findByProps({ inputId: "comments-replyCommentForm-rte-comment-0" }) .props.onChange({ html: "Hello world!" }); - timekeeper.freeze(new Date("2018-07-06T18:24:00.000Z")); + timekeeper.freeze(new Date(baseComment.createdAt)); testRenderer.root .findByProps({ id: "comments-replyCommentForm-form-comment-0" }) .props.onSubmit(); diff --git a/src/core/client/stream/test/fixtures.ts b/src/core/client/stream/test/fixtures.ts index 3eee6a7eb..0b3cc05f9 100644 --- a/src/core/client/stream/test/fixtures.ts +++ b/src/core/client/stream/test/fixtures.ts @@ -21,127 +21,66 @@ export const users = [ }, ]; +export const baseComment = { + author: users[0], + body: "Comment Body", + createdAt: "2018-07-06T18:24:00.000Z", + replies: { edges: [], pageInfo: { endCursor: null, hasNextPage: false } }, + editing: { + edited: false, + editableUntil: "2018-07-06T18:24:30.000Z", + }, + actionCounts: { + reaction: { + total: 0, + }, + }, +}; + export const comments = [ { + ...baseComment, id: "comment-0", author: users[0], body: "Joining Too", - createdAt: "2018-07-06T18:24:00.000Z", - replies: { edges: [], pageInfo: { endCursor: null, hasNextPage: false } }, - editing: { - edited: false, - editableUntil: "2018-07-06T18:24:30.000Z", - }, - actionCounts: { - reaction: { - total: 0, - }, - }, }, { + ...baseComment, id: "comment-1", author: users[1], body: "What's up?", - createdAt: "2018-07-06T18:20:00.000Z", - replies: { edges: [], pageInfo: { endCursor: null, hasNextPage: false } }, - editing: { - edited: false, - editableUntil: "2018-07-06T18:20:30.000Z", - }, - actionCounts: { - reaction: { - total: 0, - }, - }, }, { + ...baseComment, id: "comment-2", author: users[2], body: "Hey!", - createdAt: "2018-07-06T18:14:00.000Z", - replies: { edges: [], pageInfo: { endCursor: null, hasNextPage: false } }, - editing: { - edited: false, - editableUntil: "2018-07-06T18:14:30.000Z", - }, - actionCounts: { - reaction: { - total: 0, - }, - }, }, { + ...baseComment, id: "comment-3", author: users[2], body: "Comment Body 3", - createdAt: "2018-07-06T18:14:00.000Z", - replies: { edges: [], pageInfo: { endCursor: null, hasNextPage: false } }, - editing: { - edited: false, - editableUntil: "2018-07-06T18:14:30.000Z", - }, - actionCounts: { - reaction: { - total: 0, - }, - }, }, { + ...baseComment, id: "comment-4", author: users[2], body: "Comment Body 4", - createdAt: "2018-07-06T18:14:00.000Z", - replies: { edges: [], pageInfo: { endCursor: null, hasNextPage: false } }, - editing: { - edited: false, - editableUntil: "2018-07-06T18:14:30.000Z", - }, - actionCounts: { - reaction: { - total: 0, - }, - }, }, { + ...baseComment, id: "comment-5", author: users[2], body: "Comment Body 5", - createdAt: "2018-07-06T18:14:00.000Z", - replies: { edges: [], pageInfo: { endCursor: null, hasNextPage: false } }, - editing: { - edited: false, - editableUntil: "2018-07-06T18:14:30.000Z", - }, - actionCounts: { - reaction: { - total: 0, - }, - }, - }, -]; - -export const assets = [ - { - id: "asset-1", - url: "http://localhost/assets/asset-1", - isClosed: false, - comments: { - edges: [ - { node: comments[0], cursor: comments[0].createdAt }, - { node: comments[1], cursor: comments[1].createdAt }, - ], - pageInfo: { - hasNextPage: false, - }, - }, }, ]; export const commentWithReplies = { + ...baseComment, id: "comment-with-replies", author: users[0], body: "I like yoghurt", - createdAt: "2018-07-06T18:24:00.000Z", replies: { edges: [ { node: comments[3], cursor: comments[3].createdAt }, @@ -151,22 +90,13 @@ export const commentWithReplies = { hasNextPage: false, }, }, - editing: { - edited: false, - editableUntil: "2018-07-06T18:24:30.000Z", - }, - actionCounts: { - reaction: { - total: 0, - }, - }, }; export const commentWithDeepReplies = { + ...baseComment, id: "comment-with-deep-replies", author: users[0], body: "I like yoghurt", - createdAt: "2018-07-06T18:24:00.000Z", replies: { edges: [ { node: commentWithReplies, cursor: commentWithReplies.createdAt }, @@ -176,112 +106,69 @@ export const commentWithDeepReplies = { hasNextPage: false, }, }, - editing: { - edited: false, - editableUntil: "2018-07-06T18:24:30.000Z", - }, - actionCounts: { - reaction: { - total: 0, - }, - }, -}; - -export const assetWithReplies = { - id: "asset-with-replies", - url: "http://localhost/assets/asset-with-replies", - isClosed: false, - comments: { - edges: [ - { node: comments[0], cursor: comments[0].createdAt }, - { node: commentWithReplies, cursor: commentWithReplies.createdAt }, - ], - pageInfo: { - hasNextPage: false, - }, - }, -}; - -export const assetWithDeepReplies = { - id: "asset-with-deep-replies", - url: "http://localhost/assets/asset-with-replies", - isClosed: false, - comments: { - edges: [ - { node: comments[0], cursor: comments[0].createdAt }, - { - node: commentWithDeepReplies, - cursor: commentWithDeepReplies.createdAt, - }, - ], - pageInfo: { - hasNextPage: false, - }, - }, }; export const commentWithDeepestReplies = { - ...commentWithReplies, + ...baseComment, id: "comment-with-deepest-replies", body: "body 0", replies: { - ...commentWithReplies.replies, + ...baseComment.replies, edges: [ { - cursor: commentWithReplies.createdAt, + cursor: baseComment.createdAt, node: { - ...commentWithReplies, + ...baseComment, id: "comment-with-deepest-replies-1", body: "body 1", replies: { - ...commentWithReplies.replies, + ...baseComment.replies, edges: [ { - cursor: commentWithReplies.createdAt, + cursor: baseComment.createdAt, node: { - ...commentWithReplies, + ...baseComment, id: "comment-with-deepest-replies-2", body: "body 2", replies: { - ...commentWithReplies.replies, + ...baseComment.replies, edges: [ { - cursor: commentWithReplies.createdAt, + cursor: baseComment.createdAt, node: { - ...commentWithReplies, + ...baseComment, id: "comment-with-deepest-replies-3", body: "body 3", replies: { - ...commentWithReplies.replies, + ...baseComment.replies, edges: [ { - cursor: commentWithReplies.createdAt, + cursor: baseComment.createdAt, node: { - ...commentWithReplies, + ...baseComment, id: "comment-with-deepest-replies-4", body: "body 4", replies: { - ...commentWithReplies.replies, + ...baseComment.replies, edges: [ { - cursor: commentWithReplies.createdAt, + cursor: baseComment.createdAt, node: { - ...commentWithReplies, + ...baseComment, id: "comment-with-deepest-replies-5", body: "body 5", replies: { - ...commentWithReplies.replies, + ...baseComment.replies, edges: [ { - cursor: - commentWithReplies.createdAt, + cursor: baseComment.createdAt, node: { - ...commentWithReplies, + ...baseComment, id: "comment-with-deepest-replies-6", body: "body 6", replies: { - ...commentWithReplies.replies, + ...baseComment.replies, edges: [], }, }, @@ -310,10 +197,70 @@ export const commentWithDeepestReplies = { }, }; +export const baseAsset = { + isClosed: false, + comments: { + edges: [], + pageInfo: { + hasNextPage: false, + }, + }, +}; + +export const assets = [ + { + ...baseAsset, + id: "asset-1", + url: "http://localhost/assets/asset-1", + comments: { + edges: [ + { node: comments[0], cursor: comments[0].createdAt }, + { node: comments[1], cursor: comments[1].createdAt }, + ], + pageInfo: { + hasNextPage: false, + }, + }, + }, +]; + +export const assetWithReplies = { + ...baseAsset, + id: "asset-with-replies", + url: "http://localhost/assets/asset-with-replies", + comments: { + edges: [ + { node: comments[0], cursor: comments[0].createdAt }, + { node: commentWithReplies, cursor: commentWithReplies.createdAt }, + ], + pageInfo: { + hasNextPage: false, + }, + }, +}; + +export const assetWithDeepReplies = { + ...baseAsset, + id: "asset-with-deep-replies", + url: "http://localhost/assets/asset-with-replies", + comments: { + edges: [ + { node: comments[0], cursor: comments[0].createdAt }, + { + node: commentWithDeepReplies, + cursor: commentWithDeepReplies.createdAt, + }, + ], + pageInfo: { + hasNextPage: false, + }, + }, +}; + export const assetWithDeepestReplies = { + ...baseAsset, id: "asset-with-deepest-replies", url: "http://localhost/assets/asset-with-replies", - isClosed: false, comments: { edges: [ {