Skip to content

Commit

Permalink
Keep the account navigation menu open when changing the locale
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Nov 15, 2023
1 parent fe6da39 commit 74efa66
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
data-controller="details-click-outside"
class="relative w-full"
aria-label="<%= t('.account') %>"
<%= :open if params[:account_menu_open] %>
>
<summary
class="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def update_user_locale
session[set_user_language_locale_key] = requested_locale

flash[:notice] = t('spree.locale_changed')
redirect_to url_for(request.params.except(:switch_to_locale))
redirect_to params.except(:switch_to_locale).permit!.to_h.merge(account_menu_open: true)
end
end

Expand Down
18 changes: 18 additions & 0 deletions admin/spec/features/accounts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,22 @@
expect(page).to have_content(user.email)
expect(current_path).to eq("/admin/users/#{user.id}/edit")
end

it "can change locale", :js do
I18n.config.available_locales_set << :"en-UK"
I18n.config.available_locales_set << "en-UK"
I18n.backend.store_translations('en-UK', spree: { i18n: { this_file_language: "English (UK)" } })

user = create(:admin_user, email: '[email protected]')
stub_authorization! user
sign_in user

visit "/admin/products"
find('summary', text: user.email).click
expect(page).to have_content("English (US)")
select "English (UK)", from: "switch_to_locale"
expect(page).to have_content("English (UK)")
select "English (US)", from: 'switch_to_locale'
expect(page).to have_content("English (US)")
end
end

0 comments on commit 74efa66

Please sign in to comment.