Skip to content

Commit

Permalink
Add specs for #2844
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Jun 26, 2019
1 parent a8ba19d commit 68c2260
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
78 changes: 78 additions & 0 deletions spec/helpers/rails_admin/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,29 @@
@action = RailsAdmin::Config::Actions.find :dashboard
expect(helper.menu_for(:root)).not_to match(/Dashboard/)
end

it 'shows actions which are marked as show_in_menu' do
I18n.backend.store_translations(
:en, admin: {actions: {
shown_in_menu: {menu: 'Look this'},
}}
)
RailsAdmin.config do |config|
config.actions do
dashboard do
show_in_menu false
end
root :shown_in_menu, :dashboard do
action_name :dashboard
show_in_menu true
end
end
end

@action = RailsAdmin::Config::Actions.find :dashboard
expect(helper.menu_for(:root)).not_to match(/Dashboard/)
expect(helper.menu_for(:root)).to match(/Look this/)
end
end

describe '#main_navigation' do
Expand Down Expand Up @@ -286,6 +309,61 @@
end
end

describe '#root_navigation' do
it 'shows actions which are marked as show_in_sidebar' do
I18n.backend.store_translations(
:en, admin: {actions: {
shown_in_sidebar: {menu: 'Look this'},
}}
)
RailsAdmin.config do |config|
config.actions do
dashboard do
show_in_sidebar false
end
root :shown_in_sidebar, :dashboard do
action_name :dashboard
show_in_sidebar true
end
end
end

expect(helper.root_navigation).not_to match(/Dashboard/)
expect(helper.root_navigation).to match(/Look this/)
end

it 'allows grouping by sidebar_label' do
I18n.backend.store_translations(
:en, admin: {
actions: {
foo: {menu: 'Foo'},
bar: {menu: 'Bar'},
},
}
)
RailsAdmin.config do |config|
config.actions do
dashboard do
show_in_sidebar true
sidebar_label 'One'
end
root :foo, :dashboard do
action_name :dashboard
show_in_sidebar true
sidebar_label 'Two'
end
root :bar, :dashboard do
action_name :dashboard
show_in_sidebar true
sidebar_label 'Two'
end
end
end

expect(helper.strip_tags(helper.root_navigation).delete(' ')).to eq 'OneDashboardTwoFooBar'
end
end

describe '#static_navigation' do
it 'shows not show static nav if no static links defined' do
RailsAdmin.config do |config|
Expand Down
23 changes: 23 additions & 0 deletions spec/integration/rails_admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@
visit dashboard_path
is_expected.to have_selector('.label-danger')
end

it 'has links for actions which are marked as show_in_navigation' do
I18n.backend.store_translations(
:en, admin: {actions: {
shown_in_navigation: {menu: 'Look this'},
}}
)
RailsAdmin.config do |config|
config.actions do
dashboard do
show_in_navigation false
end
root :shown_in_navigation, :dashboard do
action_name :dashboard
show_in_navigation true
end
end
end

visit dashboard_path
is_expected.not_to have_css '.root_links li', text: 'Dashboard'
is_expected.to have_css '.root_links li', text: 'Look this'
end
end

describe 'CSRF protection' do
Expand Down

0 comments on commit 68c2260

Please sign in to comment.