Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Nov 24, 2023
1 parent dca8e35 commit dd519fa
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def default_font_color_over_bg

def default_address_text
@default_address_text ||= NewsletterAgenda.default_address_text ||
NewsletterAgenda.themes.dig(theme, :default_address_text)
NewsletterAgenda.themes.dig(theme, :default_address_text) ||
""
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<% form.fields_for :settings, settings do |settings_fields| %>
<%= settings_fields.translated :text_field, :intro_title, label: t(".intro_title") %>
<%= settings_fields.translated :editor, :intro_text, label: t(".intro_text") %>
<%= settings_fields.translated :text_field, :intro_link_text, label: t(".intro_link_text") if theme == "capitalitat" %>
<%= settings_fields.text_field :intro_link_url, label: t(".intro_link_url") if theme == "capitalitat" %>
<%= settings_fields.translated :text_field, :intro_link_text, label: t(".intro_link_text") if theme == :capitalitat %>
<%= settings_fields.text_field :intro_link_url, label: t(".intro_link_url") if theme == :capitalitat %>
<% end %>
<% form.fields_for :images, form.object.images do |images_fields| %>
<%= images_fields.upload :main_image, label: t(".main_image") %>
Expand All @@ -29,8 +29,8 @@
<p><%= t(".tab_body_description") %></p>
<fieldset class="fieldset">
<% form.fields_for :settings, settings do |settings_fields| %>
<%= settings_fields.translated :text_field, :body_title, label: t(".body_title") unless theme == "capitalitat" %>
<%= settings_fields.translated :text_field, :body_subtitle, label: t(".body_subtitle") unless theme == "capitalitat" %>
<%= settings_fields.translated :text_field, :body_title, label: t(".body_title") unless theme == :capitalitat %>
<%= settings_fields.translated :text_field, :body_subtitle, label: t(".body_subtitle") unless theme == :capitalitat %>
<ul id="box-container" class="accordion" data-accordion data-multi-expand="true" data-allow-all-closed="true">
<% (1..4).each do |num| %>
<li class="box accordion-item" id="box<%= num %>" data-accordion-item>
Expand Down Expand Up @@ -76,9 +76,9 @@
</li>
<% end %>
</ul>
<%= settings_fields.editor :footer_address_text, label: t(".footer_address") unless theme == "capitalitat" %>
<%= settings_fields.editor :footer_address_text, label: t(".footer_address") unless theme == :capitalitat %>
<%= settings_fields.translated :text_field, :footer_social_links_title, label: t(".footer_social_links_title") %>
<%= settings_fields.translated :text_field, :footer_additional_text if theme == "capitalitat" %>
<%= settings_fields.translated :text_field, :footer_additional_text if theme == :capitalitat %>

<div class="label--tabs">
<label for="organization_social_handlers">
Expand All @@ -97,7 +97,7 @@
<div class="tabs-content" data-tabs-content="organization_social_handlers">
<% social_handlers&.each do |handler| %>
<div class="tabs-panel <% if handler == social_handlers.first %> is-active <% end %>" id="<%= handler %>">
<%= settings_fields.text_field "#{handler}_handler", placeholder: organization_handler_attributes["#{handler}_handler"], label: false %>
<%= settings_fields.text_field "#{handler}_handler", placeholder: t(".wont_show"), label: false %>
</div>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ def settings
hash[locale] = I18n.t("decidim.newsletter_templates.agenda_events.footer_social_links_title_preview", locale: locale) if hash[locale].nil?
end
end
settings[:footer_address_text] ||= default_address_text

settings[:footer_address_text] = default_address_text if settings[:footer_address_text].blank?

# social handlers
social_handlers&.each do |handler|
settings["#{handler}_handler"] ||= ""
settings["#{handler}_handler"] ||= organization_handler_attributes["#{handler}_handler"]
end

# boxes
Expand Down
7 changes: 4 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ en:
decidim:
newsletter_agenda:
agenda_events_settings_form:
link_color: Link color
background_color: Background color
body: Body
body_box_date_time: Body event date/time
Expand Down Expand Up @@ -58,6 +57,7 @@ en:
intro_text: Introduction text
intro_title: Introduction title
introduction: Introduction
link_color: Link color
main_image: Introduction image
mastodon: Mastodon
peertube: PeerTube
Expand All @@ -74,6 +74,7 @@ en:
to fill in all 3 events, missing entries won't appear in the newsletter.
telegram: Telegram
twitter: Twitter
wont_show: Won't be shown
youtube: Youtube
newsletter_templates:
agenda_events:
Expand All @@ -83,6 +84,8 @@ en:
body_box_title_preview: This is an event title for this agenda
body_final_text_preview: But there's more
body_title_preview: What is happening during the week
canodrom_name: Agenda events (edition Canòdrom)
capitalitat_name: Agenda events (edition Capitalitat)
footer_additional_text_preview: This is a footer additional text for this
agenda
footer_box_date_time_preview: 7 – 15 Novembre, 10:00
Expand All @@ -103,5 +106,3 @@ en:
enim. In eget magna sed enim efficitur elementum sit amet aliquam quam.
Donec fermentum metus eget urna luctus pulvinar. <a href="#">Read more</a>'
intro_title_preview: Dummy title for the newsletter.
canodrom_name: Agenda events (edition Canòdrom)
capitalitat_name: Agenda events (edition Capitalitat)
2 changes: 1 addition & 1 deletion lib/decidim/newsletter_agenda/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Engine < ::Rails::Engine
:footer_address_text,
type: :text,
translated: false,
preview: -> { NewsletterAgenda.default_address_text }
preview: -> { NewsletterAgenda.default_address_text || properties[:default_address_text] }
)
settings.attribute(
:footer_social_links_title,
Expand Down
41 changes: 12 additions & 29 deletions spec/system/agenda_events_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

let(:settings) do
{
background_color: "#7636d2",
font_color_over_bg: "#FF0FF0",
intro_title: "Intro title",
intro_text: "Intro text",
footer_address_text: Decidim::NewsletterAgenda.default_address_text
background_color: "#7636d1",
link_color: "#FF0FF0",
font_color_over_bg: "#FFFFF0",
intro_title_en: "Intro title",
intro_text_en: "Intro text",
footer_address_text: "Some address"
}
end

Expand Down Expand Up @@ -52,11 +53,13 @@
end

context "when automatic customizable settings" do
it "renders the correct the settings form" do
it "renders the default settings" do
expect(page).to have_content("Background color")
expect(page).to have_field("newsletter[settings][background_color]", with: "#7636d2")
expect(page).to have_content("Link color")
expect(page).to have_field("newsletter[settings][link_color]", with: "#7636d2")
expect(page).to have_content("Font color over background")
expect(page).to have_field("newsletter[settings][font_color_over_bg]", with: "#ff0ff0")
expect(page).to have_field("newsletter[settings][font_color_over_bg]", with: "#ffffff")

click_link "Body"
expect(page).to have_content("EVENT 1:")
Expand All @@ -78,33 +81,12 @@
expect(page).to have_content("Footer event title")

expect(page).to have_content("Organization address")
expect(page).to have_content("C/Concepció Arenal 165")
expect(page).to have_content("Social links title")

address = ActionController::Base.helpers.strip_tags(content_block.settings.footer_address_text)
expect(page.html.gsub(/[\n ]+/, " ")).to have_content(address.gsub(/[\n ]+/, " ").strip)
expect(address.lines[1..3]).to all(match(/^\S/))
end
end

context "when settings from the form" do
let!(:content_block_new) do
content_block = Decidim::ContentBlock.find_by(organization: organization, scope_name: :newsletter_template, scoped_resource_id: newsletter.id, manifest_name: :canodrom_agenda_events)
content_block.destroy!
content_block = create(
:content_block,
:newsletter_template,
organization: organization,
scoped_resource_id: newsletter.id,
manifest_name: :canodrom_agenda_events,
settings: {
intro_title: Decidim::Faker::Localized.word,
intro_text: Decidim::Faker::Localized.word,
body_box_link: I18n.available_locales.index_with { |_locale| Faker::Internet.url }
}
)
content_block
end

before do
fill_in :newsletter_subject_en, with: "Subject"
find('input[name="newsletter[settings][intro_title_en]"]').fill_in with: "Intro title"
Expand All @@ -130,6 +112,7 @@

click_link "Footer"
find("input[name='newsletter[settings][footer_title_en]']").fill_in with: "Footer title"
click_link "Mastodon"
find("input[name='newsletter[settings][mastodon_handler]']").fill_in with: "super_mastodon"

(1..3).each do |i|
Expand Down

0 comments on commit dd519fa

Please sign in to comment.