From 170fb47daea9f4556b561b50c862e51fafc1fef0 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 11 Sep 2018 17:32:46 +0200 Subject: [PATCH] More unit tests --- .../client/stream/components/Comment/Comment.spec.tsx | 2 ++ src/core/client/stream/components/Comment/Comment.tsx | 4 ++-- .../Comment/__snapshots__/Comment.spec.tsx.snap | 7 ++++++- .../Comment/__snapshots__/IndentedComment.spec.tsx.snap | 1 - src/core/common/utils/isBeforeDate.spec.ts | 9 +++++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/core/client/stream/components/Comment/Comment.spec.tsx b/src/core/client/stream/components/Comment/Comment.spec.tsx index cae068012..f8d14f6eb 100644 --- a/src/core/client/stream/components/Comment/Comment.spec.tsx +++ b/src/core/client/stream/components/Comment/Comment.spec.tsx @@ -12,6 +12,8 @@ it("renders username and body", () => { }, body: "Woof", createdAt: "1995-12-17T03:24:00.000Z", + topBarRight: "topBarRight", + footer: "footer", }; const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); diff --git a/src/core/client/stream/components/Comment/Comment.tsx b/src/core/client/stream/components/Comment/Comment.tsx index 02dd50bfd..9a03094cc 100644 --- a/src/core/client/stream/components/Comment/Comment.tsx +++ b/src/core/client/stream/components/Comment/Comment.tsx @@ -15,8 +15,8 @@ export interface CommentProps { } | null; body: string | null; createdAt: string; - topBarRight?: ReactElement | Array>; - footer?: ReactElement | Array>; + topBarRight?: React.ReactNode; + footer?: React.ReactNode; } const Comment: StatelessComponent = props => { diff --git a/src/core/client/stream/components/Comment/__snapshots__/Comment.spec.tsx.snap b/src/core/client/stream/components/Comment/__snapshots__/Comment.spec.tsx.snap index cf9aa58ab..7d13e23ea 100644 --- a/src/core/client/stream/components/Comment/__snapshots__/Comment.spec.tsx.snap +++ b/src/core/client/stream/components/Comment/__snapshots__/Comment.spec.tsx.snap @@ -18,6 +18,9 @@ exports[`renders username and body 1`] = ` 1995-12-17T03:24:00.000Z +
+ topBarRight +
Woof @@ -26,6 +29,8 @@ exports[`renders username and body 1`] = ` className="Comment-footer" direction="row" itemGutter="half" - /> + > + footer + `; diff --git a/src/core/client/stream/components/Comment/__snapshots__/IndentedComment.spec.tsx.snap b/src/core/client/stream/components/Comment/__snapshots__/IndentedComment.spec.tsx.snap index ae2d56dee..d264e4050 100644 --- a/src/core/client/stream/components/Comment/__snapshots__/IndentedComment.spec.tsx.snap +++ b/src/core/client/stream/components/Comment/__snapshots__/IndentedComment.spec.tsx.snap @@ -12,7 +12,6 @@ exports[`renders correctly 1`] = ` } body="Woof" createdAt="1995-12-17T03:24:00.000Z" - id="comment-id" /> `; diff --git a/src/core/common/utils/isBeforeDate.spec.ts b/src/core/common/utils/isBeforeDate.spec.ts index e69de29bb..4359ca55a 100644 --- a/src/core/common/utils/isBeforeDate.spec.ts +++ b/src/core/common/utils/isBeforeDate.spec.ts @@ -0,0 +1,9 @@ +import timekeeper from "timekeeper"; +import isBeforeDate from "./isBeforeDate"; + +it("works correctly", () => { + timekeeper.freeze(new Date("2018-07-06T18:24:00.000Z")); + expect(isBeforeDate(new Date("2018-07-06T18:24:30.000Z"))).toBe(true); + expect(isBeforeDate(new Date("2018-07-06T18:23:30.000Z"))).toBe(false); + timekeeper.reset(); +});