-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17b3d9d
commit da27ded
Showing
1 changed file
with
186 additions
and
0 deletions.
There are no files selected for viewing
186 changes: 186 additions & 0 deletions
186
...k/plugins/enterprise_search/public/applications/shared/layout/classic_nav_helpers.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,186 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { mockKibanaValues } from '../../__mocks__/kea_logic'; | ||
import '../../__mocks__/react_router'; | ||
|
||
jest.mock('../react_router_helpers/link_events', () => ({ | ||
letBrowserHandleEvent: jest.fn(), | ||
})); | ||
|
||
import { ClassicNavItem } from '../types'; | ||
|
||
import { generateSideNavItems } from './classic_nav_helpers'; | ||
|
||
describe('generateSideNavItems', () => { | ||
const deepLinksMap = { | ||
enterpriseSearch: { | ||
id: 'enterpriseSearch', | ||
url: '/app/enterprise_search/overview', | ||
title: 'Overview', | ||
}, | ||
'enterpriseSearchContent:searchIndices': { | ||
id: 'enterpriseSearchContent:searchIndices', | ||
title: 'Indices', | ||
url: '/app/enterprise_search/content/search_indices', | ||
}, | ||
'enterpriseSearchContent:connectors': { | ||
id: 'enterpriseSearchContent:connectors', | ||
title: 'Connectors', | ||
url: '/app/enterprise_search/content/connectors', | ||
}, | ||
'enterpriseSearchContent:webCrawlers': { | ||
id: 'enterpriseSearchContent:webCrawlers', | ||
title: 'Web crawlers', | ||
url: '/app/enterprise_search/content/crawlers', | ||
}, | ||
}; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockKibanaValues.history.location.pathname = '/'; | ||
}); | ||
|
||
it('renders top-level items', () => { | ||
const classicNavItems: ClassicNavItem[] = [ | ||
{ | ||
id: 'unit-test', | ||
deepLink: { | ||
link: 'enterpriseSearch', | ||
}, | ||
}, | ||
]; | ||
|
||
expect(generateSideNavItems(classicNavItems, deepLinksMap)).toEqual([ | ||
{ | ||
href: '/app/enterprise_search/overview', | ||
id: 'unit-test', | ||
isSelected: false, | ||
name: 'Overview', | ||
onClick: expect.any(Function), | ||
}, | ||
]); | ||
}); | ||
|
||
it('renders items with children', () => { | ||
const classicNavItems: ClassicNavItem[] = [ | ||
{ | ||
id: 'parent', | ||
name: 'Parent', | ||
items: [ | ||
{ | ||
id: 'unit-test', | ||
deepLink: { | ||
link: 'enterpriseSearch', | ||
}, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
expect(generateSideNavItems(classicNavItems, deepLinksMap)).toEqual([ | ||
{ | ||
id: 'parent', | ||
items: [ | ||
{ | ||
href: '/app/enterprise_search/overview', | ||
id: 'unit-test', | ||
isSelected: false, | ||
name: 'Overview', | ||
onClick: expect.any(Function), | ||
}, | ||
], | ||
name: 'Parent', | ||
}, | ||
]); | ||
}); | ||
|
||
it('renders classic nav name over deep link title if provided', () => { | ||
const classicNavItems: ClassicNavItem[] = [ | ||
{ | ||
deepLink: { | ||
link: 'enterpriseSearch', | ||
}, | ||
id: 'unit-test', | ||
name: 'Home', | ||
}, | ||
]; | ||
|
||
expect(generateSideNavItems(classicNavItems, deepLinksMap)).toEqual([ | ||
{ | ||
href: '/app/enterprise_search/overview', | ||
id: 'unit-test', | ||
isSelected: false, | ||
name: 'Home', | ||
onClick: expect.any(Function), | ||
}, | ||
]); | ||
}); | ||
|
||
it('removes item if deep link is not defined', () => { | ||
const classicNavItems: ClassicNavItem[] = [ | ||
{ | ||
deepLink: { | ||
link: 'enterpriseSearch', | ||
}, | ||
id: 'unit-test', | ||
name: 'Home', | ||
}, | ||
{ | ||
deepLink: { | ||
link: 'enterpriseSearchApplications:playground', | ||
}, | ||
id: 'unit-test-missing', | ||
}, | ||
]; | ||
|
||
expect(generateSideNavItems(classicNavItems, deepLinksMap)).toEqual([ | ||
{ | ||
href: '/app/enterprise_search/overview', | ||
id: 'unit-test', | ||
isSelected: false, | ||
name: 'Home', | ||
onClick: expect.any(Function), | ||
}, | ||
]); | ||
}); | ||
|
||
it('adds pre-rendered child items provided', () => { | ||
const classicNavItems: ClassicNavItem[] = [ | ||
{ | ||
id: 'unit-test', | ||
name: 'Indices', | ||
}, | ||
]; | ||
const subItems = { | ||
'unit-test': [ | ||
{ | ||
href: '/app/unit-test', | ||
id: 'child', | ||
isSelected: true, | ||
name: 'Index', | ||
onClick: jest.fn(), | ||
}, | ||
], | ||
}; | ||
|
||
expect(generateSideNavItems(classicNavItems, deepLinksMap, subItems)).toEqual([ | ||
{ | ||
id: 'unit-test', | ||
items: [ | ||
{ | ||
href: '/app/unit-test', | ||
id: 'child', | ||
isSelected: true, | ||
name: 'Index', | ||
onClick: expect.any(Function), | ||
}, | ||
], | ||
name: 'Indices', | ||
}, | ||
]); | ||
}); | ||
}); |