Skip to content

Commit

Permalink
Respect "rich text editor" setting in Initiatives
Browse files Browse the repository at this point in the history
* Replace editor field with helper to toggle wysiwyg editor

* Adding specs, fixing testsuite

* Apply review recommendations

* Implement Review recommendations

Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>

Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
  • Loading branch information
alecslupu and ahukkanen committed Jan 27, 2023
1 parent 730e5e6 commit 64bfb5d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
Expand Up @@ -34,7 +34,7 @@
</div>

<div class="field">
<%= f.editor :description, lines: 8, toolbar: :full %>
<%= text_editor_for(f, :description, lines: 8, toolbar: :full) %>
</div>

<% signature_type_options = signature_type_options(f.object) %>
Expand Down
Expand Up @@ -27,7 +27,7 @@
</div>

<div class="field">
<%= f.editor :description, lines: 8, toolbar: :full %>
<%= text_editor_for(f, :description, lines: 8, toolbar: :full) %>
</div>

<div class="actions">
Expand Down
Expand Up @@ -5,7 +5,7 @@
</div>

<div class="field">
<%= form.editor :description, toolbar: :full, lines: 8, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative), value: translated_attribute(@form.description) %>
<%= text_editor_for(form, :description, toolbar: :full, lines: 8, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative), value: translated_attribute(@form.description)) %>
</div>

<div class="field">
Expand Down
40 changes: 32 additions & 8 deletions decidim-initiatives/spec/system/create_initiative_spec.rb
Expand Up @@ -88,6 +88,30 @@
end
end

context "when rich text editor is enabled for participants" do
let(:initiative_type_minimum_committee_members) { 2 }
let(:signature_type) { "any" }
let(:initiative_type_promoting_committee_enabled) { true }
let(:initiative_type) do
create(:initiatives_type,
organization: organization,
minimum_committee_members: initiative_type_minimum_committee_members,
promoting_committee_enabled: initiative_type_promoting_committee_enabled,
signature_type: signature_type)
end
let!(:other_initiative_type) { create(:initiatives_type, organization: organization) }
let!(:initiative_type_scope) { create(:initiatives_type_scope, type: initiative_type) }
let!(:other_initiative_type_scope) { create(:initiatives_type_scope, type: initiative_type) }

before do
organization.update(rich_text_editor_in_public_views: true)
click_link "New initiative"
find_button("I want to promote this initiative").click
end

it_behaves_like "having a rich text editor", "new_initiative_previous_form", "full"
end

describe "creating an initiative" do
context "without validation" do
let(:initiative_type_minimum_committee_members) { 2 }
Expand Down Expand Up @@ -142,7 +166,7 @@

it "have fields for title and description" do
expect(page).to have_xpath("//input[@id='initiative_title']")
expect(page).to have_xpath("//input[@id='initiative_description']", visible: :all)
expect(page).to have_xpath("//textarea[@id='initiative_description']", visible: :all)
end

it "offers contextual help" do
Expand Down Expand Up @@ -172,7 +196,7 @@

it "have fields for title and description" do
expect(page).to have_xpath("//input[@id='initiative_title']")
expect(page).to have_xpath("//input[@id='initiative_description']", visible: :all)
expect(page).to have_xpath("//textarea[@id='initiative_description']", visible: :all)
end

it "offers contextual help" do
Expand All @@ -188,7 +212,7 @@
before do
find_button("I want to promote this initiative").click
fill_in "Title", with: translated(initiative.title, locale: :en)
fill_in_editor "initiative_description", with: translated(initiative.description, locale: :en)
fill_in "initiative_description", with: translated(initiative.description, locale: :en)
find_button("Continue").click
end

Expand Down Expand Up @@ -219,7 +243,7 @@

before do
fill_in "Title", with: translated(initiative.title, locale: :en)
fill_in_editor "initiative_description", with: translated(initiative.description, locale: :en)
fill_in "initiative_description", with: translated(initiative.description, locale: :en)
find_button("Continue").click
end

Expand All @@ -233,7 +257,7 @@
before do
find_button("I want to promote this initiative").click
fill_in "Title", with: translated(initiative.title, locale: :en)
fill_in_editor "initiative_description", with: translated(initiative.description, locale: :en)
fill_in "initiative_description", with: translated(initiative.description, locale: :en)
find_button("Continue").click
end

Expand All @@ -252,7 +276,7 @@
it "shows information collected in previous steps already filled" do
expect(find(:xpath, "//input[@id='initiative_type_id']", visible: :all).value).to eq(initiative_type.id.to_s)
expect(find(:xpath, "//input[@id='initiative_title']").value).to eq(translated(initiative.title, locale: :en))
expect(find(:xpath, "//input[@id='initiative_description']", visible: :all).value).to eq(translated(initiative.description, locale: :en))
expect(find(:xpath, "//textarea[@id='initiative_description']", visible: :all).value).to eq(translated(initiative.description, locale: :en))
end

context "when only one signature collection and scope are available" do
Expand Down Expand Up @@ -312,7 +336,7 @@
find_button("I want to promote this initiative").click

fill_in "Title", with: translated(initiative.title, locale: :en)
fill_in_editor "initiative_description", with: translated(initiative.description, locale: :en)
fill_in "initiative_description", with: translated(initiative.description, locale: :en)
find_button("Continue").click

select("Online", from: "Signature collection type")
Expand Down Expand Up @@ -366,7 +390,7 @@
find_button("I want to promote this initiative").click

fill_in "Title", with: translated(initiative.title, locale: :en)
fill_in_editor "initiative_description", with: translated(initiative.description, locale: :en)
fill_in "initiative_description", with: translated(initiative.description, locale: :en)
find_button("Continue").click

select(translated(initiative_type_scope.scope.name, locale: :en), from: "Scope")
Expand Down

0 comments on commit 64bfb5d

Please sign in to comment.