decidim-comments 0.23.6 → 0.24.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/comments/bundle.js.map +1 -1
  3. data/app/assets/javascripts/decidim/comments/comments.component.js.es6 +292 -0
  4. data/app/assets/javascripts/decidim/comments/comments.component.test.js +581 -0
  5. data/app/assets/javascripts/decidim/comments/comments.js.erb +1 -1
  6. data/app/cells/decidim/comments/comment/actions.erb +7 -0
  7. data/app/cells/decidim/comments/comment/alignment_badge.erb +4 -0
  8. data/app/cells/decidim/comments/comment/author.erb +1 -0
  9. data/app/cells/decidim/comments/comment/show.erb +40 -0
  10. data/app/cells/decidim/comments/comment/utilities.erb +13 -0
  11. data/app/cells/decidim/comments/comment/votes.erb +25 -0
  12. data/app/cells/decidim/comments/comment_card_cell.rb +22 -0
  13. data/app/cells/decidim/comments/comment_cell.rb +142 -8
  14. data/app/cells/decidim/comments/comment_form/comment_as.erb +10 -0
  15. data/app/cells/decidim/comments/comment_form/show.erb +24 -0
  16. data/app/cells/decidim/comments/comment_form_cell.rb +94 -0
  17. data/app/cells/decidim/comments/comment_m/top.erb +1 -1
  18. data/app/cells/decidim/comments/comment_thread/show.erb +6 -0
  19. data/app/cells/decidim/comments/comment_thread/title.erb +3 -0
  20. data/app/cells/decidim/comments/comment_thread_cell.rb +30 -0
  21. data/app/cells/decidim/comments/comments/add_comment.erb +30 -0
  22. data/app/cells/decidim/comments/comments/blocked_comments_warning.erb +3 -0
  23. data/app/cells/decidim/comments/comments/order_control.erb +37 -0
  24. data/app/cells/decidim/comments/comments/show.erb +32 -0
  25. data/app/cells/decidim/comments/comments/single_comment_warning.erb +9 -0
  26. data/app/cells/decidim/comments/comments/user_comments_blocked_warning.erb +3 -0
  27. data/app/cells/decidim/comments/comments_cell.rb +134 -0
  28. data/app/commands/decidim/comments/vote_comment.rb +34 -10
  29. data/app/controllers/decidim/comments/application_controller.rb +16 -0
  30. data/app/controllers/decidim/comments/comments_controller.rb +122 -0
  31. data/app/controllers/decidim/comments/votes_controller.rb +41 -0
  32. data/app/events/decidim/comments/comment_created_event.rb +1 -1
  33. data/app/events/decidim/comments/comment_downvoted_event.rb +8 -0
  34. data/app/events/decidim/comments/comment_upvoted_event.rb +8 -0
  35. data/app/events/decidim/comments/comment_voted_event.rb +26 -0
  36. data/app/forms/decidim/comments/comment_form.rb +6 -2
  37. data/app/models/decidim/comments/comment.rb +22 -8
  38. data/app/models/decidim/comments/seed.rb +1 -1
  39. data/app/permissions/decidim/comments/permissions.rb +59 -0
  40. data/app/queries/decidim/comments/metrics/comment_participants_metric_measure.rb +2 -2
  41. data/app/queries/decidim/comments/metrics/comments_metric_manage.rb +5 -6
  42. data/app/queries/decidim/comments/sorted_comments.rb +18 -14
  43. data/app/views/decidim/comments/comments/_comment.html.erb +5 -0
  44. data/app/views/decidim/comments/comments/_comments.html.erb +1 -0
  45. data/app/views/decidim/comments/comments/create.js.erb +16 -0
  46. data/app/views/decidim/comments/comments/error.js.erb +1 -0
  47. data/app/views/decidim/comments/comments/index.js.erb +24 -0
  48. data/app/views/decidim/comments/comments/reload.js.erb +21 -0
  49. data/app/views/decidim/comments/votes/create.js.erb +23 -0
  50. data/app/views/decidim/comments/votes/error.js.erb +1 -0
  51. data/config/locales/ar.yml +0 -2
  52. data/config/locales/ca.yml +7 -2
  53. data/config/locales/cs.yml +24 -7
  54. data/config/locales/de.yml +17 -2
  55. data/config/locales/el.yml +0 -2
  56. data/config/locales/en.yml +17 -2
  57. data/config/locales/es-MX.yml +7 -2
  58. data/config/locales/es-PY.yml +7 -2
  59. data/config/locales/es.yml +7 -2
  60. data/config/locales/eu.yml +0 -2
  61. data/config/locales/fi-plain.yml +17 -2
  62. data/config/locales/fi.yml +17 -2
  63. data/config/locales/fr-CA.yml +17 -2
  64. data/config/locales/fr.yml +17 -2
  65. data/config/locales/gl.yml +7 -2
  66. data/config/locales/hu.yml +0 -2
  67. data/config/locales/id-ID.yml +0 -2
  68. data/config/locales/is-IS.yml +0 -1
  69. data/config/locales/it.yml +4 -2
  70. data/config/locales/ja.yml +8 -4
  71. data/config/locales/lv.yml +0 -2
  72. data/config/locales/nl.yml +0 -2
  73. data/config/locales/no.yml +0 -2
  74. data/config/locales/pl.yml +19 -2
  75. data/config/locales/pt-BR.yml +0 -2
  76. data/config/locales/pt.yml +0 -2
  77. data/config/locales/ro-RO.yml +0 -3
  78. data/config/locales/ru.yml +0 -2
  79. data/config/locales/sk.yml +0 -2
  80. data/config/locales/sv.yml +7 -2
  81. data/config/locales/tr-TR.yml +7 -2
  82. data/config/locales/uk.yml +0 -1
  83. data/config/locales/zh-CN.yml +0 -2
  84. data/lib/decidim/api/add_comment_type.rb +13 -0
  85. data/lib/decidim/api/comment_mutation_type.rb +22 -0
  86. data/lib/decidim/api/comment_type.rb +89 -0
  87. data/lib/decidim/api/commentable_interface.rb +50 -0
  88. data/lib/decidim/api/commentable_mutation_type.rb +30 -0
  89. data/{app/types/decidim/comments → lib/decidim/api}/commentable_type.rb +2 -5
  90. data/lib/decidim/comments/api.rb +12 -0
  91. data/lib/decidim/comments/comments_helper.rb +10 -52
  92. data/lib/decidim/comments/engine.rb +9 -7
  93. data/lib/decidim/comments/mutation_extensions.rb +22 -22
  94. data/lib/decidim/comments/query_extensions.rb +12 -14
  95. data/lib/decidim/comments/test/shared_examples/comment_voted_event.rb +65 -0
  96. data/lib/decidim/comments/test.rb +1 -0
  97. data/lib/decidim/comments/version.rb +1 -1
  98. data/lib/decidim/comments.rb +1 -3
  99. metadata +67 -66
  100. data/app/assets/javascripts/decidim/comments/bundle.js +0 -268
  101. data/app/frontend/application/apollo_client.ts +0 -12
  102. data/app/frontend/application/application.component.test.tsx +0 -23
  103. data/app/frontend/application/application.component.tsx +0 -35
  104. data/app/frontend/application/icon.component.test.tsx +0 -38
  105. data/app/frontend/application/icon.component.tsx +0 -46
  106. data/app/frontend/comments/add_comment_form.component.test.tsx +0 -265
  107. data/app/frontend/comments/add_comment_form.component.tsx +0 -482
  108. data/app/frontend/comments/comment.component.test.tsx +0 -490
  109. data/app/frontend/comments/comment.component.tsx +0 -677
  110. data/app/frontend/comments/comment_order_selector.component.test.tsx +0 -29
  111. data/app/frontend/comments/comment_order_selector.component.tsx +0 -106
  112. data/app/frontend/comments/comment_thread.component.test.tsx +0 -82
  113. data/app/frontend/comments/comment_thread.component.tsx +0 -81
  114. data/app/frontend/comments/comments.component.test.tsx +0 -150
  115. data/app/frontend/comments/comments.component.tsx +0 -289
  116. data/app/frontend/comments/down_vote_button.component.test.tsx +0 -59
  117. data/app/frontend/comments/down_vote_button.component.tsx +0 -133
  118. data/app/frontend/comments/up_vote_button.component.test.tsx +0 -59
  119. data/app/frontend/comments/up_vote_button.component.tsx +0 -133
  120. data/app/frontend/comments/vote_button.component.tsx +0 -50
  121. data/app/frontend/comments/vote_button_component.test.tsx +0 -64
  122. data/app/frontend/entry.ts +0 -38
  123. data/app/frontend/entry_test.ts +0 -6
  124. data/app/frontend/fragments/add_comment_form_commentable.fragment.graphql +0 -4
  125. data/app/frontend/fragments/add_comment_form_session.fragment.graphql +0 -6
  126. data/app/frontend/fragments/comment.fragment.graphql +0 -14
  127. data/app/frontend/fragments/comment_data.fragment.graphql +0 -27
  128. data/app/frontend/fragments/comment_thread.fragment.graphql +0 -6
  129. data/app/frontend/fragments/down_vote_button.fragment.graphql +0 -6
  130. data/app/frontend/fragments/up_vote_button.fragment.graphql +0 -6
  131. data/app/frontend/mutations/add_comment.mutation.graphql +0 -9
  132. data/app/frontend/mutations/down_vote.mutation.graphql +0 -9
  133. data/app/frontend/mutations/up_vote.mutation.graphql +0 -9
  134. data/app/frontend/queries/comments.query.graphql +0 -26
  135. data/app/frontend/support/asset_url.ts +0 -11
  136. data/app/frontend/support/generate_comments_data.ts +0 -49
  137. data/app/frontend/support/generate_user_data.ts +0 -14
  138. data/app/frontend/support/generate_user_group_data.ts +0 -14
  139. data/app/frontend/support/graphql_transformer.js +0 -32
  140. data/app/frontend/support/load_translations.ts +0 -48
  141. data/app/frontend/support/require_all.ts +0 -10
  142. data/app/frontend/support/resolve_graphql_query.ts +0 -37
  143. data/app/frontend/support/schema.ts +0 -2026
  144. data/app/types/decidim/comments/commentable_interface.rb +0 -61
  145. data/app/types/decidim/comments/commentable_mutation_type.rb +0 -33
  146. data/lib/decidim/comments/api/add_comment_type.rb +0 -13
  147. data/lib/decidim/comments/api/comment_mutation_type.rb +0 -20
  148. data/lib/decidim/comments/api/comment_type.rb +0 -89
@@ -1,106 +0,0 @@
1
- import * as React from "react";
2
-
3
- const { I18n } = require("react-i18nify");
4
-
5
- interface CommentOrderSelectorProps {
6
- defaultOrderBy: string;
7
- reorderComments: (orderBy: string) => void;
8
- }
9
-
10
- interface CommentOrderSelectorState {
11
- orderBy: string;
12
- }
13
-
14
- /**
15
- * A simple static component with the comment's order selector markup
16
- * @class
17
- * @augments Component
18
- * @todo Needs a proper implementation
19
- */
20
- class CommentOrderSelector extends React.Component<CommentOrderSelectorProps, CommentOrderSelectorState> {
21
- private dropdown: HTMLUListElement;
22
-
23
- constructor(props: CommentOrderSelectorProps) {
24
- super(props);
25
-
26
- this.state = {
27
- orderBy: this.props.defaultOrderBy
28
- };
29
- }
30
-
31
- public setDropdown = (dropdown: HTMLUListElement) => this.dropdown = dropdown;
32
-
33
- public componentDidMount() {
34
- window.$(this.dropdown).foundation();
35
- }
36
-
37
- public render() {
38
- const { orderBy } = this.state;
39
-
40
- return (
41
- <div className="order-by__dropdown order-by__dropdown--right">
42
- <span className="order-by__text">{I18n.t("components.comment_order_selector.title")}</span>
43
- <ul
44
- className="dropdown menu"
45
- data-dropdown-menu="data-dropdown-menu"
46
- data-autoclose="false"
47
- data-disable-hover="true"
48
- data-click-open="true"
49
- data-close-on-click="true"
50
- tabIndex={-1}
51
- ref={this.setDropdown}
52
- >
53
- <li className="is-dropdown-submenu-parent" tabIndex={-1}>
54
- <a
55
- href="#"
56
- id="comments-order-menu-control"
57
- aria-label={I18n.t("components.comment_order_selector.title")}
58
- aria-controls="comments-order-menu"
59
- aria-haspopup="true"
60
- >
61
- {I18n.t(`components.comment_order_selector.order.${orderBy}`)}
62
- </a>
63
- <ul
64
- className="menu is-dropdown-submenu"
65
- id="language-chooser-menu"
66
- role="menu"
67
- aria-labelledby="comments-order-menu-control"
68
- tabIndex={-1}
69
- >
70
- <li>
71
- <a href="#" className="test" onClick={this.updateOrder("best_rated")} tabIndex={-1}>
72
- {I18n.t("components.comment_order_selector.order.best_rated")}
73
- </a>
74
- </li>
75
- <li>
76
- <a href="#" onClick={this.updateOrder("recent")} tabIndex={-1}>
77
- {I18n.t("components.comment_order_selector.order.recent")}
78
- </a>
79
- </li>
80
- <li>
81
- <a href="#" onClick={this.updateOrder("older")} tabIndex={-1}>
82
- {I18n.t("components.comment_order_selector.order.older")}
83
- </a>
84
- </li>
85
- <li>
86
- <a href="" onClick={this.updateOrder("most_discussed")} tabIndex={-1}>
87
- {I18n.t("components.comment_order_selector.order.most_discussed")}
88
- </a>
89
- </li>
90
- </ul>
91
- </li>
92
- </ul>
93
- </div>
94
- );
95
- }
96
-
97
- private updateOrder = (orderBy: string) => {
98
- return (event: React.MouseEvent<HTMLAnchorElement>) => {
99
- event.preventDefault();
100
- this.setState({ orderBy });
101
- this.props.reorderComments(orderBy);
102
- };
103
- }
104
- }
105
-
106
- export default CommentOrderSelector;
@@ -1,82 +0,0 @@
1
- import { shallow } from "enzyme";
2
- import * as React from "react";
3
-
4
- import { CommentFragment } from "../support/schema";
5
- import Comment from "./comment.component";
6
- import CommentThread from "./comment_thread.component";
7
-
8
- import generateCommentsData from "../support/generate_comments_data";
9
- import generateCUserData from "../support/generate_user_data";
10
- import { loadLocaleTranslations } from "../support/load_translations";
11
-
12
- describe("<CommentThread commentsMaxLength={commentsMaxLength} />", () => {
13
- const commentsMaxLength: number = 1000;
14
- const orderBy = "older";
15
- const rootCommentable = {
16
- id: "1",
17
- type: "Decidim::DummyResources::DummyResource"
18
- };
19
- let comment: CommentFragment;
20
- let session: any = null;
21
-
22
- beforeEach(() => {
23
- loadLocaleTranslations("en");
24
- const commentsData = generateCommentsData(1);
25
-
26
- session = {
27
- user: generateCUserData()
28
- };
29
- comment = commentsData[0];
30
- });
31
-
32
- describe("when comment doesn't have comments", () => {
33
- it("should not render a title with author name", () => {
34
- const wrapper = shallow(<CommentThread commentsMaxLength={commentsMaxLength} comment={comment} session={session} rootCommentable={rootCommentable} orderBy={orderBy} />);
35
- expect(wrapper.find("h6.comment-thread__title").exists()).toBeFalsy();
36
- });
37
- });
38
-
39
- describe("when comment does has comments", () => {
40
- beforeEach(() => {
41
- comment.hasComments = true;
42
- });
43
-
44
- it("should render a h6 comment-thread__title with author name", () => {
45
- const wrapper = shallow(<CommentThread commentsMaxLength={commentsMaxLength} comment={comment} session={session} rootCommentable={rootCommentable} orderBy={orderBy} />);
46
- expect(wrapper.find("h6.comment-thread__title").text()).toContain(`Conversation with ${comment.author.name}`);
47
- });
48
-
49
- describe("when the author's account has been deleted", () => {
50
- beforeEach(() => {
51
- comment.author.deleted = true;
52
- });
53
-
54
- it("should render a h6 comment-thread__title with 'Deleted participant'", () => {
55
- const wrapper = shallow(<CommentThread commentsMaxLength={commentsMaxLength} comment={comment} session={session} rootCommentable={rootCommentable} orderBy={orderBy} />);
56
- expect(wrapper.find("h6.comment-thread__title").text()).toContain("Conversation with Deleted participant");
57
- });
58
- });
59
- });
60
-
61
- describe("should render a Comment", () => {
62
- it("and pass the session as a prop to it", () => {
63
- const wrapper = shallow(<CommentThread commentsMaxLength={commentsMaxLength} comment={comment} session={session} rootCommentable={rootCommentable} orderBy={orderBy} />);
64
- expect(wrapper.find(Comment).first().props()).toHaveProperty("session", session);
65
- });
66
-
67
- it("and pass comment data as a prop to it", () => {
68
- const wrapper = shallow(<CommentThread commentsMaxLength={commentsMaxLength} comment={comment} session={session} rootCommentable={rootCommentable} orderBy={orderBy} />);
69
- expect(wrapper.find(Comment).first().props()).toHaveProperty("comment", comment);
70
- });
71
-
72
- it("and pass the votable as a prop to it", () => {
73
- const wrapper = shallow(<CommentThread commentsMaxLength={commentsMaxLength} comment={comment} session={session} votable={true} rootCommentable={rootCommentable} orderBy={orderBy} />);
74
- expect(wrapper.find(Comment).first().props()).toHaveProperty("votable", true);
75
- });
76
-
77
- it("and pass the isRootComment equal true", () => {
78
- const wrapper = shallow(<CommentThread commentsMaxLength={commentsMaxLength} comment={comment} session={session} votable={true} rootCommentable={rootCommentable} orderBy={orderBy} />);
79
- expect(wrapper.find(Comment).first().props()).toHaveProperty("isRootComment", true);
80
- });
81
- });
82
- });
@@ -1,81 +0,0 @@
1
- import * as React from "react";
2
-
3
- import Comment from "./comment.component";
4
-
5
- import {
6
- AddCommentFormCommentableFragment,
7
- AddCommentFormSessionFragment,
8
- CommentFragment
9
- } from "../support/schema";
10
-
11
- const { I18n } = require("react-i18nify");
12
-
13
- interface CommentThreadProps {
14
- comment: CommentFragment;
15
- session: AddCommentFormSessionFragment & {
16
- user: any;
17
- } | null;
18
- votable?: boolean;
19
- rootCommentable: AddCommentFormCommentableFragment;
20
- orderBy: string;
21
- commentsMaxLength: number;
22
- }
23
-
24
- /**
25
- * Define a collection of comments. It represents a conversation with multiple users.
26
- * @class
27
- * @augments Component
28
- * @todo It doesn't handle multiple comments yet
29
- */
30
- class CommentThread extends React.Component<CommentThreadProps> {
31
- public static defaultProps: any = {
32
- session: null,
33
- votable: false
34
- };
35
-
36
- public render() {
37
- const { comment, session, votable, rootCommentable, orderBy, commentsMaxLength } = this.props;
38
-
39
- return (
40
- <div>
41
- {this._renderTitle()}
42
- <div className="comment-thread">
43
- <Comment
44
- comment={comment}
45
- session={session}
46
- votable={votable}
47
- isRootComment={true}
48
- rootCommentable={rootCommentable}
49
- orderBy={orderBy}
50
- commentsMaxLength={commentsMaxLength}
51
- />
52
- </div>
53
- </div>
54
- );
55
- }
56
-
57
- /**
58
- * Render conversation title if comment has commments
59
- * @private
60
- * @returns {Void|DOMElement} - The conversation's title
61
- */
62
- private _renderTitle() {
63
- const { comment: { author, hasComments } } = this.props;
64
-
65
- if (hasComments) {
66
- return (
67
- <h6 className="comment-thread__title">
68
- {
69
- author.deleted ?
70
- I18n.t("components.comment_thread.title", { authorName: I18n.t("components.comment.deleted_user") }) :
71
- I18n.t("components.comment_thread.title", { authorName: author.name })
72
- }
73
- </h6>
74
- );
75
- }
76
-
77
- return null;
78
- }
79
- }
80
-
81
- export default CommentThread;
@@ -1,150 +0,0 @@
1
- import { shallow } from "enzyme";
2
- import * as React from "react";
3
-
4
- import AddCommentForm from "./add_comment_form.component";
5
- import CommentOrderSelector from "./comment_order_selector.component";
6
- import CommentThread from "./comment_thread.component";
7
- import { Comments, commentsQuery } from "./comments.component";
8
-
9
- import generateCommentsData from "../support/generate_comments_data";
10
- import generateUserData from "../support/generate_user_data";
11
- import resolveGraphQLQuery from "../support/resolve_graphql_query";
12
-
13
- import { loadLocaleTranslations } from "../support/load_translations";
14
-
15
- describe("<Comments commentsMaxLength={commentsMaxLength} />", () => {
16
- let commentable: any = {};
17
- let session: any = null;
18
- const commentsMaxLength: number = 1000;
19
- const commentableId = "1";
20
- const commentableType = "Decidim::DummyResources::DummyResource";
21
- const orderBy = "older";
22
- const locale = "en";
23
- const toggleTranslations = false;
24
- const reorderComments = jasmine.createSpy("reorderComments");
25
-
26
- beforeEach(() => {
27
- loadLocaleTranslations("en");
28
- const userData = generateUserData();
29
- const commentsData = generateCommentsData(15);
30
-
31
- const result = resolveGraphQLQuery(commentsQuery, {
32
- filterResult: false,
33
- rootValue: {
34
- session: {
35
- user: userData
36
- },
37
- commentable: {
38
- acceptsNewComments: true,
39
- userAllowedToComment: true,
40
- commentsHaveAlignment: true,
41
- commentsHaveVotes: true,
42
- totalCommentsCount: 15,
43
- comments: commentsData
44
- }
45
- },
46
- variables: {
47
- orderBy,
48
- commentableId,
49
- commentableType
50
- }
51
- });
52
-
53
- session = result.session;
54
- commentable = result.commentable;
55
- });
56
-
57
- it("renders loading-comments class and the respective loading text", () => {
58
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} loading={true} />);
59
- expect(wrapper.find(".loading-comments").exists()).toBeTruthy();
60
- expect(wrapper.find("h2").text()).toEqual("Loading comments ...");
61
- });
62
-
63
- it("renders a div of id comments", () => {
64
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} />);
65
- expect(wrapper.find("#comments").exists()).toBeTruthy();
66
- });
67
-
68
- describe("renders a CommentThread component for each comment", () => {
69
- it("and pass filter comment data as a prop to it", () => {
70
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} />);
71
- expect(wrapper.find(CommentThread).length).toEqual(commentable.comments.length);
72
- wrapper.find(CommentThread).forEach((node, idx) => {
73
- expect(node.prop("comment")).toEqual(commentable.comments[idx]);
74
- });
75
- });
76
-
77
- it("and pass the session as a prop to it", () => {
78
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} />);
79
- expect(wrapper.find(CommentThread).length).toEqual(commentable.comments.length);
80
- wrapper.find(CommentThread).forEach((node) => {
81
- expect(node.prop("session")).toEqual(session);
82
- });
83
- });
84
-
85
- it("and pass the commentable 'commentsHaveVotes' property as a prop to it", () => {
86
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} />);
87
- expect(wrapper.find(CommentThread).length).toEqual(commentable.comments.length);
88
- wrapper.find(CommentThread).forEach((node) => {
89
- expect(node.prop("votable")).toBeTruthy();
90
- });
91
- });
92
- });
93
-
94
- it("renders comments count", () => {
95
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} />);
96
- const rex = new RegExp(`${commentable.comments.length} comments`);
97
- expect(wrapper.find("h2.section-heading").text()).toMatch(rex);
98
- });
99
-
100
- it("renders a AddCommentForm component and pass the commentable 'commentsHaveAlignment' as a prop", () => {
101
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} />);
102
- expect(wrapper.find(AddCommentForm).length).toEqual(1);
103
- expect(wrapper.find(AddCommentForm).prop("arguable")).toBeTruthy();
104
- });
105
-
106
- describe("when the commentable cannot accept new comments", () => {
107
- beforeEach(() => {
108
- commentable.acceptsNewComments = false;
109
- commentable.userAllowedToComment = false;
110
- });
111
-
112
- it("doesn't render an AddCommentForm component", () => {
113
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} />);
114
- expect(wrapper.find(AddCommentForm).exists()).toBeFalsy();
115
- });
116
-
117
- it("renders a callout message to inform the user that comments are blocked", () => {
118
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} />);
119
- expect(wrapper.find(".callout.warning").text()).toContain("disabled");
120
- });
121
- });
122
-
123
- describe("when the commentable can accept new comments but user is not allowed to comment", () => {
124
- beforeEach(() => {
125
- commentable.userAllowedToComment = false;
126
- });
127
-
128
- it("doesn't render an AddCommentForm component", () => {
129
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} />);
130
- expect(wrapper.find(AddCommentForm).exists()).toBeFalsy();
131
- });
132
-
133
- it("renders a callout message to inform the user that comments are blocked", () => {
134
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} />);
135
- expect(wrapper.find(".callout.warning").text()).toContain("not able");
136
- });
137
- });
138
-
139
- describe("renders a CommentOrderSelector component", () => {
140
- it("and pass the reorderComments as a prop to it", () => {
141
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} />);
142
- expect(wrapper.find(CommentOrderSelector).prop("reorderComments")).toEqual(reorderComments);
143
- });
144
-
145
- it("and pass the orderBy as a prop to it", () => {
146
- const wrapper = shallow(<Comments locale={locale} toggleTranslations={toggleTranslations} commentsMaxLength={commentsMaxLength} commentable={commentable} session={session} reorderComments={reorderComments} orderBy={orderBy} />);
147
- expect(wrapper.find(CommentOrderSelector).prop("defaultOrderBy")).toEqual("older");
148
- });
149
- });
150
- });