Commit d5bb7ee3 authored by Mark Fletcher's avatar Mark Fletcher

Fix Insights displaying JSON on back navigation

- This fix means that Reopening a closed insights tab or navigating back
  to insights will not cause the JSON payload to be displayed
parent a5bed62a
---
title: Fix Insights displaying JSON on back navigation
merge_request: 25801
author:
type: fixed
- @no_container = true - @no_container = true
= render('shared/insights', endpoint: group_insights_path(@group), query_endpoint: query_group_insights_path(@group)) = render('shared/insights', endpoint: group_insights_path(@group, format: :json), query_endpoint: query_group_insights_path(@group))
- @no_container = true - @no_container = true
= render('shared/insights', endpoint: namespace_project_insights_path(@project.namespace, @project), query_endpoint: query_namespace_project_insights_path(@project.namespace, @project)) = render('shared/insights', endpoint: namespace_project_insights_path(@project.namespace, @project, format: :json), query_endpoint: query_namespace_project_insights_path(@project.namespace, @project))
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
RSpec.shared_examples 'Insights page' do RSpec.shared_examples 'Insights page' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
context 'as a permitted user' do describe 'as a permitted user' do
before(:context) do before(:context) do
entity.add_maintainer(user) entity.add_maintainer(user)
end end
...@@ -24,22 +24,43 @@ RSpec.shared_examples 'Insights page' do ...@@ -24,22 +24,43 @@ RSpec.shared_examples 'Insights page' do
expect(page).to have_content('Insights') expect(page).to have_content('Insights')
end end
context 'hash fragment navigation', :js do context 'navigation' do
let(:config) { entity.insights_config } let(:config) { entity.insights_config }
let(:non_default_tab_id) { config.keys.last } let(:default_tab_id) { config.each_key.first }
let(:non_default_tab_title) { config[non_default_tab_id][:title] } let(:default_tab_title) { config[default_tab_id][:title] }
let(:hash_fragment) { "#/#{non_default_tab_id}" } let(:route) { path }
let(:route) { path + hash_fragment }
before do before do
visit route visit route
wait_for_requests wait_for_requests
end end
it 'loads the correct page' do it 'by default loads the first page', :js do
page.within(".insights-container") do
expect(page).to have_content(default_tab_title)
end
end
context 'hash fragment navigation' do
let(:non_default_tab_id) { config.keys.last }
let(:non_default_tab_title) { config[non_default_tab_id][:title] }
let(:hash_fragment) { "#/#{non_default_tab_id}" }
let(:route) { path + hash_fragment }
it 'loads the correct page', :js do
page.within(".insights-container") do
expect(page).to have_content(non_default_tab_title)
end
end
end
it 'displays correctly when navigating back to insights', :js do
visit root_path
page.evaluate_script('window.history.back()')
page.within(".insights-container") do page.within(".insights-container") do
expect(page).to have_content(non_default_tab_title) expect(page).to have_content(default_tab_title)
end end
end end
end end
......
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