Skip to content

Commit

Permalink
navigate back to the previous page using the browser's history.
Browse files Browse the repository at this point in the history
  • Loading branch information
shandilya3 committed Oct 30, 2023
1 parent 1d68658 commit c17c361
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/components/Personalization/dom-actions/redirectWithHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright 2023 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
export default window => url => {
window.location.href = url;
// Return a promise that never resolves because redirects never complete
// within the current page.
return new Promise(() => undefined);
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { createNode } from "../../../../utils/dom";
import { objectOf } from "../../../../utils/validation";
import { PropositionEventType } from "../../../../constants/propositionEventType";
import { EVENT_TYPE_TRUE, INTERACT } from "../../../../constants/eventType";
import createRedirect from "../../dom-actions/createRedirect";
import redirectWithHistory from "../../dom-actions/redirectWithHistory";

const MESSAGING_CONTAINER_ID = "alloy-messaging-container";
const OVERLAY_CONTAINER_ID = "alloy-overlay-container";
Expand All @@ -28,7 +28,7 @@ const dismissMessage = () =>
[MESSAGING_CONTAINER_ID, OVERLAY_CONTAINER_ID].forEach(removeElementById);
export const createIframeClickHandler = (
interact,
navigateToUrl = createRedirect(window)
navigateToUrl = redirectWithHistory(window)
) => {
return event => {
event.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2023 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
import redirectWithHistory from "../../../../../../src/components/Personalization/dom-actions/redirectWithHistory";

describe("redirectWithHistory", () => {
it("should set window.location.href to the provided url", () => {
const window = {
location: {
href: ""
}
};
const redirectUrl = "https://www.adobe.com";

const redirect = redirectWithHistory(window);
redirect(redirectUrl);
expect(window.location.href).toBe(redirectUrl);
});
});

0 comments on commit c17c361

Please sign in to comment.