decidim-chatbot 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.erb_lint.yml +2134 -0
- data/.github/workflows/website.yml +57 -0
- data/.gitignore +13 -0
- data/.gitlab-ci.yml +204 -0
- data/.node-version +1 -0
- data/.nvmrc +1 -0
- data/.rspec +2 -0
- data/.rubocop.yml +17 -0
- data/.ruby-version +1 -0
- data/.simplecov +36 -0
- data/CONTRIBUTING.md +54 -0
- data/Gemfile +50 -0
- data/Gemfile.lock +1013 -0
- data/LICENSE.md +661 -0
- data/README.md +62 -0
- data/Rakefile +54 -0
- data/app/commands/decidim/chatbot/admin/destroy_item.rb +25 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_exit.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_login.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_propose_proposals.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_read_blogs.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_read_proposals.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_vote_on_proposal.rb +12 -0
- data/app/commands/decidim/chatbot/admin/notifications/update_manual.rb +12 -0
- data/app/commands/decidim/chatbot/admin/notifications/update_phase.rb +12 -0
- data/app/commands/decidim/chatbot/admin/persist_item.rb +47 -0
- data/app/commands/decidim/chatbot/admin/reorder_items.rb +51 -0
- data/app/commands/decidim/chatbot/admin/send_test_notification.rb +74 -0
- data/app/commands/decidim/chatbot/admin/unsubscribe_user.rb +35 -0
- data/app/commands/decidim/chatbot/admin/update_chatbot.rb +17 -0
- data/app/commands/decidim/chatbot/notifications/deliver.rb +30 -0
- data/app/commands/decidim/chatbot/notifications/enqueue_phase.rb +67 -0
- data/app/commands/decidim/chatbot/notifications/send.rb +115 -0
- data/app/commands/decidim/chatbot/whatsapp/create_from_phone.rb +95 -0
- data/app/commands/decidim/chatbot/whatsapp/sync_phone.rb +56 -0
- data/app/controllers/decidim/api/rest_full/chatbot/base_controller.rb +52 -0
- data/app/controllers/decidim/api/rest_full/chatbot/chatbot_menu_items_controller.rb +49 -0
- data/app/controllers/decidim/api/rest_full/chatbot/chatbot_users_controller.rb +46 -0
- data/app/controllers/decidim/api/rest_full/chatbot/chatbots_controller.rb +40 -0
- data/app/controllers/decidim/chatbot/admin/chatbot_edit.rb +85 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/generals_controller.rb +43 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/menu_items_controller.rb +32 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/notifications_controller.rb +92 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/users/filterable.rb +33 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/users_controller.rb +53 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/whatsapps_controller.rb +59 -0
- data/app/controllers/decidim/chatbot/admin/chatbots_controller.rb +20 -0
- data/app/controllers/decidim/chatbot/admin/items_crud.rb +183 -0
- data/app/forms/decidim/chatbot/admin/chatbot_form.rb +20 -0
- data/app/forms/decidim/chatbot/admin/config_form.rb +20 -0
- data/app/forms/decidim/chatbot/admin/menu_item_form.rb +80 -0
- data/app/forms/decidim/chatbot/admin/menu_items/component_id_form.rb +60 -0
- data/app/forms/decidim/chatbot/admin/menu_items/exit_form.rb +24 -0
- data/app/forms/decidim/chatbot/admin/menu_items/login_form.rb +35 -0
- data/app/forms/decidim/chatbot/admin/menu_items/propose_proposals_form.rb +23 -0
- data/app/forms/decidim/chatbot/admin/menu_items/propose_proposals_labels.rb +53 -0
- data/app/forms/decidim/chatbot/admin/menu_items/read_blogs_form.rb +23 -0
- data/app/forms/decidim/chatbot/admin/menu_items/read_content_labels.rb +51 -0
- data/app/forms/decidim/chatbot/admin/menu_items/read_proposals_form.rb +23 -0
- data/app/forms/decidim/chatbot/admin/menu_items/vote_on_proposal_form.rb +123 -0
- data/app/forms/decidim/chatbot/admin/notification_item_form.rb +111 -0
- data/app/forms/decidim/chatbot/admin/notifications/manual_form.rb +13 -0
- data/app/forms/decidim/chatbot/admin/notifications/phase_form.rb +79 -0
- data/app/forms/decidim/chatbot/admin/notifications/template_fields.rb +60 -0
- data/app/forms/decidim/chatbot/admin/notifications/test_form.rb +179 -0
- data/app/helpers/decidim/chatbot/admin/items_helper.rb +44 -0
- data/app/jobs/decidim/chatbot/chatbot_webhook_job.rb +59 -0
- data/app/jobs/decidim/chatbot/send_notification_job.rb +33 -0
- data/app/models/decidim/chatbot/chatbot.rb +47 -0
- data/app/models/decidim/chatbot/item.rb +99 -0
- data/app/packs/.keep +0 -0
- data/app/presenters/decidim/chatbot/admin_log/chatbot_presenter.rb +42 -0
- data/app/presenters/decidim/chatbot/admin_log/item_presenter.rb +32 -0
- data/app/queries/decidim/chatbot/admin/proposal_vote_mode.rb +41 -0
- data/app/queries/decidim/chatbot/whatsapp_users.rb +58 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_menu_item_serializer.rb +113 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_notification_serializer.rb +19 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_serializer.rb +66 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_user_identity_serializer.rb +23 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_user_serializer.rb +28 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_webhook_serializer.rb +21 -0
- data/app/services/decidim/chatbot/chatbot_webhook_handler.rb +40 -0
- data/app/services/decidim/chatbot/notifications/bindings.rb +87 -0
- data/app/services/decidim/chatbot/whatsapp/body_parameters.rb +29 -0
- data/app/services/decidim/chatbot/whatsapp/graph_client.rb +136 -0
- data/app/services/decidim/chatbot/whatsapp/status_mapper.rb +93 -0
- data/app/services/decidim/chatbot/whatsapp/template_manager_url.rb +35 -0
- data/app/views/decidim/chatbot/admin/chatbots/generals/_menu_preview.html.erb +49 -0
- data/app/views/decidim/chatbot/admin/chatbots/generals/edit.html.erb +79 -0
- data/app/views/decidim/chatbot/admin/chatbots/index.html.erb +50 -0
- data/app/views/decidim/chatbot/admin/chatbots/menu_items/_form.html.erb +2 -0
- data/app/views/decidim/chatbot/admin/chatbots/menu_items/edit.html.erb +2 -0
- data/app/views/decidim/chatbot/admin/chatbots/menu_items/index.html.erb +43 -0
- data/app/views/decidim/chatbot/admin/chatbots/menu_items/new.html.erb +12 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/_form.html.erb +4 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/_manual_fields.html.erb +8 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/_phase_fields.html.erb +6 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/edit.html.erb +3 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/index.html.erb +40 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/new.html.erb +11 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/test.html.erb +35 -0
- data/app/views/decidim/chatbot/admin/chatbots/tabs/_whatsapp.html.erb +47 -0
- data/app/views/decidim/chatbot/admin/chatbots/users/_filters.html.erb +23 -0
- data/app/views/decidim/chatbot/admin/chatbots/users/index.html.erb +56 -0
- data/app/views/decidim/chatbot/admin/chatbots/whatsapps/show.html.erb +5 -0
- data/app/views/decidim/chatbot/admin/shared/_item_form.html.erb +64 -0
- data/app/views/decidim/chatbot/admin/shared/_row_actions.html.erb +28 -0
- data/app/views/decidim/chatbot/admin/shared/_tabs_menu.html.erb +13 -0
- data/app/views/decidim/chatbot/admin/shared/_type_fields.html.erb +2 -0
- data/app/views/decidim/chatbot/admin/shared/_type_picker.html.erb +15 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_component_id.html.erb +9 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_exit.html.erb +5 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_login.html.erb +8 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_manual.html.erb +16 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_phase.html.erb +46 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_propose_proposals.html.erb +10 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_read_blogs.html.erb +16 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_read_proposals.html.erb +16 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_vote_on_proposal.html.erb +26 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_abstention_label.html.erb +7 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_vote_label.html.erb +7 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_votes_closed_warning.html.erb +6 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_weight_labels.html.erb +15 -0
- data/bin/check +13 -0
- data/bin/ci-setup +38 -0
- data/bin/gen-node-client +112 -0
- data/bin/gen-openapi +248 -0
- data/bin/i18n-tasks +27 -0
- data/bin/postversion +17 -0
- data/config/i18n-tasks.yml +38 -0
- data/config/locales/decidim_chatbot.en.yml +323 -0
- data/config/locales/decidim_chatbot.fr.yml +29 -0
- data/contrib/decidim-node-client/.gitignore +4 -0
- data/contrib/decidim-node-client/.npmignore +1 -0
- data/contrib/decidim-node-client/.openapi-generator/FILES +8 -0
- data/contrib/decidim-node-client/.openapi-generator/VERSION +1 -0
- data/contrib/decidim-node-client/.openapi-generator-ignore +13 -0
- data/contrib/decidim-node-client/.yarnrc.yml +5 -0
- data/contrib/decidim-node-client/README.md +37 -0
- data/contrib/decidim-node-client/api.ts +14193 -0
- data/contrib/decidim-node-client/base.ts +70 -0
- data/contrib/decidim-node-client/common.ts +185 -0
- data/contrib/decidim-node-client/configuration.ts +138 -0
- data/contrib/decidim-node-client/git_push.sh +57 -0
- data/contrib/decidim-node-client/index.ts +16 -0
- data/contrib/decidim-node-client/package.json +49 -0
- data/contrib/decidim-node-client/packup.config.ts +7 -0
- data/contrib/decidim-node-client/tsconfig.json +25 -0
- data/contrib/decidim-node-client/yarn.lock +2367 -0
- data/crowdin.yml +15 -0
- data/db/migrate/20260725120000_create_decidim_chatbot_chatbots.rb +20 -0
- data/db/migrate/20260822120000_create_decidim_chatbot_items.rb +20 -0
- data/db/migrate/20260824120000_add_menu_and_error_copy_to_decidim_chatbot_chatbots.rb +13 -0
- data/db/migrate/20260824140000_add_enabled_to_decidim_chatbot_items.rb +7 -0
- data/decidim-chatbot.gemspec +40 -0
- data/docker-compose.ci.yml +59 -0
- data/docker-compose.yml +47 -0
- data/lib/decidim/chatbot/admin_engine.rb +67 -0
- data/lib/decidim/chatbot/admin_menu.rb +41 -0
- data/lib/decidim/chatbot/default_manifests.rb +91 -0
- data/lib/decidim/chatbot/engine.rb +107 -0
- data/lib/decidim/chatbot/manifest.rb +31 -0
- data/lib/decidim/chatbot/menu_item_label_keys.rb +26 -0
- data/lib/decidim/chatbot/registry.rb +42 -0
- data/lib/decidim/chatbot/rest_full_ability.rb +24 -0
- data/lib/decidim/chatbot/settings_tab.rb +18 -0
- data/lib/decidim/chatbot/test_definitions.rb +352 -0
- data/lib/decidim/chatbot/variable_interpolator.rb +30 -0
- data/lib/decidim/chatbot/version.rb +21 -0
- data/lib/decidim/chatbot/webhook_publisher.rb +29 -0
- data/lib/decidim/chatbot.rb +41 -0
- data/lib/decidim-chatbot.rb +3 -0
- data/lib/tasks/chatbot.rake +64 -0
- data/openapi/openapi.json +37801 -0
- data/openapitools.json +7 -0
- data/package.json +22 -0
- data/prettier.config.js +15 -0
- data/spec/commands/decidim/chatbot/admin/destroy_item_spec.rb +24 -0
- data/spec/commands/decidim/chatbot/admin/persist_item_spec.rb +80 -0
- data/spec/commands/decidim/chatbot/admin/reorder_items_spec.rb +53 -0
- data/spec/commands/decidim/chatbot/admin/send_test_notification_spec.rb +105 -0
- data/spec/commands/decidim/chatbot/admin/unsubscribe_user_spec.rb +46 -0
- data/spec/commands/decidim/chatbot/admin/update_chatbot_spec.rb +56 -0
- data/spec/commands/decidim/chatbot/notifications/enqueue_phase_spec.rb +59 -0
- data/spec/commands/decidim/chatbot/notifications/send_spec.rb +101 -0
- data/spec/commands/decidim/chatbot/whatsapp/create_from_phone_spec.rb +122 -0
- data/spec/commands/decidim/chatbot/whatsapp/sync_phone_spec.rb +110 -0
- data/spec/controllers/decidim/chatbot/admin/chatbots_controller_spec.rb +25 -0
- data/spec/factories/chatbot.rb +44 -0
- data/spec/forms/decidim/chatbot/admin/chatbot_form_spec.rb +41 -0
- data/spec/forms/decidim/chatbot/admin/config_form_spec.rb +30 -0
- data/spec/forms/decidim/chatbot/admin/menu_item_form_spec.rb +49 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/component_id_form_spec.rb +54 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/component_id_forms_spec.rb +512 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/exit_form_spec.rb +39 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/login_form_spec.rb +101 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/propose_proposals_form_prefill_spec.rb +26 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/read_blogs_form_prefill_spec.rb +22 -0
- data/spec/forms/decidim/chatbot/admin/notifications/manual_form_spec.rb +130 -0
- data/spec/forms/decidim/chatbot/admin/notifications/phase_form_spec.rb +79 -0
- data/spec/forms/decidim/chatbot/admin/notifications/test_form_spec.rb +172 -0
- data/spec/jobs/decidim/chatbot/chatbot_webhook_job_spec.rb +47 -0
- data/spec/jobs/decidim/chatbot/send_notification_job_spec.rb +53 -0
- data/spec/lib/decidim/chatbot/engine_spec.rb +44 -0
- data/spec/lib/decidim/chatbot/registry_spec.rb +30 -0
- data/spec/lib/decidim/chatbot/settings_tab_spec.rb +21 -0
- data/spec/lib/decidim/chatbot/variable_interpolator_spec.rb +34 -0
- data/spec/lib/decidim/chatbot/whatsapp/status_mapper_spec.rb +64 -0
- data/spec/lib/decidim/chatbot_spec.rb +59 -0
- data/spec/models/decidim/chatbot/chatbot_spec.rb +23 -0
- data/spec/models/decidim/chatbot/item_spec.rb +88 -0
- data/spec/presenters/decidim/chatbot/admin_log/chatbot_presenter_spec.rb +64 -0
- data/spec/queries/decidim/chatbot/admin/proposal_vote_mode_spec.rb +74 -0
- data/spec/queries/decidim/chatbot/whatsapp_users_spec.rb +57 -0
- data/spec/requests/decidim/api/rest_full/chatbot/chatbot_menu_items_controller_spec.rb +344 -0
- data/spec/requests/decidim/api/rest_full/chatbot/chatbot_users_controller_spec.rb +140 -0
- data/spec/requests/decidim/api/rest_full/chatbot/chatbots_controller_spec.rb +195 -0
- data/spec/requests/decidim/chatbot/admin/chatbots/notifications_controller_spec.rb +44 -0
- data/spec/requests/decidim/chatbot/admin/tenant_isolation_spec.rb +133 -0
- data/spec/requests/decidim/chatbot/admin/unsubscribe_user_spec.rb +28 -0
- data/spec/serializers/decidim/api/rest_full/chatbot/chatbot_menu_item_serializer_spec.rb +321 -0
- data/spec/serializers/decidim/api/rest_full/chatbot/chatbot_serializer_spec.rb +49 -0
- data/spec/serializers/decidim/api/rest_full/chatbot/chatbot_user_serializer_spec.rb +40 -0
- data/spec/services/decidim/chatbot/chatbot_webhook_handler_spec.rb +43 -0
- data/spec/services/decidim/chatbot/notifications/bindings_spec.rb +86 -0
- data/spec/services/decidim/chatbot/whatsapp/body_parameters_spec.rb +22 -0
- data/spec/services/decidim/chatbot/whatsapp/graph_client_spec.rb +205 -0
- data/spec/services/decidim/chatbot/whatsapp/template_manager_url_spec.rb +33 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/allow_all_hosts.rb +9 -0
- data/spec/support/chatbot_admin.rb +16 -0
- data/spec/support/decidim_factories.rb +7 -0
- data/spec/support/decidim_system_factories.rb +3 -0
- data/spec/support/devise.rb +5 -0
- data/spec/support/rack_test_system_driver.rb +43 -0
- data/spec/support/whatsapp_graph.rb +15 -0
- data/spec/swagger_helper.rb +47 -0
- data/spec/system/decidim/chatbot/admin/admin_can_send_manual_when_ready_spec.rb +35 -0
- data/spec/system/decidim/chatbot/admin/admin_configures_vote_on_proposal_menu_item_spec.rb +84 -0
- data/spec/system/decidim/chatbot/admin/admin_confirms_send_now_recipient_count_spec.rb +40 -0
- data/spec/system/decidim/chatbot/admin/admin_creates_menu_item_with_demo_field_spec.rb +65 -0
- data/spec/system/decidim/chatbot/admin/admin_creates_phase_and_manual_notifications_spec.rb +52 -0
- data/spec/system/decidim/chatbot/admin/admin_does_not_see_other_org_processes_in_phase_select_spec.rb +27 -0
- data/spec/system/decidim/chatbot/admin/admin_does_not_see_other_organization_chatbots_spec.rb +25 -0
- data/spec/system/decidim/chatbot/admin/admin_is_redirected_when_chatbot_is_disabled_spec.rb +28 -0
- data/spec/system/decidim/chatbot/admin/admin_lists_organization_chatbots_spec.rb +36 -0
- data/spec/system/decidim/chatbot/admin/admin_manual_notification_sends_with_nickname_spec.rb +68 -0
- data/spec/system/decidim/chatbot/admin/admin_navigates_chatbot_main_tabs_spec.rb +52 -0
- data/spec/system/decidim/chatbot/admin/admin_phase_notification_sends_on_step_change_spec.rb +79 -0
- data/spec/system/decidim/chatbot/admin/admin_picks_published_blog_component_spec.rb +205 -0
- data/spec/system/decidim/chatbot/admin/admin_picks_published_participatory_space_spec.rb +45 -0
- data/spec/system/decidim/chatbot/admin/admin_reorders_chatbot_menu_items_spec.rb +29 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_disabled_menu_item_faded_on_the_table_spec.rb +23 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_disabled_notification_item_faded_on_the_table_spec.rb +40 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_notification_facts_and_frozen_template_name_spec.rb +71 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_propose_proposals_defaults_prefilled_spec.rb +119 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_type_specific_fields_spec.rb +89 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_whatsapp_facts_and_can_sync_spec.rb +48 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_whatsapp_template_edit_link_spec.rb +37 -0
- data/spec/system/decidim/chatbot/admin/admin_tests_notification_spec.rb +125 -0
- data/spec/system/decidim/chatbot/admin/admin_unchecks_enabled_on_a_menu_item_spec.rb +30 -0
- data/spec/system/decidim/chatbot/admin/admin_unsubscribes_whatsapp_user_from_chatbot_spec.rb +35 -0
- data/spec/system/decidim/chatbot/admin/admin_updates_welcome_message_from_general_tab_spec.rb +84 -0
- data/spec/system/decidim/chatbot/system/admin_updates_organization_chatbot_settings_spec.rb +33 -0
- data/spec/tasks/chatbot_create_spec.rb +99 -0
- data/spec/tasks/chatbot_sync_spec.rb +90 -0
- data/website/.node-version +1 -0
- data/website/.nvmrc +1 -0
- data/website/docs/developer/_category_.json +4 -0
- data/website/docs/developer/contribute.md +87 -0
- data/website/docs/index.md +42 -0
- data/website/docs/integrate/_category_.json +4 -0
- data/website/docs/integrate/index.md +214 -0
- data/website/docusaurus.config.ts +93 -0
- data/website/package.json +37 -0
- data/website/sidebars.ts +7 -0
- data/website/src/css/custom.css +37 -0
- data/website/static/api-docs.html +2218 -0
- data/website/static/img/logo.svg +1 -0
- data/website/static/openapi.json +37801 -0
- data/website/tsconfig.json +6 -0
- data/website/yarn.lock +9782 -0
- data/yarn.lock +1003 -0
- metadata +424 -0
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Chatbot
|
|
7
|
+
module Admin
|
|
8
|
+
module MenuItems
|
|
9
|
+
shared_examples "a component id settings form" do |item_manifest, component_factory|
|
|
10
|
+
subject do
|
|
11
|
+
described_class.from_params(attributes).with_context(current_organization: organization)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:organization) { create(:organization) }
|
|
15
|
+
let(:space) { create(:participatory_process, :published, organization:) }
|
|
16
|
+
let(:component) { create(component_factory, participatory_space: space) }
|
|
17
|
+
let(:attributes) do
|
|
18
|
+
{
|
|
19
|
+
title_en: "Title",
|
|
20
|
+
introduction_en: "Intro",
|
|
21
|
+
manifest_name: item_manifest,
|
|
22
|
+
component_id: component.id,
|
|
23
|
+
menu_button_label_en: "Back to menu",
|
|
24
|
+
read_more_button_label_en: "Read more",
|
|
25
|
+
nothing_to_read_label_en: "Nothing to read"
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it { is_expected.to be_valid }
|
|
30
|
+
|
|
31
|
+
it "keeps translated title and introduction" do
|
|
32
|
+
expect(subject.title["en"]).to eq("Title")
|
|
33
|
+
expect(subject.introduction["en"]).to eq("Intro")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "exposes component_id in settings" do
|
|
37
|
+
expect(subject.settings_hash).to include("component_id" => component.id)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe ReadBlogsForm do
|
|
42
|
+
include_examples "a component id settings form", "read_blogs", :post_component
|
|
43
|
+
|
|
44
|
+
it "exposes menu_button_label and read_more_button_label in settings" do
|
|
45
|
+
expect(subject.settings_hash).to include(
|
|
46
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
47
|
+
"read_more_button_label" => { "en" => "Read more" },
|
|
48
|
+
"nothing_to_read_label" => { "en" => "Nothing to read" }
|
|
49
|
+
)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "when menu_button_label is blank" do
|
|
53
|
+
let(:attributes) do
|
|
54
|
+
{
|
|
55
|
+
title_en: "Title",
|
|
56
|
+
introduction_en: "Intro",
|
|
57
|
+
manifest_name: "read_blogs",
|
|
58
|
+
component_id: component.id,
|
|
59
|
+
menu_button_label_en: "",
|
|
60
|
+
read_more_button_label_en: "Read more",
|
|
61
|
+
nothing_to_read_label_en: "Nothing to read"
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it { is_expected.not_to be_valid }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context "when read_more_button_label is blank" do
|
|
69
|
+
let(:attributes) do
|
|
70
|
+
{
|
|
71
|
+
title_en: "Title",
|
|
72
|
+
introduction_en: "Intro",
|
|
73
|
+
manifest_name: "read_blogs",
|
|
74
|
+
component_id: component.id,
|
|
75
|
+
menu_button_label_en: "Back to menu",
|
|
76
|
+
read_more_button_label_en: "",
|
|
77
|
+
nothing_to_read_label_en: "Nothing to read"
|
|
78
|
+
}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it { is_expected.not_to be_valid }
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context "when nothing_to_read_label is blank" do
|
|
85
|
+
let(:attributes) do
|
|
86
|
+
{
|
|
87
|
+
title_en: "Title",
|
|
88
|
+
introduction_en: "Intro",
|
|
89
|
+
manifest_name: "read_blogs",
|
|
90
|
+
component_id: component.id,
|
|
91
|
+
menu_button_label_en: "Back to menu",
|
|
92
|
+
read_more_button_label_en: "Read more",
|
|
93
|
+
nothing_to_read_label_en: ""
|
|
94
|
+
}
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it { is_expected.not_to be_valid }
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe ReadProposalsForm do
|
|
102
|
+
include_examples "a component id settings form", "read_proposals", :proposal_component
|
|
103
|
+
|
|
104
|
+
it "exposes menu_button_label and read_more_button_label in settings" do
|
|
105
|
+
expect(subject.settings_hash).to include(
|
|
106
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
107
|
+
"read_more_button_label" => { "en" => "Read more" },
|
|
108
|
+
"nothing_to_read_label" => { "en" => "Nothing to read" }
|
|
109
|
+
)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
context "when menu_button_label is blank" do
|
|
113
|
+
let(:attributes) do
|
|
114
|
+
{
|
|
115
|
+
title_en: "Title",
|
|
116
|
+
introduction_en: "Intro",
|
|
117
|
+
manifest_name: "read_proposals",
|
|
118
|
+
component_id: component.id,
|
|
119
|
+
menu_button_label_en: "",
|
|
120
|
+
read_more_button_label_en: "Read more",
|
|
121
|
+
nothing_to_read_label_en: "Nothing to read"
|
|
122
|
+
}
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it { is_expected.not_to be_valid }
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
context "when read_more_button_label is blank" do
|
|
129
|
+
let(:attributes) do
|
|
130
|
+
{
|
|
131
|
+
title_en: "Title",
|
|
132
|
+
introduction_en: "Intro",
|
|
133
|
+
manifest_name: "read_proposals",
|
|
134
|
+
component_id: component.id,
|
|
135
|
+
menu_button_label_en: "Back to menu",
|
|
136
|
+
read_more_button_label_en: "",
|
|
137
|
+
nothing_to_read_label_en: "Nothing to read"
|
|
138
|
+
}
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it { is_expected.not_to be_valid }
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
context "when nothing_to_read_label is blank" do
|
|
145
|
+
let(:attributes) do
|
|
146
|
+
{
|
|
147
|
+
title_en: "Title",
|
|
148
|
+
introduction_en: "Intro",
|
|
149
|
+
manifest_name: "read_proposals",
|
|
150
|
+
component_id: component.id,
|
|
151
|
+
menu_button_label_en: "Back to menu",
|
|
152
|
+
read_more_button_label_en: "Read more",
|
|
153
|
+
nothing_to_read_label_en: ""
|
|
154
|
+
}
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it { is_expected.not_to be_valid }
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
describe ProposeProposalsForm do
|
|
162
|
+
# Shared examples define a baseline `let(:attributes)`; override after include.
|
|
163
|
+
# rubocop:disable RSpec/LetBeforeExamples
|
|
164
|
+
include_examples "a component id settings form", "propose_proposals", :proposal_component
|
|
165
|
+
|
|
166
|
+
let(:attributes) do
|
|
167
|
+
{
|
|
168
|
+
title_en: "Title",
|
|
169
|
+
introduction_en: "Intro",
|
|
170
|
+
manifest_name: "propose_proposals",
|
|
171
|
+
component_id: component.id,
|
|
172
|
+
default_title_label_en: "{{id}} Anonymous proposal",
|
|
173
|
+
body_label_en: "Please write your proposal",
|
|
174
|
+
verification_label_en: "Thanks, here is your proposal:",
|
|
175
|
+
action_prompt_label_en: "What do you want to do with the proposal?",
|
|
176
|
+
save_button_label_en: "Save",
|
|
177
|
+
success_label_en: "Your proposal has been submitted",
|
|
178
|
+
withdraw_button_label_en: "Withdraw",
|
|
179
|
+
withdraw_success_label_en: "Your proposal has been withdrawn",
|
|
180
|
+
creation_not_enabled_label_en: "Proposal creation is not available right now, please come back later.",
|
|
181
|
+
title_blank_label_en: "cannot be blank",
|
|
182
|
+
body_blank_label_en: "cannot be blank",
|
|
183
|
+
title_must_start_with_caps_label_en: "must start with a capital letter",
|
|
184
|
+
body_must_start_with_caps_label_en: "must start with a capital letter",
|
|
185
|
+
title_too_much_caps_label_en: "is using too many capital letters (over 25% of the text)",
|
|
186
|
+
body_too_much_caps_label_en: "is using too many capital letters (over 25% of the text)",
|
|
187
|
+
title_too_short_label_en: "is too short (under %{count} characters)",
|
|
188
|
+
body_too_short_label_en: "is too short (under %{count} characters)",
|
|
189
|
+
title_too_long_label_en: "is too long (maximum is %{count} characters)",
|
|
190
|
+
body_too_long_label_en: "is too long (maximum is %{count} characters)",
|
|
191
|
+
title_too_many_marks_label_en: "is using too many consecutive punctuation marks (e.g. ! and ?)",
|
|
192
|
+
body_too_many_marks_label_en: "is using too many consecutive punctuation marks (e.g. ! and ?)"
|
|
193
|
+
}
|
|
194
|
+
end
|
|
195
|
+
# rubocop:enable RSpec/LetBeforeExamples
|
|
196
|
+
|
|
197
|
+
it "exposes propose labels in settings" do
|
|
198
|
+
expect(subject.settings_hash).to eq(
|
|
199
|
+
"component_id" => component.id,
|
|
200
|
+
"default_title_label" => { "en" => "{{id}} Anonymous proposal" },
|
|
201
|
+
"body_label" => { "en" => "Please write your proposal" },
|
|
202
|
+
"verification_label" => { "en" => "Thanks, here is your proposal:" },
|
|
203
|
+
"action_prompt_label" => { "en" => "What do you want to do with the proposal?" },
|
|
204
|
+
"save_button_label" => { "en" => "Save" },
|
|
205
|
+
"success_label" => { "en" => "Your proposal has been submitted" },
|
|
206
|
+
"withdraw_button_label" => { "en" => "Withdraw" },
|
|
207
|
+
"withdraw_success_label" => { "en" => "Your proposal has been withdrawn" },
|
|
208
|
+
"creation_not_enabled_label" => { "en" => "Proposal creation is not available right now, please come back later." },
|
|
209
|
+
"title_blank_label" => { "en" => "cannot be blank" },
|
|
210
|
+
"body_blank_label" => { "en" => "cannot be blank" },
|
|
211
|
+
"title_must_start_with_caps_label" => { "en" => "must start with a capital letter" },
|
|
212
|
+
"body_must_start_with_caps_label" => { "en" => "must start with a capital letter" },
|
|
213
|
+
"title_too_much_caps_label" => { "en" => "is using too many capital letters (over 25% of the text)" },
|
|
214
|
+
"body_too_much_caps_label" => { "en" => "is using too many capital letters (over 25% of the text)" },
|
|
215
|
+
"title_too_short_label" => { "en" => "is too short (under %{count} characters)" },
|
|
216
|
+
"body_too_short_label" => { "en" => "is too short (under %{count} characters)" },
|
|
217
|
+
"title_too_long_label" => { "en" => "is too long (maximum is %{count} characters)" },
|
|
218
|
+
"body_too_long_label" => { "en" => "is too long (maximum is %{count} characters)" },
|
|
219
|
+
"title_too_many_marks_label" => { "en" => "is using too many consecutive punctuation marks (e.g. ! and ?)" },
|
|
220
|
+
"body_too_many_marks_label" => { "en" => "is using too many consecutive punctuation marks (e.g. ! and ?)" }
|
|
221
|
+
)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
context "when default_title_label is blank" do
|
|
225
|
+
let(:attributes) { super().merge(default_title_label_en: "") }
|
|
226
|
+
|
|
227
|
+
it { is_expected.not_to be_valid }
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
context "when body_label is blank" do
|
|
231
|
+
let(:attributes) { super().merge(body_label_en: "") }
|
|
232
|
+
|
|
233
|
+
it { is_expected.not_to be_valid }
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
context "when verification_label is blank" do
|
|
237
|
+
let(:attributes) { super().merge(verification_label_en: "") }
|
|
238
|
+
|
|
239
|
+
it { is_expected.not_to be_valid }
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
context "when action_prompt_label is blank" do
|
|
243
|
+
let(:attributes) { super().merge(action_prompt_label_en: "") }
|
|
244
|
+
|
|
245
|
+
it { is_expected.not_to be_valid }
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
context "when save_button_label is blank" do
|
|
249
|
+
let(:attributes) { super().merge(save_button_label_en: "") }
|
|
250
|
+
|
|
251
|
+
it { is_expected.not_to be_valid }
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
context "when success_label is blank" do
|
|
255
|
+
let(:attributes) { super().merge(success_label_en: "") }
|
|
256
|
+
|
|
257
|
+
it { is_expected.not_to be_valid }
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
context "when withdraw_button_label is blank" do
|
|
261
|
+
let(:attributes) { super().merge(withdraw_button_label_en: "") }
|
|
262
|
+
|
|
263
|
+
it { is_expected.not_to be_valid }
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
context "when withdraw_success_label is blank" do
|
|
267
|
+
let(:attributes) { super().merge(withdraw_success_label_en: "") }
|
|
268
|
+
|
|
269
|
+
it { is_expected.not_to be_valid }
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
context "when creation_not_enabled_label is blank" do
|
|
273
|
+
let(:attributes) { super().merge(creation_not_enabled_label_en: "") }
|
|
274
|
+
|
|
275
|
+
it { is_expected.not_to be_valid }
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
{
|
|
279
|
+
title_blank_label_en: "",
|
|
280
|
+
body_blank_label_en: "",
|
|
281
|
+
title_must_start_with_caps_label_en: "",
|
|
282
|
+
body_must_start_with_caps_label_en: "",
|
|
283
|
+
title_too_much_caps_label_en: "",
|
|
284
|
+
body_too_much_caps_label_en: "",
|
|
285
|
+
title_too_short_label_en: "",
|
|
286
|
+
body_too_short_label_en: "",
|
|
287
|
+
title_too_long_label_en: "",
|
|
288
|
+
body_too_long_label_en: "",
|
|
289
|
+
title_too_many_marks_label_en: "",
|
|
290
|
+
body_too_many_marks_label_en: ""
|
|
291
|
+
}.each do |attr, blank_value|
|
|
292
|
+
context "when #{attr} is blank" do
|
|
293
|
+
let(:attributes) { super().merge(attr => blank_value) }
|
|
294
|
+
|
|
295
|
+
it { is_expected.not_to be_valid }
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
describe VoteOnProposalForm do
|
|
301
|
+
subject do
|
|
302
|
+
described_class.from_params(attributes).with_context(current_organization: organization)
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
let(:organization) { create(:organization) }
|
|
306
|
+
let(:space) { create(:participatory_process, :published, :with_steps, organization:) }
|
|
307
|
+
let(:component) do
|
|
308
|
+
create(:proposal_component, :with_votes_enabled, participatory_space: space)
|
|
309
|
+
end
|
|
310
|
+
let(:attributes) do
|
|
311
|
+
{
|
|
312
|
+
title_en: "Title",
|
|
313
|
+
introduction_en: "Intro",
|
|
314
|
+
manifest_name: "vote_on_proposal",
|
|
315
|
+
component_id: component.id,
|
|
316
|
+
action_prompt_label_en: "Here the actions you can do:",
|
|
317
|
+
menu_button_label_en: "Back to menu",
|
|
318
|
+
menu_connector_label_en: "See more",
|
|
319
|
+
skip_menu_button_en: "Skip",
|
|
320
|
+
vote_label_en: "Support"
|
|
321
|
+
}
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
it { is_expected.to be_valid }
|
|
325
|
+
|
|
326
|
+
it "exposes simple vote settings" do
|
|
327
|
+
expect(subject.settings_hash).to eq(
|
|
328
|
+
"component_id" => component.id,
|
|
329
|
+
"action_prompt_label" => { "en" => "Here the actions you can do:" },
|
|
330
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
331
|
+
"menu_connector_label" => { "en" => "See more" },
|
|
332
|
+
"skip_menu_button" => { "en" => "Skip" },
|
|
333
|
+
"vote_label" => { "en" => "Support" }
|
|
334
|
+
)
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
it "shows the vote label and not weight labels" do
|
|
338
|
+
expect(subject).to be_shows_vote_label
|
|
339
|
+
expect(subject).not_to be_shows_weight_labels
|
|
340
|
+
expect(subject).not_to be_shows_abstention_label
|
|
341
|
+
expect(subject).not_to be_shows_votes_closed_warning
|
|
342
|
+
expect(subject).not_to be_shows_vote_behavior_fields
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
context "when action_prompt_label is blank" do
|
|
346
|
+
let(:attributes) { super().merge(action_prompt_label_en: "") }
|
|
347
|
+
|
|
348
|
+
it { is_expected.not_to be_valid }
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
context "when menu_button_label is blank" do
|
|
352
|
+
let(:attributes) { super().merge(menu_button_label_en: "") }
|
|
353
|
+
|
|
354
|
+
it { is_expected.not_to be_valid }
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
context "when menu_connector_label is blank" do
|
|
358
|
+
let(:attributes) { super().merge(menu_connector_label_en: "") }
|
|
359
|
+
|
|
360
|
+
it { is_expected.not_to be_valid }
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
context "when skip_menu_button is blank" do
|
|
364
|
+
let(:attributes) { super().merge(skip_menu_button_en: "") }
|
|
365
|
+
|
|
366
|
+
it { is_expected.not_to be_valid }
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
context "when vote_label is blank on create" do
|
|
370
|
+
let(:attributes) { super().merge(vote_label_en: "") }
|
|
371
|
+
|
|
372
|
+
it { is_expected.to be_valid }
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
context "when editing an existing item" do
|
|
376
|
+
let(:attributes) { super().merge(id: 1, vote_label_en: "") }
|
|
377
|
+
|
|
378
|
+
it { is_expected.not_to be_valid }
|
|
379
|
+
|
|
380
|
+
it { is_expected.to be_shows_vote_behavior_fields }
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
context "when component_id is blank" do
|
|
384
|
+
let(:attributes) { super().merge(component_id: "") }
|
|
385
|
+
|
|
386
|
+
it { is_expected.not_to be_valid }
|
|
387
|
+
|
|
388
|
+
it "skips vote/weight labels when no component is selected" do
|
|
389
|
+
expect(subject).not_to be_shows_vote_label
|
|
390
|
+
expect(subject).not_to be_shows_weight_labels
|
|
391
|
+
expect(subject.settings_hash).to eq(
|
|
392
|
+
"component_id" => nil,
|
|
393
|
+
"action_prompt_label" => { "en" => "Here the actions you can do:" },
|
|
394
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
395
|
+
"menu_connector_label" => { "en" => "See more" },
|
|
396
|
+
"skip_menu_button" => { "en" => "Skip" }
|
|
397
|
+
)
|
|
398
|
+
end
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
context "when votes are disabled" do
|
|
402
|
+
let(:component) do
|
|
403
|
+
create(:proposal_component, :with_votes_disabled, participatory_space: space)
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
it { is_expected.to be_valid }
|
|
407
|
+
|
|
408
|
+
it "warns that votes are closed" do
|
|
409
|
+
expect(subject).to be_shows_votes_closed_warning
|
|
410
|
+
end
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
context "when voting cards are enabled" do
|
|
414
|
+
let(:vote_mode) do
|
|
415
|
+
instance_double(
|
|
416
|
+
ProposalVoteMode,
|
|
417
|
+
votes_open?: true,
|
|
418
|
+
simple_vote?: false,
|
|
419
|
+
voting_cards?: true,
|
|
420
|
+
abstention?: false
|
|
421
|
+
)
|
|
422
|
+
end
|
|
423
|
+
let(:attributes) do
|
|
424
|
+
{
|
|
425
|
+
title_en: "Title",
|
|
426
|
+
introduction_en: "Intro",
|
|
427
|
+
manifest_name: "vote_on_proposal",
|
|
428
|
+
component_id: component.id,
|
|
429
|
+
action_prompt_label_en: "Here the actions you can do:",
|
|
430
|
+
menu_button_label_en: "Back to menu",
|
|
431
|
+
menu_connector_label_en: "See more",
|
|
432
|
+
skip_menu_button_en: "Skip",
|
|
433
|
+
weight_1_label_en: "Disagree",
|
|
434
|
+
weight_2_label_en: "Neutral",
|
|
435
|
+
weight_3_label_en: "Agree"
|
|
436
|
+
}
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
before do
|
|
440
|
+
allow(ProposalVoteMode).to receive(:new).and_return(vote_mode)
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
it { is_expected.to be_valid }
|
|
444
|
+
|
|
445
|
+
it "exposes weight labels without abstention" do
|
|
446
|
+
expect(subject.settings_hash).to eq(
|
|
447
|
+
"component_id" => component.id,
|
|
448
|
+
"action_prompt_label" => { "en" => "Here the actions you can do:" },
|
|
449
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
450
|
+
"menu_connector_label" => { "en" => "See more" },
|
|
451
|
+
"skip_menu_button" => { "en" => "Skip" },
|
|
452
|
+
"weight_1_label" => { "en" => "Disagree" },
|
|
453
|
+
"weight_2_label" => { "en" => "Neutral" },
|
|
454
|
+
"weight_3_label" => { "en" => "Agree" }
|
|
455
|
+
)
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
it "shows weight labels" do
|
|
459
|
+
expect(subject).to be_shows_weight_labels
|
|
460
|
+
expect(subject).not_to be_shows_vote_label
|
|
461
|
+
expect(subject).not_to be_shows_abstention_label
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
context "when a weight label is blank on create" do
|
|
465
|
+
let(:attributes) { super().merge(weight_2_label_en: "") }
|
|
466
|
+
|
|
467
|
+
it { is_expected.to be_valid }
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
context "when a weight label is blank on edit" do
|
|
471
|
+
let(:attributes) { super().merge(id: 1, weight_2_label_en: "") }
|
|
472
|
+
|
|
473
|
+
it { is_expected.not_to be_valid }
|
|
474
|
+
end
|
|
475
|
+
|
|
476
|
+
context "when abstention is enabled" do
|
|
477
|
+
let(:vote_mode) do
|
|
478
|
+
instance_double(
|
|
479
|
+
ProposalVoteMode,
|
|
480
|
+
votes_open?: true,
|
|
481
|
+
simple_vote?: false,
|
|
482
|
+
voting_cards?: true,
|
|
483
|
+
abstention?: true
|
|
484
|
+
)
|
|
485
|
+
end
|
|
486
|
+
let(:attributes) { super().merge(abstention_label_en: "Skip") }
|
|
487
|
+
|
|
488
|
+
it { is_expected.to be_valid }
|
|
489
|
+
|
|
490
|
+
it "includes abstention_label" do
|
|
491
|
+
expect(subject.settings_hash).to include("abstention_label" => { "en" => "Skip" })
|
|
492
|
+
expect(subject).to be_shows_abstention_label
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
context "when abstention_label is blank on create" do
|
|
496
|
+
let(:attributes) { super().merge(abstention_label_en: "") }
|
|
497
|
+
|
|
498
|
+
it { is_expected.to be_valid }
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
context "when abstention_label is blank on edit" do
|
|
502
|
+
let(:attributes) { super().merge(id: 1, abstention_label_en: "") }
|
|
503
|
+
|
|
504
|
+
it { is_expected.not_to be_valid }
|
|
505
|
+
end
|
|
506
|
+
end
|
|
507
|
+
end
|
|
508
|
+
end
|
|
509
|
+
end
|
|
510
|
+
end
|
|
511
|
+
end
|
|
512
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Chatbot
|
|
7
|
+
module Admin
|
|
8
|
+
module MenuItems
|
|
9
|
+
describe ExitForm do
|
|
10
|
+
subject do
|
|
11
|
+
described_class.from_params(attributes).with_context(current_organization: organization)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:organization) { create(:organization) }
|
|
15
|
+
let(:attributes) do
|
|
16
|
+
{ title_en: "Exit", introduction_en: "Intro", manifest_name: "exit", response_label_en: "Leave" }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it { is_expected.to be_valid }
|
|
20
|
+
|
|
21
|
+
it "keeps translated title and introduction" do
|
|
22
|
+
expect(subject.title["en"]).to eq("Exit")
|
|
23
|
+
expect(subject.introduction["en"]).to eq("Intro")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "exposes response_label in settings" do
|
|
27
|
+
expect(subject.settings_hash).to eq("response_label" => { "en" => "Leave" })
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "when response_label is blank" do
|
|
31
|
+
let(:attributes) { { title_en: "Exit", manifest_name: "exit", response_label_en: "" } }
|
|
32
|
+
|
|
33
|
+
it { is_expected.not_to be_valid }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Chatbot
|
|
7
|
+
module Admin
|
|
8
|
+
module MenuItems
|
|
9
|
+
describe LoginForm do
|
|
10
|
+
subject do
|
|
11
|
+
described_class.from_params(attributes).with_context(current_organization: organization)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:organization) { create(:organization) }
|
|
15
|
+
let(:attributes) do
|
|
16
|
+
{
|
|
17
|
+
title_en: "Login",
|
|
18
|
+
manifest_name: "login",
|
|
19
|
+
redirect_path: "/users/sign_in",
|
|
20
|
+
response_label_en: "Open {{login_url}} to continue"
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it { is_expected.to be_valid }
|
|
25
|
+
|
|
26
|
+
it "exposes redirect_path and response_label in settings" do
|
|
27
|
+
expect(subject.settings_hash).to eq(
|
|
28
|
+
"redirect_path" => "/users/sign_in",
|
|
29
|
+
"response_label" => { "en" => "Open {{login_url}} to continue" }
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "when redirect_path is blank" do
|
|
34
|
+
let(:attributes) do
|
|
35
|
+
{
|
|
36
|
+
title_en: "Login",
|
|
37
|
+
manifest_name: "login",
|
|
38
|
+
redirect_path: "",
|
|
39
|
+
response_label_en: "Open {{login_url}}"
|
|
40
|
+
}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it { is_expected.not_to be_valid }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context "when response_label is blank" do
|
|
47
|
+
let(:attributes) do
|
|
48
|
+
{
|
|
49
|
+
title_en: "Login",
|
|
50
|
+
manifest_name: "login",
|
|
51
|
+
redirect_path: "/users/sign_in",
|
|
52
|
+
response_label_en: ""
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it { is_expected.not_to be_valid }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "when redirect_path does not start with /" do
|
|
60
|
+
let(:attributes) do
|
|
61
|
+
{
|
|
62
|
+
title_en: "Login",
|
|
63
|
+
manifest_name: "login",
|
|
64
|
+
redirect_path: "users/sign_in",
|
|
65
|
+
response_label_en: "Open {{login_url}}"
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it { is_expected.not_to be_valid }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context "when redirect_path is protocol-relative" do
|
|
73
|
+
let(:attributes) do
|
|
74
|
+
{
|
|
75
|
+
title_en: "Login",
|
|
76
|
+
manifest_name: "login",
|
|
77
|
+
redirect_path: "//evil.example/x",
|
|
78
|
+
response_label_en: "Open {{login_url}}"
|
|
79
|
+
}
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it { is_expected.not_to be_valid }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "when redirect_path is a full URL" do
|
|
86
|
+
let(:attributes) do
|
|
87
|
+
{
|
|
88
|
+
title_en: "Login",
|
|
89
|
+
manifest_name: "login",
|
|
90
|
+
redirect_path: "https://example.com/",
|
|
91
|
+
response_label_en: "Open {{login_url}}"
|
|
92
|
+
}
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it { is_expected.not_to be_valid }
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Admin::MenuItems::ProposeProposalsForm do
|
|
6
|
+
subject(:form) do
|
|
7
|
+
described_class.from_params(
|
|
8
|
+
manifest_name: "propose_proposals"
|
|
9
|
+
).with_context(current_organization: organization)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
let(:organization) { create(:organization, available_locales: %w(en fr), default_locale: :en) }
|
|
13
|
+
|
|
14
|
+
it "shares LABEL_KEYS with MenuItemLabelKeys" do
|
|
15
|
+
expect(Decidim::Chatbot::MenuItemLabelKeys::PROPOSE_PROPOSALS).to include(:body_label, :title_blank_label)
|
|
16
|
+
expect(Decidim::Chatbot::MenuItemLabelKeys::PROPOSE_PROPOSALS.size).to eq(21)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "prefills defaults for every label key" do
|
|
20
|
+
form.prefill_defaults!
|
|
21
|
+
|
|
22
|
+
Decidim::Chatbot::MenuItemLabelKeys::PROPOSE_PROPOSALS.each do |attr|
|
|
23
|
+
expect(form.public_send(attr)["en"]).to be_present, "expected #{attr} to be prefilled"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|