-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Serverless] fix discover breadcrumbs missing search title (#163607)
## Summary Aaddress #163337 for discover saved search ### Context: In serverless navigation, we changed how breadcrumbs work. Instead of setting the full path manually, we automatically calculate the main parts of the path from the side nav + current URL. This was done to keep side nav and breadcrumbs in sync as much as possible and solve consistency issues with breadcrumbs across apps. https://docs.elastic.dev/kibana-dev-docs/serverless-project-navigation#breadcrumbs Apps can append custom deeper context using the serverless.setBreadcrumbs API. Regular core.chrome.setBreadcrumbs has no effect when the serverless nav is rendered. <img width="1624" alt="Screenshot 2023-08-10 at 15 22 08" src="https://github.com/elastic/kibana/assets/7784120/269879b0-6fcc-4606-816e-5d76616db60a">
- Loading branch information
Showing
10 changed files
with
167 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { serverlessMock } from '@kbn/serverless/public/mocks'; | ||
import { createDiscoverServicesMock } from '../__mocks__/services'; | ||
import { setBreadcrumbs } from './breadcrumbs'; | ||
import { createMemoryHistory } from 'history'; | ||
import type { HistoryLocationState } from '../build_services'; | ||
|
||
describe('Breadcrumbs', () => { | ||
const discoverServiceMock = createDiscoverServicesMock(); | ||
beforeEach(() => { | ||
(discoverServiceMock.chrome.setBreadcrumbs as jest.Mock).mockClear(); | ||
}); | ||
|
||
test('should set breadcrumbs with default root', () => { | ||
setBreadcrumbs({ services: discoverServiceMock }); | ||
expect(discoverServiceMock.chrome.setBreadcrumbs).toHaveBeenCalledWith([{ text: 'Discover' }]); | ||
}); | ||
|
||
test('should set breadcrumbs with title', () => { | ||
setBreadcrumbs({ services: discoverServiceMock, titleBreadcrumbText: 'Saved Search' }); | ||
expect(discoverServiceMock.chrome.setBreadcrumbs).toHaveBeenCalledWith([ | ||
{ text: 'Discover', href: '#/' }, | ||
{ text: 'Saved Search' }, | ||
]); | ||
}); | ||
|
||
test('should set breadcrumbs with custom root path', () => { | ||
setBreadcrumbs({ | ||
services: discoverServiceMock, | ||
titleBreadcrumbText: 'Saved Search', | ||
rootBreadcrumbPath: '#/custom-path', | ||
}); | ||
expect(discoverServiceMock.chrome.setBreadcrumbs).toHaveBeenCalledWith([ | ||
{ text: 'Discover', href: '#/custom-path' }, | ||
{ text: 'Saved Search' }, | ||
]); | ||
}); | ||
|
||
test('should set breadcrumbs with profile root path', () => { | ||
setBreadcrumbs({ | ||
services: { | ||
...discoverServiceMock, | ||
history: () => { | ||
const history = createMemoryHistory<HistoryLocationState>({}); | ||
history.push('/p/my-profile'); | ||
return history; | ||
}, | ||
}, | ||
titleBreadcrumbText: 'Saved Search', | ||
}); | ||
expect(discoverServiceMock.chrome.setBreadcrumbs).toHaveBeenCalledWith([ | ||
{ text: 'Discover', href: '#/p/my-profile/' }, | ||
{ text: 'Saved Search' }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('Serverless Breadcrumbs', () => { | ||
const discoverServiceMock = { | ||
...createDiscoverServicesMock(), | ||
serverless: serverlessMock.createStart(), | ||
}; | ||
beforeEach(() => { | ||
(discoverServiceMock.serverless.setBreadcrumbs as jest.Mock).mockClear(); | ||
}); | ||
|
||
test('should not set any root', () => { | ||
setBreadcrumbs({ services: discoverServiceMock }); | ||
expect(discoverServiceMock.serverless.setBreadcrumbs).toHaveBeenCalledWith([]); | ||
}); | ||
|
||
test('should set title breadcrumb', () => { | ||
setBreadcrumbs({ services: discoverServiceMock, titleBreadcrumbText: 'Saved Search' }); | ||
expect(discoverServiceMock.serverless.setBreadcrumbs).toHaveBeenCalledWith([ | ||
{ text: 'Saved Search' }, | ||
]); | ||
}); | ||
|
||
test("shouldn't set root breadcrumbs, even when there is a custom root path", () => { | ||
setBreadcrumbs({ | ||
services: discoverServiceMock, | ||
titleBreadcrumbText: 'Saved Search', | ||
rootBreadcrumbPath: '#/custom-path', | ||
}); | ||
expect(discoverServiceMock.serverless.setBreadcrumbs).toHaveBeenCalledWith([ | ||
{ text: 'Saved Search' }, | ||
]); | ||
}); | ||
|
||
test("shouldn't set root breadcrumbs, even when there is a custom profile", () => { | ||
setBreadcrumbs({ | ||
services: { | ||
...discoverServiceMock, | ||
history: () => { | ||
const history = createMemoryHistory<HistoryLocationState>({}); | ||
history.push('/p/my-profile'); | ||
return history; | ||
}, | ||
}, | ||
titleBreadcrumbText: 'Saved Search', | ||
}); | ||
expect(discoverServiceMock.serverless.setBreadcrumbs).toHaveBeenCalledWith([ | ||
{ text: 'Saved Search' }, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters