-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- will be used by new set_chrome helper
- Loading branch information
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...plugins/enterprise_search/public/applications/shared/kibana_chrome/generate_title.test.ts
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,60 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
generateTitle, | ||
enterpriseSearchTitle, | ||
appSearchTitle, | ||
workplaceSearchTitle, | ||
} from './generate_title'; | ||
|
||
describe('generateTitle', () => { | ||
it('creates a pipe separated string from an array of page titles', () => { | ||
const title = generateTitle(['Curations', 'some Engine', 'App Search']); | ||
expect(title).toEqual('Curations | some Engine | App Search'); | ||
}); | ||
}); | ||
|
||
describe('enterpriseSearchTitle', () => { | ||
it('automatically appends the Enterprise Search product onto the pages array', () => { | ||
const title = enterpriseSearchTitle(['Setup Guide']); | ||
expect(title).toEqual('Setup Guide | Enterprise Search'); | ||
}); | ||
|
||
it('can be mixed and matched', () => { | ||
const title = enterpriseSearchTitle([appSearchTitle(['Some Page'])]); | ||
expect(title).toEqual('Some Page | App Search | Enterprise Search'); | ||
}); | ||
|
||
it('falls back to product name', () => { | ||
const title = enterpriseSearchTitle(); | ||
expect(title).toEqual('Enterprise Search'); | ||
}); | ||
}); | ||
|
||
describe('appSearchTitle', () => { | ||
it('automatically appends the App Search product onto the pages array', () => { | ||
const title = appSearchTitle(['Engines']); | ||
expect(title).toEqual('Engines | App Search'); | ||
}); | ||
|
||
it('falls back to product name', () => { | ||
const title = appSearchTitle(); | ||
expect(title).toEqual('App Search'); | ||
}); | ||
}); | ||
|
||
describe('workplaceSearchTitle', () => { | ||
it('automatically appends the Workplace Search product onto the pages array', () => { | ||
const title = workplaceSearchTitle(['Sources']); | ||
expect(title).toEqual('Sources | Workplace Search'); | ||
}); | ||
|
||
it('falls back to product name', () => { | ||
const title = workplaceSearchTitle(); | ||
expect(title).toEqual('Workplace Search'); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/generate_title.ts
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,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
ENTERPRISE_SEARCH_PLUGIN, | ||
APP_SEARCH_PLUGIN, | ||
WORKPLACE_SEARCH_PLUGIN, | ||
} from '../../../../common/constants'; | ||
|
||
/** | ||
* Generate a document title that generally follows our breadcrumb trails | ||
* https://github.com/elastic/kibana/blob/master/docs/development/core/public/kibana-plugin-core-public.chromedoctitle.md | ||
*/ | ||
|
||
export type TTitle = string[]; | ||
|
||
/** | ||
* Given an array of page titles, return a final formatted document title | ||
* @param pages - e.g., ['Curations', 'some Engine', 'App Search'] | ||
* @returns - e.g., 'Curations | some Engine | App Search' | ||
*/ | ||
export const generateTitle = (pages: TTitle) => pages.join(' | '); | ||
|
||
/** | ||
* Product-specific helpers | ||
*/ | ||
|
||
export const enterpriseSearchTitle = (page: TTitle = []) => | ||
generateTitle([...page, ENTERPRISE_SEARCH_PLUGIN.NAME]); | ||
|
||
export const appSearchTitle = (page: TTitle = []) => | ||
generateTitle([...page, APP_SEARCH_PLUGIN.NAME]); | ||
|
||
export const workplaceSearchTitle = (page: TTitle = []) => | ||
generateTitle([...page, WORKPLACE_SEARCH_PLUGIN.NAME]); |