From e3e441aed48912885cdb8e23d5764796961c0533 Mon Sep 17 00:00:00 2001 From: Jon Snyder Date: Wed, 18 Oct 2023 10:58:31 -0600 Subject: [PATCH] Add functional test for viewName in click notification. Fix logic to include viewName. --- .../Personalization/createClickStorage.js | 22 +++--- .../specs/Personalization/C14286730.js | 79 +++++++++++++++++++ .../createClickStorage.spec.js | 10 ++- 3 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 test/functional/specs/Personalization/C14286730.js diff --git a/src/components/Personalization/createClickStorage.js b/src/components/Personalization/createClickStorage.js index 353113511..3306125cc 100644 --- a/src/components/Personalization/createClickStorage.js +++ b/src/components/Personalization/createClickStorage.js @@ -14,9 +14,7 @@ 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] }; }); }; @@ -24,14 +22,18 @@ const metasToArray = metas => { 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 }; }; diff --git a/test/functional/specs/Personalization/C14286730.js b/test/functional/specs/Personalization/C14286730.js new file mode 100644 index 000000000..51a768645 --- /dev/null +++ b/test/functional/specs/Personalization/C14286730.js @@ -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( + `
Products
` + ); + 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"); +}); diff --git a/test/unit/specs/components/Personalization/createClickStorage.spec.js b/test/unit/specs/components/Personalization/createClickStorage.spec.js index de67741fd..2d8561203 100644 --- a/test/unit/specs/components/Personalization/createClickStorage.spec.js +++ b/test/unit/specs/components/Personalization/createClickStorage.spec.js @@ -21,7 +21,9 @@ describe("Personalization::createClickStorage", () => { scope: "__view__", scopeDetails: { test: "blah1" - } + }, + trackingLabel: "mylabel", + scopeType: "myscopetype" } }; const SECOND_CLICK = { @@ -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"); @@ -114,7 +117,8 @@ describe("Personalization::createClickStorage", () => { id: "AT:123", scope: "__view__", scopeDetails: { test: "blah1" }, - trackingLabel: undefined + trackingLabel: "mylabel", + scopeType: "myscopetype" }); }); });