diff --git a/src/plugins/comment_paragraph/hotspot/article-content/article-content.component.spec.ts b/src/plugins/comment_paragraph/hotspot/article-content/article-content.component.spec.ts index 429f7a1..ad38832 100644 --- a/src/plugins/comment_paragraph/hotspot/article-content/article-content.component.spec.ts +++ b/src/plugins/comment_paragraph/hotspot/article-content/article-content.component.spec.ts @@ -24,13 +24,87 @@ describe("Components", () => { }); it("return false in isDiscussion when other type was specified", () => { - helper.changeProperties({article: {type: "TextArticle"}}); + helper.changeProperties({ article: { type: "TextArticle" } }); expect(helper.component.isDiscussion()).toBeFalsy(); }); it("return true in isDiscussion when discussion type was specified", () => { - helper.changeProperties({article: {type: "CommentParagraphPlugin::Discussion"}}); + helper.changeProperties({ article: { type: "CommentParagraphPlugin::Discussion" } }); expect(helper.component.isDiscussion()).toBeTruthy(); }); + + it("return true in notOpened when start date is after today", () => { + let date = new Date(); + date.setDate(date.getDate() + 1); + helper.changeProperties({ article: { start_date: date.toISOString() } }); + expect(helper.component.notOpened()).toBeTruthy(); + expect(helper.component.available()).toBeFalsy(); + expect(helper.component.closed()).toBeFalsy(); + }); + + it("return false in notOpened when start date is before today", () => { + let date = new Date(); + date.setDate(date.getDate() - 1); + helper.changeProperties({ article: { start_date: date.toISOString() } }); + expect(helper.component.notOpened()).toBeFalsy(); + }); + + it("return false in notOpened when start date is null", () => { + helper.changeProperties({ article: { start_date: null } }); + expect(helper.component.notOpened()).toBeFalsy(); + }); + + it("return true in closed when end date is before today", () => { + let date = new Date(); + date.setDate(date.getDate() - 1); + helper.changeProperties({ article: { end_date: date.toISOString() } }); + expect(helper.component.closed()).toBeTruthy(); + expect(helper.component.available()).toBeFalsy(); + expect(helper.component.notOpened()).toBeFalsy(); + }); + + it("return false in closed when start date is after today", () => { + let date = new Date(); + date.setDate(date.getDate() + 1); + helper.changeProperties({ article: { end_date: date.toISOString() } }); + expect(helper.component.closed()).toBeFalsy(); + }); + + it("return false in closed when end date is null", () => { + helper.changeProperties({ article: { start_date: null } }); + expect(helper.component.closed()).toBeFalsy(); + }); + + it("return true in available when start date is before today and end date is after", () => { + let date = new Date(); + date.setDate(date.getDate() - 1); + let startDate = date.toISOString(); + date.setDate(date.getDate() + 3); + let endDate = date.toISOString(); + helper.changeProperties({ article: { start_date: startDate, end_date: endDate } }); + expect(helper.component.available()).toBeTruthy(); + expect(helper.component.closed()).toBeFalsy(); + expect(helper.component.notOpened()).toBeFalsy(); + }); + + it("return true in available when start date is before today and end date is null", () => { + let date = new Date(); + date.setDate(date.getDate() - 1); + let startDate = date.toISOString(); + helper.changeProperties({ article: { start_date: startDate, end_date: null } }); + expect(helper.component.available()).toBeTruthy(); + expect(helper.component.closed()).toBeFalsy(); + expect(helper.component.notOpened()).toBeFalsy(); + }); + + it("return true in available when start date is null and end date is after today", () => { + let date = new Date(); + date.setDate(date.getDate() + 3); + let endDate = date.toISOString(); + helper.changeProperties({ article: { start_date: null, end_date: endDate } }); + expect(helper.component.available()).toBeTruthy(); + expect(helper.component.closed()).toBeFalsy(); + expect(helper.component.notOpened()).toBeFalsy(); + }); }); }); diff --git a/src/plugins/comment_paragraph/hotspot/article-content/article-content.component.ts b/src/plugins/comment_paragraph/hotspot/article-content/article-content.component.ts index 2feffec..ff65503 100644 --- a/src/plugins/comment_paragraph/hotspot/article-content/article-content.component.ts +++ b/src/plugins/comment_paragraph/hotspot/article-content/article-content.component.ts @@ -13,4 +13,20 @@ export class CommentParagraphArticleContentHotspotComponent { isDiscussion() { return this.article.type === "CommentParagraphPlugin::Discussion"; } + + notOpened() { + let now = new Date(); + return !!this.article.start_date && new Date(this.article.start_date) > now; + } + + available() { + let now = new Date(); + return (!this.article.start_date || new Date(this.article.start_date) <= now) && + (!this.article.end_date || new Date(this.article.end_date) >= now); + } + + closed() { + let now = new Date(); + return !!this.article.end_date && new Date(this.article.end_date) < now; + } } diff --git a/src/plugins/comment_paragraph/hotspot/article-content/article-content.html b/src/plugins/comment_paragraph/hotspot/article-content/article-content.html index 936ae69..f1acb89 100644 --- a/src/plugins/comment_paragraph/hotspot/article-content/article-content.html +++ b/src/plugins/comment_paragraph/hotspot/article-content/article-content.html @@ -1,11 +1,21 @@