Skip to content

Commit

Permalink
[feature] Added option to display authMessage in info toast
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed Jan 5, 2024
1 parent 210f5bc commit 6ee8b5e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
21 changes: 15 additions & 6 deletions client/components/status/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,24 @@ export default class Status extends React.Component {
event.origin === window.location.origin
) {
switch (type) {
case "authMessage":
case "authError":
if (!message) break;
toast.dismiss();
/* disable ttag */
toast.error(gettext(message), {
autoClose: 10000,
});
/* enable ttag */
logout(cookies, orgSlug);
if (type === "authMessage") {
/* disable ttag */
toast.info(gettext(message), {
autoClose: 10000,
});
/* enable ttag */
} else {
/* disable ttag */
toast.error(gettext(message), {
autoClose: 10000,
});
/* enable ttag */
logout(cookies, orgSlug);
}
setLoading(false);
break;

Expand Down
23 changes: 20 additions & 3 deletions client/components/status/status.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe("<Status /> rendering", () => {
});
});

describe("<Status /> interactions", () => {
describe.only("<Status /> interactions", () => {
// eslint-disable-next-line
let props;
let wrapper;
Expand Down Expand Up @@ -503,7 +503,7 @@ describe("<Status /> interactions", () => {
expect(handlePostMessageMock).toHaveBeenCalledTimes(1);
});

it("test handlePostMessage authError", async () => {
it.only("test handlePostMessage", async () => {
props = createTestProps();
const setLoadingMock = jest.fn();
wrapper = shallow(<Status {...props} />, {
Expand All @@ -512,6 +512,7 @@ describe("<Status /> interactions", () => {
});
jest.spyOn(toast, "error");
jest.spyOn(toast, "dismiss");
jest.spyOn(toast, "info");
const status = wrapper.instance();

// Test missing message
Expand Down Expand Up @@ -544,7 +545,7 @@ describe("<Status /> interactions", () => {
expect(props.logout).toHaveBeenCalledTimes(0);
expect(setLoadingMock).toHaveBeenCalledTimes(0);

// Test valid message
// Test valid authError message
wrapper.instance().componentDidMount();
status.handlePostMessage({
data: {message: "RADIUS Error", type: "authError"},
Expand All @@ -555,6 +556,22 @@ describe("<Status /> interactions", () => {
expect(props.logout).toHaveBeenCalledTimes(1);
expect(setLoadingMock).toHaveBeenCalledTimes(2);
expect(setLoadingMock).toHaveBeenLastCalledWith(false);

toast.dismiss.mockReset();
props.logout.mockReset();
setLoadingMock.mockReset();
expect(props.logout).toHaveBeenCalledTimes(0);

// Test valid authMessage message
status.handlePostMessage({
data: {message: "RADIUS Info", type: "authMessage"},
origin: "http://localhost",
});
expect(toast.dismiss).toHaveBeenCalledTimes(1);
expect(toast.info).toHaveBeenCalledTimes(1);
expect(props.logout).toHaveBeenCalledTimes(0);
expect(setLoadingMock).toHaveBeenCalledTimes(1);
expect(setLoadingMock).toHaveBeenLastCalledWith(false);
});

it("test handlePostMessage internet-mode", async () => {
Expand Down

0 comments on commit 6ee8b5e

Please sign in to comment.