Skip to content

Commit

Permalink
Removes more of NavConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
HazelGrant committed Mar 28, 2024
1 parent 673d1be commit 5aac3ca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 76 deletions.
6 changes: 1 addition & 5 deletions apps/dashboard/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ def set_my_balances
private

def filter_groups(groups)
if @user_configuration.filter_nav_categories?
OodAppGroup.select(titles: @user_configuration.nav_categories, groups: groups)
else
OodAppGroup.order(titles: @user_configuration.nav_categories, groups: groups)
end
OodAppGroup.select(titles: @user_configuration.nav_categories, groups: groups)
end
end
11 changes: 2 additions & 9 deletions apps/dashboard/app/models/user_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,9 @@ def announcement_path
end
end

DEFAULT_CATEGORIES = ['Apps', 'Files', 'Jobs', 'Clusters', 'Interactive Apps'].freeze

# Filtering is false unless the configuration property categories is defined.
# If categories are defined, filter_nav_categories? will always be true.
def filter_nav_categories?
!!fetch(:nav_categories, nil)
end

DEFAULT_NAV_CATEGORIES = ['Apps', 'Files', 'Jobs', 'Clusters', 'Interactive Apps'].freeze
def nav_categories
fetch(:nav_categories, DEFAULT_CATEGORIES)
fetch(:nav_categories, DEFAULT_NAV_CATEGORIES)
end

# Create support ticket service class based on the configuration
Expand Down
69 changes: 7 additions & 62 deletions apps/dashboard/test/integration/dashboard_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,55 +148,25 @@ def teardown
assert_select "nav a[href='#{batch_connect_sessions_path}']", 0
end

test 'should not create app menus if NavConfig.categories is empty and whitelist is enabled' do
test 'uses UserConfiguration::DEFAULT_NAV_CATEGORIES if :nav_categories is absent' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(true)
NavConfig.stubs(:categories).returns([])

get root_path
assert_response :success
assert_select dropdown_links, 1 # +1 here is 'Help'
assert_select dropdown_link(1), text: 'Help' # ensure is Help
end

test 'should exclude gateway apps if NavConfig.categories is set to default and whitelist is enabled' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(true)
NavConfig.stubs(:categories).returns(['Files', 'Jobs', 'Clusters', 'Interactive Apps'])

get root_path
assert_response :success
assert_select dropdown_links, 5 # +1 here is 'Help'
assert_select dropdown_link(1), text: 'Files'
assert_select dropdown_link(2), text: 'Jobs'
assert_select dropdown_link(3), text: 'Clusters'
assert_select dropdown_link(4), text: 'Interactive Apps'
assert_select dropdown_link(5), text: 'Help'
end

test 'uses NavConfig.categories as sort order if whitelist is false' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(false)
NavConfig.stubs(:categories).returns(['Jobs', 'Interactive Apps', 'Files', 'Clusters'])
stub_user_configuration({})

get root_path
assert_response :success
assert_select dropdown_links, 6 # +1 here is 'Help'
assert_select dropdown_link(1), text: 'Jobs'
assert_select dropdown_link(2), text: 'Interactive Apps'
assert_select dropdown_link(3), text: 'Files'
assert_select dropdown_link(1), text: 'Apps'
assert_select dropdown_link(2), text: 'Files'
assert_select dropdown_link(3), text: 'Jobs'
assert_select dropdown_link(4), text: 'Clusters'
assert_select dropdown_link(5), text: 'Gateway Apps'
assert_select dropdown_link(5), text: 'Interactive Apps'
end

test 'UserConfiguration.categories should filter and order the navigation and have precedence over NavConfig' do
test 'UserConfiguration.categories should filter and order the navigation' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(false)
NavConfig.stubs(:categories).returns(['Jobs', 'Interactive Apps', 'Files', 'Clusters'])

stub_user_configuration({
nav_categories: ['Files', 'Interactive Apps', 'Clusters']
Expand All @@ -213,8 +183,6 @@ def teardown
test 'should not create app menus if UserConfiguration.categories is empty' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(false)
NavConfig.stubs(:categories).returns(['Jobs', 'Interactive Apps', 'Files', 'Clusters'])

stub_user_configuration({
nav_categories: []
Expand All @@ -226,32 +194,9 @@ def teardown
assert_select dropdown_link(1), text: 'Help' # ensure is Help
end

test 'verify default values for NavConfig' do
refute NavConfig.categories_whitelist?
assert NavConfig
end

test 'display all app menus in alphabetical order if NavConfig.whitelist false & NavConfig.categories nil or []' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(false)
NavConfig.stubs(:categories).returns([])

get root_path
assert_response :success
assert_select dropdown_links, 6 # +1 here is 'Help'

assert_select dropdown_link(1), text: 'Clusters'
assert_select dropdown_link(2), text: 'Files'
assert_select dropdown_link(3), text: 'Gateway Apps'
assert_select dropdown_link(4), text: 'Interactive Apps'
assert_select dropdown_link(5), text: 'Jobs'
end

test 'apps with no category should not appear in menu' do
SysRouter.stubs(:base_path).returns(Rails.root.join('test/fixtures/sys_with_gateway_apps'))
OodAppkit.stubs(:clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))
NavConfig.stubs(:categories_whitelist?).returns(false)

get root_path

Expand Down

0 comments on commit 5aac3ca

Please sign in to comment.