This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
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
5c15552
commit 69d3707
Showing
5 changed files
with
274 additions
and
3 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...res/dashboard/components/AppDashboardContainer/__tests__/app-dashboard-container.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,27 @@ | ||
import React from 'react'; | ||
import { cleanup, render, screen } from '@site/src/test-utils'; | ||
import AppDashboardContainer from '..'; | ||
|
||
describe('AppDashboardContainer', () => { | ||
afterEach(() => { | ||
cleanup(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('Should render the page heading', () => { | ||
render(<AppDashboardContainer />); | ||
|
||
const label = screen.getByText(/App dashboard/i); | ||
expect(label).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should render children component in the screen', () => { | ||
render( | ||
<AppDashboardContainer> | ||
<div>Test Component</div> | ||
</AppDashboardContainer>, | ||
); | ||
const label = screen.getByText(/Test Component/i); | ||
expect(label).toBeInTheDocument(); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
src/features/dashboard/components/AppRegister/__tests__/app-register.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,19 @@ | ||
import React from 'react'; | ||
import { cleanup, render, screen } from '@site/src/test-utils'; | ||
import AppRegister from '..'; | ||
|
||
const mock_submit = jest.fn(); | ||
|
||
describe('AppRegister', () => { | ||
afterEach(() => { | ||
cleanup(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('Should render the register form with register button', () => { | ||
render(<AppRegister submit={mock_submit} />); | ||
|
||
const button = screen.getByText(/Register now/i); | ||
expect(button).toBeInTheDocument(); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
...d/components/Modals/AppRegisterSuccessModal/__tests__/app-register-success-modal.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,68 @@ | ||
import React from 'react'; | ||
import { cleanup, render, screen } from '@site/src/test-utils'; | ||
import { AppRegisterSuccessModal } from '..'; | ||
import useAppManager from '@site/src/hooks/useAppManager'; | ||
|
||
const mock_cancel = jest.fn(); | ||
const mock_configure = jest.fn(); | ||
|
||
jest.mock('@site/src/hooks/useAppManager'); | ||
const mockUseAppManager = useAppManager as jest.MockedFunction< | ||
() => Partial<ReturnType<typeof useAppManager>> | ||
>; | ||
mockUseAppManager.mockImplementation(() => ({ | ||
app_register_modal_open: true, | ||
})); | ||
|
||
describe('AppRegisterSuccessModal', () => { | ||
afterEach(() => { | ||
cleanup(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('Should render the success modal in desktop', () => { | ||
render( | ||
<AppRegisterSuccessModal | ||
is_desktop={true} | ||
onCancel={mock_cancel} | ||
onConfigure={mock_configure} | ||
/>, | ||
); | ||
|
||
const label = screen.getByText(/Application registered successfully!/i); | ||
expect(label).toBeInTheDocument(); | ||
const imgElement = screen.getByAltText('check icon'); | ||
expect(imgElement).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should render the success modal in mobile', () => { | ||
render( | ||
<AppRegisterSuccessModal | ||
is_desktop={false} | ||
onCancel={mock_cancel} | ||
onConfigure={mock_configure} | ||
/>, | ||
); | ||
|
||
const label = screen.getByText(/Application registered successfully!/i); | ||
expect(label).toBeInTheDocument(); | ||
const imgElement = screen.queryByAltText('check icon'); | ||
expect(imgElement).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('Should handle click events properly', () => { | ||
render( | ||
<AppRegisterSuccessModal | ||
is_desktop={false} | ||
onCancel={mock_cancel} | ||
onConfigure={mock_configure} | ||
/>, | ||
); | ||
const configure_btn = screen.getByText(/Configure now/i); | ||
const maybe_later_btn = screen.getByText(/Maybe later/i); | ||
configure_btn.click(); | ||
expect(mock_configure).toBeCalled(); | ||
maybe_later_btn.click(); | ||
expect(mock_cancel).toBeCalled(); | ||
}); | ||
}); |
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
157 changes: 157 additions & 0 deletions
157
src/features/dashboard/manage-dashboard/__tests__/manage-dashboard.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,157 @@ | ||
import React from 'react'; | ||
import { cleanup, render, screen } from '@site/src/test-utils'; | ||
import MemoizedManageDashboard from '..'; | ||
import useAppManager from '@site/src/hooks/useAppManager'; | ||
import useDeviceType from '@site/src/hooks/useDeviceType'; | ||
import userEvent from '@testing-library/user-event'; | ||
import apiManager from '@site/src/configs/websocket'; | ||
|
||
jest.mock('@site/src/hooks/useAppManager'); | ||
const mockUseAppManager = useAppManager as jest.MockedFunction< | ||
() => Partial<ReturnType<typeof useAppManager>> | ||
>; | ||
mockUseAppManager.mockImplementation(() => ({ | ||
getApps: jest.fn(), | ||
apps: undefined, | ||
tokens: undefined, | ||
})); | ||
|
||
jest.mock('@site/src/hooks/useDeviceType'); | ||
const mockDeviceType = useDeviceType as jest.MockedFunction< | ||
() => Partial<ReturnType<typeof useDeviceType>> | ||
>; | ||
mockDeviceType.mockImplementation(() => ({ | ||
deviceType: 'desktop', | ||
})); | ||
|
||
jest.mock('@site/src/configs/websocket'); | ||
const mockApiManager = apiManager as jest.Mocked<typeof apiManager>; | ||
|
||
describe('ManageDashboard', () => { | ||
afterEach(() => { | ||
cleanup(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('Should render the initial compoent with loader', () => { | ||
const { container } = render(<MemoizedManageDashboard />); | ||
expect(container).toBeInTheDocument(); | ||
const loader = screen.getByTestId('dt_spinner'); | ||
expect(loader).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should render the content App Register page in mobile device - if no token or app is available', () => { | ||
mockUseAppManager.mockImplementation(() => ({ | ||
apps: [], | ||
tokens: [], | ||
getApps: jest.fn(), | ||
})); | ||
mockDeviceType.mockImplementation(() => ({ | ||
deviceType: 'mobile', | ||
})); | ||
render(<MemoizedManageDashboard />); | ||
const register_button = screen.getByText(/Register now/i); | ||
expect(register_button).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should call getApps on submit button press if all the fields are filled up', async () => { | ||
const mockGetApps = jest.fn(); | ||
mockUseAppManager.mockImplementation(() => ({ | ||
apps: [], | ||
tokens: [], | ||
getApps: mockGetApps, | ||
})); | ||
render(<MemoizedManageDashboard />); | ||
|
||
const name_input = screen.getByRole('textbox'); | ||
await userEvent.type(name_input, 'test create token'); | ||
const tnc_input = screen.getByRole('checkbox'); | ||
await userEvent.click(tnc_input); | ||
const register_button = screen.getByText(/Register now/i); | ||
await userEvent.click(register_button); | ||
|
||
expect(mockGetApps).toHaveBeenCalled(); | ||
}); | ||
|
||
it('Should trigger the success modal in desktop', async () => { | ||
const mockModalOpenSetter = jest.fn(); | ||
mockApiManager.augmentedSend.mockResolvedValue({ | ||
app_register: { | ||
active: 1, | ||
app_id: 1234, | ||
app_markup_percentage: 0, | ||
appstore: '', | ||
github: '', | ||
googleplay: '', | ||
homepage: '', | ||
name: 'TestApp1', | ||
redirect_uri: '', | ||
scopes: [], | ||
verification_uri: '', | ||
}, | ||
echo_req: { | ||
app_markup_percentage: 0, | ||
app_register: 1, | ||
name: 'TestApp1', | ||
req_id: 4, | ||
scopes: [], | ||
}, | ||
msg_type: 'app_register', | ||
req_id: 4, | ||
}); | ||
|
||
mockUseAppManager.mockImplementation(() => ({ | ||
getApps: jest.fn(), | ||
apps: [], | ||
tokens: [], | ||
setAppRegisterModalOpen: mockModalOpenSetter, | ||
})); | ||
|
||
render(<MemoizedManageDashboard />); | ||
|
||
const name_input = screen.getByRole('textbox'); | ||
await userEvent.type(name_input, 'test create token'); | ||
const tnc_input = screen.getByRole('checkbox'); | ||
await userEvent.click(tnc_input); | ||
const register_button = screen.getByText(/Register now/i); | ||
await userEvent.click(register_button); | ||
|
||
expect(mockModalOpenSetter).toBeCalledWith(true); | ||
}); | ||
|
||
it('Should close the modal on config button click', async () => { | ||
const mockModalOpenSetter = jest.fn(); | ||
mockUseAppManager.mockImplementation(() => ({ | ||
getApps: jest.fn(), | ||
apps: [], | ||
tokens: [], | ||
setAppRegisterModalOpen: mockModalOpenSetter, | ||
app_register_modal_open: true, | ||
})); | ||
|
||
render(<MemoizedManageDashboard />); | ||
|
||
const config_button = screen.getByText(/Config/i); | ||
await userEvent.click(config_button); | ||
|
||
expect(mockModalOpenSetter).toBeCalledWith(false); | ||
}); | ||
|
||
it('Should close the modal on cancel button click', async () => { | ||
const mockModalOpenSetter = jest.fn(); | ||
mockUseAppManager.mockImplementation(() => ({ | ||
getApps: jest.fn(), | ||
apps: [], | ||
tokens: [], | ||
setAppRegisterModalOpen: mockModalOpenSetter, | ||
app_register_modal_open: true, | ||
})); | ||
|
||
render(<MemoizedManageDashboard />); | ||
|
||
const cancel_button = screen.getByText(/Maybe Later/i); | ||
await userEvent.click(cancel_button); | ||
|
||
expect(mockModalOpenSetter).toBeCalledWith(false); | ||
}); | ||
}); |