-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(opentrons-ai-client): add auth0 package (#15148)
* feat(opentrons-ai-client): add auth0 package
- Loading branch information
Showing
12 changed files
with
173 additions
and
29 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
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 |
---|---|---|
@@ -1,29 +1,66 @@ | ||
import React from 'react' | ||
import { screen } from '@testing-library/react' | ||
import { describe, it, vi, beforeEach } from 'vitest' | ||
import { fireEvent, screen } from '@testing-library/react' | ||
import { describe, it, vi, beforeEach, expect } from 'vitest' | ||
import * as auth0 from '@auth0/auth0-react' | ||
|
||
import { renderWithProviders } from './__testing-utils__' | ||
import { i18n } from './i18n' | ||
import { SidePanel } from './molecules/SidePanel' | ||
import { ChatContainer } from './organisms/ChatContainer' | ||
import { Loading } from './molecules/Loading' | ||
|
||
import { App } from './App' | ||
|
||
vi.mock('@auth0/auth0-react') | ||
|
||
const mockLogout = vi.fn() | ||
|
||
vi.mock('./molecules/SidePanel') | ||
vi.mock('./organisms/ChatContainer') | ||
vi.mock('./molecules/Loading') | ||
|
||
const render = (): ReturnType<typeof renderWithProviders> => { | ||
return renderWithProviders(<App />) | ||
return renderWithProviders(<App />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
|
||
describe('App', () => { | ||
beforeEach(() => { | ||
vi.mocked(SidePanel).mockReturnValue(<div>mock SidePanel</div>) | ||
vi.mocked(ChatContainer).mockReturnValue(<div>mock ChatContainer</div>) | ||
vi.mocked(Loading).mockReturnValue(<div>mock Loading</div>) | ||
}) | ||
|
||
it('should render loading screen when isLoading is true', () => { | ||
;(auth0 as any).useAuth0 = vi.fn().mockReturnValue({ | ||
isAuthenticated: false, | ||
isLoading: true, | ||
}) | ||
render() | ||
screen.getByText('mock Loading') | ||
}) | ||
|
||
it('should render text', () => { | ||
;(auth0 as any).useAuth0 = vi.fn().mockReturnValue({ | ||
isAuthenticated: true, | ||
isLoading: false, | ||
}) | ||
render() | ||
screen.getByText('mock SidePanel') | ||
screen.getByText('mock ChatContainer') | ||
screen.getByText('Logout') | ||
}) | ||
|
||
it('should call a mock function when clicking logout button', () => { | ||
;(auth0 as any).useAuth0 = vi.fn().mockReturnValue({ | ||
isAuthenticated: true, | ||
isLoading: false, | ||
logout: mockLogout, | ||
}) | ||
render() | ||
const logoutButton = screen.getByText('Logout') | ||
fireEvent.click(logoutButton) | ||
expect(mockLogout).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
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
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
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
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
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
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,27 @@ | ||
import React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { | ||
ALIGN_CENTER, | ||
DIRECTION_COLUMN, | ||
Flex, | ||
Icon, | ||
JUSTIFY_CENTER, | ||
SPACING, | ||
StyledText, | ||
} from '@opentrons/components' | ||
|
||
export function Loading(): JSX.Element { | ||
const { t } = useTranslation('protocol_generator') | ||
return ( | ||
<Flex | ||
flexDirection={DIRECTION_COLUMN} | ||
justifyContent={JUSTIFY_CENTER} | ||
alignItems={ALIGN_CENTER} | ||
gridGap={SPACING.spacing16} | ||
height="100vh" | ||
> | ||
<StyledText as="h3">{t('loading')}</StyledText> | ||
<Icon name="ot-spinner" size="3rem" spin /> | ||
</Flex> | ||
) | ||
} |
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
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
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 |
---|---|---|
|
@@ -30,6 +30,18 @@ | |
"@jridgewell/gen-mapping" "^0.3.5" | ||
"@jridgewell/trace-mapping" "^0.3.24" | ||
|
||
"@auth0/[email protected]": | ||
version "2.2.4" | ||
resolved "https://registry.yarnpkg.com/@auth0/auth0-react/-/auth0-react-2.2.4.tgz#7f21751a219d4e0e019141819f00e76e436176dd" | ||
integrity sha512-l29PQC0WdgkCoOc6WeMAY26gsy/yXJICW0jHfj0nz8rZZphYKrLNqTRWFFCMJY+sagza9tSgB1kG/UvQYgGh9A== | ||
dependencies: | ||
"@auth0/auth0-spa-js" "^2.1.3" | ||
|
||
"@auth0/auth0-spa-js@^2.1.3": | ||
version "2.1.3" | ||
resolved "https://registry.yarnpkg.com/@auth0/auth0-spa-js/-/auth0-spa-js-2.1.3.tgz#aabf6f439e41edbeef0cf4766ad754e5b47616e5" | ||
integrity sha512-NMTBNuuG4g3rame1aCnNS5qFYIzsTUV5qTFPRfTyYFS1feS6jsCBR+eTq9YkxCp1yuoM2UIcjunPaoPl77U9xQ== | ||
|
||
"@aw-web-design/[email protected]": | ||
version "1.4.126" | ||
resolved "https://registry.yarnpkg.com/@aw-web-design/x-default-browser/-/x-default-browser-1.4.126.tgz#43e4bd8f0314ed907a8718d7e862a203af79bc16" | ||
|