decidim 0.0.1.alpha9 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of decidim might be problematic. Click here for more details.

Files changed (488) hide show
  1. checksums.yaml +4 -4
  2. data/.babelrc +16 -0
  3. data/.codeclimate.yml +16 -2
  4. data/.eslintignore +11 -0
  5. data/.eslintrc.json +275 -11
  6. data/.gitattributes +1 -0
  7. data/.gitignore +8 -0
  8. data/.hound.yml +2 -4
  9. data/.rubocop.yml +8 -4
  10. data/.ruby-version +1 -1
  11. data/.travis.yml +7 -8
  12. data/Dockerfile +16 -5
  13. data/Gemfile +4 -6
  14. data/Gemfile.lock +148 -70
  15. data/{LICENSE.txt → LICENSE-AGPLv3.txt} +42 -0
  16. data/README.md +28 -10
  17. data/Rakefile +53 -2
  18. data/codecov.yml +14 -6
  19. data/crowdin.yaml +1 -2
  20. data/decidim-admin/README.md +33 -8
  21. data/decidim-admin/Rakefile +0 -25
  22. data/decidim-admin/app/assets/javascripts/decidim/admin/application.js.es6 +17 -10
  23. data/decidim-admin/app/assets/javascripts/decidim/admin/sort_steps.js.es6 +20 -11
  24. data/decidim-admin/app/assets/javascripts/decidim/admin/tab_focus.js.es6 +22 -0
  25. data/decidim-admin/app/assets/stylesheets/decidim/admin/_forms.scss +10 -0
  26. data/decidim-admin/app/assets/stylesheets/decidim/admin/_layout.scss +11 -0
  27. data/decidim-admin/app/assets/stylesheets/decidim/admin/_tables.scss +4 -0
  28. data/decidim-admin/app/assets/stylesheets/decidim/admin/application.scss +8 -2
  29. data/decidim-admin/app/commands/decidim/admin/activate_participatory_process_step.rb +1 -1
  30. data/decidim-admin/app/commands/decidim/admin/create_category.rb +44 -0
  31. data/decidim-admin/app/commands/decidim/admin/create_feature.rb +48 -0
  32. data/decidim-admin/app/commands/decidim/admin/create_participatory_process.rb +3 -6
  33. data/decidim-admin/app/commands/decidim/admin/create_participatory_process_admin.rb +51 -0
  34. data/decidim-admin/app/commands/decidim/admin/create_participatory_process_attachment.rb +44 -0
  35. data/decidim-admin/app/commands/decidim/admin/create_participatory_process_step.rb +3 -3
  36. data/decidim-admin/app/commands/decidim/admin/create_scope.rb +38 -0
  37. data/decidim-admin/app/commands/decidim/admin/create_static_page.rb +40 -0
  38. data/decidim-admin/app/commands/decidim/admin/destroy_category.rb +36 -0
  39. data/decidim-admin/app/commands/decidim/admin/destroy_feature.rb +39 -0
  40. data/decidim-admin/app/commands/decidim/admin/publish_participatory_process.rb +1 -1
  41. data/decidim-admin/app/commands/decidim/admin/reorder_participatory_process_steps.rb +5 -2
  42. data/decidim-admin/app/commands/decidim/admin/unpublish_participatory_process.rb +1 -1
  43. data/decidim-admin/app/commands/decidim/admin/update_category.rb +48 -0
  44. data/decidim-admin/app/commands/decidim/admin/update_organization.rb +49 -0
  45. data/decidim-admin/app/commands/decidim/admin/update_participatory_process.rb +2 -2
  46. data/decidim-admin/app/commands/decidim/admin/update_participatory_process_attachment.rb +49 -0
  47. data/decidim-admin/app/commands/decidim/admin/update_participatory_process_step.rb +1 -1
  48. data/decidim-admin/app/commands/decidim/admin/update_scope.rb +43 -0
  49. data/decidim-admin/app/commands/decidim/admin/update_static_page.rb +45 -0
  50. data/decidim-admin/app/constraints/decidim/admin/organization_dashboard_constraint.rb +5 -1
  51. data/decidim-admin/app/controllers/decidim/admin/application_controller.rb +8 -0
  52. data/decidim-admin/app/controllers/decidim/admin/categories_controller.rb +90 -0
  53. data/decidim-admin/app/controllers/decidim/admin/concerns/participatory_process_admin.rb +31 -0
  54. data/decidim-admin/app/controllers/decidim/admin/features_controller.rb +74 -0
  55. data/decidim-admin/app/controllers/decidim/admin/organization_controller.rb +40 -0
  56. data/decidim-admin/app/controllers/decidim/admin/participatory_process_attachments_controller.rb +84 -0
  57. data/decidim-admin/app/controllers/decidim/admin/participatory_process_publications_controller.rb +2 -7
  58. data/decidim-admin/app/controllers/decidim/admin/participatory_process_step_activations_controller.rb +6 -8
  59. data/decidim-admin/app/controllers/decidim/admin/participatory_process_step_ordering_controller.rb +2 -4
  60. data/decidim-admin/app/controllers/decidim/admin/participatory_process_steps_controller.rb +13 -11
  61. data/decidim-admin/app/controllers/decidim/admin/participatory_process_user_roles_controller.rb +54 -0
  62. data/decidim-admin/app/controllers/decidim/admin/participatory_processes_controller.rb +11 -6
  63. data/decidim-admin/app/controllers/decidim/admin/scopes_controller.rb +79 -0
  64. data/decidim-admin/app/controllers/decidim/admin/static_pages_controller.rb +94 -0
  65. data/decidim-admin/app/forms/decidim/admin/category_form.rb +37 -0
  66. data/decidim-admin/app/forms/decidim/admin/feature_form.rb +16 -0
  67. data/decidim-admin/app/forms/decidim/admin/organization_form.rb +31 -0
  68. data/decidim-admin/app/forms/decidim/admin/participatory_process_attachment_form.rb +19 -0
  69. data/decidim-admin/app/forms/decidim/admin/participatory_process_form.rb +4 -7
  70. data/decidim-admin/app/forms/decidim/admin/participatory_process_step_form.rb +12 -2
  71. data/decidim-admin/app/forms/decidim/admin/participatory_process_user_role_form.rb +15 -0
  72. data/decidim-admin/app/forms/decidim/admin/scope_form.rb +24 -0
  73. data/decidim-admin/app/forms/decidim/admin/static_page_form.rb +30 -0
  74. data/decidim-admin/app/helpers/decidim/admin/application_helper.rb +1 -0
  75. data/decidim-admin/app/helpers/decidim/admin/aria_selected_link_to_helper.rb +28 -0
  76. data/decidim-admin/app/helpers/decidim/admin/attributes_display_helper.rb +13 -5
  77. data/decidim-admin/app/models/decidim/admin/abilities/admin_user.rb +34 -0
  78. data/decidim-admin/app/models/decidim/admin/abilities/base.rb +19 -0
  79. data/decidim-admin/app/models/decidim/admin/abilities/participatory_process_admin.rb +51 -0
  80. data/decidim-admin/app/models/decidim/admin/participatory_process_user_role.rb +14 -0
  81. data/decidim-admin/app/queries/decidim/admin/manageable_participatory_processes_for_user.rb +41 -0
  82. data/decidim-admin/app/queries/decidim/admin/process_admin_roles_for_process.rb +35 -0
  83. data/decidim-admin/app/views/decidim/admin/categories/_form.html.erb +12 -0
  84. data/decidim-admin/app/views/decidim/admin/categories/edit.html.erb +9 -0
  85. data/decidim-admin/app/views/decidim/admin/categories/index.html.erb +44 -0
  86. data/decidim-admin/app/views/decidim/admin/categories/new.html.erb +9 -0
  87. data/decidim-admin/app/views/decidim/admin/categories/show.html.erb +14 -0
  88. data/decidim-admin/app/views/decidim/admin/features/_feature.html.erb +20 -0
  89. data/decidim-admin/app/views/decidim/admin/features/_form.html.erb +3 -0
  90. data/decidim-admin/app/views/decidim/admin/features/index.html.erb +23 -0
  91. data/decidim-admin/app/views/decidim/admin/features/new.html.erb +9 -0
  92. data/decidim-admin/app/views/decidim/admin/organization/_form.html.erb +23 -0
  93. data/decidim-admin/app/views/decidim/admin/organization/edit.html.erb +11 -0
  94. data/decidim-admin/app/views/decidim/admin/participatory_process_attachments/_form.html.erb +11 -0
  95. data/decidim-admin/app/views/decidim/admin/participatory_process_attachments/edit.html.erb +9 -0
  96. data/decidim-admin/app/views/decidim/admin/participatory_process_attachments/index.html.erb +37 -0
  97. data/decidim-admin/app/views/decidim/admin/participatory_process_attachments/new.html.erb +9 -0
  98. data/decidim-admin/app/views/decidim/admin/participatory_process_attachments/show.html.erb +25 -0
  99. data/decidim-admin/app/views/decidim/admin/participatory_process_steps/_form.html.erb +2 -2
  100. data/decidim-admin/app/views/decidim/admin/participatory_process_steps/edit.html.erb +1 -3
  101. data/decidim-admin/app/views/decidim/admin/participatory_process_steps/{_table.html.erb → index.html.erb} +15 -11
  102. data/decidim-admin/app/views/decidim/admin/participatory_process_steps/new.html.erb +1 -3
  103. data/decidim-admin/app/views/decidim/admin/participatory_process_steps/show.html.erb +1 -4
  104. data/decidim-admin/app/views/decidim/admin/participatory_process_user_roles/index.html.erb +34 -0
  105. data/decidim-admin/app/views/decidim/admin/participatory_processes/_form.html.erb +2 -2
  106. data/decidim-admin/app/views/decidim/admin/participatory_processes/edit.html.erb +13 -3
  107. data/decidim-admin/app/views/decidim/admin/participatory_processes/index.html.erb +5 -14
  108. data/decidim-admin/app/views/decidim/admin/participatory_processes/show.html.erb +19 -36
  109. data/decidim-admin/app/views/decidim/admin/scopes/_form.html.erb +3 -0
  110. data/decidim-admin/app/views/decidim/admin/scopes/edit.html.erb +11 -0
  111. data/decidim-admin/app/views/decidim/admin/scopes/index.html.erb +38 -0
  112. data/decidim-admin/app/views/decidim/admin/scopes/new.html.erb +11 -0
  113. data/decidim-admin/app/views/decidim/admin/static_pages/_form.html.erb +13 -0
  114. data/decidim-admin/app/views/decidim/admin/static_pages/edit.html.erb +11 -0
  115. data/decidim-admin/app/views/decidim/admin/static_pages/index.html.erb +40 -0
  116. data/decidim-admin/app/views/decidim/admin/static_pages/new.html.erb +11 -0
  117. data/decidim-admin/app/views/decidim/admin/static_pages/show.html.erb +22 -0
  118. data/decidim-admin/app/views/layouts/decidim/admin/_application.html.erb +40 -0
  119. data/decidim-admin/app/views/layouts/decidim/admin/_sidebar.html.erb +5 -2
  120. data/decidim-admin/app/views/layouts/decidim/admin/application.html.erb +3 -40
  121. data/decidim-admin/app/views/layouts/decidim/admin/participatory_process.html.erb +54 -0
  122. data/decidim-admin/config/i18n-tasks.yml +3 -2
  123. data/decidim-admin/config/locales/ca.yml +138 -6
  124. data/decidim-admin/config/locales/en.yml +191 -13
  125. data/decidim-admin/config/locales/es.yml +139 -7
  126. data/decidim-admin/config/routes.rb +23 -1
  127. data/decidim-admin/db/migrate/20161102144648_add_admin_participatory_process_user_roles.rb +15 -0
  128. data/decidim-admin/db/seeds.rb +21 -0
  129. data/decidim-admin/decidim-admin.gemspec +6 -11
  130. data/decidim-admin/lib/decidim/admin.rb +1 -0
  131. data/decidim-admin/lib/decidim/admin/engine.rb +10 -3
  132. data/decidim-admin/lib/decidim/admin/features.rb +10 -0
  133. data/decidim-admin/lib/decidim/admin/features/base_controller.rb +33 -0
  134. data/decidim-admin/spec/commands/create_category_spec.rb +61 -0
  135. data/decidim-admin/spec/commands/create_feature_spec.rb +60 -0
  136. data/decidim-admin/spec/commands/create_participatory_process_admin_spec.rb +42 -0
  137. data/decidim-admin/spec/commands/create_participatory_process_spec.rb +37 -0
  138. data/decidim-admin/spec/commands/create_scope_spec.rb +24 -0
  139. data/decidim-admin/spec/commands/create_static_page_spec.rb +42 -0
  140. data/decidim-admin/spec/commands/destroy_category_spec.rb +46 -0
  141. data/decidim-admin/spec/commands/destroy_feature_spec.rb +31 -0
  142. data/decidim-admin/spec/commands/update_category_spec.rb +64 -0
  143. data/decidim-admin/spec/commands/update_organization_spec.rb +73 -0
  144. data/decidim-admin/spec/commands/update_scope_spec.rb +24 -0
  145. data/decidim-admin/spec/commands/update_static_page_spec.rb +50 -0
  146. data/decidim-admin/spec/controllers/static_pages_controller_spec.rb +50 -0
  147. data/decidim-admin/spec/factories.rb +8 -0
  148. data/decidim-admin/spec/features/admin_invite_spec.rb +6 -2
  149. data/decidim-admin/spec/features/admin_manages_features_spec.rb +75 -0
  150. data/decidim-admin/spec/features/admin_manages_organization_scopes_spec.rb +80 -0
  151. data/decidim-admin/spec/features/admin_manages_organization_spec.rb +38 -0
  152. data/decidim-admin/spec/features/admin_manages_participatory_process_admins_spec.rb +10 -0
  153. data/decidim-admin/spec/features/admin_manages_participatory_process_attachments_spec.rb +10 -0
  154. data/decidim-admin/spec/features/admin_manages_participatory_process_categories_spec.rb +18 -0
  155. data/decidim-admin/spec/features/admin_manages_participatory_process_steps_spec.rb +10 -0
  156. data/decidim-admin/spec/features/admin_manages_participatory_processes_spec.rb +95 -0
  157. data/decidim-admin/spec/features/participatory_process_admin_manages_participatory_process_admins_spec.rb +27 -0
  158. data/decidim-admin/spec/features/participatory_process_admin_manages_participatory_process_attachments_spec.rb +13 -0
  159. data/decidim-admin/spec/features/participatory_process_admin_manages_participatory_process_steps_spec.rb +12 -0
  160. data/decidim-admin/spec/features/participatory_process_admin_manages_participatory_processes_spec.rb +36 -0
  161. data/decidim-admin/spec/features/process_admin_manages_participatory_process_categories_spec.rb +20 -0
  162. data/decidim-admin/spec/features/static_pages_spec.rb +120 -0
  163. data/decidim-admin/spec/forms/category_form_spec.rb +94 -0
  164. data/decidim-admin/spec/forms/organization_form_spec.rb +60 -0
  165. data/decidim-admin/spec/forms/participatory_process_form_spec.rb +19 -6
  166. data/decidim-admin/spec/forms/participatory_process_step_form_spec.rb +21 -1
  167. data/decidim-admin/spec/forms/participatory_process_user_role_form_spec.rb +29 -0
  168. data/decidim-admin/spec/forms/scope_form_spec.rb +60 -0
  169. data/decidim-admin/spec/forms/static_page_form_spec.rb +97 -0
  170. data/decidim-admin/spec/helpers/aria_selected_link_to_helper_spec.rb +46 -0
  171. data/decidim-admin/spec/models/abilities/admin_user_spec.rb +62 -0
  172. data/decidim-admin/spec/models/abilities/participatory_process_admin_spec.rb +50 -0
  173. data/decidim-admin/spec/models/participatory_process_user_role_spec.rb +21 -0
  174. data/decidim-admin/spec/queries/manageable_participatory_processes_for_user_spec.rb +30 -0
  175. data/decidim-admin/spec/queries/process_admin_roles_for_process_spec.rb +17 -0
  176. data/decidim-admin/spec/shared/manage_process_admins_examples.rb +56 -0
  177. data/decidim-admin/spec/shared/manage_process_attachments_examples.rb +105 -0
  178. data/decidim-admin/spec/shared/manage_process_categories_examples.rb +129 -0
  179. data/decidim-admin/spec/shared/manage_process_steps_examples.rb +153 -0
  180. data/decidim-admin/spec/shared/manage_processes_examples.rb +139 -0
  181. data/decidim-admin/spec/shared/participatory_admin_shared_context.rb +19 -0
  182. data/decidim-admin/spec/spec_helper.rb +4 -0
  183. data/decidim-admin/spec/support/processes_menu_links_helpers.rb +12 -0
  184. data/decidim-admin/spec/views/decidim/static_pages/_form.html.erb_spec.rb +35 -0
  185. data/decidim-admin/vendor/assets/javascripts/html.sortable.js +691 -0
  186. data/decidim-api/README.md +11 -10
  187. data/decidim-api/Rakefile +0 -25
  188. data/decidim-api/app/assets/config/decidim_api_manifest.js +1 -0
  189. data/decidim-api/app/assets/javascripts/decidim/api/docs.js.es6 +23 -0
  190. data/decidim-api/app/controllers/decidim/api/documentation_controller.rb +10 -0
  191. data/decidim-api/app/controllers/decidim/api/queries_controller.rb +3 -2
  192. data/decidim-api/app/views/decidim/api/documentation/show.html.erb +10 -0
  193. data/decidim-api/app/views/layouts/decidim/api/documentation.html.erb +9 -0
  194. data/decidim-api/config/routes.rb +4 -3
  195. data/decidim-api/decidim-api.gemspec +6 -9
  196. data/decidim-api/lib/decidim/api.rb +7 -0
  197. data/decidim-api/lib/decidim/api/engine.rb +14 -0
  198. data/decidim-api/lib/decidim/api/graphiql-initial-query.txt +11 -0
  199. data/decidim-api/{app/schemas → lib}/decidim/api/schema.rb +1 -0
  200. data/decidim-api/lib/decidim/api/test/type_context.rb +41 -0
  201. data/decidim-api/{app/types/decidim/api/localized_string_type.rb → lib/decidim/api/types/localized_string.rb} +1 -1
  202. data/decidim-api/lib/decidim/api/types/mutation.rb +10 -0
  203. data/decidim-api/lib/decidim/api/types/query.rb +10 -0
  204. data/decidim-api/{app/types/decidim/api/translated_field_type.rb → lib/decidim/api/types/translated_field.rb} +2 -2
  205. data/decidim-api/spec/factories.rb +1 -0
  206. data/decidim-api/spec/features/documentation_spec.rb +22 -0
  207. data/decidim-api/spec/features/graphiql_spec.rb +22 -0
  208. data/decidim-api/spec/types/localized_string_type_spec.rb +2 -1
  209. data/decidim-api/spec/types/mutation_type_spec.rb +38 -0
  210. data/decidim-api/spec/types/query_type_spec.rb +2 -1
  211. data/decidim-api/spec/types/translated_field_type_spec.rb +2 -1
  212. data/decidim-api/vendor/assets/javascripts/decidim/api/graphql-docs.js +3518 -0
  213. data/decidim-api/vendor/assets/javascripts/decidim/api/react-dom.js +42 -0
  214. data/decidim-api/vendor/assets/javascripts/decidim/api/react.js +20595 -0
  215. data/decidim-comments/.gitignore +2 -0
  216. data/decidim-comments/Gemfile +6 -0
  217. data/decidim-comments/README.md +42 -0
  218. data/decidim-comments/Rakefile +2 -0
  219. data/decidim-comments/app/assets/config/decidim_comments_manifest.js +1 -0
  220. data/decidim-comments/app/assets/javascripts/decidim/comments/bundle.js +0 -0
  221. data/decidim-comments/app/assets/javascripts/decidim/comments/comments.js.erb +8 -0
  222. data/decidim-comments/app/commands/decidim/comments/create_comment.rb +40 -0
  223. data/decidim-comments/app/forms/decidim/comments/comment_form.rb +16 -0
  224. data/decidim-comments/app/frontend/application/apollo_client.js +16 -0
  225. data/decidim-comments/app/frontend/application/application.component.jsx +37 -0
  226. data/decidim-comments/app/frontend/application/application.component.test.jsx +33 -0
  227. data/decidim-comments/app/frontend/application/icon.component.jsx +21 -0
  228. data/decidim-comments/app/frontend/application/icon.component.test.jsx +43 -0
  229. data/decidim-comments/app/frontend/comments/add_comment_form.component.jsx +250 -0
  230. data/decidim-comments/app/frontend/comments/add_comment_form.component.test.jsx +173 -0
  231. data/decidim-comments/app/frontend/comments/add_comment_form.mutation.graphql +8 -0
  232. data/decidim-comments/app/frontend/comments/comment.component.jsx +202 -0
  233. data/decidim-comments/app/frontend/comments/comment.component.test.jsx +125 -0
  234. data/decidim-comments/app/frontend/comments/comment.fragment.graphql +12 -0
  235. data/decidim-comments/app/frontend/comments/comment_data.fragment.graphql +11 -0
  236. data/decidim-comments/app/frontend/comments/comment_order_selector.component.jsx +28 -0
  237. data/decidim-comments/app/frontend/comments/comment_order_selector.component.test.jsx +9 -0
  238. data/decidim-comments/app/frontend/comments/comment_thread.component.jsx +64 -0
  239. data/decidim-comments/app/frontend/comments/comment_thread.component.test.jsx +71 -0
  240. data/decidim-comments/app/frontend/comments/comment_thread.fragment.graphql +9 -0
  241. data/decidim-comments/app/frontend/comments/comments.component.jsx +139 -0
  242. data/decidim-comments/app/frontend/comments/comments.component.test.jsx +106 -0
  243. data/decidim-comments/app/frontend/comments/comments.query.graphql +10 -0
  244. data/decidim-comments/app/frontend/comments/featured_comment.component.jsx +23 -0
  245. data/decidim-comments/app/frontend/comments/featured_comment.component.test.jsx +15 -0
  246. data/decidim-comments/app/frontend/entry.js +24 -0
  247. data/decidim-comments/app/frontend/entry.test.js +29 -0
  248. data/decidim-comments/app/frontend/support/asset_url.js +11 -0
  249. data/decidim-comments/app/frontend/support/generate_comments_data.js +29 -0
  250. data/decidim-comments/app/frontend/support/generate_current_user_data.js +13 -0
  251. data/decidim-comments/app/frontend/support/load_translations.js +23 -0
  252. data/decidim-comments/app/frontend/support/require_all.js +10 -0
  253. data/decidim-comments/app/frontend/support/resolve_graphql_query.js +37 -0
  254. data/decidim-comments/app/frontend/support/stub_component.js +29 -0
  255. data/decidim-comments/app/helpers/decidim/comments/comments_helper.rb +51 -0
  256. data/decidim-comments/app/models/decidim/comments/comment.rb +55 -0
  257. data/decidim-comments/app/types/decidim/comments/add_comment_type.rb +12 -0
  258. data/decidim-comments/app/types/decidim/comments/author_type.rb +15 -0
  259. data/decidim-comments/app/types/decidim/comments/comment_type.rb +28 -0
  260. data/decidim-comments/bin/rails +14 -0
  261. data/decidim-comments/config/i18n-tasks.yml +124 -0
  262. data/decidim-comments/config/locales/ca.yml +35 -0
  263. data/decidim-comments/config/locales/en.yml +36 -0
  264. data/decidim-comments/config/locales/es.yml +35 -0
  265. data/decidim-comments/db/migrate/20161130143508_create_comments.rb +11 -0
  266. data/decidim-comments/db/migrate/20161214082645_add_depth_to_comments.rb +5 -0
  267. data/decidim-comments/db/migrate/20161216102820_add_alignment_to_comments.rb +5 -0
  268. data/decidim-comments/db/seeds.rb +11 -0
  269. data/decidim-comments/decidim-comments.gemspec +25 -0
  270. data/decidim-comments/lib/decidim/comments.rb +10 -0
  271. data/decidim-comments/lib/decidim/comments/engine.rb +34 -0
  272. data/decidim-comments/lib/decidim/comments/mutation_extensions.rb +36 -0
  273. data/decidim-comments/lib/decidim/comments/query_extensions.rb +33 -0
  274. data/decidim-comments/package.json +21 -0
  275. data/decidim-comments/spec/commands/create_comment_spec.rb +64 -0
  276. data/decidim-comments/spec/factories.rb +9 -0
  277. data/decidim-comments/spec/features/comments_spec.rb +97 -0
  278. data/decidim-comments/spec/forms/comment_form_spec.rb +48 -0
  279. data/decidim-comments/spec/helpers/comments_helper_spec.rb +48 -0
  280. data/decidim-comments/spec/models/comment_spec.rb +64 -0
  281. data/decidim-comments/spec/spec_helper.rb +2 -0
  282. data/decidim-comments/spec/support/dummy.rb +20 -0
  283. data/decidim-comments/spec/types/author_type_spec.rb +21 -0
  284. data/decidim-comments/spec/types/comment_type_spec.rb +51 -0
  285. data/decidim-comments/spec/types/query_type_spec.rb +49 -0
  286. data/decidim-dev/decidim-dev.gemspec +11 -7
  287. data/decidim-dev/lib/decidim/common_rake.rb +20 -6
  288. data/decidim-dev/lib/decidim/dummy_authorization_handler.rb +9 -2
  289. data/decidim-dev/lib/decidim/test/base_spec_helper.rb +25 -6
  290. data/decidim-dev/lib/decidim/test/i18n_spec.rb +1 -1
  291. data/decidim-dev/lib/decidim/test/rspec_support/capybara.rb +66 -5
  292. data/decidim-dev/lib/decidim/test/rspec_support/database_cleaner.rb +2 -2
  293. data/decidim-dev/lib/decidim/test/rspec_support/feature.rb +22 -0
  294. data/decidim-dev/lib/decidim/test/rspec_support/feature_context.rb +44 -0
  295. data/decidim-dev/lib/decidim/test/rspec_support/helpers.rb +42 -0
  296. data/decidim-dev/lib/decidim/test/rspec_support/translation_helpers.rb +63 -0
  297. data/decidim-dev/spec/support/Exampledocument.docx +0 -0
  298. data/decidim-dev/spec/support/Exampledocument.odt +0 -0
  299. data/decidim-dev/spec/support/Exampledocument.pdf +0 -0
  300. data/decidim-dev/spec/support/avatar.svg +14 -0
  301. data/decidim-dev/spec/support/malicious.jpg +0 -0
  302. data/decidim-meetings/.gitignore +7 -0
  303. data/decidim-meetings/README.md +23 -0
  304. data/decidim-meetings/Rakefile +2 -0
  305. data/decidim-meetings/app/commands/decidim/meetings/admin/create_meeting.rb +40 -0
  306. data/decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb +44 -0
  307. data/decidim-meetings/app/controllers/decidim/meetings/admin/application_controller.rb +14 -0
  308. data/decidim-meetings/app/controllers/decidim/meetings/admin/meetings_controller.rb +69 -0
  309. data/decidim-meetings/app/controllers/decidim/meetings/application_controller.rb +13 -0
  310. data/decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb +24 -0
  311. data/decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb +30 -0
  312. data/decidim-meetings/app/models/decidim/meetings/application_record.rb +9 -0
  313. data/decidim-meetings/app/models/decidim/meetings/meeting.rb +12 -0
  314. data/decidim-meetings/app/views/decidim/meetings/admin/meetings/_form.html.erb +32 -0
  315. data/decidim-meetings/app/views/decidim/meetings/admin/meetings/edit.html.erb +9 -0
  316. data/decidim-meetings/app/views/decidim/meetings/admin/meetings/index.html.erb +39 -0
  317. data/decidim-meetings/app/views/decidim/meetings/admin/meetings/new.html.erb +9 -0
  318. data/decidim-meetings/app/views/decidim/meetings/meetings/_address_details.html.erb +5 -0
  319. data/decidim-meetings/app/views/decidim/meetings/meetings/index.html.erb +30 -0
  320. data/decidim-meetings/app/views/decidim/meetings/meetings/show.html.erb +39 -0
  321. data/decidim-meetings/bin/rails +14 -0
  322. data/decidim-meetings/config/i18n-tasks.yml +4 -0
  323. data/decidim-meetings/config/locales/ca.yml +44 -0
  324. data/decidim-meetings/config/locales/en.yml +45 -0
  325. data/decidim-meetings/config/locales/es.yml +44 -0
  326. data/decidim-meetings/db/migrate/20161130121354_create_meetings.rb +18 -0
  327. data/decidim-meetings/decidim-meetings.gemspec +21 -0
  328. data/decidim-meetings/lib/decidim/meetings.rb +11 -0
  329. data/decidim-meetings/lib/decidim/meetings/admin.rb +9 -0
  330. data/decidim-meetings/lib/decidim/meetings/admin_engine.rb +22 -0
  331. data/decidim-meetings/lib/decidim/meetings/feature.rb +42 -0
  332. data/decidim-meetings/lib/decidim/meetings/list_engine.rb +16 -0
  333. data/decidim-meetings/spec/commands/create_meeting_spec.rb +38 -0
  334. data/decidim-meetings/spec/commands/update_meeting_spec.rb +36 -0
  335. data/decidim-meetings/spec/factories.rb +16 -0
  336. data/decidim-meetings/spec/features/admin_manages_meetings_spec.rb +16 -0
  337. data/decidim-meetings/spec/features/explore_meetings_spec.rb +54 -0
  338. data/decidim-meetings/spec/features/process_admin_manages_meetings_spec.rb +17 -0
  339. data/decidim-meetings/spec/forms/meeting_form_spec.rb +115 -0
  340. data/decidim-meetings/spec/models/meeting_spec.rb +10 -0
  341. data/decidim-meetings/spec/shared/admin_shared_context.rb +9 -0
  342. data/decidim-meetings/spec/shared/manage_meetings_examples.rb +118 -0
  343. data/decidim-meetings/spec/spec_helper.rb +2 -0
  344. data/decidim-pages/.gitignore +3 -0
  345. data/decidim-pages/README.md +24 -0
  346. data/decidim-pages/Rakefile +2 -0
  347. data/decidim-pages/app/commands/decidim/pages/admin/update_page.rb +39 -0
  348. data/decidim-pages/app/commands/decidim/pages/create_page.rb +21 -0
  349. data/decidim-pages/app/commands/decidim/pages/destroy_page.rb +17 -0
  350. data/decidim-pages/app/controllers/decidim/pages/admin/application_controller.rb +13 -0
  351. data/decidim-pages/app/controllers/decidim/pages/admin/pages_controller.rb +35 -0
  352. data/decidim-pages/app/controllers/decidim/pages/application_controller.rb +16 -0
  353. data/decidim-pages/app/forms/decidim/pages/admin/page_form.rb +17 -0
  354. data/decidim-pages/app/helpers/decidim/pages/application_helper.rb +10 -0
  355. data/decidim-pages/app/models/decidim/pages/application_record.rb +9 -0
  356. data/decidim-pages/app/models/decidim/pages/page.rb +12 -0
  357. data/decidim-pages/app/views/decidim/pages/admin/pages/_form.html.erb +5 -0
  358. data/decidim-pages/app/views/decidim/pages/admin/pages/edit.html.erb +9 -0
  359. data/decidim-pages/app/views/decidim/pages/application/show.html.erb +16 -0
  360. data/decidim-pages/bin/rails +14 -0
  361. data/decidim-pages/config/i18n-tasks.yml +4 -0
  362. data/decidim-pages/config/locales/ca.yml +19 -0
  363. data/decidim-pages/config/locales/en.yml +20 -0
  364. data/decidim-pages/config/locales/es.yml +19 -0
  365. data/decidim-pages/db/migrate/20161116121353_create_decidim_pages.rb +11 -0
  366. data/decidim-pages/db/migrate/20161214150429_add_commentable_to_pages.rb +5 -0
  367. data/decidim-pages/decidim-pages.gemspec +21 -0
  368. data/decidim-pages/lib/decidim/pages.rb +12 -0
  369. data/decidim-pages/lib/decidim/pages/admin.rb +9 -0
  370. data/decidim-pages/lib/decidim/pages/admin_engine.rb +21 -0
  371. data/decidim-pages/lib/decidim/pages/engine.rb +15 -0
  372. data/decidim-pages/lib/decidim/pages/feature.rb +41 -0
  373. data/decidim-pages/lib/tasks/decidim/pages_tasks.rake +1 -0
  374. data/decidim-pages/spec/commands/create_page_spec.rb +46 -0
  375. data/decidim-pages/spec/commands/destroy_page_spec.rb +24 -0
  376. data/decidim-pages/spec/commands/update_page_spec.rb +57 -0
  377. data/decidim-pages/spec/factories.rb +10 -0
  378. data/decidim-pages/spec/features/admin_spec.rb +71 -0
  379. data/decidim-pages/spec/features/page_show_spec.rb +67 -0
  380. data/decidim-pages/spec/forms/page_form_spec.rb +63 -0
  381. data/decidim-pages/spec/models/page_spec.rb +18 -0
  382. data/decidim-pages/spec/spec_helper.rb +2 -0
  383. data/decidim-proposals/.gitignore +3 -0
  384. data/decidim-proposals/README.md +24 -0
  385. data/decidim-proposals/Rakefile +2 -0
  386. data/decidim-proposals/app/commands/decidim/proposals/admin/create_proposal.rb +43 -0
  387. data/decidim-proposals/app/commands/decidim/proposals/create_proposal.rb +42 -0
  388. data/decidim-proposals/app/controllers/decidim/proposals/admin/application_controller.rb +14 -0
  389. data/decidim-proposals/app/controllers/decidim/proposals/admin/proposals_controller.rb +37 -0
  390. data/decidim-proposals/app/controllers/decidim/proposals/application_controller.rb +13 -0
  391. data/decidim-proposals/app/controllers/decidim/proposals/proposals_controller.rb +41 -0
  392. data/decidim-proposals/app/forms/decidim/proposals/admin/proposal_form.rb +38 -0
  393. data/decidim-proposals/app/forms/decidim/proposals/proposal_form.rb +37 -0
  394. data/decidim-proposals/app/helpers/decidim/proposals/application_helper.rb +10 -0
  395. data/decidim-proposals/app/models/decidim/proposals/application_record.rb +9 -0
  396. data/decidim-proposals/app/models/decidim/proposals/proposal.rb +53 -0
  397. data/decidim-proposals/app/services/decidim/proposals/proposal_search.rb +36 -0
  398. data/decidim-proposals/app/views/decidim/proposals/admin/proposals/_form.html.erb +19 -0
  399. data/decidim-proposals/app/views/decidim/proposals/admin/proposals/index.html.erb +34 -0
  400. data/decidim-proposals/app/views/decidim/proposals/admin/proposals/new.html.erb +9 -0
  401. data/decidim-proposals/app/views/decidim/proposals/proposals/_proposal.html.erb +34 -0
  402. data/decidim-proposals/app/views/decidim/proposals/proposals/index.html.erb +23 -0
  403. data/decidim-proposals/app/views/decidim/proposals/proposals/new.html.erb +40 -0
  404. data/decidim-proposals/app/views/decidim/proposals/proposals/show.html.erb +37 -0
  405. data/decidim-proposals/bin/rails +14 -0
  406. data/decidim-proposals/config/i18n-tasks.yml +4 -0
  407. data/decidim-proposals/config/locales/ca.yml +46 -0
  408. data/decidim-proposals/config/locales/en.yml +47 -0
  409. data/decidim-proposals/config/locales/es.yml +46 -0
  410. data/decidim-proposals/db/migrate/20161212110850_create_decidim_proposals.rb +14 -0
  411. data/decidim-proposals/decidim-proposals.gemspec +22 -0
  412. data/decidim-proposals/lib/decidim/proposals.rb +12 -0
  413. data/decidim-proposals/lib/decidim/proposals/admin.rb +9 -0
  414. data/decidim-proposals/lib/decidim/proposals/admin_engine.rb +20 -0
  415. data/decidim-proposals/lib/decidim/proposals/engine.rb +18 -0
  416. data/decidim-proposals/lib/decidim/proposals/feature.rb +35 -0
  417. data/decidim-proposals/spec/commands/decidim/proposals/create_proposal_spec.rb +58 -0
  418. data/decidim-proposals/spec/factories.rb +18 -0
  419. data/decidim-proposals/spec/features/admin_manages_proposals_spec.rb +16 -0
  420. data/decidim-proposals/spec/features/process_admin_manages_proposals_spec.rb +17 -0
  421. data/decidim-proposals/spec/features/proposals_spec.rb +117 -0
  422. data/decidim-proposals/spec/forms/decidim/proposals/proposal_form_spec.rb +104 -0
  423. data/decidim-proposals/spec/lib/decidim/proposals/feature_spec.rb +31 -0
  424. data/decidim-proposals/spec/models/decidim/proposals/proposal_spec.rb +30 -0
  425. data/decidim-proposals/spec/services/decidim/proposals/proposal_search_spec.rb +62 -0
  426. data/decidim-proposals/spec/shared/admin_shared_context.rb +11 -0
  427. data/decidim-proposals/spec/shared/manage_proposals_examples.rb +40 -0
  428. data/decidim-proposals/spec/spec_helper.rb +2 -0
  429. data/decidim-system/Rakefile +0 -25
  430. data/decidim-system/app/assets/javascripts/decidim/system/application.js.es6 +6 -5
  431. data/decidim-system/app/assets/stylesheets/decidim/system/application.scss +7 -2
  432. data/decidim-system/app/commands/decidim/system/create_admin.rb +1 -1
  433. data/decidim-system/app/commands/decidim/system/create_default_pages.rb +43 -0
  434. data/decidim-system/app/commands/decidim/system/register_organization.rb +4 -2
  435. data/decidim-system/app/commands/decidim/system/update_admin.rb +1 -1
  436. data/decidim-system/app/commands/decidim/system/update_organization.rb +1 -2
  437. data/decidim-system/app/controllers/decidim/system/admins_controller.rb +4 -4
  438. data/decidim-system/app/controllers/decidim/system/application_controller.rb +1 -0
  439. data/decidim-system/app/controllers/decidim/system/organizations_controller.rb +4 -4
  440. data/decidim-system/app/forms/decidim/system/admin_form.rb +1 -1
  441. data/decidim-system/app/forms/decidim/system/register_organization_form.rb +6 -5
  442. data/decidim-system/app/forms/decidim/system/update_organization_form.rb +1 -3
  443. data/decidim-system/app/helpers/decidim/system/application_helper.rb +2 -0
  444. data/decidim-system/app/views/decidim/system/organizations/edit.html.erb +0 -4
  445. data/decidim-system/app/views/decidim/system/organizations/new.html.erb +23 -3
  446. data/decidim-system/config/i18n-tasks.yml +3 -1
  447. data/decidim-system/config/locales/ca.yml +15 -10
  448. data/decidim-system/config/locales/en.yml +6 -0
  449. data/decidim-system/config/locales/es.yml +11 -6
  450. data/decidim-system/db/seeds.rb +5 -2
  451. data/decidim-system/decidim-system.gemspec +6 -10
  452. data/decidim-system/lib/decidim/system/engine.rb +7 -2
  453. data/decidim-system/spec/commands/decidim/system/create_default_pages_spec.rb +30 -0
  454. data/decidim-system/spec/commands/decidim/system/register_organization_spec.rb +9 -3
  455. data/decidim-system/spec/features/organizations_spec.rb +4 -3
  456. data/decidim.gemspec +7 -8
  457. data/docs/features_and_components.md +45 -0
  458. data/docs/how_to_create_a_plugin.md +183 -0
  459. data/jsconfig.json +3 -0
  460. data/karma.conf.js +43 -0
  461. data/lib/decidim.rb +4 -0
  462. data/lib/generators/decidim/app_builder.rb +2 -0
  463. data/lib/generators/decidim/demo_generator.rb +27 -0
  464. data/lib/generators/decidim/docker_generator.rb +65 -0
  465. data/lib/generators/decidim/install_generator.rb +4 -25
  466. data/lib/generators/decidim/templates/Dockerfile.dev.erb +21 -0
  467. data/lib/generators/decidim/templates/app.json.erb +4 -1
  468. data/lib/generators/decidim/templates/initializer.rb +3 -0
  469. data/package.json +53 -8
  470. data/run_ci.sh +3 -0
  471. data/webpack.config.js +66 -0
  472. data/yarn.lock +4665 -456
  473. metadata +437 -35
  474. data/decidim-admin/LICENSE.txt +0 -619
  475. data/decidim-admin/app/models/decidim/admin/abilities/admin.rb +0 -21
  476. data/decidim-admin/spec/features/manage_participatory_process_steps_spec.rb +0 -151
  477. data/decidim-admin/spec/features/manage_participatory_processes_spec.rb +0 -227
  478. data/decidim-admin/spec/models/abilities/admin_spec.rb +0 -25
  479. data/decidim-admin/vendor/assets/javascripts/html.sortable.min.js +0 -2
  480. data/decidim-api/LICENSE.txt +0 -619
  481. data/decidim-api/app/types/decidim/api/process_step_type.rb +0 -26
  482. data/decidim-api/app/types/decidim/api/process_type.rb +0 -18
  483. data/decidim-api/app/types/decidim/api/query_type.rb +0 -19
  484. data/decidim-api/spec/schemas/schema_spec.rb +0 -38
  485. data/decidim-api/spec/support/type_helpers.rb +0 -46
  486. data/decidim-api/spec/types/process_step_type_spec.rb +0 -50
  487. data/decidim-api/spec/types/process_type_spec.rb +0 -39
  488. data/decidim-system/LICENSE.txt +0 -619
@@ -0,0 +1,173 @@
1
+ /* eslint-disable no-unused-expressions */
2
+ import { shallow, mount } from 'enzyme';
3
+
4
+ import { AddCommentForm } from './add_comment_form.component';
5
+
6
+ import generateCurrentUserData from '../support/generate_current_user_data';
7
+
8
+ describe("<AddCommentForm />", () => {
9
+ let currentUser = null;
10
+ const commentableId = "1";
11
+ const commentableType = "Decidim::ParticipatoryProcess";
12
+ const addCommentStub = () => {
13
+ return null;
14
+ }
15
+
16
+ beforeEach(() => {
17
+ currentUser = generateCurrentUserData();
18
+ });
19
+
20
+ it("should render a div with class add-comment", () => {
21
+ const wrapper = shallow(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} />);
22
+ expect(wrapper.find('div.add-comment')).to.present();
23
+ });
24
+
25
+ it("should have a reference to body textarea", () => {
26
+ const wrapper = mount(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} />);
27
+ expect(wrapper.instance().bodyTextArea).to.be.ok;
28
+ });
29
+
30
+ it("should initialize with a state property disabled as true", () => {
31
+ const wrapper = mount(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} />);
32
+ expect(wrapper).to.have.state('disabled', true);
33
+ });
34
+
35
+ it("should have a default prop showTitle as true", () => {
36
+ const wrapper = mount(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} />);
37
+ expect(wrapper).to.have.prop('showTitle').equal(true);
38
+ });
39
+
40
+ it("should not render the title if prop showTitle is false", () => {
41
+ const wrapper = shallow(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} showTitle={false} />);
42
+ expect(wrapper.find('h5.section-heading')).not.to.be.present();
43
+ });
44
+
45
+ it("should have a default prop submitButtonClassName as 'button button--sc'", () => {
46
+ const wrapper = mount(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} />);
47
+ expect(wrapper).to.have.prop('submitButtonClassName').equal('button button--sc');
48
+ });
49
+
50
+ it("should use prop submitButtonClassName as a className prop for submit button", () => {
51
+ const wrapper = shallow(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} submitButtonClassName="button small hollow" />);
52
+ expect(wrapper.find('input[type="submit"]')).to.have.className('button');
53
+ expect(wrapper.find('input[type="submit"]')).to.have.className('small');
54
+ expect(wrapper.find('input[type="submit"]')).to.have.className('hollow');
55
+ });
56
+
57
+ it("should enable the submit button if textarea is not blank", () => {
58
+ const wrapper = mount(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} />);
59
+ wrapper.find('textarea').simulate('change', {
60
+ target: {
61
+ value: 'This is a comment'
62
+ }
63
+ });
64
+ expect(wrapper.find('input[type="submit"]')).not.to.be.disabled();
65
+ });
66
+
67
+ it("should disable the submit button if textarea is blank", () => {
68
+ const wrapper = mount(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} />);
69
+ wrapper.find('textarea').simulate('change', {
70
+ target: {
71
+ value: 'This will be deleted'
72
+ }
73
+ });
74
+ wrapper.find('textarea').simulate('change', {
75
+ target: {
76
+ value: ''
77
+ }
78
+ });
79
+ expect(wrapper.find('input[type="submit"]')).to.be.disabled();
80
+ });
81
+
82
+ it("should not render a div with class 'opinion-toggle'", () => {
83
+ const wrapper = shallow(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} />);
84
+ expect(wrapper.find('.opinion-toggle')).not.to.be.present();
85
+ });
86
+
87
+ describe("submitting the form", () => {
88
+ let addComment = null;
89
+ let onCommentAdded = null;
90
+ let wrapper = null;
91
+ let message = null;
92
+
93
+ beforeEach(() => {
94
+ addComment = sinon.spy();
95
+ onCommentAdded = sinon.spy();
96
+ wrapper = mount(<AddCommentForm addComment={addComment} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} onCommentAdded={onCommentAdded} />);
97
+ message = 'This will be submitted';
98
+ wrapper.instance().bodyTextArea.value = message;
99
+ });
100
+
101
+ it("should call addComment prop with the textarea value and state property alignment", () => {
102
+ wrapper.find('form').simulate('submit');
103
+ expect(addComment).to.calledWith({ body: message, alignment: 0 });
104
+ });
105
+
106
+ it("should reset textarea", () => {
107
+ wrapper.find('form').simulate('submit');
108
+ expect(wrapper.find('textarea')).to.have.value('');
109
+ });
110
+
111
+ it("should prevent default form submission", () => {
112
+ const preventDefault = sinon.spy();
113
+ wrapper.find('form').simulate('submit', { preventDefault });
114
+ expect(preventDefault).to.have.been.called;
115
+ });
116
+
117
+ it("should call the prop onCommentAdded function", () => {
118
+ wrapper.find('form').simulate('submit');
119
+ expect(onCommentAdded).to.have.been.called;
120
+ });
121
+ });
122
+
123
+ it("should initialize state with a property alignment and value 0", () => {
124
+ const wrapper = shallow(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} arguable />);
125
+ expect(wrapper).to.have.state('alignment').equal(0);
126
+ });
127
+
128
+ describe("when receiving an optional prop arguable with value true", () => {
129
+ it("should render a div with class 'opinion-toggle'", () => {
130
+ const wrapper = shallow(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} arguable />);
131
+ expect(wrapper.find('.opinion-toggle')).to.be.present();
132
+ });
133
+
134
+ it("should set state alignment to 1 if user clicks ok button and change its class", () => {
135
+ const wrapper = shallow(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} arguable />);
136
+ wrapper.find('.opinion-toggle--ok').simulate('click');
137
+ expect(wrapper.find('.opinion-toggle--ok')).to.have.className('is-active');
138
+ expect(wrapper).to.have.state('alignment').equal(1);
139
+ });
140
+
141
+ it("should set state alignment to -11 if user clicks ko button and change its class", () => {
142
+ const wrapper = shallow(<AddCommentForm addComment={addCommentStub} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} arguable />);
143
+ wrapper.find('.opinion-toggle--ko').simulate('click');
144
+ expect(wrapper.find('.opinion-toggle--ko')).to.have.className('is-active');
145
+ expect(wrapper).to.have.state('alignment').equal(-1);
146
+ });
147
+
148
+ describe("submitting the form", () => {
149
+ let addComment = null;
150
+ let wrapper = null;
151
+ let message = null;
152
+
153
+ beforeEach(() => {
154
+ addComment = sinon.spy();
155
+ wrapper = mount(<AddCommentForm addComment={addComment} currentUser={currentUser} commentableId={commentableId} commentableType={commentableType} arguable />);
156
+ message = 'This will be submitted';
157
+ wrapper.instance().bodyTextArea.value = message;
158
+ });
159
+
160
+ it("should call addComment prop with the state's property alignment", () => {
161
+ wrapper.find('button.opinion-toggle--ko').simulate('click');
162
+ wrapper.find('form').simulate('submit');
163
+ expect(addComment).to.calledWith({ body: message, alignment: -1 });
164
+ });
165
+
166
+ it("should reset the state to its initial state", () => {
167
+ wrapper.find('button.opinion-toggle--ok').simulate('click');
168
+ wrapper.find('form').simulate('submit');
169
+ expect(wrapper).to.have.state('alignment').eq(0);
170
+ });
171
+ });
172
+ });
173
+ });
@@ -0,0 +1,8 @@
1
+ mutation addComment($commentableId: String!, $commentableType: String!, $body: String!, $alignment: Int) {
2
+ addComment(commentableId: $commentableId, commentableType: $commentableType, body: $body, alignment: $alignment) {
3
+ ...CommentData
4
+ replies {
5
+ id
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,202 @@
1
+ import { Component, PropTypes } from 'react';
2
+ import { propType } from 'graphql-anywhere';
3
+ import gql from 'graphql-tag';
4
+ import moment from 'moment';
5
+ import { I18n } from 'react-i18nify';
6
+ import classnames from 'classnames';
7
+
8
+ import AddCommentForm from './add_comment_form.component';
9
+
10
+ import commentFragment from './comment.fragment.graphql';
11
+ import commentDataFragment from './comment_data.fragment.graphql';
12
+
13
+ /**
14
+ * A single comment component with the author info and the comment's body
15
+ * @class
16
+ * @augments Component
17
+ */
18
+ class Comment extends Component {
19
+ constructor(props) {
20
+ super(props);
21
+
22
+ this.state = {
23
+ showReplyForm: false
24
+ };
25
+ }
26
+
27
+ render() {
28
+ const { comment: { id, author, body, createdAt }, articleClassName } = this.props;
29
+
30
+ const formattedCreatedAt = ` ${moment(createdAt, "YYYY-MM-DD HH:mm:ss z").format("LLL")}`;
31
+
32
+ return (
33
+ <article id={`comment_${id}`} className={articleClassName}>
34
+ <div className="comment__header">
35
+ <div className="author-data">
36
+ <div className="author-data__main">
37
+ <div className="author author--inline">
38
+ <a className="author__avatar">
39
+ <img src={author.avatarUrl} alt="author-avatar" />
40
+ </a>
41
+ <a className="author__name">{author.name}</a>
42
+ <time dateTime={createdAt}>{formattedCreatedAt}</time>
43
+ </div>
44
+ </div>
45
+ </div>
46
+ </div>
47
+ <div className="comment__content">
48
+ <p>
49
+ { this._renderAlignmentBadge() }
50
+ { body }
51
+ </p>
52
+ </div>
53
+ {this._renderReplies()}
54
+ <div className="comment__footer">
55
+ {this._renderReplyButton()}
56
+ </div>
57
+ {this._renderReplyForm()}
58
+ </article>
59
+ );
60
+ }
61
+
62
+ /**
63
+ * Render reply button if user can reply the comment
64
+ * @private
65
+ * @returns {Void|DOMElement} - Render the reply button or not if user can reply
66
+ */
67
+ _renderReplyButton() {
68
+ const { comment: { canHaveReplies }, currentUser } = this.props;
69
+ const { showReplyForm } = this.state;
70
+
71
+ if (currentUser && canHaveReplies) {
72
+ return (
73
+ <button
74
+ className="comment__reply muted-link"
75
+ aria-controls="comment1-reply"
76
+ onClick={() => this.setState({ showReplyForm: !showReplyForm })}
77
+ >
78
+ { I18n.t("components.comment.reply") }
79
+ </button>
80
+ );
81
+ }
82
+
83
+ return <div>&nbsp;</div>;
84
+ }
85
+
86
+ /**
87
+ * Render comment replies alternating the css class
88
+ * @private
89
+ * @returns {Void|DomElement} - A wrapper element with comment replies inside
90
+ */
91
+ _renderReplies() {
92
+ const { comment: { id, replies }, currentUser, articleClassName } = this.props;
93
+ let replyArticleClassName = 'comment comment--nested';
94
+
95
+ if (articleClassName === 'comment comment--nested') {
96
+ replyArticleClassName = `${replyArticleClassName} comment--nested--alt`;
97
+ }
98
+
99
+ if (replies) {
100
+ return (
101
+ <div>
102
+ {
103
+ replies.map((reply) => (
104
+ <Comment
105
+ key={`comment_${id}_reply_${reply.id}`}
106
+ comment={reply}
107
+ currentUser={currentUser}
108
+ articleClassName={replyArticleClassName}
109
+ />
110
+ ))
111
+ }
112
+ </div>
113
+ );
114
+ }
115
+
116
+ return null;
117
+ }
118
+
119
+ /**
120
+ * Render reply form based on the current component state
121
+ * @private
122
+ * @returns {Void|ReactElement} - Render the AddCommentForm component or not
123
+ */
124
+ _renderReplyForm() {
125
+ const { currentUser, comment } = this.props;
126
+ const { showReplyForm } = this.state;
127
+
128
+ if (showReplyForm) {
129
+ return (
130
+ <AddCommentForm
131
+ commentableId={comment.id}
132
+ commentableType="Decidim::Comments::Comment"
133
+ currentUser={currentUser}
134
+ showTitle={false}
135
+ submitButtonClassName="button small hollow"
136
+ onCommentAdded={() => this.setState({ showReplyForm: false })}
137
+ />
138
+ );
139
+ }
140
+
141
+ return null;
142
+ }
143
+
144
+ /**
145
+ * Render alignment badge if comment's alignment is 0 or -1
146
+ * @private
147
+ * @returns {Void|DOMElement} - The alignment's badge or not
148
+ */
149
+ _renderAlignmentBadge() {
150
+ const { comment: { alignment } } = this.props;
151
+ const spanClassName = classnames('label', {
152
+ success: alignment === 1,
153
+ alert: alignment === -1
154
+ });
155
+
156
+ let label = '';
157
+
158
+ if (alignment === 1) {
159
+ label = I18n.t('components.comment.alignment.in_favor');
160
+ } else {
161
+ label = I18n.t('components.comment.alignment.against');
162
+ }
163
+
164
+ if (alignment === 1 || alignment === -1) {
165
+ return (
166
+ <span>
167
+ <span className={spanClassName}>{ label }</span>
168
+ &nbsp;
169
+ </span>
170
+ );
171
+ }
172
+
173
+ return null;
174
+ }
175
+ }
176
+
177
+ Comment.fragments = {
178
+ comment: gql`
179
+ ${commentFragment}
180
+ ${commentDataFragment}
181
+ `,
182
+ commentData: gql`
183
+ ${commentDataFragment}
184
+ `
185
+ };
186
+
187
+ Comment.defaultProps = {
188
+ articleClassName: 'comment'
189
+ };
190
+
191
+ Comment.propTypes = {
192
+ comment: PropTypes.oneOfType([
193
+ propType(Comment.fragments.comment).isRequired,
194
+ propType(Comment.fragments.commentData).isRequired
195
+ ]).isRequired,
196
+ currentUser: PropTypes.shape({
197
+ name: PropTypes.string.isRequired
198
+ }),
199
+ articleClassName: PropTypes.string.isRequired
200
+ };
201
+
202
+ export default Comment;
@@ -0,0 +1,125 @@
1
+ import { shallow, mount } from 'enzyme';
2
+ import { filter } from 'graphql-anywhere';
3
+ import gql from 'graphql-tag';
4
+
5
+ import Comment from './comment.component';
6
+ import AddCommentForm from './add_comment_form.component';
7
+
8
+ import commentFragment from './comment.fragment.graphql';
9
+ import commentDataFragment from './comment_data.fragment.graphql';
10
+
11
+ import stubComponent from '../support/stub_component';
12
+ import generateCommentsData from '../support/generate_comments_data';
13
+ import generateCurrentUserData from '../support/generate_current_user_data';
14
+
15
+ describe("<Comment />", () => {
16
+ let comment = {};
17
+ let currentUser = null;
18
+
19
+ stubComponent(AddCommentForm);
20
+
21
+ beforeEach(() => {
22
+ let commentsData = generateCommentsData(1);
23
+ commentsData[0].replies = generateCommentsData(3);
24
+ const currentUserData = generateCurrentUserData();
25
+
26
+ const fragment = gql`
27
+ ${commentFragment}
28
+ ${commentDataFragment}
29
+ `;
30
+
31
+ comment = filter(fragment, commentsData[0]);
32
+ currentUser = currentUserData;
33
+ });
34
+
35
+ it("should render an article with class comment", () => {
36
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} />);
37
+ expect(wrapper.find('article.comment')).to.present();
38
+ });
39
+
40
+ it("should render a time tag with comment's created at", () => {
41
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} />);
42
+ expect(wrapper.find('time')).to.have.text(comment.created_at);
43
+ });
44
+
45
+ it("should render author's name in a link with class author__name", () => {
46
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} />);
47
+ expect(wrapper.find('a.author__name')).to.have.text(comment.author.name);
48
+ });
49
+
50
+ it("should render author's avatar as a image tag", () => {
51
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} />);
52
+ expect(wrapper.find('a.author__avatar img')).to.have.attr('src').equal(comment.author.avatarUrl);
53
+ });
54
+
55
+ it("should render comment's body on a div with class comment__content", () => {
56
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} />);
57
+ expect(wrapper.find('div.comment__content')).to.have.text(comment.body);
58
+ });
59
+
60
+ it("should initialize with a state property showReplyForm as false", () => {
61
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} />);
62
+ expect(wrapper).to.have.state('showReplyForm', false);
63
+ });
64
+
65
+ it("should render a AddCommentForm component with the correct props when clicking the reply button", () => {
66
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} />);
67
+ expect(wrapper.find(AddCommentForm)).not.to.be.present();
68
+ wrapper.find('button.comment__reply').simulate('click');
69
+ expect(wrapper.find(AddCommentForm)).to.have.prop('currentUser').deep.equal(currentUser);
70
+ expect(wrapper.find(AddCommentForm)).to.have.prop('commentableId').equal(comment.id);
71
+ expect(wrapper.find(AddCommentForm)).to.have.prop('commentableType').equal("Decidim::Comments::Comment");
72
+ expect(wrapper.find(AddCommentForm)).to.have.prop('showTitle').equal(false);
73
+ expect(wrapper.find(AddCommentForm)).to.have.prop('submitButtonClassName').equal('button small hollow');
74
+ });
75
+
76
+ it("should not render the reply button if the comment cannot have replies", () => {
77
+ comment.canHaveReplies = false;
78
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} />);
79
+ expect(wrapper.find('button.comment__reply')).not.to.be.present();
80
+ });
81
+
82
+ it("should render comment replies a separate Comment components", () => {
83
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} />);
84
+ wrapper.find(Comment).forEach((node, idx) => {
85
+ expect(node).to.have.prop("comment").deep.equal(comment.replies[idx]);
86
+ expect(node).to.have.prop("currentUser").deep.equal(currentUser);
87
+ expect(node).to.have.prop("articleClassName").equal("comment comment--nested")
88
+ });
89
+ });
90
+
91
+ it("should render comment replies with articleClassName as 'comment comment--nested comment--nested--alt' when articleClassName is 'comment comment--nested'", () => {
92
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} articleClassName="comment comment--nested" />);
93
+ wrapper.find(Comment).forEach((node) => {
94
+ expect(node).to.have.prop("articleClassName").equal("comment comment--nested comment--nested--alt")
95
+ });
96
+ });
97
+
98
+ it("should have a default prop articleClassName with value 'comment'", () => {
99
+ const wrapper = mount(<Comment comment={comment} currentUser={currentUser} />);
100
+ expect(wrapper).to.have.prop("articleClassName").equal("comment");
101
+ });
102
+
103
+ describe("when user is not logged in", () => {
104
+ beforeEach(() => {
105
+ currentUser = null;
106
+ });
107
+
108
+ it("should not render reply button", () => {
109
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} />);
110
+ expect(wrapper.find('button.comment__reply')).not.to.be.present();
111
+ });
112
+ });
113
+
114
+ it("should render a 'in favor' badge if comment's alignment is 1", () => {
115
+ comment.alignment = 1;
116
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} />);
117
+ expect(wrapper.find('span.success.label')).to.have.text('In favor');
118
+ });
119
+
120
+ it("should render a 'against' badge if comment's alignment is -1", () => {
121
+ comment.alignment = -1;
122
+ const wrapper = shallow(<Comment comment={comment} currentUser={currentUser} />);
123
+ expect(wrapper.find('span.alert.label')).to.have.text('Against');
124
+ });
125
+ });