mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
[Spaces] Added additional tests for space next route navigation (#189497)
## Summary Added additional tests for space next route navigation with default route, specifically: - `defaultRoute` with and without hash - `defaultRoute` with and without search - `defaultRoute` check for not navigating outside of space base 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/189481__
This commit is contained in:
parent
02510bae9e
commit
4edcdef311
3 changed files with 121 additions and 102 deletions
|
@ -107,72 +107,63 @@ describe('Enter Space view routes', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('correctly enters space default route.', async () => {
|
const testCase = (
|
||||||
const request = httpServerMock.createKibanaRequest();
|
description: string,
|
||||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
{
|
||||||
const contextMock = coreMock.createRequestHandlerContext();
|
query,
|
||||||
|
defaultRoute,
|
||||||
|
expectedLocation,
|
||||||
|
}: { query?: Record<string, string>; defaultRoute?: string; expectedLocation: string }
|
||||||
|
) => {
|
||||||
|
it(description, async () => {
|
||||||
|
const request = httpServerMock.createKibanaRequest({
|
||||||
|
query,
|
||||||
|
});
|
||||||
|
|
||||||
contextMock.uiSettings.client.get.mockResolvedValue('/home');
|
const responseFactory = httpResourcesMock.createResponseFactory();
|
||||||
|
const contextMock = coreMock.createRequestHandlerContext();
|
||||||
|
contextMock.uiSettings.client.get.mockResolvedValue(defaultRoute);
|
||||||
|
|
||||||
await routeHandler(
|
await routeHandler(
|
||||||
{ core: contextMock } as unknown as RequestHandlerContext,
|
{ core: contextMock } as unknown as RequestHandlerContext,
|
||||||
request,
|
request,
|
||||||
responseFactory
|
responseFactory
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(responseFactory.redirected).toHaveBeenCalledWith({
|
expect(responseFactory.redirected).toHaveBeenCalledWith({
|
||||||
headers: { location: '/mock-server-basepath/home' },
|
headers: { location: expectedLocation },
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
testCase('correctly enters space default route.', {
|
||||||
|
defaultRoute: '/home',
|
||||||
|
expectedLocation: '/mock-server-basepath/home',
|
||||||
});
|
});
|
||||||
|
|
||||||
it('correctly enters space with specified route.', async () => {
|
testCase('correctly enters space with specified route.', {
|
||||||
const nextRoute = '/app/management/kibana/objects';
|
query: {
|
||||||
const request = httpServerMock.createKibanaRequest({
|
next: '/app/management/kibana/objects',
|
||||||
query: {
|
},
|
||||||
next: nextRoute,
|
expectedLocation: '/mock-server-basepath/app/management/kibana/objects',
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
|
||||||
const contextMock = coreMock.createRequestHandlerContext();
|
|
||||||
|
|
||||||
await routeHandler(
|
|
||||||
{ core: contextMock } as unknown as RequestHandlerContext,
|
|
||||||
request,
|
|
||||||
responseFactory
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(responseFactory.redirected).toHaveBeenCalledWith({
|
|
||||||
headers: { location: `/mock-server-basepath${nextRoute}` },
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('correctly enters space with specified route without leading slash.', async () => {
|
testCase('correctly enters space with specified route without leading slash.', {
|
||||||
const nextRoute = 'app/management/kibana/objects';
|
query: {
|
||||||
const request = httpServerMock.createKibanaRequest({
|
next: 'app/management/kibana/objects',
|
||||||
query: {
|
},
|
||||||
next: nextRoute,
|
expectedLocation: '/mock-server-basepath/app/management/kibana/objects',
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
|
||||||
const contextMock = coreMock.createRequestHandlerContext();
|
|
||||||
|
|
||||||
await routeHandler(
|
|
||||||
{ core: contextMock } as unknown as RequestHandlerContext,
|
|
||||||
request,
|
|
||||||
responseFactory
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(responseFactory.redirected).toHaveBeenCalledWith({
|
|
||||||
headers: { location: `/mock-server-basepath/${nextRoute}` },
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('correctly enters space and normalizes specified route.', async () => {
|
testCase('correctly enters space with default route if specified route is not relative.', {
|
||||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
query: {
|
||||||
const contextMock = coreMock.createRequestHandlerContext();
|
next: 'http://evil.com/mock-server-basepath/app/kibana',
|
||||||
|
},
|
||||||
|
defaultRoute: '/home',
|
||||||
|
expectedLocation: '/mock-server-basepath/home',
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('specified route normalization', () => {
|
||||||
for (const { query, expectedLocation } of [
|
for (const { query, expectedLocation } of [
|
||||||
{
|
{
|
||||||
query: {
|
query: {
|
||||||
|
@ -205,56 +196,47 @@ describe('Enter Space view routes', () => {
|
||||||
expectedLocation:
|
expectedLocation:
|
||||||
'/mock-server-basepath/app/management/kibana/objects?initialQuery=type:(visualization)',
|
'/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({
|
testCase(`url ${query.next}`, { query, expectedLocation });
|
||||||
query,
|
|
||||||
});
|
|
||||||
await routeHandler(
|
|
||||||
{ core: contextMock } as unknown as RequestHandlerContext,
|
|
||||||
request,
|
|
||||||
responseFactory
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(responseFactory.redirected).toHaveBeenCalledWith({
|
|
||||||
headers: { location: expectedLocation },
|
|
||||||
});
|
|
||||||
|
|
||||||
responseFactory.redirected.mockClear();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('correctly enters space with default route if specificed route is not relative.', async () => {
|
describe('default route', () => {
|
||||||
const request = httpServerMock.createKibanaRequest({
|
for (const { defaultRoute, expectedLocation, query, testCaseName } of [
|
||||||
query: {
|
{
|
||||||
next: 'http://evil.com/mock-server-basepath/app/kibana',
|
defaultRoute: '/home',
|
||||||
|
expectedLocation: '/mock-server-basepath/home',
|
||||||
|
testCaseName: 'correctly enters space with default route.',
|
||||||
},
|
},
|
||||||
});
|
{
|
||||||
|
defaultRoute: '/home',
|
||||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
expectedLocation: '/mock-server-basepath/home',
|
||||||
const contextMock = coreMock.createRequestHandlerContext();
|
testCaseName: 'correctly enters space with default route if specified url is empty string.',
|
||||||
contextMock.uiSettings.client.get.mockResolvedValue('/home');
|
query: { next: '' },
|
||||||
|
},
|
||||||
await routeHandler(
|
{
|
||||||
{ core: contextMock } as unknown as RequestHandlerContext,
|
defaultRoute: '/home/#view',
|
||||||
request,
|
expectedLocation: '/mock-server-basepath/home/#view',
|
||||||
responseFactory
|
testCaseName: 'correctly enters space with default route preserving url hash.',
|
||||||
);
|
},
|
||||||
|
{
|
||||||
expect(responseFactory.redirected).toHaveBeenCalledWith({
|
defaultRoute: '/home?initialQuery=type:(visualization)',
|
||||||
headers: { location: '/mock-server-basepath/home' },
|
expectedLocation: '/mock-server-basepath/home?initialQuery=type:(visualization)',
|
||||||
});
|
testCaseName: 'correctly enters space with default route preserving url search.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
defaultRoute: '/app/discover?initialQuery=type:(visualization)#/view/uuid',
|
||||||
|
expectedLocation:
|
||||||
|
'/mock-server-basepath/app/discover?initialQuery=type:(visualization)#/view/uuid',
|
||||||
|
testCaseName: 'correctly enters space with default route preserving url search and hash.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
defaultRoute: '../../app/../app/management/kibana/objects',
|
||||||
|
expectedLocation: '/mock-server-basepath/app/management/kibana/objects',
|
||||||
|
testCaseName: 'correctly enters space with default route normalizing url.',
|
||||||
|
},
|
||||||
|
]) {
|
||||||
|
testCase(testCaseName, { query, defaultRoute, expectedLocation });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -44,6 +44,7 @@ export function initSpacesViewsRoutes(deps: ViewRouteDeps) {
|
||||||
// need to get reed of ../../ to make sure we will not be out of space basePath
|
// need to get reed of ../../ to make sure we will not be out of space basePath
|
||||||
const normalizedRoute = new URL(route, 'https://localhost');
|
const normalizedRoute = new URL(route, 'https://localhost');
|
||||||
|
|
||||||
|
// preserving of the hash is important for the navigation to work correctly with default route
|
||||||
return response.redirected({
|
return response.redirected({
|
||||||
headers: {
|
headers: {
|
||||||
location: `${basePath}${normalizedRoute.pathname}${normalizedRoute.search}${normalizedRoute.hash}`,
|
location: `${basePath}${normalizedRoute.pathname}${normalizedRoute.search}${normalizedRoute.hash}`,
|
||||||
|
|
|
@ -110,10 +110,37 @@ export default function enterSpaceFunctionalTests({
|
||||||
const anchorElement = await PageObjects.spaceSelector.getSpaceCardAnchor(spaceId);
|
const anchorElement = await PageObjects.spaceSelector.getSpaceCardAnchor(spaceId);
|
||||||
const path = await anchorElement.getAttribute('href');
|
const path = await anchorElement.getAttribute('href');
|
||||||
|
|
||||||
const pathWithNextRoute = `${path}?next=/app/management/kibana/objects?initialQuery=type:(visualization)#/view`;
|
const pathWithNextRoute = `${path}?next=/app/management/kibana/objects?initialQuery=type:(visualization)#/view/uuid`;
|
||||||
|
|
||||||
await browser.navigateTo(pathWithNextRoute);
|
await browser.navigateTo(pathWithNextRoute);
|
||||||
|
|
||||||
|
await PageObjects.spaceSelector.expectRoute(
|
||||||
|
spaceId,
|
||||||
|
'/app/management/kibana/objects?initialQuery=type%3A(visualization)#/view/uuid'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows user to navigate to different space with default route preserving url hash and search', async () => {
|
||||||
|
const spaceId = 'another-space';
|
||||||
|
|
||||||
|
await kibanaServer.uiSettings.replace(
|
||||||
|
{
|
||||||
|
defaultRoute: '/app/management/kibana/objects?initialQuery=type:(visualization)#/view',
|
||||||
|
buildNum: 8467,
|
||||||
|
'dateFormat:tz': 'UTC',
|
||||||
|
},
|
||||||
|
{ space: 'another-space' }
|
||||||
|
);
|
||||||
|
|
||||||
|
await PageObjects.security.login(undefined, undefined, {
|
||||||
|
expectSpaceSelector: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const anchorElement = await PageObjects.spaceSelector.getSpaceCardAnchor(spaceId);
|
||||||
|
const path = await anchorElement.getAttribute('href');
|
||||||
|
|
||||||
|
await browser.navigateTo(path!);
|
||||||
|
|
||||||
await PageObjects.spaceSelector.expectRoute(
|
await PageObjects.spaceSelector.expectRoute(
|
||||||
spaceId,
|
spaceId,
|
||||||
'/app/management/kibana/objects?initialQuery=type%3A(visualization)#/view'
|
'/app/management/kibana/objects?initialQuery=type%3A(visualization)#/view'
|
||||||
|
@ -142,6 +169,15 @@ export default function enterSpaceFunctionalTests({
|
||||||
it('falls back to the default home page if provided next route is malformed', async () => {
|
it('falls back to the default home page if provided next route is malformed', async () => {
|
||||||
const spaceId = 'another-space';
|
const spaceId = 'another-space';
|
||||||
|
|
||||||
|
await kibanaServer.uiSettings.replace(
|
||||||
|
{
|
||||||
|
defaultRoute: '/app/canvas',
|
||||||
|
buildNum: 8467,
|
||||||
|
'dateFormat:tz': 'UTC',
|
||||||
|
},
|
||||||
|
{ space: 'another-space' }
|
||||||
|
);
|
||||||
|
|
||||||
await PageObjects.security.login(undefined, undefined, {
|
await PageObjects.security.login(undefined, undefined, {
|
||||||
expectSpaceSelector: true,
|
expectSpaceSelector: true,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue