Skip to content

Commit

Permalink
Merge branch 'main' into issues/716-Replace_margin_physical_propertie…
Browse files Browse the repository at this point in the history
…s_with_logical
  • Loading branch information
magdalenajadach committed Oct 31, 2023
2 parents 382c8c3 + 42e70c2 commit 78ed6a4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

## [0.19.3] - 2023-10-25

### Added

- `stepChanged` custom event for the web component (#709)
Expand All @@ -24,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed

- Clipped icon in "Save your work" toast (#707)
- Hydra logout flow to delete session (#714)

## [0.19.2] - 2023-10-12

Expand Down Expand Up @@ -548,7 +551,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Events in Web Component indicating whether Mission Zero criteria have been met (#113)

[unreleased]: https://github.com/RaspberryPiFoundation/editor-ui/compare/v0.19.2...HEAD
[unreleased]: https://github.com/RaspberryPiFoundation/editor-ui/compare/v0.19.3...HEAD
[0.19.3]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.19.3
[0.19.2]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.19.2
[0.19.1]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.19.1
[0.19.0]: https://github.com/RaspberryPiFoundation/editor-ui/releases/tag/v0.19.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@raspberrypifoundation/editor-ui",
"version": "0.19.2",
"version": "0.19.3",
"private": true,
"dependencies": {
"@RaspberryPiFoundation/design-system-react": "^0.1.2",
Expand Down
5 changes: 4 additions & 1 deletion src/components/Login/LoginMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const LoginMenu = () => {
>
{t("globalNav.accountMenu.projects")}
</Link>
<LogoutButton className="btn--tertiary dropdown-container--list__item" />
<LogoutButton
user={user}
className="btn--tertiary dropdown-container--list__item"
/>
</>
) : (
<LoginButton
Expand Down
15 changes: 10 additions & 5 deletions src/components/Login/LogoutButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import React from "react";
import userManager from "../../utils/userManager";
import { useTranslation } from "react-i18next";
import Button from "../Button/Button";
import { useNavigate } from "react-router-dom";
import PropTypes from "prop-types";

const LogoutButton = (props) => {
const { className } = props;
const LogoutButton = ({ className, user }) => {
const { t } = useTranslation();
const navigate = useNavigate();

const onLogoutButtonClick = async (event) => {
event.preventDefault();
userManager.signoutRedirect({ id_token_hint: user?.id_token });
await userManager.removeUser();
localStorage.clear();
navigate("/");
};

return (
Expand All @@ -25,4 +23,11 @@ const LogoutButton = (props) => {
);
};

LogoutButton.propTypes = {
className: PropTypes.string,
user: PropTypes.shape({
id_token: PropTypes.string.isRequired,
}).isRequired,
};

export default LogoutButton;
19 changes: 10 additions & 9 deletions src/components/Login/LogoutButton.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@ import userManager from "../../utils/userManager";
import LogoutButton from "./LogoutButton";

jest.mock("../../utils/userManager", () => ({
signoutRedirect: jest.fn(),
removeUser: jest.fn(),
}));

let logoutButton;

const user = {
id_token: "1234",
};

beforeEach(() => {
const middlewares = [];
const mockStore = configureStore(middlewares);
const initialState = {
editor: {
project: {},
},
auth: {
user: {},
},
};
const initialState = {};
const store = mockStore(initialState);
render(
<MemoryRouter initialEntries={["/"]}>
<Provider store={store}>
<LogoutButton />
<LogoutButton user={user} />
</Provider>
</MemoryRouter>,
);
Expand All @@ -40,5 +38,8 @@ test("Log out button shown", () => {

test("Clicking log out button signs the user out", () => {
fireEvent.click(logoutButton);
expect(userManager.signoutRedirect).toBeCalledWith({
id_token_hint: user.id_token,
});
expect(userManager.removeUser).toHaveBeenCalled();
});
1 change: 1 addition & 0 deletions src/utils/userManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const host = `${window.location.protocol}//${window.location.hostname}${
const userManagerConfig = {
client_id: process.env.REACT_APP_AUTHENTICATION_CLIENT_ID,
redirect_uri: `${host}/auth/callback`,
post_logout_redirect_uri: host,
response_type: "code",
scope: "openid email profile force-consent allow-u13-login",
authority: process.env.REACT_APP_AUTHENTICATION_URL,
Expand Down

0 comments on commit 78ed6a4

Please sign in to comment.