Skip to content

Commit

Permalink
Extract redirect into its own util
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsnyder committed Oct 18, 2023
1 parent 2e81956 commit 6bcaeb1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/components/Personalization/dom-actions/createRedirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
Copyright 2019 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.replace(url);
3 changes: 2 additions & 1 deletion src/components/Personalization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import createProcessDomAction from "./handlers/createProcessDomAction";
import createProcessHtmlContent from "./handlers/createProcessHtmlContent";
import createProcessRedirect from "./handlers/createProcessRedirect";
import createProcessPropositions from "./handlers/createProcessPropositions";
import createRedirect from "./dom-actions/createRedirect";

const createPersonalization = ({ config, logger, eventManager }) => {
const { targetMigrationEnabled, prehidingStyle } = config;
Expand All @@ -58,7 +59,7 @@ const createPersonalization = ({ config, logger, eventManager }) => {
});
const viewCache = createViewCacheManager({ createProposition });

const executeRedirect = url => window.location.replace(url);
const executeRedirect = createRedirect(window);
const schemaProcessors = {
[schema.DEFAULT_CONTENT_ITEM]: processDefaultContent,
[schema.DOM_ACTION]: createProcessDomAction({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import createRedirect from "../../../../../../src/components/Personalization/dom-actions/createRedirect";

describe("createRedirect", () => {
it("redirects", () => {
const window = {
location: {
replace: jasmine.createSpy()
}
};
const redirect = createRedirect(window);
redirect("myurl");
expect(window.location.replace).toHaveBeenCalledWith("myurl");
});
});

0 comments on commit 6bcaeb1

Please sign in to comment.