Skip to content

Commit

Permalink
search: remove appSearch & workplaceSearch chrome items
Browse files Browse the repository at this point in the history
  • Loading branch information
TattdCodeMonkey committed Jan 9, 2025
1 parent c0a7335 commit 647d299
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import {
useGenerateBreadcrumbs,
useEuiBreadcrumbs,
useEnterpriseSearchBreadcrumbs,
useAppSearchBreadcrumbs,
useSearchBreadcrumbs,
useWorkplaceSearchBreadcrumbs,
} from './generate_breadcrumbs';

describe('useGenerateBreadcrumbs', () => {
Expand Down Expand Up @@ -228,115 +226,3 @@ describe('useEnterpriseSearchBreadcrumbs', () => {
]);
});
});

describe('useAppSearchBreadcrumbs', () => {
beforeEach(() => {
jest.clearAllMocks();
mockHistory.createHref.mockImplementation(
({ pathname }: any) => `/app/enterprise_search/app_search${pathname}`
);
});

it('Builds a chain of breadcrumbs with Enterprise Search and App Search at the root', () => {
const breadcrumbs = [
{
text: 'Page 1',
path: '/page1',
},
{
text: 'Page 2',
path: '/page2',
},
];

expect(useAppSearchBreadcrumbs(breadcrumbs)).toEqual([
{
text: 'Enterprise Search',
href: '/app/elasticsearch/overview',
onClick: expect.any(Function),
},
{
text: 'App Search',
href: '/app/enterprise_search/app_search/',
onClick: expect.any(Function),
},
{
text: 'Page 1',
href: '/app/enterprise_search/app_search/page1',
onClick: expect.any(Function),
},
{
text: 'Page 2',
},
]);
});

it('shows just the root if breadcrumbs is empty', () => {
expect(useAppSearchBreadcrumbs()).toEqual([
{
text: 'Enterprise Search',
href: '/app/elasticsearch/overview',
onClick: expect.any(Function),
},
{
text: 'App Search',
},
]);
});
});

describe('useWorkplaceSearchBreadcrumbs', () => {
beforeEach(() => {
jest.clearAllMocks();
mockHistory.createHref.mockImplementation(
({ pathname }: any) => `/app/enterprise_search/workplace_search${pathname}`
);
});

it('Builds a chain of breadcrumbs with Enterprise Search and Workplace Search at the root', () => {
const breadcrumbs = [
{
text: 'Page 1',
path: '/page1',
},
{
text: 'Page 2',
path: '/page2',
},
];

expect(useWorkplaceSearchBreadcrumbs(breadcrumbs)).toEqual([
{
text: 'Enterprise Search',
href: '/app/elasticsearch/overview',
onClick: expect.any(Function),
},
{
text: 'Workplace Search',
href: '/app/enterprise_search/workplace_search/',
onClick: expect.any(Function),
},
{
text: 'Page 1',
href: '/app/enterprise_search/workplace_search/page1',
onClick: expect.any(Function),
},
{
text: 'Page 2',
},
]);
});

it('shows just the root if breadcrumbs is empty', () => {
expect(useWorkplaceSearchBreadcrumbs()).toEqual([
{
text: 'Enterprise Search',
href: '/app/elasticsearch/overview',
onClick: expect.any(Function),
},
{
text: 'Workplace Search',
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { generateTitle, searchTitle, appSearchTitle, workplaceSearchTitle } from './generate_title';
import { generateTitle, searchTitle } from './generate_title';

describe('generateTitle', () => {
it('creates a hyphen separated string from an array of page titles', () => {
Expand All @@ -21,7 +21,7 @@ describe('searchTitle', () => {
});

it('can be mixed and matched', () => {
const title = searchTitle([appSearchTitle(['Some Page'])]);
const title = searchTitle([generateTitle(['Some Page', 'App Search'])]);
expect(title).toEqual('Some Page - App Search - Elasticsearch');
});

Expand All @@ -30,27 +30,3 @@ describe('searchTitle', () => {
expect(title).toEqual('Elasticsearch');
});
});

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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export {
SetEnterpriseSearchContentChrome,
SetElasticsearchChrome,
SetAiSearchChrome,
SetAppSearchChrome,
SetWorkplaceSearchChrome,
SetSearchExperiencesChrome,
SetEnterpriseSearchApplicationsChrome,
SetSemanticSearchChrome,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,17 @@ import { shallow } from 'enzyme';
jest.mock('./generate_breadcrumbs', () => ({
useGenerateBreadcrumbs: jest.requireActual('./generate_breadcrumbs').useGenerateBreadcrumbs,
useSearchBreadcrumbs: jest.fn(() => (crumbs: any) => crumbs),
useAppSearchBreadcrumbs: jest.fn(() => (crumbs: any) => crumbs),
useWorkplaceSearchBreadcrumbs: jest.fn(() => (crumbs: any) => crumbs),
}));
import {
useSearchBreadcrumbs,
useAppSearchBreadcrumbs,
useWorkplaceSearchBreadcrumbs,
} from './generate_breadcrumbs';
import { useSearchBreadcrumbs } from './generate_breadcrumbs';

jest.mock('./generate_title', () => ({
searchTitle: jest.fn((title: any) => title),
appSearchTitle: jest.fn((title: any) => title),
workplaceSearchTitle: jest.fn((title: any) => title),
}));
import { searchTitle, appSearchTitle, workplaceSearchTitle } from './generate_title';
import { searchTitle } from './generate_title';

import { SetSearchChrome, SetAppSearchChrome, SetWorkplaceSearchChrome } from '.';
import { SetSearchChrome } from '.';

describe('Set Kibana Chrome helpers', () => {
const mockCurrentPath = (pathname: string) =>
setMockValues({ history: { location: { pathname } } });

beforeEach(() => {
jest.clearAllMocks();
setMockValues({ history: mockHistory });
Expand Down Expand Up @@ -68,52 +57,4 @@ describe('Set Kibana Chrome helpers', () => {
expect(useSearchBreadcrumbs).toHaveBeenCalledWith([]);
});
});

describe('SetAppSearchChrome', () => {
it('sets breadcrumbs and document title', () => {
mockCurrentPath('/engines/{name}/curations');
shallow(<SetAppSearchChrome trail={['Engines', 'Some Engine', 'Curations']} />);

expect(appSearchTitle).toHaveBeenCalledWith(['Curations', 'Some Engine', 'Engines']);
expect(useAppSearchBreadcrumbs).toHaveBeenCalledWith([
{ text: 'Engines', path: '/engines' },
{ text: 'Some Engine', path: '/engines/{name}' },
{ text: 'Curations', path: '/engines/{name}/curations' },
]);
});

it('handles empty trails as a root-level page', () => {
shallow(<SetAppSearchChrome />);

expect(appSearchTitle).toHaveBeenCalledWith([]);
expect(useAppSearchBreadcrumbs).toHaveBeenCalledWith([]);
});
});

describe('SetWorkplaceSearchChrome', () => {
it('sets breadcrumbs and document title', () => {
mockCurrentPath('/groups/{id}/source_prioritization');
shallow(
<SetWorkplaceSearchChrome trail={['Groups', 'Some Group', 'Source Prioritization']} />
);

expect(workplaceSearchTitle).toHaveBeenCalledWith([
'Source Prioritization',
'Some Group',
'Groups',
]);
expect(useWorkplaceSearchBreadcrumbs).toHaveBeenCalledWith([
{ text: 'Groups', path: '/groups' },
{ text: 'Some Group', path: '/groups/{id}' },
{ text: 'Source Prioritization', path: '/groups/{id}/source_prioritization' },
]);
});

it('handles empty trails as a root-level page', () => {
shallow(<SetWorkplaceSearchChrome />);

expect(workplaceSearchTitle).toHaveBeenCalledWith([]);
expect(useWorkplaceSearchBreadcrumbs).toHaveBeenCalledWith([]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {
useEnterpriseSearchContentBreadcrumbs,
useAiSearchBreadcrumbs,
useElasticsearchBreadcrumbs,
useAppSearchBreadcrumbs,
useWorkplaceSearchBreadcrumbs,
BreadcrumbTrail,
useSearchExperiencesBreadcrumbs,
useVectorSearchBreadcrumbs,
Expand All @@ -30,7 +28,6 @@ import {
import {
aiSearchTitle,
analyticsTitle,
appSearchTitle,
elasticsearchTitle,
enterpriseSearchContentTitle,
generateTitle,
Expand All @@ -39,7 +36,6 @@ import {
searchTitle,
semanticSearchTitle,
vectorSearchTitle,
workplaceSearchTitle,
} from './generate_title';

/**
Expand Down Expand Up @@ -112,23 +108,6 @@ export const SetElasticsearchChrome: React.FC<SetChromeProps> = ({ trail = [] })
return null;
};

export const SetAppSearchChrome: React.FC<SetChromeProps> = ({ trail = [] }) => {
const { setBreadcrumbs, setDocTitle } = useValues(KibanaLogic);

const title = reverseArray(trail);
const docTitle = appSearchTitle(title);

const crumbs = useGenerateBreadcrumbs(trail);
const breadcrumbs = useAppSearchBreadcrumbs(crumbs);

useEffect(() => {
setBreadcrumbs(breadcrumbs);
setDocTitle(docTitle);
}, [trail]);

return null;
};

export const SetAiSearchChrome: React.FC<SetChromeProps> = ({ trail = [] }) => {
const { setBreadcrumbs, setDocTitle } = useValues(KibanaLogic);

Expand All @@ -146,23 +125,6 @@ export const SetAiSearchChrome: React.FC<SetChromeProps> = ({ trail = [] }) => {
return null;
};

export const SetWorkplaceSearchChrome: React.FC<SetChromeProps> = ({ trail = [] }) => {
const { setBreadcrumbs, setDocTitle } = useValues(KibanaLogic);

const title = reverseArray(trail);
const docTitle = workplaceSearchTitle(title);

const crumbs = useGenerateBreadcrumbs(trail);
const breadcrumbs = useWorkplaceSearchBreadcrumbs(crumbs);

useEffect(() => {
setBreadcrumbs(breadcrumbs);
setDocTitle(docTitle);
}, [trail]);

return null;
};

export const SetEnterpriseSearchContentChrome: React.FC<SetChromeProps> = ({ trail = [] }) => {
const { setBreadcrumbs, setDocTitle } = useValues(KibanaLogic);

Expand Down

0 comments on commit 647d299

Please sign in to comment.