diff --git a/app/cells/decidim/challenges/challenge_cell.rb b/app/cells/decidim/challenges/challenge_cell.rb index 5e83876e..da7bce1b 100644 --- a/app/cells/decidim/challenges/challenge_cell.rb +++ b/app/cells/decidim/challenges/challenge_cell.rb @@ -8,6 +8,8 @@ class ChallengeCell < Decidim::ViewModel include Cell::ViewModel::Partial def show + @has_sdgs = current_component.participatory_space.components.where(manifest_name: "sdgs").where.not(published_at: nil).present? + cell card_size, model, options end diff --git a/app/cells/decidim/challenges/challenge_g/show.erb b/app/cells/decidim/challenges/challenge_g/show.erb index 04f99394..03b174d9 100644 --- a/app/cells/decidim/challenges/challenge_g/show.erb +++ b/app/cells/decidim/challenges/challenge_g/show.erb @@ -1,47 +1,45 @@ -<%= link_to resource_path, class: classes[:default], id: resource_id do %> -
+<%= link_to resource_path, class: "card__list", id: resource_id do %> +
<% if has_image? %> - <%= image_tag resource_image_url, alt: alt_title %> + <%= image_tag resource_image_url, class: "w-full h-full object-cover" %> <% else %> - <%= external_icon "media/images/placeholder-card-g.svg", class: "card__placeholder-g" %> +
+
+
+ <%= external_icon "media/images/placeholder-card-l.svg", class: "card__placeholder-l" %> +
<% end %>
-
- <%= content_tag title_tag, title, class: title_class %> - <%= t(resource_state, scope: 'decidim.challenges.states') %> - <%= description %> - <% if metadata_cell.present? %> -
- <%= cell metadata_cell, resource, links: false, **options %> -
+
+ <%= content_tag title_tag, class: "h4 card__list-title" do %> + <%= title %> <% end %> - -
-
-
- <% if resource_sdg %> -
-

<%= t(resource_sdg + ".logo.line1", scope: "decidim.components.sdgs") %>

-

<%= t(resource_sdg + ".logo.line2", scope: "decidim.components.sdgs") %>

+
+ <%= description %> + <% if has_sdgs? %> +
+
+
+ <% if resource_sdg_index %> + <%= image_pack_tag "media/images/ods-#{resource_sdg_index}.svg", alt: "Logo SDG #{resource_sdg_index}", class: "challenge--view" %> + <% end %>
- <% end %> - <% if resource_sdg_index %> - <%= image_pack_tag "media/images/ods-#{resource_sdg_index}.svg", alt: "Logo SDG #{resource_sdg_index}", class: "challenge--view" %> - <% end %> +
+
+ <% if resource_sdg %> + <%= t_sdg(resource_sdg) %> + <% end %> +
-
-
- <% if resource_sdg %> -

<%= t('sdg', scope: "activemodel.attributes.challenge") %>

- <%= t_sdg(resource_sdg) %> - <% end %> + <% end %> +
+
-
-
- <% end %> -
diff --git a/app/cells/decidim/challenges/challenge_g_cell.rb b/app/cells/decidim/challenges/challenge_g_cell.rb index 4863061f..48cdadc8 100644 --- a/app/cells/decidim/challenges/challenge_g_cell.rb +++ b/app/cells/decidim/challenges/challenge_g_cell.rb @@ -23,6 +23,12 @@ def has_image? @has_image ||= model.component.settings.allow_card_image && model.card_image.attached? end + def has_sdgs? + sdgs_component = model.participatory_space.components.where(manifest_name: "sdgs").where.not(published_at: nil) + + sdgs_component.present? + end + def resource_image_path @resource_image_path ||= has_image? ? model.attached_uploader(:card_image).path : nil end diff --git a/app/controllers/decidim/challenges/challenges_controller.rb b/app/controllers/decidim/challenges/challenges_controller.rb index d360832e..4c54382b 100644 --- a/app/controllers/decidim/challenges/challenges_controller.rb +++ b/app/controllers/decidim/challenges/challenges_controller.rb @@ -9,15 +9,13 @@ class ChallengesController < Decidim::Challenges::ApplicationController include FilterResource include Paginable include OrderableChallenges - include ChallengesHelper - include Decidim::Sdgs::SdgsHelper - include Decidim::ShowFiltersHelper helper Decidim::CheckBoxesTreeHelper helper Decidim::Sdgs::SdgsHelper helper Decidim::ShowFiltersHelper + helper Decidim::Challenges::ChallengesHelper - helper_method :challenges + helper_method :challenges, :has_sdgs def index @challenges = search.result @@ -34,17 +32,29 @@ def show private + def has_sdgs + sdgs_component = current_component.participatory_space.components.where(manifest_name: "sdgs").where.not(published_at: nil) + + sdgs_component.present? + end + def challenge_scope @challenge_scope ||= current_organization.scopes.find_by(id: @challenge.decidim_scope_id) end def default_filter_params - { - search_text_cont: "", - with_any_state: %w(proposal execution finished), - with_any_scope: nil, - with_any_sdgs_codes: [], - } + if has_sdgs + { + search_text_cont: "", + with_any_state: %w(proposal execution finished), + with_any_sdgs_codes: [], + } + else + { + search_text_cont: "", + with_any_state: %w(proposal execution finished), + } + end end def challenges diff --git a/app/helpers/decidim/challenges/challenges_helper.rb b/app/helpers/decidim/challenges/challenges_helper.rb index 3496aabf..0742be71 100644 --- a/app/helpers/decidim/challenges/challenges_helper.rb +++ b/app/helpers/decidim/challenges/challenges_helper.rb @@ -6,11 +6,16 @@ module Challenges # module ChallengesHelper def filter_sections - [ - { method: :with_any_state, collection: filter_challenges_state_values, label_scope: "decidim.shared.filters", id: "state" }, - { method: :with_any_scope, collection: filter_global_scopes_values, label_scope: "decidim.shared.participatory_space_filters.filters", id: "scope" }, - { method: :with_any_sdgs_codes, collection: filter_sdgs_values, label_scope: "decidim.shared.filters", id: "sdgs" }, - ].reject { |item| item[:collection].blank? } + if has_sdgs + [ + { method: :with_any_state, collection: filter_challenges_state_values, label_scope: "decidim.shared.filters", id: "state" }, + { method: :with_any_sdgs_codes, collection: filter_sdgs_values, label_scope: "decidim.shared.filters", id: "sdgs" }, + ].reject { |item| item[:collection].blank? } + else + [ + { method: :with_any_state, collection: filter_challenges_state_values, label_scope: "decidim.shared.filters", id: "state" }, + ].reject { |item| item[:collection].blank? } + end end def filter_challenges_state_values diff --git a/app/packs/stylesheets/decidim/challenges/challenges.scss b/app/packs/stylesheets/decidim/challenges/challenges.scss index ed1ef12d..35b6d7c4 100644 --- a/app/packs/stylesheets/decidim/challenges/challenges.scss +++ b/app/packs/stylesheets/decidim/challenges/challenges.scss @@ -1,94 +1,60 @@ -@import "stylesheets/decidim/sdgs/ods.scss"; @import "stylesheets/decidim/sdgs/sdgs_filter/button.scss"; @import "stylesheets/decidim/sdgs/sdgs_filter/modal.scss"; -.card__highlight-text { - .proposal { - color: rgb(254, 174, 2); - } - - .executing { - color: rgb(0, 163, 144); - } - - .finished { - color: rgb(0, 188, 255); - } - - .card_text--sdg--image { - display: inline-block; - width: 20%; - - img { - vertical-align: bottom; - } +.card__list { + .card__list-content { + width: 100%; } - - .card__sdg { - display: inline-flex; + + .card__list-image { + margin-right: 14px; } - - .card_text--sdg--text { - display: inline-block; - width: 75%; - padding-left: 5px; - + + .card__list-text { + display: flex; + p { - margin-bottom: 8px; + width: 650px; + min-width: 650px; + } + + .card__sdg { + margin-right: 20px; + } + + .card_text--sdg--image { + width: 48px; + + img { + vertical-align: bottom; + } + } + + .card_text--sdg--text { + font-size: 12px; } } - - .card__text--paragraph--status { - font-weight: bold; - display: inline; - text-transform: uppercase; - padding-right: 5px; - } - - .card__text--paragraph p:first-of-type { - display: inline; + + .card__list-metadata { + .label.proposal { + background-color: rgb(254, 174, 2); + color: rgb(86, 59, 1); + } + + .label.executing { + background-color: rgb(0, 163, 144); + color: rgb(0, 49, 43); + } + + .label.finished { + background-color: rgb(0, 188, 255); + color: rgb(0, 49, 43); + } } } -.challenge-status { - text-transform: uppercase; - font-weight: bold; -} - -.defininition-data__title { - text-transform: uppercase; -} - -.definition-data__image { - padding-top: 0.1em; -} - -.section p.tags{ - color: #D04040; - font-weight: 600; -} - -.ods.challenges { - display: flex; - justify-content: center; - cursor: default; - &:hover { - -webkit-box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0.0); - -moz-box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0.0); - box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0.0); - transition: all 0.0s ease; - } - - img.challenge--view { - width: 100%; - max-width: 100px; +.layout-item__aside { + .ods.challenges { + width: 150px; } } - -.card-associated-problem { - padding: 5px 10px; -} - -.card-proposed-solution { - padding: 5px 10px; -} diff --git a/app/views/decidim/challenges/challenges/_challenge.html.erb b/app/views/decidim/challenges/challenges/_challenge.html.erb index 51f2a17a..944de26d 100644 --- a/app/views/decidim/challenges/challenges/_challenge.html.erb +++ b/app/views/decidim/challenges/challenges/_challenge.html.erb @@ -1,3 +1 @@ -
- <%= card_for challenge, highlight: true, size: :g %> -
+<%= card_for challenge, highlight: true, size: :g, has_sdgs: %> diff --git a/app/views/decidim/challenges/challenges/_challenges.html.erb b/app/views/decidim/challenges/challenges/_challenges.html.erb index 49b57f32..0f850e50 100644 --- a/app/views/decidim/challenges/challenges/_challenges.html.erb +++ b/app/views/decidim/challenges/challenges/_challenges.html.erb @@ -5,9 +5,7 @@ <%= order_selector available_orders, i18n_scope: "decidim.challenges.challenges.orders" %> -
- <%= render @challenges %> -
+ <%= render @challenges, locals: { has_sdgs: } %> <%= decidim_paginate @challenges %> <% end %> diff --git a/app/views/decidim/challenges/challenges/_count.html.erb b/app/views/decidim/challenges/challenges/_count.html.erb deleted file mode 100644 index 5905bc92..00000000 --- a/app/views/decidim/challenges/challenges/_count.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= t(".challenges_count", count: challenges.count) %> diff --git a/app/views/decidim/challenges/challenges/_filters.html.erb b/app/views/decidim/challenges/challenges/_filters.html.erb deleted file mode 100644 index 07ce772b..00000000 --- a/app/views/decidim/challenges/challenges/_filters.html.erb +++ /dev/null @@ -1,30 +0,0 @@ -<%= filter_form_for filter do |form| %> -
- -
- - <%= form.check_boxes_tree :with_any_state, filter_challenges_state_values, legend_title: t(".state") %> - - <% if current_participatory_space.has_subscopes? %> - <%= form.check_boxes_tree :with_any_scope, filter_scopes_values, legend_title: t(".scope") %> - <% end %> - - <% if current_component.categories.any? %> - <%= form.check_boxes_tree :with_any_category, filter_categories_values, legend_title: t(".category") %> - <% end %> - - <% if current_participatory_space.components.published.where(manifest_name: "sdgs").any? %> - <%= sdgs_filter_selector(form) %> - <% end %> - - <%= hidden_field_tag :order, order, id: nil, class: "order_filter" %> -<% end %> diff --git a/app/views/decidim/challenges/challenges/_filters_small_view.html.erb b/app/views/decidim/challenges/challenges/_filters_small_view.html.erb deleted file mode 100644 index b009ae0b..00000000 --- a/app/views/decidim/challenges/challenges/_filters_small_view.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -
- -
- -
-
-

<%= t ".filter_by" %>:

- -
-
- <%= render partial: "filters" %> -
-
diff --git a/app/views/decidim/challenges/challenges/_related_problems.html.erb b/app/views/decidim/challenges/challenges/_related_problems.html.erb new file mode 100644 index 00000000..64d0eb98 --- /dev/null +++ b/app/views/decidim/challenges/challenges/_related_problems.html.erb @@ -0,0 +1,14 @@ +
+

+ <%= resource_type_icon "Decidim::Amendment", class: "fill-tertiary w-6 h-6" %> + <%= t("decidim.problems.problems.count.problems_count", count: problems.count) %> +

+ +
+ <% problems.each do |problem| %> + <%= link_to resource_locator(problem).path, class: "card__link" do %> + <%= translated_attribute problem.title %> + <% end %> + <% end %> +
+
diff --git a/app/views/decidim/challenges/challenges/_related_solutions.html.erb b/app/views/decidim/challenges/challenges/_related_solutions.html.erb new file mode 100644 index 00000000..6ebeb830 --- /dev/null +++ b/app/views/decidim/challenges/challenges/_related_solutions.html.erb @@ -0,0 +1,14 @@ +
+

+ <%= resource_type_icon "Decidim::Amendment", class: "fill-tertiary w-6 h-6" %> + <%= t("decidim.solutions.solutions.count.solutions_count", count: solutions.count) %> +

+ +
+ <% solutions.each do |solution| %> + <%= link_to resource_locator(solution).path, class: "card__link" do %> + <%= translated_attribute solution.title %> + <% end %> + <% end %> +
+
diff --git a/app/views/decidim/challenges/challenges/index.html.erb b/app/views/decidim/challenges/challenges/index.html.erb index f6fdb301..604e7339 100644 --- a/app/views/decidim/challenges/challenges/index.html.erb +++ b/app/views/decidim/challenges/challenges/index.html.erb @@ -1,12 +1,12 @@ <% add_decidim_page_title(t("name", scope: "decidim.components.challenges")) %> -<%= append_stylesheet_pack_tag "decidim_challenges", media: "all" %> +<%= append_stylesheet_pack_tag "decidim_challenges" %> <% content_for :aside do %>

<%= component_name %>

- <% if !@component_settings.hide_filters %> - <%= render layout: "decidim/shared/filters", locals: { filter_sections:, search_variable: :search_text_cont, skip_to_id: "challenges" } do %> + <% unless @component_settings.hide_filters %> + <%= render layout: "decidim/shared/filters", locals: { filter_sections:, has_sdgs: ,search_variable: :search_text_cont, skip_to_id: "challenges" } do %> <%= hidden_field_tag :order, order, id: nil, class: "order_filter" %> <% end %> <% end %> @@ -16,6 +16,6 @@ <%= render partial: "decidim/shared/component_announcement" %>
- <%= render partial: "challenges" %> + <%= render partial: "challenges", locals: { has_sdgs: } %>
<% end %> diff --git a/app/views/decidim/challenges/challenges/show.html.erb b/app/views/decidim/challenges/challenges/show.html.erb index 18fa22f9..908231a4 100644 --- a/app/views/decidim/challenges/challenges/show.html.erb +++ b/app/views/decidim/challenges/challenges/show.html.erb @@ -9,7 +9,6 @@
- <%= resource_reference(current_participatory_space) %> <%= render partial: "decidim/shared/share_modal" %>

<%= t("local_description", scope: "activemodel.attributes.challenge") %>

@@ -27,40 +26,12 @@

<%= present(@challenge).tags %>

<% end %> - <% if @challenge.problems.present? %> -

<%= t("associated_problems", scope: "decidim.challenges.show") %>

- <% @challenge.problems.each do |problem| %> -
- <%= link_to resource_locator(problem).path, class: "card__link" do %> - <%= translated_attribute problem.title %> - <% end %> -
-
- <%= truncate_description(problem.description) %> -
- <% end %> - -
- <% @challenge.problems.each do |problem| %> -
-
-
- <% end %> -
+ <% if @challenge.problems.present? %> + <%= render partial: "related_problems", locals: {problems: @challenge.problems} %> <% end %> <% if challenge_associated_solutions(@challenge).present? %> -

<%= t("proposed_solutions", scope: "decidim.challenges.show") %>

-
- <% challenge_associated_solutions(@challenge).each do |solution| %> - <%= link_to resource_locator(solution).path, class: "card__link" do %> -
- <%= translated_attribute solution.title %> -
- <% end %> - <% end %> - <%= truncate_description(solution.description) %> -
+ <%= render partial: "related_solutions", locals: {solutions: challenge_associated_solutions(@challenge)} %> <% end %>
@@ -100,10 +71,9 @@ <% end %>
- <% if @sdg %> + <% if has_sdgs && @sdg %>

<%= t("sdg", scope: "activemodel.attributes.challenge") %>

-

<%= t_sdg(@sdg) %>

<%= t(@sdg + ".logo.line1", scope: "decidim.components.sdgs") %>

@@ -116,6 +86,7 @@
+ <%= resource_reference(current_participatory_space) %> <%= render partial: "decidim/shared/follow_button", class: "text-center", locals: { followable: current_participatory_space, large: false } %> <%= cell "decidim/share_button", nil %>
diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 52125e63..983ab704 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -153,11 +153,6 @@ ca: search: Cerca state: Estat sdgs: SDGs - filters_small_view: - close_modal: Tancar finestra - filter: Filtra - filter_by: Filtra per - unfold: Desplega orders: label: Ordenacions random: Aleatori @@ -1076,11 +1071,6 @@ ca: state: Estat technological_scope: Àmbit tecnològic territorial_scope: Àmbit territorial - filters_small_view: - close_modal: Tancar finestra - filter: Filtra - filter_by: Filtra per - unfold: Desplega orders: label: test random: Aleatori @@ -1235,11 +1225,6 @@ ca: scope: Àmbit search: Cerca territorial_scope: Àmbit territorial - filters_small_view: - close_modal: Tancar finestra - filter: Filtra - filter_by: Filtra per - unfold: Desplega orders: label: Ordenacions random: Aleatori diff --git a/config/locales/cs.yml b/config/locales/cs.yml index b1e7baea..dce61fdc 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -127,11 +127,6 @@ cs: scope: Rozsah působnosti search: Hledat state: Stav - filters_small_view: - close_modal: Zavřít okno - filter: Filtrovat - filter_by: Filtrovat podle - unfold: Rozbalit orders: label: test random: Náhodně @@ -539,11 +534,6 @@ cs: state: State technological_scope: Technologický rozsah territorial_scope: Územní rozsah - filters_small_view: - close_modal: Zavřít modální okno - filter: Filtrovat - filter_by: Filtrovat podle - unfold: Rozbalit orders: label: test random: Náhodně @@ -664,11 +654,6 @@ cs: scope: Rozsah působnosti search: Hledat territorial_scope: Územní rozsah působnosti - filters_small_view: - close_modal: Zavřít modální okno - filter: Filtrovat - filter_by: Filtrovat podle - unfold: Rozbalit orders: label: Seřadit random: Náhodně diff --git a/config/locales/en.yml b/config/locales/en.yml index a67573e3..94d60bec 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -151,11 +151,6 @@ en: scope: Scope search: Search state: State - filters_small_view: - close_modal: Close window - filter: Filter - filter_by: Filter by - unfold: Unfold orders: label: test random: Random @@ -1074,11 +1069,6 @@ en: state: State technological_scope: Technological scope territorial_scope: Territorial scope - filters_small_view: - close_modal: Close modal - filter: Filter - filter_by: Filter by - unfold: Unfold orders: label: test random: Random @@ -1232,11 +1222,6 @@ en: scope: Scope search: Search territorial_scope: Territorial scope - filters_small_view: - close_modal: Close window - filter: Filter - filter_by: Filter by - unfold: Unfold orders: label: Sorts random: Random diff --git a/config/locales/es.yml b/config/locales/es.yml index 53ab0c5d..465c1766 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -151,11 +151,6 @@ es: scope: Ámbito search: Búsqueda state: Estado - filters_small_view: - close_modal: Cerrar ventana - filter: Filtra - filter_by: Filtrar por - unfold: Despliega orders: label: Ordenaciones random: Aleatorio @@ -1085,11 +1080,6 @@ es: state: Estado technological_scope: Ámbito tecnológico territorial_scope: Ámbito territorial - filters_small_view: - close_modal: Cerrar ventana - filter: Filtrar - filter_by: Filtrar por - unfold: Despliega orders: label: test random: Aleatorio @@ -1243,11 +1233,6 @@ es: scope: Ámbito search: Búsqueda territorial_scope: Ámbito territorial - filters_small_view: - close_modal: Cerrar ventana - filter: Filtra - filter_by: Filtra por - unfold: Despliega orders: label: Ordenaciones random: Aleatorio diff --git a/config/locales/oc.yml b/config/locales/oc.yml index 7fe0187c..74dee6a2 100644 --- a/config/locales/oc.yml +++ b/config/locales/oc.yml @@ -151,11 +151,6 @@ oc: scope: Àmbit search: Cerca state: Estat - filters_small_view: - close_modal: Tancar finestra - filter: Filtra - filter_by: Filtra per - unfold: Desplega orders: label: Ordenacions random: Aleatori @@ -1070,11 +1065,6 @@ oc: state: Estat technological_scope: Àmbit tecnològic territorial_scope: Àmbit territorial - filters_small_view: - close_modal: Tancar finestra - filter: Filtra - filter_by: Filtra per - unfold: Desplega orders: label: test random: Aleatori @@ -1222,11 +1212,6 @@ oc: scope: Àmbit search: Cerca territorial_scope: Àmbit territorial - filters_small_view: - close_modal: Tancar finestra - filter: Filtra - filter_by: Filtra per - unfold: Desplega orders: label: Ordenacions random: Aleatori diff --git a/spec/lib/decidim/challenges/component_spec.rb b/spec/lib/decidim/challenges/component_spec.rb index e3ac2c80..40cd8d5c 100644 --- a/spec/lib/decidim/challenges/component_spec.rb +++ b/spec/lib/decidim/challenges/component_spec.rb @@ -5,7 +5,7 @@ describe "Challenges component" do subject { component } - let(:component) { create :challenges_component } + let(:component) { create(:challenges_component) } context "when check filters are hide in settings" do before do diff --git a/spec/models/decidim/challenges/survey_spec.rb b/spec/models/decidim/challenges/survey_spec.rb index 855780b3..e372cd24 100644 --- a/spec/models/decidim/challenges/survey_spec.rb +++ b/spec/models/decidim/challenges/survey_spec.rb @@ -8,13 +8,13 @@ module Decidim::Challenges let(:challenge) { create(:challenge) } let(:user) { create(:user, organization: challenge.organization) } - let(:survey) { build :survey, challenge: challenge, user: user } + let(:survey) { build(:survey, challenge: challenge, user: user) } it { is_expected.to be_valid } context "when a survey already exists for the same user and challenge" do before do - create :survey, challenge: challenge, user: user + create(:survey, challenge: challenge, user: user) end it { is_expected.not_to be_valid } diff --git a/spec/serializers/decidim/challenges/survey_serializer_spec.rb b/spec/serializers/decidim/challenges/survey_serializer_spec.rb index 841600cb..1e61af59 100644 --- a/spec/serializers/decidim/challenges/survey_serializer_spec.rb +++ b/spec/serializers/decidim/challenges/survey_serializer_spec.rb @@ -25,37 +25,37 @@ module Decidim::Challenges end context "when questionnaire enabled" do - let(:challenge) { create :challenge, :with_survey_enabled } + let(:challenge) { create(:challenge, :with_survey_enabled) } let(:serialized) { subject.serialize } let!(:user) { create(:user, organization: challenge.organization) } let!(:survey) { create(:survey, challenge: challenge, user: user) } - let!(:questions) { create_list :questionnaire_question, 3, questionnaire: challenge.questionnaire } + let!(:questions) { create_list(:questionnaire_question, 3, questionnaire: challenge.questionnaire) } let!(:answers) do questions.map do |question| - create :answer, questionnaire: challenge.questionnaire, question: question, user: user + create(:answer, questionnaire: challenge.questionnaire, question: question, user: user) end end - let!(:multichoice_question) { create :questionnaire_question, questionnaire: challenge.questionnaire, question_type: "multiple_option" } - let!(:multichoice_answer_options) { create_list :answer_option, 2, question: multichoice_question } + let!(:multichoice_question) { create(:questionnaire_question, questionnaire: challenge.questionnaire, question_type: "multiple_option") } + let!(:multichoice_answer_options) { create_list(:answer_option, 2, question: multichoice_question) } let!(:multichoice_answer) do - create :answer, questionnaire: challenge.questionnaire, question: multichoice_question, user: user, body: nil + create(:answer, questionnaire: challenge.questionnaire, question: multichoice_question, user: user, body: nil) end let!(:multichoice_answer_choices) do multichoice_answer_options.map do |answer_option| - create :answer_choice, answer: multichoice_answer, answer_option: answer_option, body: answer_option.body[I18n.locale.to_s] + create(:answer_choice, answer: multichoice_answer, answer_option: answer_option, body: answer_option.body[I18n.locale.to_s]) end end - let!(:singlechoice_question) { create :questionnaire_question, questionnaire: challenge.questionnaire, question_type: "single_option" } - let!(:singlechoice_answer_options) { create_list :answer_option, 2, question: multichoice_question } + let!(:singlechoice_question) { create(:questionnaire_question, questionnaire: challenge.questionnaire, question_type: "single_option") } + let!(:singlechoice_answer_options) { create_list(:answer_option, 2, question: multichoice_question) } let!(:singlechoice_answer) do - create :answer, questionnaire: challenge.questionnaire, question: singlechoice_question, user: user, body: nil + create(:answer, questionnaire: challenge.questionnaire, question: singlechoice_question, user: user, body: nil) end let!(:singlechoice_answer_choice) do answer_option = singlechoice_answer_options.first - create :answer_choice, answer: singlechoice_answer, answer_option: answer_option, body: answer_option.body[I18n.locale.to_s] + create(:answer_choice, answer: singlechoice_answer, answer_option: answer_option, body: answer_option.body[I18n.locale.to_s]) end subject { described_class.new(survey) } diff --git a/spec/shared/export_survey_user_answers_examples.rb b/spec/shared/export_survey_user_answers_examples.rb index ccc14f7d..e9e34b9c 100644 --- a/spec/shared/export_survey_user_answers_examples.rb +++ b/spec/shared/export_survey_user_answers_examples.rb @@ -2,22 +2,22 @@ shared_examples "export survey user answers" do let!(:questionnaire) { create(:questionnaire) } - let!(:questions) { create_list :questionnaire_question, 3, questionnaire: questionnaire } + let!(:questions) { create_list(:questionnaire_question, 3, questionnaire: questionnaire) } let!(:answers) do questions.map do |question| - create_list :answer, 3, questionnaire: questionnaire, question: question + create_list(:answer, 3, questionnaire: questionnaire, question: question) end.flatten end it "exports a CSV" do visit_component_admin - click_link("Survey") - click_link("Edit survey") + click_on("Survey") + click_on("Edit survey") - find(".exports.dropdown").click - perform_enqueued_jobs { click_link "CSV" } + find(".exports.button").click + perform_enqueued_jobs { click_on "CSV" } - within ".callout.success" do + within ".flash.success" do expect(page).to have_content("in progress") end @@ -28,13 +28,13 @@ it "exports a JSON" do visit_component_admin - click_link("Survey") - click_link("Edit survey") + click_on("Survey") + click_on("Edit survey") - find(".exports.dropdown").click - perform_enqueued_jobs { click_link "JSON" } + find(".exports.button").click + perform_enqueued_jobs { click_on "JSON" } - within ".callout.success" do + within ".flash.success" do expect(page).to have_content("in progress") end @@ -45,13 +45,13 @@ it "exports a PDF" do visit_component_admin - click_link("Survey") - click_link("Edit survey") + click_on("Survey") + click_on("Edit survey") - find(".exports.dropdown").click - perform_enqueued_jobs { click_link "PDF" } + find(".exports.button").click + perform_enqueued_jobs { click_on "PDF" } - within ".callout.success" do + within ".flash.success" do expect(page).to have_content("in progress") end diff --git a/spec/shared/manage_challenges_examples.rb b/spec/shared/manage_challenges_examples.rb index e084ccfa..eb01dabf 100644 --- a/spec/shared/manage_challenges_examples.rb +++ b/spec/shared/manage_challenges_examples.rb @@ -14,66 +14,61 @@ find("a", class: "action-icon--new").click end - it "shows help text" do - expect(help_text_for("label[for*='challenge_start_date']")).to be_present - expect(help_text_for("label[for*='challenge_end_date']")).to be_present - end - context "when there are multiple locales" do it "shows the title correctly in all available locales" do within "#challenge-title-tabs" do - click_link "English" + click_on "English" end expect(page).to have_css("input", text: challenge.title[:en], visible: :visible) within "#challenge-title-tabs" do - click_link "Català" + click_on "Català" end expect(page).to have_css("input", text: challenge.title[:ca], visible: :visible) within "#challenge-title-tabs" do - click_link "Castellano" + click_on "Castellano" end expect(page).to have_css("input", text: challenge.title[:es], visible: :visible) end it "shows the local description correctly in all available locales" do within "#challenge-local_description-tabs" do - click_link "English" + click_on "English" end expect(page).to have_css("input", text: challenge.local_description[:en], visible: :visible) within "#challenge-local_description-tabs" do - click_link "Català" + click_on "Català" end expect(page).to have_css("input", text: challenge.local_description[:ca], visible: :visible) within "#challenge-local_description-tabs" do - click_link "Castellano" + click_on "Castellano" end expect(page).to have_css("input", text: challenge.local_description[:es], visible: :visible) end it "shows the global description correctly in all available locales" do within "#challenge-global_description-tabs" do - click_link "English" + click_on "English" end expect(page).to have_css("input", text: challenge.global_description[:en], visible: :visible) within "#challenge-global_description-tabs" do - click_link "Català" + click_on "Català" end expect(page).to have_css("input", text: challenge.global_description[:ca], visible: :visible) within "#challenge-global_description-tabs" do - click_link "Castellano" + click_on "Castellano" end expect(page).to have_css("input", text: challenge.global_description[:es], visible: :visible) end end context "when there is only one locale" do - let(:organization) { create :organization, available_locales: [:en] } + let(:organization) { create(:organization, available_locales: [:en]) } let(:component) { create(:component, manifest_name: manifest_name, organization: organization) } let!(:challenge) do create(:challenge, scope: scope, component: component, @@ -83,19 +78,19 @@ end it "shows the title correctly" do - expect(page).not_to have_css("#challenge-title-tabs") + expect(page).to have_no_css("#challenge-title-tabs") expect(page).to have_css("input", text: challenge.title[:en], visible: :visible) end it "shows the description correctly" do - expect(page).not_to have_css("#challenge-description-tabs") + expect(page).to have_no_css("#challenge-description-tabs") expect(page).to have_css("input", text: challenge.local_description[:en], visible: :visible) end end end it "updates a challenge" do - within find("tr", text: Decidim::Challenges::ChallengePresenter.new(challenge).title) do + within "tr", text: Decidim::Challenges::ChallengePresenter.new(challenge).title do find("a", class: "action-icon--new").click end @@ -118,7 +113,7 @@ end end - it "allows the user to preview the challenge" + # it "allows the user to preview the challenge" # do # within find("tr", text: Decidim::Challenges::ChallengePresenter.new(challenge).title) do # klass = "action-icon--preview" @@ -133,7 +128,7 @@ # end it "creates a new challenge" do - find(".card-title a.button").click + find(".item_show__header-title a.button", text: "New challenge").click fill_in_i18n( :challenge_title, @@ -157,13 +152,10 @@ ca: "Descripció global" ) - page.execute_script("$('#challenge_start_date').focus()") - page.find(".datepicker-dropdown .day", text: "12").click + fill_in :challenge_start_date, with: Time.current.change(day: 12, hour: 10, min: 50) + fill_in :challenge_end_date, with: Time.current.change(day: 12, hour: 10, min: 50) - page.execute_script("$('#challenge_end_date').focus()") - page.find(".datepicker-dropdown .day", text: "12").click - - scope_pick select_data_picker(:challenge_decidim_scope_id), scope + select translated(scope.name), from: :challenge_decidim_scope_id within ".new_challenge" do find("*[type=submit]").click @@ -171,7 +163,7 @@ expect(page).to have_admin_callout("successfully") - within "table" do + within ".card" do expect(page).to have_content("My challenge") end end @@ -184,8 +176,8 @@ end it "deletes a challenge" do - within find("tr", text: Decidim::Challenges::ChallengePresenter.new(challenge_2).title) do - accept_confirm { click_link "Delete" } + within "tr", text: Decidim::Challenges::ChallengePresenter.new(challenge_2).title do + accept_confirm { click_on "Delete" } end expect(page).to have_admin_callout("successfully") @@ -195,10 +187,4 @@ end end end - - private - - def help_text_for(css) - page.find_all(css).first.sibling(".help-text") - end end diff --git a/spec/shared/manage_questionnaires_answers_examples.rb b/spec/shared/manage_questionnaires_answers_examples.rb index c3d24a88..40b811e5 100644 --- a/spec/shared/manage_questionnaires_answers_examples.rb +++ b/spec/shared/manage_questionnaires_answers_examples.rb @@ -5,10 +5,10 @@ shared_examples_for "manage questionnaire answers" do let(:first_type) { "short_answer" } let!(:first) do - create :questionnaire_question, questionnaire: questionnaire, position: 1, question_type: first_type + create(:questionnaire_question, questionnaire: questionnaire, position: 1, question_type: first_type) end let!(:second) do - create :questionnaire_question, questionnaire: questionnaire, position: 2, question_type: "single_option" + create(:questionnaire_question, questionnaire: questionnaire, position: 2, question_type: "single_option") end let(:questions) do [first, second] @@ -17,30 +17,30 @@ context "when there are no answers" do it "do not answer admin link" do visit questionnaire_edit_path - click_link("Survey") - click_link("Edit survey") + click_on("Survey") + click_on("Edit survey") expect(page).to have_content("No answers yet") end end context "when there are answers" do - let!(:answer_1) { create :answer, questionnaire: questionnaire, question: first } - let!(:answer_2) { create :answer, body: "second answer", questionnaire: questionnaire, question: first } - let!(:answer_3) { create :answer, questionnaire: questionnaire, question: second } + let!(:answer_1) { create(:answer, questionnaire: questionnaire, question: first) } + let!(:answer_2) { create(:answer, body: "second answer", questionnaire: questionnaire, question: first) } + let!(:answer_3) { create(:answer, questionnaire: questionnaire, question: second) } it "shows the answer admin link" do visit questionnaire_edit_path - click_link("Survey") - click_link("Edit survey") + click_on("Survey") + click_on("Edit survey") expect(page).to have_content("Show responses") end context "and managing answers page" do before do visit questionnaire_edit_path - click_link("Survey") - click_link("Edit survey") - click_link "Show responses" + click_on("Survey") + click_on("Edit survey") + click_on "Show responses" end it "shows the anwers page" do @@ -68,7 +68,7 @@ let(:first_type) { "long_answer" } it "shows session token" do - expect(page).not_to have_content(answer_1.body) + expect(page).to have_no_content(answer_1.body) expect(page).to have_content(answer_1.session_token) expect(page).to have_content(answer_2.session_token) expect(page).to have_content(answer_3.session_token) @@ -78,37 +78,37 @@ end context "and managing individual answer page" do - let!(:answer_11) { create :answer, questionnaire: questionnaire, body: "", user: answer_1.user, question: second } + let!(:answer_11) { create(:answer, questionnaire: questionnaire, body: "", user: answer_1.user, question: second) } before do visit questionnaire_edit_path - click_link("Survey") - click_link("Edit survey") - click_link "Show responses" + click_on("Survey") + click_on("Edit survey") + click_on "Show responses" end it "shows all the questions and responses" do - click_link answer_1.body, match: :first + click_on answer_1.body, match: :first expect(page).to have_content(first.body["en"]) expect(page).to have_content(second.body["en"]) expect(page).to have_content(answer_1.body) end it "first answer has a next link" do - click_link answer_1.body, match: :first + click_on answer_1.body, match: :first expect(page).to have_link("Next ›") - expect(page).not_to have_link("‹ Prev") + expect(page).to have_no_link("‹ Prev") end it "second answer has prev/next links" do - click_link answer_2.body, match: :first + click_on answer_2.body, match: :first expect(page).to have_link("Next ›") expect(page).to have_link("‹ Prev") end it "third answer has prev link" do - click_link answer_3.session_token, match: :first - expect(page).not_to have_link("Next ›") + click_on answer_3.session_token, match: :first + expect(page).to have_no_link("Next ›") expect(page).to have_link("‹ Prev") end end diff --git a/spec/shared/manage_questionnaires_examples.rb b/spec/shared/manage_questionnaires_examples.rb index 7bbee5c6..4f3e04e9 100644 --- a/spec/shared/manage_questionnaires_examples.rb +++ b/spec/shared/manage_questionnaires_examples.rb @@ -18,8 +18,8 @@ it "updates the questionnaire" do visit questionnaire_edit_path - click_link("Survey") - click_link("Edit survey") + click_on("Survey") + click_on("Edit survey") new_description = { en: "

New description

", @@ -29,14 +29,14 @@ within "form.edit_questionnaire" do fill_in_i18n_editor(:questionnaire_description, "#questionnaire-description-tabs", new_description) - click_button "Save" + click_on "Save" end expect(page).to have_admin_callout("successfully") visit questionnaire_edit_path - click_link("Survey") - click_link("Edit survey") + click_on("Survey") + click_on("Edit survey") expect(page).to have_content("New description") end @@ -44,8 +44,6 @@ # context "when the questionnaire is not already answered" do # before do # visit questionnaire_edit_path - # click_link("Survey") - # click_link("Edit survey") # end # it_behaves_like "add questions" @@ -60,19 +58,19 @@ it "cannot modify questionnaire questions" do visit questionnaire_edit_path - click_link("Survey") - click_link("Edit survey") + click_on("Survey") + click_on("Edit survey") expect(page).to have_no_content("Add question") expect(page).to have_no_content("Remove") expand_all_questions - expect(page).to have_selector("input[value='This is the first question'][disabled]") - expect(page).to have_selector("select[id$=question_type][disabled]") - expect(page).to have_selector("select[id$=max_choices][disabled]") - expect(page).to have_selector("input[id$=max_characters][disabled]") - expect(page).to have_selector(".ql-editor[contenteditable=false]") + expect(page).to have_css("input[value='This is the first question'][disabled]") + expect(page).to have_css("select[id$=question_type][disabled]") + expect(page).to have_css("select[id$=max_choices][disabled]") + expect(page).to have_css("input[id$=max_characters][disabled]") + expect(page).to have_css(".ProseMirror[contenteditable=false]") end end @@ -100,7 +98,7 @@ def nested_form_field_selector(attribute) def within_add_display_condition(&block) within ".questionnaire-question:last-of-type" do - click_button "Add display condition" + click_on "Add display condition" within ".questionnaire-question-display-condition:last-of-type", &block end @@ -112,8 +110,8 @@ def expand_all_questions def visit_questionnaire_edit_path_and_expand_all visit questionnaire_edit_path - click_link("Survey") - click_link("Edit survey") + click_on("Survey") + click_on("Edit survey") expand_all_questions end end diff --git a/spec/system/decidim/challenges/challenge_surveys_spec.rb b/spec/system/decidim/challenges/challenge_surveys_spec.rb index 3a1757a9..115e56ca 100644 --- a/spec/system/decidim/challenges/challenge_surveys_spec.rb +++ b/spec/system/decidim/challenges/challenge_surveys_spec.rb @@ -3,14 +3,14 @@ require "spec_helper" require "decidim/forms/test/shared_examples/has_questionnaire" -describe "Challenge surveys", type: :system do +describe "Challenge surveys" do include_context "with a component" let(:manifest_name) { "challenges" } let!(:questionnaire) { create(:questionnaire) } let!(:question) { create(:questionnaire_question, questionnaire: questionnaire, position: 0) } - let!(:challenge) { create :challenge, component: component, questionnaire: questionnaire } - let!(:user) { create :user, :confirmed, organization: organization } + let!(:challenge) { create(:challenge, component: component, questionnaire: questionnaire) } + let!(:user) { create(:user, :confirmed, organization: organization) } let(:survey_enabled) { true } let(:survey_form_enabled) { false } @@ -35,8 +35,8 @@ def questionnaire_public_path it "the survey button is not visible" do visit_challenge - within ".card.extra .card__content" do - expect(page).not_to have_button("ANSWER SURVEY") + within ".layout-aside__buttons" do + expect(page).to have_no_button("ANSWER SURVEY") end end @@ -58,8 +58,8 @@ def questionnaire_public_path it "they have the option to sign in" do visit questionnaire_public_path - expect(page).not_to have_css(".form.answer-questionnaire") - expect(page).to have_content("Sign in with your account or sign up to answer the form") + expect(page).to have_no_css(".form.answer-questionnaire") + expect(page).to have_content("Already have an account?") end end end diff --git a/spec/system/decidim/challenges/challenges_global_search_spec.rb b/spec/system/decidim/challenges/challenges_global_search_spec.rb index b5fa46a1..030a4422 100644 --- a/spec/system/decidim/challenges/challenges_global_search_spec.rb +++ b/spec/system/decidim/challenges/challenges_global_search_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "Search challenges", type: :system do +describe "Search challenges" do include_context "with a component" let(:manifest_name) { "challenges" } let!(:searchables) { create_list(:challenge, 3, component: component) } diff --git a/spec/system/decidim/challenges/challenges_spec.rb b/spec/system/decidim/challenges/challenges_spec.rb index 38761f86..1b1a521a 100644 --- a/spec/system/decidim/challenges/challenges_spec.rb +++ b/spec/system/decidim/challenges/challenges_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "Challenges", type: :system do +describe "Challenges" do include_context "with a component" let(:manifest_name) { "challenges" } @@ -12,20 +12,20 @@ context "when a challenge has contents" do let!(:challenge) { create(:challenge, component: component) } let(:problems_component) { create(:problems_component, participatory_space: challenge.participatory_space) } - let(:problem) { create :problem, component: problems_component, challenge: challenge } + let!(:problem) { create(:problem, component: problems_component, challenge: challenge) } let!(:solution) { create(:solution, component: solutions_component, problem: problem) } before do visit_component - click_link translated(challenge.title) + click_on translated(challenge.title) end it "does render the contents" do expect(page).to have_content("Keywords") expect(page).to have_content(translated(challenge.tags)) - expect(page).to have_content("Associated problems") + expect(page).to have_content("1 problem") expect(page).to have_content(translated(problem.title)) - expect(page).to have_content("Proposed solutions") + expect(page).to have_content("1 solution") expect(page).to have_content(translated(solution.title)) end end @@ -35,13 +35,13 @@ before do visit_component - click_link translated(challenge.title) + click_on translated(challenge.title) end it "does not render titles for empty contents" do - expect(page).not_to have_content("Keywords") - expect(page).not_to have_content("Associated problems") - expect(page).not_to have_content("Proposed solutions") + expect(page).to have_no_content("Keywords") + expect(page).to have_no_content("1 problem") + expect(page).to have_no_content("1 solution") end end end @@ -59,30 +59,29 @@ end it "show only challenges of current component" do - expect(page).to have_selector(".card--challenge", count: 4) + expect(page).to have_css(".card__list", count: 4) expect(page).to have_content(translated(challenges.first.title)) expect(page).to have_content(translated(challenges.last.title)) end it "ordered randomly" do within ".order-by" do - expect(page).to have_selector("ul[data-dropdown-menu$=dropdown-menu]", text: "Random") + expect(page).to have_content("Random") end - expect(page).to have_selector(".card--challenge", count: 4) + expect(page).to have_css(".card__list", count: 4) expect(page).to have_content(translated(challenges.first.title)) expect(page).to have_content(translated(challenges.last.title)) end it "ordered by created at" do within ".order-by" do - expect(page).to have_selector("ul[data-dropdown-menu$=dropdown-menu]", text: "Random") page.find("a", text: "Random").click - click_link "Most recent" + click_on "Most recent" end - expect(page).to have_selector("#challenges .card-grid .column:first-child", text: recent_challenge.title[:en]) - expect(page).to have_selector("#challenges .card-grid .column:last-child", text: older_challenge.title[:en]) + expect(page).to have_css(".order-by .button:first-child", text: recent_challenge.title[:en]) + expect(page).to have_css(".order-by .button:last-child", text: older_challenge.title[:en]) end end @@ -97,8 +96,8 @@ end it "show cards with images" do - expect(page).to have_selector(".card--challenge", count: 2) - expect(page).to have_selector(".card__image", count: 1) + expect(page).to have_css(".card__list", count: 2) + expect(page).to have_css(".card__list-image", count: 2) expect(page).to have_content(translated(challenge_with_card_image.title)) expect(page).to have_content(translated(challenge.title)) diff --git a/spec/system/decidim/challenges/filter_challenges_spec.rb b/spec/system/decidim/challenges/filter_challenges_spec.rb index fa975004..13d843e0 100644 --- a/spec/system/decidim/challenges/filter_challenges_spec.rb +++ b/spec/system/decidim/challenges/filter_challenges_spec.rb @@ -2,18 +2,18 @@ require "spec_helper" -describe "Filter Challenges", :slow, type: :system do +describe "Filter Challenges", :slow do include_context "with a component" let(:manifest_name) { "challenges" } - let!(:category) { create :category, participatory_space: participatory_process } - let!(:scope) { create :scope, organization: organization } - let!(:user) { create :user, :confirmed, organization: organization } + let!(:category) { create(:category, participatory_space: participatory_process) } + let!(:scope) { create(:scope, organization: organization) } + let!(:user) { create(:user, :confirmed, organization: organization) } let(:scoped_participatory_process) { create(:participatory_process, :with_steps, organization: organization, scope: scope) } describe "when filtering challenges by SCOPE" do let(:scopes_picker) { select_data_picker(:filter_scope_id, multiple: true, global_value: "global") } - let!(:scope_2) { create :scope, organization: participatory_process.organization } + let!(:scope_2) { create(:scope, organization: participatory_process.organization) } before do create_list(:challenge, 2, component: component, scope: scope) @@ -91,7 +91,7 @@ end context "with subscopes" do - let!(:subscopes) { create_list :subscope, 5, parent: scope } + let!(:subscopes) { create_list(:subscope, 5, parent: scope) } it "can be filtered by scope" do visit_component @@ -157,7 +157,7 @@ end it "the filter is not rendered" do - expect(page).not_to have_css(".filters__section.sdgs-filter") + expect(page).to have_no_css(".filters__section.sdgs-filter") end end @@ -230,7 +230,7 @@ page.find(".card--challenge .card__link").click - click_link "Return to list" + click_on "Return to list" expect(page).to have_css(".card--challenge", count: 1) end diff --git a/spec/system/decidim/challenges/without_filters_challenges_spec.rb b/spec/system/decidim/challenges/without_filters_challenges_spec.rb index 1e7be8ec..b442e5b0 100644 --- a/spec/system/decidim/challenges/without_filters_challenges_spec.rb +++ b/spec/system/decidim/challenges/without_filters_challenges_spec.rb @@ -2,18 +2,18 @@ require "spec_helper" -describe "Without filters Challenges", :slow, type: :system do +describe "Without filters Challenges", :slow do include_context "with a component" let(:manifest_name) { "challenges" } - let!(:category) { create :category, participatory_space: participatory_process } - let!(:scope) { create :scope, organization: organization } - let!(:user) { create :user, :confirmed, organization: organization } + let!(:category) { create(:category, participatory_space: participatory_process) } + let!(:scope) { create(:scope, organization: organization) } + let!(:user) { create(:user, :confirmed, organization: organization) } let(:scoped_participatory_process) { create(:participatory_process, :with_steps, organization: organization, scope: scope) } describe "when filters are hide" do let(:scopes_picker) { select_data_picker(:filter_scope_id, multiple: true, global_value: "global") } - let!(:scope_2) { create :scope, organization: participatory_process.organization } + let!(:scope_2) { create(:scope, organization: participatory_process.organization) } before do component.settings = { hide_filters: true } @@ -24,12 +24,8 @@ visit_component end - it "show challenges in three columns" do - expect(page).to have_css(".mediumlarge-11.large-12") - end - it "not show filters" do - expect(page).not_to have_css(".filters") + expect(page).to have_no_css(".filters") end end end