-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in feature/SHIBUI-1926 (pull request #490)
Feature/SHIBUI-1926
- Loading branch information
Showing
69 changed files
with
3,600 additions
and
2,120 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,41 @@ | ||
import React from 'react'; | ||
import { act, render, fireEvent, waitFor, screen } from '@testing-library/react'; | ||
import { BrowserRouter, MemoryRouter, Route } from 'react-router-dom'; | ||
import { AdminRoute } from './AdminRoute'; | ||
|
||
const mockIsAdmin = jest.fn(); | ||
|
||
jest.mock('../user/UserContext', () => ({ | ||
useIsAdmin: () => mockIsAdmin() | ||
})); | ||
|
||
const renderWithRouter = (ui, { route = '/' } = {}) => { | ||
window.history.pushState({}, 'Test page', route) | ||
|
||
return render(ui, { wrapper: BrowserRouter }) | ||
} | ||
|
||
describe('AdminRoute user is admin', () => { | ||
beforeEach(() => { | ||
mockIsAdmin.mockReturnValue(true); | ||
}); | ||
|
||
it('should render the component if user is an admin', () => { | ||
render(<AdminRoute><React.Fragment>hi there</React.Fragment></AdminRoute>, { wrapper: MemoryRouter }); | ||
expect(screen.getByText('hi there')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('AdminRoute user is NOT admin', () => { | ||
beforeEach(() => { | ||
mockIsAdmin.mockReturnValue(false); | ||
}); | ||
|
||
it('should redirect the user to the dashboard if not admin', () => { | ||
renderWithRouter(<React.Fragment> | ||
<AdminRoute path="/foo"><React.Fragment>hi there</React.Fragment></AdminRoute> | ||
<Route path="/dashboard" render={ () => 'dashboard' } /> | ||
</React.Fragment>, {route: '/foo'}); | ||
expect(screen.getByText('dashboard')).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
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,12 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { Footer } from './Footer'; | ||
|
||
jest.mock('../../i18n/hooks', () => ({ | ||
useTranslation: (value) => value | ||
})); | ||
|
||
it('should display the footer', () => { | ||
render(<Footer />); | ||
expect(screen.getByText('brand.footer.text')).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import { Header } from './Header'; | ||
|
||
jest.mock('../../i18n/hooks', () => ({ | ||
useTranslator: () => (value) => value, | ||
useTranslation: (value) => value | ||
})); | ||
|
||
const mockIsAdmin = jest.fn(); | ||
|
||
jest.mock('../user/UserContext', () => ({ | ||
useIsAdmin: () => mockIsAdmin() | ||
})); | ||
|
||
describe('header for admins', () => { | ||
beforeEach(() => { | ||
mockIsAdmin.mockReturnValue(true); | ||
}); | ||
|
||
it('should display logo and navigation', () => { | ||
render(<Router><Header /></Router>); | ||
expect(screen.getByText('brand.logo-link-label')).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
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,95 @@ | ||
import React from 'react'; | ||
import { act, render, fireEvent, waitFor, screen } from '@testing-library/react'; | ||
import { UserConfirmation, ConfirmWindow } from './UserConfirmation'; | ||
|
||
jest.mock('../../i18n/hooks', () => ({ | ||
useTranslator: () => (value) => value, | ||
useTranslation: (value) => value | ||
})); | ||
|
||
const mockReload = jest.fn(); | ||
|
||
jest.mock('../utility/window', () => ({ | ||
reload: () => mockReload() | ||
})) | ||
|
||
const mockIncludes = jest.fn(); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
useHistory: () => ({ | ||
location: { | ||
pathname: { | ||
includes: mockIncludes | ||
} | ||
} | ||
}) | ||
})); | ||
|
||
const TestWindow = ({getConfirmation, message}) => { | ||
React.useEffect(() => getConfirmation('foo', jest.fn()), []) | ||
return <span>{message}</span>; | ||
} | ||
|
||
describe('user confirmation context', () => { | ||
it('should render its children with a function', () => { | ||
render(<UserConfirmation> | ||
{(message, confirm, confirmCallback, setConfirm, getConfirmation) => <p><span>hi there</span> <TestWindow message={message} getConfirmation={getConfirmation} /></p>} | ||
</UserConfirmation>); | ||
expect(screen.getByText('hi there')).toBeInTheDocument(); | ||
expect(screen.getByText('foo')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('confirmation window', () => { | ||
|
||
it('should provide buttons to confirm', async () => { | ||
|
||
const message = 'hi there'; | ||
const confirm = true; | ||
const confirmCallback = jest.fn(); | ||
const setConfirm = jest.fn(); | ||
|
||
render(<ConfirmWindow message={message} confirm={confirm} confirmCallback={confirmCallback} setConfirm={setConfirm} /> ); | ||
expect(screen.getByText('hi there')).toBeInTheDocument(); | ||
|
||
fireEvent.click(screen.getByText('action.discard-changes')); | ||
|
||
expect(confirmCallback).toHaveBeenCalledWith(true); | ||
|
||
}); | ||
|
||
it('should provide buttons to stop', async () => { | ||
|
||
const message = 'hi there'; | ||
const confirm = true; | ||
const confirmCallback = jest.fn(); | ||
const setConfirm = jest.fn(); | ||
|
||
render(<ConfirmWindow message={message} confirm={confirm} confirmCallback={confirmCallback} setConfirm={setConfirm} />); | ||
expect(screen.getByText('hi there')).toBeInTheDocument(); | ||
|
||
fireEvent.click(screen.getByText('action.cancel')); | ||
|
||
expect(confirmCallback).toHaveBeenCalledWith(false); | ||
|
||
}); | ||
|
||
it('should redirect if on a provider', () => { | ||
mockIncludes.mockReturnValue(true); | ||
|
||
const message = 'hi there'; | ||
const confirm = true; | ||
const confirmCallback = jest.fn(); | ||
const setConfirm = jest.fn(); | ||
|
||
render(<ConfirmWindow message={message} confirm={confirm} confirmCallback={confirmCallback} setConfirm={setConfirm} />); | ||
expect(screen.getByText('hi there')).toBeInTheDocument(); | ||
|
||
fireEvent.click(screen.getByText('action.discard-changes')); | ||
|
||
expect(confirmCallback).toHaveBeenCalledWith(true); | ||
|
||
expect(mockReload).toHaveBeenCalled(); | ||
}) | ||
}); | ||
|
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { SessionModal } from './SessionModal'; | ||
|
||
jest.mock('../../i18n/hooks', () => ({ | ||
useTranslator: () => (value) => value, | ||
useTranslation: (value) => value | ||
})); | ||
|
||
describe('session modal', () => { | ||
|
||
it('should provide buttons to confirm', async () => { | ||
|
||
render(<SessionModal show={true} />); | ||
expect(screen.getByText('message.session-timeout-heading')).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { UserProvider, useIsAdmin } from './UserContext'; | ||
|
||
const getFn = jest.fn(); | ||
const okFn = jest.fn(); | ||
|
||
const mockUseFetch = { | ||
get: getFn, | ||
response: {} | ||
}; | ||
|
||
Object.defineProperty(mockUseFetch.response, 'ok', { | ||
get: okFn | ||
}); | ||
|
||
jest.mock('use-http', () => () => mockUseFetch); | ||
|
||
const TestAdmin = () => { | ||
const isAdmin = useIsAdmin(); | ||
return (<>{ isAdmin ? 'yes' : 'no' }</>) | ||
} | ||
|
||
describe('User Context defined', () => { | ||
|
||
beforeEach(() => { | ||
getFn.mockReturnValue(Promise.resolve({ | ||
role: 'ROLE_ADMIN' | ||
})); | ||
okFn.mockReturnValueOnce(true); | ||
}); | ||
|
||
it('should render the component children', async () => { | ||
render(<UserProvider> | ||
{<div>test</div>} | ||
</UserProvider>); | ||
await waitFor(() => expect(screen.getByText('test')).toBeInTheDocument()); | ||
}); | ||
|
||
it('should provide the user context', async () => { | ||
render(<UserProvider> | ||
<TestAdmin /> | ||
</UserProvider>); | ||
|
||
await waitFor(() => expect(screen.getByText('yes')).toBeInTheDocument()); | ||
}); | ||
}); |
Oops, something went wrong.