diff --git a/ee/app/helpers/dependencies_helper.rb b/ee/app/helpers/dependencies_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..f8b0f73869bd8a81b5437f6f572d2549e57146e7 --- /dev/null +++ b/ee/app/helpers/dependencies_helper.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module DependenciesHelper + def project_dependencies_data(project) + shared_dependencies_data.merge({ + endpoint: project_dependencies_path(project, format: :json), + export_endpoint: expose_path(api_v4_projects_dependency_list_exports_path(id: project.id)), + vulnerabilities_endpoint: expose_path(api_v4_occurrences_vulnerabilities_path) + }) + end + + def group_dependencies_data(group, below_group_limit) + shared_dependencies_data.merge({ + endpoint: group_dependencies_path(group, format: :json), + licenses_endpoint: licenses_group_dependencies_path(group), + locations_endpoint: locations_group_dependencies_path(group), + export_endpoint: expose_path(api_v4_groups_dependency_list_exports_path(id: group.id)), + vulnerabilities_endpoint: expose_path(api_v4_occurrences_vulnerabilities_path), + below_group_limit: below_group_limit.to_s + }) + end + + def explore_dependencies_data(organization, page_info) + shared_dependencies_data.merge({ + page_info: page_info, + endpoint: explore_dependencies_path(format: :json), + licenses_endpoint: nil, + locations_endpoint: nil, + export_endpoint: expose_path(api_v4_organizations_dependency_list_exports_path(id: organization.id)), + vulnerabilities_endpoint: nil, + below_group_limit: 'false' + }) + end + + def shared_dependencies_data + { + documentation_path: help_page_path('user/application_security/dependency_list/index'), + support_documentation_path: help_page_path('user/application_security/dependency_scanning/index', + anchor: 'supported-languages-and-package-managers'), + empty_state_svg_path: image_path('illustrations/Dependency-list-empty-state.svg') + } + end +end diff --git a/ee/app/views/explore/dependencies/index.html.haml b/ee/app/views/explore/dependencies/index.html.haml index 7a443175c6326a8c11e442b7b4edcc4e55c80a1f..8fa6452b515ed48e9c265bd460572bca0983752e 100644 --- a/ee/app/views/explore/dependencies/index.html.haml +++ b/ee/app/views/explore/dependencies/index.html.haml @@ -1,17 +1,4 @@ - breadcrumb_title _('Dependency list') - page_title _('Dependency list') -#js-dependencies-app{ - data: { - page_info: @page_info, - endpoint: explore_dependencies_path(format: :json), - licenses_endpoint: nil, - locations_endpoint: nil, - export_endpoint: expose_path(api_v4_organizations_dependency_list_exports_path(id: @organization.id)), - vulnerabilities_endpoint: nil, - documentation_path: help_page_path('user/application_security/dependency_list/index'), - support_documentation_path: help_page_path('user/application_security/dependency_scanning/index', anchor: 'supported-languages-and-package-managers'), - empty_state_svg_path: image_path('illustrations/Dependency-list-empty-state.svg'), - below_group_limit: 'false' - } -} +#js-dependencies-app{ data: explore_dependencies_data(@organization, @page_info) } diff --git a/ee/app/views/groups/dependencies/index.html.haml b/ee/app/views/groups/dependencies/index.html.haml index 3c4bf73ed725c017d09ca337e59ad610ab24f209..2fdec3b6d5e1a491397bec6ec559ce10ee5f324f 100644 --- a/ee/app/views/groups/dependencies/index.html.haml +++ b/ee/app/views/groups/dependencies/index.html.haml @@ -1,16 +1,4 @@ - breadcrumb_title _('Dependency list') - page_title _('Dependency list') -#js-dependencies-app{ - data: { - endpoint: group_dependencies_path(@group, format: :json), - licenses_endpoint: licenses_group_dependencies_path(@group), - locations_endpoint: locations_group_dependencies_path(@group), - export_endpoint: expose_path(api_v4_groups_dependency_list_exports_path(id: @group.id)), - vulnerabilities_endpoint: expose_path(api_v4_occurrences_vulnerabilities_path), - documentation_path: help_page_path('user/application_security/dependency_list/index'), - support_documentation_path: help_page_path('user/application_security/dependency_scanning/index', anchor: 'supported-languages-and-package-managers'), - empty_state_svg_path: image_path('illustrations/Dependency-list-empty-state.svg'), - below_group_limit: @below_group_limit.to_s - } -} +#js-dependencies-app{ data: group_dependencies_data(@group, @below_group_limit) } diff --git a/ee/app/views/projects/dependencies/index.html.haml b/ee/app/views/projects/dependencies/index.html.haml index a743d36ffaf273610c97b6387e4c9cabf0324567..838bb3e8c61daf6d606e6f782efb06d3004b3482 100644 --- a/ee/app/views/projects/dependencies/index.html.haml +++ b/ee/app/views/projects/dependencies/index.html.haml @@ -1,14 +1,5 @@ - breadcrumb_title _('Dependency list') - page_title _('Dependency list') -#js-dependencies-app{ - data: { - endpoint: project_dependencies_path(@project, format: :json), - export_endpoint: expose_path(api_v4_projects_dependency_list_exports_path(id: @project.id)), - vulnerabilities_endpoint: expose_path(api_v4_occurrences_vulnerabilities_path), - documentation_path: help_page_path('user/application_security/dependency_list/index'), - support_documentation_path: help_page_path('user/application_security/dependency_scanning/index', anchor: 'supported-languages-and-package-managers'), - empty_state_svg_path: image_path('illustrations/Dependency-list-empty-state.svg') - } -} +#js-dependencies-app{ data: project_dependencies_data(@project) } diff --git a/ee/spec/helpers/dependencies_helper_spec.rb b/ee/spec/helpers/dependencies_helper_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..ea0850d5c672063e43aa6d28b4369133e9dba3de --- /dev/null +++ b/ee/spec/helpers/dependencies_helper_spec.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe DependenciesHelper, feature_category: :dependency_management do + shared_examples 'a helper method that returns shared dependencies data' do + it 'returns data shared between all views' do + is_expected.to include( + documentation_path: a_string_including("user/application_security/dependency_list/index"), + support_documentation_path: a_string_including("user/application_security/dependency_scanning/index"), + empty_state_svg_path: match(%r{illustrations/Dependency-list-empty-state.*\.svg}) + ) + end + end + + describe '#project_dependencies_data' do + let_it_be(:project) { build_stubbed(:project) } + + subject { helper.project_dependencies_data(project) } + + it_behaves_like 'a helper method that returns shared dependencies data' + + it 'returns the exepected data' do + is_expected.to include( + endpoint: "/#{project.full_path}/-/dependencies.json", + export_endpoint: "/api/v4/projects/#{project.id}/dependency_list_exports", + vulnerabilities_endpoint: "/api/v4/occurrences/vulnerabilities" + ) + end + end + + describe '#group_dependencies_data' do + let_it_be(:group) { build_stubbed(:group) } + let(:below_group_limit) { true } + + subject { helper.group_dependencies_data(group, below_group_limit) } + + it_behaves_like 'a helper method that returns shared dependencies data' + + it 'returns the expected data' do + is_expected.to include( + endpoint: "/groups/#{group.full_path}/-/dependencies.json", + licenses_endpoint: "/groups/#{group.full_path}/-/dependencies/licenses", + locations_endpoint: "/groups/#{group.full_path}/-/dependencies/locations", + export_endpoint: "/api/v4/groups/#{group.id}/dependency_list_exports", + vulnerabilities_endpoint: "/api/v4/occurrences/vulnerabilities", + below_group_limit: "true" + ) + end + end + + describe '#explore_dependencies_data' do + let_it_be(:organization) { build_stubbed(:organization) } + let(:page_info) do + { + type: 'cursor', + has_next_page: true, + has_previous_page: false, + start_cursor: nil, + current_cursor: 'current_cursor', + end_cursor: 'next_page_cursor' + } + end + + subject { helper.explore_dependencies_data(organization, page_info) } + + it_behaves_like 'a helper method that returns shared dependencies data' + + it 'returns the expected data' do + is_expected.to include( + page_info: page_info, + endpoint: "/explore/dependencies.json", + licenses_endpoint: nil, + locations_endpoint: nil, + export_endpoint: "/api/v4/organizations/#{organization.id}/dependency_list_exports", + vulnerabilities_endpoint: nil, + below_group_limit: "false" + ) + end + end +end