-
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.
[ML] Fixes getTab() to always return an array. (#45616)
- Fixes getTabs() to always return an array. I was wondering why TypeScript didn't flag the tabs.map(...) part because tabs could possibly be undefined. It's because Record assumes that every key exists. More on that can be found in this blog post. - This PR fixes a) the type of TAB_MAP by wrapping it in Partial<...> so it correctly flags the tabs.map() part with tabs possibly being undefined and b) fixes getTabs()'s return value by always returning an array.
- Loading branch information
Showing
2 changed files
with
26 additions
and
3 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
x-pack/legacy/plugins/ml/public/components/navigation_menu/tabs.test.tsx
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,23 @@ | ||
/* | ||
* 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 { getTabs } from './tabs'; | ||
|
||
describe('Navigation Menu: Tabs', () => { | ||
test('getTabs() always returns an array', () => { | ||
const tabs1 = getTabs('anomaly_detection', false); | ||
expect(Array.isArray(tabs1)).toBeTruthy(); | ||
expect(tabs1).toHaveLength(4); | ||
|
||
const tabs2 = getTabs('access-denied', false); | ||
expect(Array.isArray(tabs2)).toBeTruthy(); | ||
expect(tabs2).toHaveLength(0); | ||
|
||
const tabs3 = getTabs('datavisualizer', false); | ||
expect(Array.isArray(tabs3)).toBeTruthy(); | ||
expect(tabs3).toHaveLength(0); | ||
}); | ||
}); |
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