Skip to content

Commit

Permalink
Merge branch 'master' into STCOR-863
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnC-80 authored Jul 2, 2024
2 parents 21b8de1 + 2bb7586 commit 5bc6309
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Avoid deprecated `getChildContext`. Refs STCOR-842.
* Read locale from stripes-config before defaulting to `en-US`. Refs STCOR-851.
* Correctly populate `stripes.user.user` on reload. Refs STCOR-860.
* Correctly evaluate `stripes.okapi` before rendering `<RootWithIntl>`. Refs STCOR-864.
* Change main navigation's skip link label to "Skip to main content". Refs STCOR-863.

## [10.1.0](https://github.com/folio-org/stripes-core/tree/v10.1.0) (2024-03-12)
Expand Down
2 changes: 1 addition & 1 deletion src/RootWithIntl.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const RootWithIntl = ({ stripes, token = '', isAuthenticated = false, disableAut
event={events.LOGIN}
stripes={connectedStripes}
/>
{ (connectedStripes.okapi !== 'object' || connectedStripes.discovery.isFinished) && (
{ (typeof connectedStripes.okapi !== 'object' || connectedStripes.discovery.isFinished) && (
<ModuleContainer id="content">
<OverlayContainer />
{connectedStripes.config.useSecureTokens && <SessionEventContainer history={history} />}
Expand Down
123 changes: 123 additions & 0 deletions src/RootWithIntl.test.js
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();
});

Check failure on line 121 in src/RootWithIntl.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Block must not be padded by blank lines

Check failure on line 121 in src/RootWithIntl.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Block must not be padded by blank lines

});
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export { default as BadRequestScreen } from './BadRequestScreen';
export { default as NoPermissionScreen } from './NoPermissionScreen';
export { default as ResetPasswordNotAvailableScreen } from './ResetPasswordNotAvailableScreen';
export { default as SessionEventContainer } from './SessionEventContainer';
export { default as StaleBundleWarning } from './StaleBundleWarning';

export * from './ModuleHierarchy';
export * from './Namespace';
3 changes: 3 additions & 0 deletions test/bigtest/helpers/setup-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export default function setupApplication({
currentPerms: permissions,
isAuthenticated: true,
};
initialState.discovery = {
isFinished: true,
};
} else {
initialState.okapi = {
ssoEnabled: true,
Expand Down
1 change: 1 addition & 0 deletions test/jest/__mock__/stripesComponents.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jest.mock('@folio/stripes-components', () => ({
<span>{children}</span>
)),
Headline: jest.fn(({ children }) => <div>{ children }</div>),
HotKeys: jest.fn(({ children }) => <>{ children }</>),
Icon: jest.fn((props) => (props && props.children ? props.children : <span />)),
IconButton: jest.fn(({
buttonProps,
Expand Down
16 changes: 8 additions & 8 deletions translations/stripes-core/en_SE.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"front.welcome": "Welcome, the Future Of Libraries Is OPEN!",
"front.home": "Home",
"front.welcome": "Välkommen till FOLIO!",
"front.home": "Start",
"front.about": "Software versions",
"button.new": "+ New",
"button.new_tooltip": "Add {entry}",
"button.edit": "Edit",
"button.delete": "Delete",
"button.deleteEntry": "Delete {entry}",
"button.saveAndClose": "Save and close",
"button.new": "+ Ny",
"button.new_tooltip": "Lägg till {entry}",
"button.edit": "Redigera",
"button.delete": "Radera",
"button.deleteEntry": "Radera {entry}",
"button.saveAndClose": "Spara och stäng",
"button.cancel": "Cancel",
"label.confirmDeleteEntry": "<strong>{name}</strong> will be <strong>removed</strong>",
"label.editEntry": "Edit {entry}",
Expand Down
12 changes: 6 additions & 6 deletions translations/stripes-core/es_419.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@
"placeholder.forgotUsername": "Introduce email o teléfono",
"title.cookieEnabled": "Cookies are required to login. Please enable cookies and try again.",
"errors.sso.session.failed": "Error al iniciar sesión en SSO. Inténtalo de nuevo",
"logoutPending": "Log out in process...",
"rtr.idleSession.modalHeader": "Your session will expire soon!",
"rtr.idleSession.timeRemaining": "Time remaining",
"rtr.idleSession.keepWorking": "Keep working",
"rtr.idleSession.sessionExpiredSoSad": "Your session expired due to inactivity.",
"rtr.idleSession.logInAgain": "Log in again"
"logoutPending": "Cierre de sesión en proceso...",
"rtr.idleSession.modalHeader": "Su sesión expirará pronto.",
"rtr.idleSession.timeRemaining": "Tiempo restante",
"rtr.idleSession.keepWorking": "Seguir trabajando",
"rtr.idleSession.sessionExpiredSoSad": "Tu sesión expiró por inactividad.",
"rtr.idleSession.logInAgain": "Ingresar de nuevo"
}
42 changes: 21 additions & 21 deletions translations/stripes-core/sv.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"front.welcome": "Welcome, the Future Of Libraries Is OPEN!",
"front.home": "Home",
"front.welcome": "Välkommen till FOLIO!",
"front.home": "Start",
"front.about": "Software versions",
"button.new": "+ New",
"button.new_tooltip": "Add {entry}",
"button.edit": "Edit",
"button.delete": "Delete",
"button.deleteEntry": "Delete {entry}",
"button.saveAndClose": "Save and close",
"button.cancel": "Cancel",
"button.new": "+Ny",
"button.new_tooltip": "Lägg till {entry}",
"button.edit": "Redigera",
"button.delete": "Radera",
"button.deleteEntry": "Radera {entry}",
"button.saveAndClose": "Spara och stäng",
"button.cancel": "Ångra",
"label.confirmDeleteEntry": "<strong>{name}</strong> will be <strong>removed</strong>",
"label.editEntry": "Edit {entry}",
"label.editEntry": "Redigera {entry}",
"label.createEntry": "Create {entry}",
"label.missingRequiredField": "Please fill this in to continue",
"label.okay": "Okay",
"label.okay": "Okej",
"successfullyDeleted": "The {entry} <strong>{name}</strong> was successfully <strong>deleted</strong>.",
"untitled": "Untitled",
"about.paneTitle": "Software versions",
Expand All @@ -40,17 +40,17 @@
"about.settingsModuleCount": "{count, number} settings {count, plural, one {module} other {modules}}",
"about.pluginModuleCount": "{count, number} plugin {count, plural, one {module} other {modules}}",
"loggedInAs": "Logged in as {firstName} {lastName}",
"logout": "Log out",
"settings": "Settings",
"folioSettings": "FOLIO settings",
"logout": "Logga ut",
"settings": "Inställningar",
"folioSettings": "FOLIO-inställningar",
"loginViaSSO": "Log in via SSO",
"button.close": "Close",
"login": "Log in",
"username": "Username",
"password": "Password",
"loggingIn": "Logging in...",
"button.back": "Back",
"button.confirm": "Confirm",
"button.close": "Stäng",
"login": "Logga in",
"username": "Användarnamn",
"password": "Lösenord",
"loggingIn": "Loggar in...",
"button.back": "Tillbaka",
"button.confirm": "Bekräfta",
"title.home": "Home",
"title.settings": "Settings",
"title.login": "Log in",
Expand Down

0 comments on commit 5bc6309

Please sign in to comment.