Merge pull request #5689 from consuldemocracy/remotely_translatable_test

Directly select language in remotely translatable tests
This commit is contained in:
Javi Martín
2024-09-24 17:51:24 +02:00
committed by GitHub

View File

@@ -5,6 +5,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
path_arguments.transform_values { |path_to_value| resource.send(path_to_value) } path_arguments.transform_values { |path_to_value| resource.send(path_to_value) }
end end
let(:path) { send(path_name, arguments) } let(:path) { send(path_name, arguments) }
let(:path_in_spanish) { send(path_name, arguments.merge(locale: :es)) }
let!(:resource) { create(factory_name) } let!(:resource) { create(factory_name) }
before do before do
@@ -20,46 +21,41 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
scenario "should not be present when current locale translation exists" do scenario "should not be present when current locale translation exists" do
visit path visit path
expect(page).not_to have_button("Translate page") expect(page).not_to have_button "Translate page"
end end
scenario "should be present when current locale translation does not exists" do scenario "should be present when current locale translation does not exists" do
visit path visit path_in_spanish
select "Español", from: "Language:" expect(page).to have_button "Traducir página"
expect(page).to have_button("Traducir página")
end end
scenario "should not be present when new current locale translation exists" do scenario "should not be present when new current locale translation exists" do
add_translations(resource, :es) add_translations(resource, :es)
visit path visit path
expect(page).not_to have_button("Translate page") expect(page).not_to have_button "Translate page"
select "Español", from: "Language:" select "Español", from: "Language:"
expect(page).not_to have_button("Traducir página") expect(page).to have_select "Idioma:"
expect(page).not_to have_button "Traducir página"
end end
scenario "should not be present when there are no resources to translate", if: index_path?(path_name) do scenario "should not be present when there are no resources to translate", if: index_path?(path_name) do
resource.destroy! resource.destroy!
visit path visit path_in_spanish
select "Español", from: "Language:" expect(page).not_to have_button "Traducir página"
expect(page).not_to have_button("Traducir página")
end end
describe "with delayed job active", :delay_jobs do describe "with delayed job active", :delay_jobs do
scenario "should not be present when an equal RemoteTranslation is enqueued" do scenario "should not be present when an equal RemoteTranslation is enqueued" do
create(:remote_translation, remote_translatable: resource, locale: :es) create(:remote_translation, remote_translatable: resource, locale: :es)
visit path visit path_in_spanish
select "Español", from: "Language:"
expect(page).not_to have_button("Traducir página")
expect(page).to have_content "En un breve periodo de tiempo refrescando la página " \ expect(page).to have_content "En un breve periodo de tiempo refrescando la página " \
"podrá ver todo el contenido en su idioma" "podrá ver todo el contenido en su idioma"
expect(page).not_to have_button "Traducir página"
end end
end end
@@ -69,11 +65,12 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
add_translations(resource, :es) add_translations(resource, :es)
create(:comment, commentable: resource) create(:comment, commentable: resource)
visit path visit path
expect(page).not_to have_button("Translate page") expect(page).not_to have_button "Translate page"
select "Español", from: "Language:" select "Español", from: "Language:"
expect(page).not_to have_button("Traducir página") expect(page).to have_select "Idioma:"
expect(page).not_to have_button "Traducir página"
end end
end end
@@ -82,22 +79,23 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
add_translations(resource, :es) add_translations(resource, :es)
create(:comment, commentable: resource) create(:comment, commentable: resource)
visit path visit path
expect(page).not_to have_button("Translate page") expect(page).not_to have_button "Translate page"
select "Español", from: "Language:" select "Español", from: "Language:"
expect(page).to have_button("Traducir página") expect(page).to have_button "Traducir página"
end end
scenario "not display when exists resource translations but his comment has tanslations" do scenario "not display when exists resource translations but his comment has tanslations" do
add_translations(resource, :es) add_translations(resource, :es)
create_comment_with_translations(resource, :es) create_comment_with_translations(resource, :es)
visit path visit path
expect(page).not_to have_button("Translate page") expect(page).not_to have_button "Translate page"
select "Español", from: "Language:" select "Español", from: "Language:"
expect(page).not_to have_button("Traducir página") expect(page).to have_select "Idioma:"
expect(page).not_to have_button "Traducir página"
end end
end end
@@ -106,11 +104,11 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
add_translations(resource, :es) add_translations(resource, :es)
create_featured_debates create_featured_debates
visit path visit path
expect(page).not_to have_button("Translate page") expect(page).not_to have_button "Translate page"
select "Español", from: "Language:" select "Español", from: "Language:"
expect(page).to have_button("Traducir página") expect(page).to have_button "Traducir página"
end end
end end
@@ -120,83 +118,48 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
add_translations(resource, :es) add_translations(resource, :es)
create_featured_proposals create_featured_proposals
visit path visit path
expect(page).not_to have_button("Translate page") expect(page).not_to have_button "Translate page"
select "Español", from: "Language:" select "Español", from: "Language:"
expect(page).to have_button("Traducir página") expect(page).to have_button "Traducir página"
end end
end end
end end
context "After click remote translations button" do context "After click remote translations button" do
describe "with delayed jobs", :delay_jobs do describe "with delayed jobs", :delay_jobs do
scenario "the remote translation button should not be present" do scenario "shows informative text when content is enqueued" do
visit path visit path_in_spanish
select "Español", from: "Language:"
click_button "Traducir página"
expect(page).not_to have_button("Traducir página")
end
scenario "the remote translation is pending to translate" do
visit path
select "Español", from: "Language:"
expect { click_button "Traducir página" }.to change { RemoteTranslation.count }.from(0).to(1)
end
scenario "should be present enqueued notice and informative text" do
visit path
select "Español", from: "Language:"
click_button "Traducir página" click_button "Traducir página"
expect(page).not_to have_button "Traducir página"
expect(page).to have_content "Se han solicitado correctamente las traducciones." expect(page).to have_content "Se han solicitado correctamente las traducciones."
expect(page).to have_content "En un breve periodo de tiempo refrescando la página " \ expect(page).to have_content "En un breve periodo de tiempo refrescando la página " \
"podrá ver todo el contenido en su idioma" "podrá ver todo el contenido en su idioma"
end
scenario "should be present only informative text when user visit page with all content enqueued" do refresh
visit path
select "Español", from: "Language:"
click_button "Traducir página"
expect(page).to have_content("Se han solicitado correctamente las traducciones.")
visit path
select "Español", from: "Idioma:"
expect(page).not_to have_button "Traducir página"
expect(page).not_to have_content "Se han solicitado correctamente las traducciones." expect(page).not_to have_content "Se han solicitado correctamente las traducciones."
expect(page).not_to have_button "Traducir página"
expect(page).to have_content "En un breve periodo de tiempo refrescando la página " \ expect(page).to have_content "En un breve periodo de tiempo refrescando la página " \
"podrá ver todo el contenido en su idioma" "podrá ver todo el contenido en su idioma"
end end
end end
describe "without delayed jobs" do describe "without delayed jobs" do
scenario "the remote translation button should not be present" do scenario "content is immediately translated" do
response = generate_response(resource) response = generate_response(resource)
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
visit path visit path_in_spanish
select "Español", from: "Language:"
click_button "Traducir página" expect(page).not_to have_content response.first
expect(page).not_to have_button("Traducir página")
end
scenario "the remote translation has been translated and destoyed" do
response = generate_response(resource)
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
visit path
select "Español", from: "Language:"
click_button "Traducir página" click_button "Traducir página"
expect(page).not_to have_button "Traducir página" expect(page).not_to have_button "Traducir página"
expect(RemoteTranslation.count).to eq(0) expect(page).to have_content response.first
expect(resource.translations.count).to eq(2)
end end
scenario "request a translation of an already translated text" do scenario "request a translation of an already translated text" do
@@ -204,15 +167,13 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
in_browser(:one) do in_browser(:one) do
visit path visit path_in_spanish
select "Español", from: "Language:"
expect(page).to have_button "Traducir página" expect(page).to have_button "Traducir página"
end end
in_browser(:two) do in_browser(:two) do
visit path visit path_in_spanish
select "Español", from: "Language:"
click_button "Traducir página" click_button "Traducir página"
expect(page).to have_content "Se han solicitado correctamente las traducciones" expect(page).to have_content "Se han solicitado correctamente las traducciones"