-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for okta login base screen
- Loading branch information
1 parent
e2aaa51
commit 6bb8ae1
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
login-workflow/src/screens/OktaLoginScreen/OktaLoginScreenBase.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,55 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent, RenderResult } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { OktaLoginScreenBase } from './OktaLoginScreenBase'; | ||
import { useOktaAuth } from '@okta/okta-react'; | ||
import { Box } from '@mui/material'; | ||
import { ErrorContextProvider } from '../../contexts/ErrorContext'; | ||
import { OktaLoginScreenProps } from './types'; | ||
import { errorContextProviderProps } from '../../contexts/ErrorContext/ErrorContextProvider.test'; | ||
|
||
jest.mock('@okta/okta-react', () => ({ | ||
useOktaAuth: jest.fn(), | ||
})); | ||
|
||
const mockSignInWithRedirect = jest.fn(); | ||
const mockOnContactSupport = jest.fn(); | ||
|
||
describe('OktaLoginScreenBase', () => { | ||
beforeEach(() => { | ||
(useOktaAuth as jest.Mock).mockReturnValue({ | ||
authState: { isAuthenticated: false }, | ||
oktaAuth: { signInWithRedirect: mockSignInWithRedirect }, | ||
}); | ||
}); | ||
|
||
const renderer = (props?: OktaLoginScreenProps): RenderResult => | ||
render( | ||
<ErrorContextProvider {...errorContextProviderProps}> | ||
<OktaLoginScreenBase {...props} /> | ||
</ErrorContextProvider> | ||
); | ||
|
||
it('renders correctly', () => { | ||
renderer({ header: <Box data-testid="test-header">Test Header</Box> }); | ||
expect(screen.getByText('Test Header')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls signInWithRedirect on login button click', () => { | ||
renderer({ loginButtonLabel: 'Login' }); | ||
const loginButton = screen.getByText('Login'); | ||
fireEvent.click(loginButton); | ||
expect(mockSignInWithRedirect).toHaveBeenCalled(); | ||
}); | ||
|
||
it('calls onContactSupport on contact support link click', () => { | ||
renderer({ | ||
showContactSupport: true, | ||
contactSupportLabel: 'Contact Support', | ||
onContactSupport: mockOnContactSupport, | ||
}); | ||
const contactSupportLink = screen.getByText('Contact Support'); | ||
fireEvent.click(contactSupportLink); | ||
expect(mockOnContactSupport).toHaveBeenCalled(); | ||
}); | ||
}); |
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