Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/redirect to current page after edit #114

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
UpdateTranslation.call(@form, translation) do
on(:ok) do
flash[:notice] = I18n.t("translations.update.success", scope: "decidim.term_customizer.admin")
redirect_to translation_set_translations_path(set)

redirect_to redirect_path_for_set(set)
end

on(:invalid) do
Expand Down Expand Up @@ -138,6 +139,15 @@
@translation ||= Decidim::TermCustomizer::Translation.find(params[:id])
end

def redirect_path_for_set(set)
page_param = params[:translation][:page]
if page_param.nil?
translation_set_translations_path(set)

Check warning on line 145 in app/controllers/decidim/term_customizer/admin/translations_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/decidim/term_customizer/admin/translations_controller.rb#L145

Added line #L145 was not covered by tests
else
translation_set_translations_path(set, page: page_param)
end
end

alias collection translations
alias set translation_set
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
<div class="row column">
<%= form.translated :text_area, :value, rows: 4 %>
</div>
<%= form.hidden_field :page, value: params[:page] %>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</td>
<td class="table-list__actions">
<% if allowed_to? :update, :translation, translation: translation %>
<%= icon_link_to "pencil", edit_translation_set_translation_path(set, translation), t("actions.configure", scope: "decidim.admin"), class: "action-icon--new" %>
<%= icon_link_to "pencil", edit_translation_set_translation_path(set, translation, page: params[:page]), t("actions.configure", scope: "decidim.admin"), class: "action-icon--new" %>
<% end %>

<% if allowed_to? :destroy, :translation, translation: translation %>
Expand Down
25 changes: 25 additions & 0 deletions lib/decidim/term_customizer/test/rspec_support/capybara.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require "selenium-webdriver"

module Decidim
# This is being added because of the issues with the chrome-driver
# in version 120 or later, and this can be removed after this pr#12160
# being merged(more info https://github.com/decidim/decidim/pull/12159).
Capybara.register_driver :headless_chrome do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
options.args << "--headless=new"
options.args << "--no-sandbox"
options.args << if ENV["BIG_SCREEN_SIZE"].present?
"--window-size=1920,3000"
else
"--window-size=1920,1080"
end
options.args << "--ignore-certificate-errors" if ENV["TEST_SSL"]
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
capabilities: [options]
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,26 @@ module TermCustomizer
put :update, params: params.merge(
id: translation.id,
key: "updated.translation.key",
value: { en: "Lorem ipsum dolor" }
value: { en: "Lorem ipsum dolor" },
translation: { page: nil }
)

expect(flash[:notice]).not_to be_empty
expect(response).to have_http_status(:found)
end

context "when page params exist" do
it "redirects to the same paginated page" do
put :update, params: params.merge(
id: translation.id,
key: "updated.translation.key",
value: { en: "Lorem ipsum dolor" },
translation: { page: "2" }
)

expect(response).to redirect_to("/sets/#{translation_set.id}/translations?page=2")
end
end
end

describe "POST export" do
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
File.expand_path(File.join(__dir__, "decidim_dummy_app"))

require "decidim/dev/test/base_spec_helper"
# This is being added because of the issues with the chrome-driver
# in version 120 or later, and this can be removed after this pr#12160
# being merged(more info https://github.com/decidim/decidim/pull/12159).
require "#{Dir.pwd}/lib/decidim/term_customizer/test/rspec_support/capybara.rb"

RSpec.configure do |config|
# Add extra traslation load path for the tests
Expand Down