Fixed URL hash appending for space next redirect URL (#189204)

## Summary

Fixed URL hash appending for space next redirect URL.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

__Fixes: https://github.com/elastic/kibana/issues/189184__
This commit is contained in:
elena-shostak 2024-07-26 10:40:50 +02:00 committed by GitHub
parent 59f7b4b3a5
commit 3f3713b567
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 1 deletions

View file

@ -205,6 +205,19 @@ describe('Enter Space view routes', () => {
expectedLocation:
'/mock-server-basepath/app/management/kibana/objects?initialQuery=type:(visualization)',
},
{
query: {
next: '/app/discover#/view/uuid',
},
expectedLocation: '/mock-server-basepath/app/discover#/view/uuid',
},
{
query: {
next: '/app/discover?initialQuery=type:(visualization)#/view/uuid',
},
expectedLocation:
'/mock-server-basepath/app/discover?initialQuery=type:(visualization)#/view/uuid',
},
]) {
const request = httpServerMock.createKibanaRequest({
query,

View file

@ -46,7 +46,7 @@ export function initSpacesViewsRoutes(deps: ViewRouteDeps) {
return response.redirected({
headers: {
location: `${basePath}${normalizedRoute.pathname}${normalizedRoute.search}`,
location: `${basePath}${normalizedRoute.pathname}${normalizedRoute.search}${normalizedRoute.hash}`,
},
});
} catch (e) {

View file

@ -100,6 +100,26 @@ export default function enterSpaceFunctionalTests({
await PageObjects.spaceSelector.expectRoute(spaceId, '/app/management/kibana/objects');
});
it('allows user to navigate to different space with provided next route preserving url hash and search', async () => {
const spaceId = 'another-space';
await PageObjects.security.login(undefined, undefined, {
expectSpaceSelector: true,
});
const anchorElement = await PageObjects.spaceSelector.getSpaceCardAnchor(spaceId);
const path = await anchorElement.getAttribute('href');
const pathWithNextRoute = `${path}?next=/app/management/kibana/objects?initialQuery=type:(visualization)#/view`;
await browser.navigateTo(pathWithNextRoute);
await PageObjects.spaceSelector.expectRoute(
spaceId,
'/app/management/kibana/objects?initialQuery=type%3A(visualization)#/view'
);
});
it('allows user to navigate to different space with provided next route, route is normalized', async () => {
const spaceId = 'another-space';