Commit c353515d authored by mo khan's avatar mo khan Committed by Stan Hu

Load js app data in controller

This change request is a continuation of a conversation started in
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/22465/diffs.

It extracts the data that is loaded for the client side application in
the controller so that each piece of data that is loaded can be tested.
parent d14a1d42
...@@ -8,6 +8,7 @@ module Projects ...@@ -8,6 +8,7 @@ module Projects
def index def index
respond_to do |format| respond_to do |format|
format.html do format.html do
@licenses_app_data = licenses_app_data
render status: :ok render status: :ok
end end
format.json do format.json do
...@@ -80,5 +81,13 @@ module Projects ...@@ -80,5 +81,13 @@ module Projects
def truthy?(value) def truthy?(value)
value.in?(%w[true 1]) value.in?(%w[true 1])
end end
def licenses_app_data
{
endpoint: project_licenses_path(project, detected: true, format: :json),
documentation_path: help_page_path('user/application_security/license_compliance/index'),
empty_state_svg_path: helpers.image_path('illustrations/Dependency-list-empty-state.svg')
}
end
end end
end end
- breadcrumb_title _('License Compliance') - breadcrumb_title _('License Compliance')
- page_title _('License Compliance') - page_title _('License Compliance')
#js-licenses-app{ data: { endpoint: project_licenses_path(@project, detected: true, format: :json), #js-licenses-app{ data: licenses_app_data }
documentation_path: help_page_path('user/application_security/license_compliance/index'),
empty_state_svg_path: image_path('illustrations/Dependency-list-empty-state.svg') } }
...@@ -27,6 +27,10 @@ describe Projects::LicensesController do ...@@ -27,6 +27,10 @@ describe Projects::LicensesController do
get :index, params: params get :index, params: params
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
licenses_app_data = assigns(:licenses_app_data)
expect(licenses_app_data[:endpoint]).to eql(controller.helpers.project_licenses_path(project, detected: true, format: :json))
expect(licenses_app_data[:documentation_path]).to eql(help_page_path('user/application_security/license_compliance/index'))
expect(licenses_app_data[:empty_state_svg_path]).to eql(controller.helpers.image_path('illustrations/Dependency-list-empty-state.svg'))
end end
it 'counts usage of the feature' do it 'counts usage of the feature' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment