Skip to content

Commit

Permalink
Add functional test for viewName in click notification. Fix logic to …
Browse files Browse the repository at this point in the history
…include viewName.
  • Loading branch information
jonsnyder committed Oct 18, 2023
1 parent eab73fb commit e3e441a
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 13 deletions.
22 changes: 12 additions & 10 deletions src/components/Personalization/createClickStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@ const metasToArray = metas => {
return Object.keys(metas).map(key => {
return {
id: key,
scope: metas[key].scope,
scopeDetails: metas[key].scopeDetails,
trackingLabel: metas[key].trackingLabel
...metas[key]
};
});
};

export default () => {
const clickStorage = {};

const storeClickMetrics = value => {
if (!clickStorage[value.selector]) {
clickStorage[value.selector] = {};
const storeClickMetrics = ({
selector,
meta: { id, scope, scopeDetails, trackingLabel, scopeType }
}) => {
if (!clickStorage[selector]) {
clickStorage[selector] = {};
}
clickStorage[value.selector][value.meta.id] = {
scope: value.meta.scope,
scopeDetails: value.meta.scopeDetails,
trackingLabel: value.meta.trackingLabel
clickStorage[selector][id] = {
scope,
scopeDetails,
trackingLabel,
scopeType
};
};

Expand Down
79 changes: 79 additions & 0 deletions test/functional/specs/Personalization/C14286730.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
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 { t } from "testcafe";
import createNetworkLogger from "../../helpers/networkLogger";
import { responseStatus } from "../../helpers/assertions/index";
import createFixture from "../../helpers/createFixture";
import {
compose,
orgMainConfigMain,
debugEnabled
} from "../../helpers/constants/configParts";
import { TEST_PAGE as TEST_PAGE_URL } from "../../helpers/constants/url";
import createAlloyProxy from "../../helpers/createAlloyProxy";
import addHtmlToBody from "../../helpers/dom/addHtmlToBody";

const networkLogger = createNetworkLogger();
const config = compose(orgMainConfigMain, debugEnabled);

createFixture({
title: "C14286730: Target SPA click interaction includes viewName",
requestHooks: [networkLogger.edgeEndpointLogs],
url: `${TEST_PAGE_URL}?test=C14286730`
});

test.meta({
ID: "C28755",
SEVERITY: "P0",
TEST_RUN: "Regression"
});

test("Test C14286730: Target SPA click interaction includes viewName", async () => {
const alloy = createAlloyProxy();
await alloy.configure(config);

await addHtmlToBody(
`<div id="personalization-products-container">Products</div>`
);
await alloy.sendEvent({
renderDecisions: true,
xdm: {
web: {
webPageDetails: {
viewName: "products"
}
}
}
});

await responseStatus(networkLogger.edgeEndpointLogs.requests, 200);

await t.expect(networkLogger.edgeEndpointLogs.count(() => true)).eql(2);

await t.click(".clickme");

await t.expect(networkLogger.edgeEndpointLogs.count(() => true)).eql(3);

const displayNotification = JSON.parse(
networkLogger.edgeEndpointLogs.requests[1].request.body
);
const interactNotification = JSON.parse(
networkLogger.edgeEndpointLogs.requests[2].request.body
);

await t
.expect(displayNotification.events[0].xdm.web.webPageDetails.viewName)
.eql("products");
await t
.expect(interactNotification.events[0].xdm.web.webPageDetails.viewName)
.eql("products");
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ describe("Personalization::createClickStorage", () => {
scope: "__view__",
scopeDetails: {
test: "blah1"
}
},
trackingLabel: "mylabel",
scopeType: "myscopetype"
}
};
const SECOND_CLICK = {
Expand Down Expand Up @@ -103,7 +105,8 @@ describe("Personalization::createClickStorage", () => {
2
);
});
it("getClickMetasBySelector returns the id, scopeDetails, scope", () => {

it("getClickMetasBySelector returns the id, scopeDetails, scope, trackingLabel, and scopeType", () => {
clickStorage.storeClickMetrics(FIRST_CLICK);

const meta = clickStorage.getClickMetasBySelector("div:123:h2");
Expand All @@ -114,7 +117,8 @@ describe("Personalization::createClickStorage", () => {
id: "AT:123",
scope: "__view__",
scopeDetails: { test: "blah1" },
trackingLabel: undefined
trackingLabel: "mylabel",
scopeType: "myscopetype"
});
});
});

0 comments on commit e3e441a

Please sign in to comment.