mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Merge pull request #2914 from luisramos0/checkout-language-bug
Fix multi lingual issue in cart and checkout: the user language selection was not being used
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
class Spree::StoreController
|
||||
layout 'darkswarm'
|
||||
|
||||
include I18nHelper
|
||||
before_filter :set_locale
|
||||
|
||||
def unauthorized
|
||||
render 'shared/unauthorized', :status => 401
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ require 'spec_helper'
|
||||
feature 'Multilingual', js: true do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
include ShopWorkflow
|
||||
|
||||
it 'has two locales available' do
|
||||
expect(Rails.application.config.i18n[:default_locale]).to eq 'en'
|
||||
@@ -16,28 +17,54 @@ feature 'Multilingual', js: true do
|
||||
expect(get_i18n_translation('label_shops')).to eq 'Shops'
|
||||
end
|
||||
|
||||
it 'can switch language by params' do
|
||||
visit root_path
|
||||
expect(get_i18n_locale).to eq 'en'
|
||||
expect(get_i18n_translation('label_shops')).to eq 'Shops'
|
||||
expect(page.driver.browser.cookies['locale']).to be_nil
|
||||
expect(page).to have_content 'Interested in getting on the Open Food Network?'
|
||||
expect(page).to have_content 'SHOPS'
|
||||
context 'can switch language by params' do
|
||||
scenario 'in root path' do
|
||||
visit root_path
|
||||
expect(get_i18n_locale).to eq 'en'
|
||||
expect(get_i18n_translation('label_shops')).to eq 'Shops'
|
||||
expect(page.driver.browser.cookies['locale']).to be_nil
|
||||
expect(page).to have_content 'Interested in getting on the Open Food Network?'
|
||||
expect(page).to have_content 'SHOPS'
|
||||
|
||||
visit root_path(locale: 'es')
|
||||
expect(get_i18n_locale).to eq 'es'
|
||||
expect(get_i18n_translation('label_shops')).to eq 'Tiendas'
|
||||
expect(page.driver.browser.cookies['locale'].value).to eq 'es'
|
||||
expect(page).to have_content '¿Estás interesada en entrar en Open Food Network?'
|
||||
expect(page).to have_content 'TIENDAS'
|
||||
visit root_path(locale: 'es')
|
||||
expect(get_i18n_locale).to eq 'es'
|
||||
expect(get_i18n_translation('label_shops')).to eq 'Tiendas'
|
||||
expect_menu_and_cookie_in_es
|
||||
expect(page).to have_content '¿Estás interesada en entrar en Open Food Network?'
|
||||
|
||||
# it is not in the list of available of available_locales
|
||||
visit root_path(locale: 'it')
|
||||
expect(get_i18n_locale).to eq 'es'
|
||||
expect(get_i18n_translation('label_shops')).to eq 'Tiendas'
|
||||
expect(page.driver.browser.cookies['locale'].value).to eq 'es'
|
||||
expect(page).to have_content '¿Estás interesada en entrar en Open Food Network?'
|
||||
expect(page).to have_content 'TIENDAS'
|
||||
# it is not in the list of available of available_locales
|
||||
visit root_path(locale: 'it')
|
||||
expect(get_i18n_locale).to eq 'es'
|
||||
expect(get_i18n_translation('label_shops')).to eq 'Tiendas'
|
||||
expect_menu_and_cookie_in_es
|
||||
expect(page).to have_content '¿Estás interesada en entrar en Open Food Network?'
|
||||
end
|
||||
|
||||
context 'with a product in the cart' do
|
||||
let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
|
||||
let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: [product.variants.first]) }
|
||||
let(:product) { create(:simple_product) }
|
||||
let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor) }
|
||||
|
||||
before do
|
||||
set_order order
|
||||
add_product_to_cart order, product, quantity: 1
|
||||
end
|
||||
|
||||
scenario "in the cart page" do
|
||||
visit spree.cart_path(locale: 'es')
|
||||
|
||||
expect_menu_and_cookie_in_es
|
||||
expect(page).to have_content 'Precio'
|
||||
end
|
||||
|
||||
scenario "in the checkout page" do
|
||||
visit checkout_path(locale: 'es')
|
||||
|
||||
expect_menu_and_cookie_in_es
|
||||
expect(page).to have_content 'Total del carrito'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with user' do
|
||||
@@ -46,12 +73,12 @@ feature 'Multilingual', js: true do
|
||||
it 'updates user locale from cookie if it is empty' do
|
||||
visit root_path(locale: 'es')
|
||||
|
||||
expect(page.driver.browser.cookies['locale'].value).to eq 'es'
|
||||
expect_menu_and_cookie_in_es
|
||||
expect(user.locale).to be_nil
|
||||
quick_login_as user
|
||||
visit root_path
|
||||
|
||||
expect(page.driver.browser.cookies['locale'].value).to eq 'es'
|
||||
expect_menu_and_cookie_in_es
|
||||
end
|
||||
|
||||
it 'updates user locale and stays in cookie after logout' do
|
||||
@@ -63,9 +90,8 @@ feature 'Multilingual', js: true do
|
||||
|
||||
logout
|
||||
|
||||
expect(page.driver.browser.cookies['locale'].value).to eq 'es'
|
||||
expect_menu_and_cookie_in_es
|
||||
expect(page).to have_content '¿Estás interesada en entrar en Open Food Network?'
|
||||
expect(page).to have_content 'TIENDAS'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -103,9 +129,13 @@ feature 'Multilingual', js: true do
|
||||
find('li a[href="?locale=es"]').click
|
||||
end
|
||||
|
||||
expect(page.driver.browser.cookies['locale'].value).to eq 'es'
|
||||
expect(page).to have_content 'TIENDAS'
|
||||
expect_menu_and_cookie_in_es
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def expect_menu_and_cookie_in_es
|
||||
expect(page.driver.browser.cookies['locale'].value).to eq 'es'
|
||||
expect(page).to have_content 'TIENDAS'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user