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,12 +0,0 @@
1
- import { InMemoryCache } from "apollo-cache-inmemory";
2
- import { ApolloClient } from "apollo-client";
3
- import { HttpLink } from "apollo-link-http";
4
-
5
- import "unfetch/polyfill";
6
-
7
- const client = new ApolloClient({
8
- link: new HttpLink({ uri: "/api", credentials: "same-origin", fetch }),
9
- cache: new InMemoryCache()
10
- });
11
-
12
- export default client;
@@ -1,23 +0,0 @@
1
- import { shallow } from "enzyme";
2
- import * as React from "react";
3
-
4
- import Application from "./application.component";
5
-
6
- const { I18n } = require("react-i18nify");
7
-
8
- describe("<Application />", () => {
9
- afterEach(() => {
10
- I18n.setLocale("en");
11
- });
12
-
13
- it("should set I18n locale to locale prop", () => {
14
- spyOn(I18n, "setLocale");
15
- const locale = "ca";
16
- shallow(
17
- <Application locale={locale}>
18
- <div>My application</div>
19
- </Application>
20
- );
21
- expect(I18n.setLocale).toHaveBeenCalledWith(locale);
22
- });
23
- });
@@ -1,35 +0,0 @@
1
- import * as React from "react";
2
- import { ApolloProvider } from "react-apollo";
3
-
4
- import apolloClient from "./apollo_client";
5
-
6
- const { I18n } = require("react-i18nify");
7
-
8
- interface ApplicationProps {
9
- locale: string;
10
- }
11
-
12
- /**
13
- * Wrapper component for all React applications using Apollo
14
- * @class
15
- * @augments Component
16
- */
17
- export default class Application extends React.Component<ApplicationProps> {
18
- constructor(props: ApplicationProps) {
19
- const { locale } = props;
20
-
21
- I18n.setLocale(locale);
22
-
23
- super(props);
24
- }
25
-
26
- public render() {
27
- const { children } = this.props;
28
-
29
- return (
30
- <ApolloProvider client={apolloClient}>
31
- {children}
32
- </ApolloProvider>
33
- );
34
- }
35
- }
@@ -1,38 +0,0 @@
1
- import { mount, shallow } from "enzyme";
2
- import * as React from "react";
3
-
4
- import { Icon } from "./icon.component";
5
-
6
- describe("<Icon /", () => {
7
- beforeEach(() => {
8
- window.DecidimComments = {
9
- assets: {
10
- "icons.svg": "/assets/icons.svg"
11
- }
12
- };
13
- });
14
-
15
- it("should render a svg with class defined by prop className", () => {
16
- const wrapper = shallow(<Icon name="icon-thumb-down" />);
17
- expect(wrapper.find("svg.icon-thumb-down").exists()).toBeTruthy();
18
- });
19
-
20
- it("should render a svg icon using the 'icons.svg' url and name", () => {
21
- const wrapper = shallow(<Icon name="icon-thumb-up" />);
22
- expect(wrapper.find("svg use").prop("xlinkHref")).toBe(
23
- "/assets/icons.svg#icon-thumb-up"
24
- );
25
- });
26
-
27
- it("has a default prop iconExtraClassName with value 'icon--before'", () => {
28
- const wrapper = mount(<Icon name="icon-thumb-up" />);
29
- expect(wrapper.prop("iconExtraClassName")).toBe("icon--before");
30
- });
31
-
32
- it("renders the svg with an extra class defined by iconExtraClassName", () => {
33
- const wrapper = mount(
34
- <Icon name="icon-thumb-up" iconExtraClassName="icon--small" />
35
- );
36
- expect(wrapper.find(".icon--small").exists()).toBeTruthy();
37
- });
38
- });
@@ -1,46 +0,0 @@
1
- import * as React from "react";
2
- import assetUrl from "../support/asset_url";
3
-
4
- interface IconProps {
5
- name: string;
6
- title?: string;
7
- iconExtraClassName?: string;
8
- role?: string;
9
- }
10
-
11
- export const Icon: React.SFC<IconProps> = ({ name, title, iconExtraClassName, role = "none presentation" }) => {
12
- let titleElement = null;
13
- if (title) {
14
- titleElement = <title>{title}</title>;
15
- }
16
-
17
- return (
18
- <svg className={`icon ${iconExtraClassName} ${name}`} role={role}>
19
- {titleElement}
20
- <use
21
- xmlnsXlink="http://www.w3.org/1999/xlink"
22
- xlinkHref={`${assetUrl("icons.svg")}#${name}`}
23
- />
24
- </svg>
25
- );
26
- };
27
-
28
- Icon.defaultProps = {
29
- iconExtraClassName: "icon--before"
30
- };
31
-
32
- interface IconWithoutUserAgentProps {
33
- name: string;
34
- title?: string;
35
- iconExtraClassName?: string;
36
- role?: string;
37
- }
38
-
39
- const IconWithoutUserAgent: React.SFC<IconWithoutUserAgentProps> = ({
40
- name,
41
- title,
42
- iconExtraClassName,
43
- role = "none presentation"
44
- }) => <Icon name={name} title={title} iconExtraClassName={iconExtraClassName} role={role} />;
45
-
46
- export default IconWithoutUserAgent;
@@ -1,265 +0,0 @@
1
- import { mount, ReactWrapper, shallow } from "enzyme";
2
- import * as $ from "jquery";
3
- import * as React from "react";
4
-
5
- import { AddCommentForm } from "./add_comment_form.component";
6
-
7
- import generateUserData from "../support/generate_user_data";
8
- import generateUserGroupData from "../support/generate_user_group_data";
9
- import { loadLocaleTranslations } from "../support/load_translations";
10
-
11
- describe("<AddCommentForm commentsMaxLength={commentsMaxLength} />", () => {
12
- let session: any = null;
13
- const commentsMaxLength: number = 1000;
14
- const commentable = {
15
- id: "1",
16
- type: "Decidim::DummyResources::DummyResource"
17
- };
18
- const orderBy = "older";
19
- const addCommentStub = (): any => {
20
- return null;
21
- };
22
- const context = {locale: undefined, toggleTranslations: undefined};
23
-
24
- beforeEach(() => {
25
- loadLocaleTranslations("en");
26
- session = {
27
- user: generateUserData(),
28
- verifiedUserGroups: []
29
- };
30
- window.DecidimComments = {
31
- assets: {
32
- "icons.svg": "/assets/icons.svg"
33
- }
34
- };
35
-
36
- window.$ = $;
37
- });
38
-
39
- it("should render a div with class add-comment", () => {
40
- const wrapper = shallow(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
41
- expect(wrapper.find("div.add-comment")).toBeDefined();
42
- });
43
-
44
- it("should have a reference to body textarea", () => {
45
- const wrapper = mount(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
46
- expect((wrapper.instance() as AddCommentForm).bodyTextArea).toBeDefined();
47
- });
48
-
49
- it("should initialize with a state property disabled as true", () => {
50
- const wrapper = mount(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
51
- expect(wrapper.state()).toHaveProperty("disabled", true);
52
- });
53
-
54
- it("should have a default prop showTitle as true", () => {
55
- const wrapper = mount(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
56
- expect(wrapper.props()).toHaveProperty("showTitle", true);
57
- });
58
-
59
- it("should not render the title if prop showTitle is false", () => {
60
- const wrapper = shallow(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} showTitle={false} rootCommentable={commentable} orderBy={orderBy} />);
61
- expect(wrapper.find("h4.section-heading").exists()).toBeFalsy();
62
- });
63
-
64
- it("should have a default prop submitButtonClassName as 'button button--sc'", () => {
65
- const wrapper = mount(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
66
- expect(wrapper.props()).toHaveProperty("submitButtonClassName", "button button--sc");
67
- });
68
-
69
- it("should use prop submitButtonClassName as a className prop for submit button", () => {
70
- const wrapper = shallow(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} submitButtonClassName="button small hollow" rootCommentable={commentable} orderBy={orderBy} />);
71
- expect(wrapper.find('button[type="submit"]').hasClass("button")).toBeTruthy();
72
- expect(wrapper.find('button[type="submit"]').hasClass("small")).toBeTruthy();
73
- expect(wrapper.find('button[type="submit"]').hasClass("hollow")).toBeTruthy();
74
- });
75
-
76
- it("should enable the submit button if textarea is not blank", () => {
77
- const wrapper = mount(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
78
- wrapper.find("textarea").simulate("change", {
79
- target: {
80
- value: "This is a comment"
81
- }
82
- });
83
- expect(wrapper.find('button[type="submit"]').props()).not.toHaveProperty("disabled", true);
84
- });
85
-
86
- it("should disable the submit button if textarea is blank", () => {
87
- const wrapper = mount(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
88
- wrapper.find("textarea").simulate("change", {
89
- target: {
90
- value: "This will be deleted"
91
- }
92
- });
93
- wrapper.find("textarea").simulate("change", {
94
- target: {
95
- value: ""
96
- }
97
- });
98
- expect(wrapper.find('button[type="submit"]').props()).toHaveProperty("disabled", true);
99
- });
100
-
101
- it("should not render a div with class 'opinion-toggle'", () => {
102
- const wrapper = shallow(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
103
- expect(wrapper.find(".opinion-toggle").exists()).toBeFalsy();
104
- });
105
-
106
- it("should render the remaining character count", () => {
107
- const wrapper = shallow(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
108
- const commentBody = "This is a new comment!";
109
- wrapper.find("textarea").simulate("change", {
110
- target: {
111
- value: commentBody
112
- }
113
- });
114
- expect(wrapper.find(".remaining-character-count").text()).toContain(commentsMaxLength - commentBody.length);
115
- });
116
-
117
- describe("submitting the form", () => {
118
- let addComment: jasmine.Spy;
119
- let onCommentAdded: jasmine.Spy ;
120
- let wrapper: ReactWrapper<any, {}>;
121
- let message: any = null;
122
-
123
- beforeEach(() => {
124
- addComment = jasmine.createSpy("addComment");
125
- onCommentAdded = jasmine.createSpy("onCommentAdded");
126
- wrapper = mount(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addComment} session={session} commentable={commentable} onCommentAdded={onCommentAdded} rootCommentable={commentable} orderBy={orderBy} />);
127
- message = "This will be submitted";
128
- (wrapper.instance() as AddCommentForm).bodyTextArea.value = message;
129
- });
130
-
131
- it("should call addComment prop with the textarea value and state property alignment", () => {
132
- wrapper.find("form").simulate("submit");
133
- expect(addComment).toHaveBeenCalledWith({ body: message, alignment: 0 }, context);
134
- });
135
-
136
- it("should reset textarea", () => {
137
- wrapper.find("form").simulate("submit");
138
- expect((wrapper.instance() as AddCommentForm).bodyTextArea.value).toBe("");
139
- });
140
-
141
- it("should prevent default form submission", () => {
142
- const preventDefault = jasmine.createSpy("preventDefault");
143
- wrapper.find("form").simulate("submit", { preventDefault });
144
- expect(preventDefault).toHaveBeenCalled();
145
- });
146
-
147
- it("should call the prop onCommentAdded function", () => {
148
- wrapper.find("form").simulate("submit");
149
- expect(onCommentAdded).toHaveBeenCalled();
150
- });
151
- });
152
-
153
- it("should initialize state with a property alignment and value 0", () => {
154
- const wrapper = shallow(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} arguable={true} rootCommentable={commentable} orderBy={orderBy} />);
155
- expect(wrapper.state()).toHaveProperty("alignment", 0);
156
- });
157
-
158
- describe("when receiving an optional prop arguable with value true", () => {
159
- it("should render a div with class 'opinion-toggle'", () => {
160
- const wrapper = shallow(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} arguable={true} rootCommentable={commentable} orderBy={orderBy} />);
161
- expect(wrapper.find(".opinion-toggle")).toBeDefined();
162
- });
163
-
164
- it("should set state alignment to 1 if user clicks ok button and change its class", () => {
165
- const wrapper = shallow(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} arguable={true} rootCommentable={commentable} orderBy={orderBy} />);
166
- wrapper.find(".opinion-toggle--ok").simulate("click");
167
- expect(wrapper.find(".opinion-toggle--ok").hasClass("is-active")).toBeTruthy();
168
- expect(wrapper.state()).toHaveProperty("alignment", 1);
169
- });
170
-
171
- it("should set state alignment to -11 if user clicks ko button and change its class", () => {
172
- const wrapper = shallow(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} arguable={true} rootCommentable={commentable} orderBy={orderBy} />);
173
- wrapper.find(".opinion-toggle--ko").simulate("click");
174
- expect(wrapper.find(".opinion-toggle--ko").hasClass("is-active")).toBeTruthy();
175
- expect(wrapper.state()).toHaveProperty("alignment", -1);
176
- });
177
-
178
- describe("submitting the form", () => {
179
- let wrapper: ReactWrapper<any, {}>;
180
- let addComment: jasmine.Spy;
181
- let message: string;
182
-
183
- beforeEach(() => {
184
- addComment = jasmine.createSpy("addComment");
185
- wrapper = mount(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addComment} session={session} commentable={commentable} arguable={true} rootCommentable={commentable} orderBy={orderBy} />);
186
- message = "This will be submitted";
187
- (wrapper.instance() as AddCommentForm).bodyTextArea.value = message;
188
- });
189
-
190
- it("should call addComment prop with the state's property alignment", () => {
191
- wrapper.find("button.opinion-toggle--ko").simulate("click");
192
- wrapper.find("form").simulate("submit");
193
- expect(addComment).toHaveBeenCalledWith({ body: message, alignment: -1 }, context);
194
- });
195
-
196
- it("should reset the state to its initial state", () => {
197
- wrapper.find("button.opinion-toggle--ok").simulate("click");
198
- wrapper.find("form").simulate("submit");
199
- expect(wrapper.state()).toHaveProperty("alignment", 0);
200
- });
201
- });
202
- });
203
-
204
- describe("when user groups are greater than 0", () => {
205
- beforeEach(() => {
206
- session.verifiedUserGroups = [
207
- generateUserGroupData(),
208
- generateUserGroupData()
209
- ];
210
- });
211
-
212
- it("should have a reference to user_group_id select", () => {
213
- const wrapper = mount(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
214
- expect((wrapper.instance() as AddCommentForm).userGroupIdSelect).toBeDefined();
215
- });
216
-
217
- it("should render a select with option tags for each verified user group", () => {
218
- const wrapper = mount(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
219
- expect(wrapper.find("select").children("option").length).toBe(3);
220
- });
221
-
222
- describe("submitting the form", () => {
223
- let addComment: jasmine.Spy;
224
- let wrapper: ReactWrapper<any, {}>;
225
- let message: string;
226
- let userGroupId: string;
227
-
228
- beforeEach(() => {
229
- addComment = jasmine.createSpy("addComment");
230
- wrapper = mount(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addComment} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
231
- message = "This will be submitted";
232
- userGroupId = session.verifiedUserGroups[1].id;
233
- (wrapper.instance() as AddCommentForm).bodyTextArea.value = message;
234
- (wrapper.instance() as AddCommentForm).userGroupIdSelect.value = userGroupId;
235
- });
236
-
237
- it("should call addComment prop with the body textarea, alignment and user_group_id select values", () => {
238
- wrapper.find("form").simulate("submit");
239
- expect(addComment).toHaveBeenCalledWith({ body: message, alignment: 0, userGroupId }, context);
240
- });
241
-
242
- describe("when user_group_id is blank", () => {
243
- beforeEach(() => {
244
- (wrapper.instance() as AddCommentForm).userGroupIdSelect.value = "";
245
- });
246
-
247
- it("should call addComment prop with the body textarea and alignment", () => {
248
- wrapper.find("form").simulate("submit");
249
- expect(addComment).toHaveBeenCalledWith({ body: message, alignment: 0 }, context);
250
- });
251
- });
252
- });
253
- });
254
-
255
- describe("when session is null", () => {
256
- beforeEach(() => {
257
- session = null;
258
- });
259
-
260
- it("display a message to sign in or sign up", () => {
261
- const wrapper = mount(<AddCommentForm commentsMaxLength={commentsMaxLength} addComment={addCommentStub} session={session} commentable={commentable} rootCommentable={commentable} orderBy={orderBy} />);
262
- expect(wrapper.find("span").text()).toContain("sign up");
263
- });
264
- });
265
- });