-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't display divider for API Keys menu item when API key is dis…
…abled Signed-off-by: Vishwas Rajashekar <[email protected]>
- Loading branch information
Showing
2 changed files
with
47 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import UserAccountMenu from 'components/Header/UserAccountMenu'; | ||
import React from 'react'; | ||
|
||
const mockIsApiKeyEnabled = jest.fn(); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useNavigate: () => {} | ||
})); | ||
|
||
jest.mock('../../utilities/authUtilities', () => ({ | ||
isApiKeyEnabled: () => { | ||
return mockIsApiKeyEnabled(); | ||
}, | ||
getLoggedInUser: () => { | ||
return 'jest-user'; | ||
}, | ||
logoutUser: () => {} | ||
})); | ||
|
||
describe('Account Menu', () => { | ||
it('displays Api Keys menu item with its divider when the API Keys config is enabled', async () => { | ||
mockIsApiKeyEnabled.mockReturnValue(true); | ||
render(<UserAccountMenu />); | ||
const userIconButton = await screen.getByTestId('user-icon-header-button'); | ||
fireEvent.click(userIconButton); | ||
expect(await screen.queryByTestId('api-keys-menu-item')).toBeInTheDocument(); | ||
expect(await screen.queryByTestId('api-keys-menu-item-divider')).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not display Api Keys menu item and divider when the API Keys config is disabled', async () => { | ||
mockIsApiKeyEnabled.mockReturnValue(false); | ||
render(<UserAccountMenu />); | ||
const userIconButton = await screen.getByTestId('user-icon-header-button'); | ||
fireEvent.click(userIconButton); | ||
expect(await screen.queryByTestId('api-keys-menu-item')).not.toBeInTheDocument(); | ||
expect(await screen.queryByTestId('api-keys-menu-item-divider')).not.toBeInTheDocument(); | ||
}); | ||
}); |
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