Skip to content

Commit

Permalink
Add tests; fix redirect to page nil
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaeftekhar committed Jan 3, 2024
1 parent 46c481d commit 7267afa
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def update
current_organization: current_organization,
translation_set: set
)
page_param = params[:translation][:page]

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, page: page_param)

redirect_to redirect_path_for_set(set)
end

on(:invalid) do
Expand Down Expand Up @@ -139,6 +139,15 @@ def translation
@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
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

0 comments on commit 7267afa

Please sign in to comment.