-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STCOR-864 correctly evaluate typeof stripes.okapi (#1497)
Stripes should render `<ModuleContainer>` either when discovery is complete or when okapi isn't present at all, i.e. when `stripes.config.js` doesn't even contain an `okapi` entry. What's most amazing about this bug is not the bug, which is a relatively simple typo, but that it didn't bite us for more than six years. BTOG init never conducted discovery, but _did_ pass an okapi object during application setup, which is another way of saying that our application didn't have anything that relied on the presence of this bug, but our test suite did. Refs STCOR-864
- Loading branch information
Showing
6 changed files
with
130 additions
and
1 deletion.
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
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,123 @@ | ||
/* shhhh, eslint, it's ok. we need "unused" imports for mocks */ | ||
/* eslint-disable no-unused-vars */ | ||
|
||
import { render, screen } from '@folio/jest-config-stripes/testing-library/react'; | ||
import { Router as DefaultRouter } from 'react-router-dom'; | ||
import { createMemoryHistory } from 'history'; | ||
|
||
import { | ||
Login, | ||
MainNav, | ||
MainContainer, | ||
ModuleContainer, | ||
OverlayContainer, | ||
StaleBundleWarning, | ||
SessionEventContainer, | ||
} from './components'; | ||
|
||
import RootWithIntl from './RootWithIntl'; | ||
import Stripes from './Stripes'; | ||
|
||
jest.mock('./components/Login', () => () => '<Login>'); | ||
jest.mock('./components/MainNav', () => () => '<MainNav>'); | ||
jest.mock('./components/OverlayContainer', () => () => '<OverlayContainer>'); | ||
jest.mock('./components/ModuleContainer', () => ({ children }) => children); | ||
jest.mock('./components/MainContainer', () => ({ children }) => children); | ||
jest.mock('./components/StaleBundleWarning', () => () => '<StaleBundleWarning>'); | ||
jest.mock('./components/SessionEventContainer', () => () => '<SessionEventContainer>'); | ||
|
||
const defaultHistory = createMemoryHistory(); | ||
|
||
const Harness = ({ | ||
Router = DefaultRouter, | ||
children, | ||
history = defaultHistory, | ||
}) => { | ||
return ( | ||
<Router history={history}> | ||
{children} | ||
</Router> | ||
); | ||
}; | ||
|
||
const store = { | ||
getState: () => ({ | ||
okapi: { | ||
token: '123', | ||
}, | ||
}), | ||
dispatch: () => {}, | ||
subscribe: () => {}, | ||
replaceReducer: () => {}, | ||
}; | ||
|
||
describe('RootWithIntl', () => { | ||
it('renders login without one of (isAuthenticated, token, disableAuth)', async () => { | ||
const stripes = new Stripes({ epics: {}, logger: {}, bindings: {}, config: {}, store, discovery: { isFinished: false } }); | ||
await render(<Harness><RootWithIntl stripes={stripes} history={defaultHistory} isAuthenticated={false} /></Harness>); | ||
|
||
expect(screen.getByText(/<Login>/)).toBeInTheDocument(); | ||
expect(screen.queryByText(/<MainNav>/)).toBeNull(); | ||
}); | ||
|
||
describe('renders MainNav', () => { | ||
it('given isAuthenticated', async () => { | ||
const stripes = new Stripes({ epics: {}, logger: {}, bindings: {}, config: {}, store, discovery: { isFinished: false } }); | ||
await render(<Harness><RootWithIntl stripes={stripes} history={defaultHistory} isAuthenticated /></Harness>); | ||
|
||
expect(screen.queryByText(/<Login>/)).toBeNull(); | ||
expect(screen.queryByText(/<MainNav>/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('given token', async () => { | ||
const stripes = new Stripes({ epics: {}, logger: {}, bindings: {}, config: {}, store, discovery: { isFinished: false } }); | ||
await render(<Harness><RootWithIntl stripes={stripes} history={defaultHistory} token /></Harness>); | ||
|
||
expect(screen.queryByText(/<Login>/)).toBeNull(); | ||
expect(screen.queryByText(/<MainNav>/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('given disableAuth', async () => { | ||
const stripes = new Stripes({ epics: {}, logger: {}, bindings: {}, config: {}, store, discovery: { isFinished: false } }); | ||
await render(<Harness><RootWithIntl stripes={stripes} history={defaultHistory} disableAuth /></Harness>); | ||
|
||
expect(screen.queryByText(/<Login>/)).toBeNull(); | ||
expect(screen.queryByText(/<MainNav>/)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('renders ModuleContainer', () => { | ||
it('if config.okapi is not an object', async () => { | ||
const stripes = new Stripes({ epics: {}, logger: {}, bindings: {}, config: {}, store, discovery: { isFinished: true } }); | ||
await render(<Harness><RootWithIntl stripes={stripes} history={defaultHistory} isAuthenticated /></Harness>); | ||
|
||
expect(screen.queryByText(/<Login>/)).toBeNull(); | ||
expect(screen.queryByText(/<MainNav>/)).toBeInTheDocument(); | ||
expect(screen.getByText(/<OverlayContainer>/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('if discovery is finished', async () => { | ||
const stripes = new Stripes({ epics: {}, logger: {}, bindings: {}, config: {}, store, okapi: {}, discovery: { isFinished: true } }); | ||
await render(<Harness><RootWithIntl stripes={stripes} history={defaultHistory} isAuthenticated /></Harness>); | ||
|
||
expect(screen.queryByText(/<Login>/)).toBeNull(); | ||
expect(screen.queryByText(/<MainNav>/)).toBeInTheDocument(); | ||
expect(screen.getByText(/<OverlayContainer>/)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('renders StaleBundleWarning', async () => { | ||
const stripes = new Stripes({ epics: {}, logger: {}, bindings: {}, config: { staleBundleWarning: {} }, store, okapi: {}, discovery: { isFinished: true } }); | ||
await render(<Harness><RootWithIntl stripes={stripes} history={defaultHistory} isAuthenticated /></Harness>); | ||
|
||
expect(screen.getByText(/<StaleBundleWarning>/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders SessionEventContainer', async () => { | ||
const stripes = new Stripes({ epics: {}, logger: {}, bindings: {}, config: { useSecureTokens: true }, store, okapi: {}, discovery: { isFinished: true } }); | ||
await render(<Harness><RootWithIntl stripes={stripes} history={defaultHistory} isAuthenticated /></Harness>); | ||
|
||
expect(screen.getByText(/<SessionEventContainer>/)).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
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