-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Click Collection Configuration Validation #1216
Open
shammowla
wants to merge
2
commits into
main
Choose a base branch
from
PDCL-10223
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+302
−4
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/components/ActivityCollector/validateClickCollectionConfig.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright 2024 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. | ||
*/ | ||
// src/components/ActivityCollector/validateClickCollectionConfig.js | ||
/* | ||
Copyright 2024 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 { DEFAULT_DOWNLOAD_QUALIFIER } from "./configValidators.js"; | ||
|
||
export default (config, logger) => { | ||
const { | ||
clickCollectionEnabled, | ||
onBeforeLinkClickSend, | ||
downloadLinkQualifier: dlq, | ||
} = config; | ||
|
||
if (clickCollectionEnabled === false) { | ||
if (onBeforeLinkClickSend) { | ||
logger.warn( | ||
"The 'onBeforeLinkClickSend' configuration was provided but will be ignored because clickCollectionEnabled is false.", | ||
); | ||
} | ||
|
||
if (dlq && dlq !== DEFAULT_DOWNLOAD_QUALIFIER) { | ||
logger.warn( | ||
"The 'downloadLinkQualifier' configuration was provided but will be ignored because clickCollectionEnabled is false.", | ||
); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
Copyright 2024 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. | ||
*/ | ||
// test/functional/specs/Data Collector/C81184.js | ||
/* | ||
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, ClientFunction } from "testcafe"; | ||
import createFixture from "../../helpers/createFixture/index.js"; | ||
import createConsoleLogger from "../../helpers/consoleLogger/index.js"; | ||
import { | ||
compose, | ||
orgMainConfigMain, | ||
debugEnabled, | ||
} from "../../helpers/constants/configParts/index.js"; | ||
import createAlloyProxy from "../../helpers/createAlloyProxy.js"; | ||
import addHtmlToBody from "../../helpers/dom/addHtmlToBody.js"; | ||
|
||
const alloyMonitorScript = ` | ||
window.__alloyMonitors = window.__alloyMonitors || []; | ||
window.__alloyMonitors.push({ | ||
onInstanceConfigured: function(data) { | ||
window.___getLinkDetails = data.getLinkDetails; | ||
} | ||
});`; | ||
|
||
createFixture({ | ||
title: "C81184: Validate click collection configuration warnings", | ||
monitoringHooksScript: alloyMonitorScript, | ||
}); | ||
|
||
test.meta({ | ||
ID: "C81184", | ||
SEVERITY: "P0", | ||
TEST_RUN: "Regression", | ||
}); | ||
|
||
test("Test C81184: Warns when click collection features configured but disabled", async () => { | ||
const consoleLogger = await createConsoleLogger(); | ||
const alloy = createAlloyProxy(); | ||
|
||
await alloy.configure( | ||
compose(orgMainConfigMain, debugEnabled, { | ||
clickCollectionEnabled: false, | ||
onBeforeLinkClickSend: () => {}, | ||
downloadLinkQualifier: "\\.pdf$", | ||
}), | ||
); | ||
|
||
await consoleLogger.warn.expectMessageMatching( | ||
/The 'onBeforeLinkClickSend' configuration was provided but will be ignored because clickCollectionEnabled is false/, | ||
); | ||
|
||
await consoleLogger.warn.expectMessageMatching( | ||
/The 'downloadLinkQualifier' configuration was provided but will be ignored because clickCollectionEnabled is false/, | ||
); | ||
}); | ||
|
||
test("Test C81184: Does not warn for default downloadLinkQualifier when disabled", async () => { | ||
const consoleLogger = await createConsoleLogger(); | ||
const alloy = createAlloyProxy(); | ||
|
||
await alloy.configure( | ||
compose(orgMainConfigMain, debugEnabled, { | ||
clickCollectionEnabled: false, | ||
}), | ||
); | ||
|
||
await consoleLogger.warn.expectNoMessageMatching( | ||
/The 'downloadLinkQualifier' configuration was provided/, | ||
); | ||
}); | ||
|
||
test("Test C81184: Does not warn when clickCollectionEnabled is true", async () => { | ||
const consoleLogger = await createConsoleLogger(); | ||
const alloy = createAlloyProxy(); | ||
|
||
await alloy.configure( | ||
compose(orgMainConfigMain, debugEnabled, { | ||
clickCollectionEnabled: true, | ||
onBeforeLinkClickSend: () => {}, | ||
downloadLinkQualifier: "\\.pdf$", | ||
}), | ||
); | ||
|
||
await consoleLogger.warn.expectNoMessageMatching( | ||
/The 'onBeforeLinkClickSend' configuration was provided/, | ||
); | ||
|
||
await consoleLogger.warn.expectNoMessageMatching( | ||
/The 'downloadLinkQualifier' configuration was provided/, | ||
); | ||
}); | ||
|
||
const getLinkDetails = ClientFunction((selector) => { | ||
const linkElement = document.getElementById(selector); | ||
// eslint-disable-next-line no-underscore-dangle | ||
const result = window.___getLinkDetails(linkElement); | ||
if (!result) { | ||
return result; | ||
} | ||
return { | ||
pageName: result.pageName, | ||
linkName: result.linkName, | ||
linkRegion: result.linkRegion, | ||
linkType: result.linkType, | ||
linkUrl: result.linkUrl, | ||
}; | ||
}); | ||
|
||
test("Test C81184: getLinkDetails works regardless of clickCollectionEnabled", async () => { | ||
const alloy = createAlloyProxy(); | ||
|
||
await alloy.configure( | ||
compose(orgMainConfigMain, debugEnabled, { | ||
clickCollectionEnabled: false, | ||
}), | ||
); | ||
|
||
await addHtmlToBody( | ||
'<a href="https://example.com" id="test-link">Test Link</a>', | ||
); | ||
|
||
const result = await getLinkDetails("test-link"); | ||
|
||
await t.expect(result).notEql(undefined); | ||
await t.expect(result.linkName).eql("Test Link"); | ||
await t.expect(result.linkUrl).contains("example.com"); | ||
await t.expect(result.linkType).eql("exit"); | ||
}); |
93 changes: 93 additions & 0 deletions
93
test/unit/specs/components/ActivityCollector/validateClickCollectionConfig.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
Copyright 2024 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 validateClickCollectionConfig from "../../../../../src/components/ActivityCollector/validateClickCollectionConfig.js"; | ||
import { DEFAULT_DOWNLOAD_QUALIFIER } from "../../../../../src/components/ActivityCollector/configValidators.js"; | ||
|
||
describe("ActivityCollector::validateClickCollectionConfig", () => { | ||
let logger; | ||
|
||
beforeEach(() => { | ||
logger = jasmine.createSpyObj("logger", ["warn"]); | ||
}); | ||
|
||
it("warns when onBeforeLinkClickSend provided with clickCollectionEnabled false", () => { | ||
const config = { | ||
clickCollectionEnabled: false, | ||
onBeforeLinkClickSend: () => {}, | ||
}; | ||
|
||
validateClickCollectionConfig(config, logger); | ||
|
||
expect(logger.warn).toHaveBeenCalledWith( | ||
"The 'onBeforeLinkClickSend' configuration was provided but will be ignored because clickCollectionEnabled is false.", | ||
); | ||
}); | ||
|
||
it("warns when custom downloadLinkQualifier provided with clickCollectionEnabled false", () => { | ||
const config = { | ||
clickCollectionEnabled: false, | ||
downloadLinkQualifier: "\\.pdf$", | ||
}; | ||
|
||
validateClickCollectionConfig(config, logger); | ||
|
||
expect(logger.warn).toHaveBeenCalledWith( | ||
"The 'downloadLinkQualifier' configuration was provided but will be ignored because clickCollectionEnabled is false.", | ||
); | ||
}); | ||
|
||
it("does not warn for default downloadLinkQualifier when disabled", () => { | ||
const config = { | ||
clickCollectionEnabled: false, | ||
downloadLinkQualifier: DEFAULT_DOWNLOAD_QUALIFIER, | ||
}; | ||
|
||
validateClickCollectionConfig(config, logger); | ||
|
||
expect(logger.warn).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("does not warn when clickCollectionEnabled is true", () => { | ||
const config = { | ||
clickCollectionEnabled: true, | ||
onBeforeLinkClickSend: () => {}, | ||
downloadLinkQualifier: "\\.pdf$", | ||
}; | ||
|
||
validateClickCollectionConfig(config, logger); | ||
|
||
expect(logger.warn).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("does not warn when no click collection features configured", () => { | ||
const config = { | ||
clickCollectionEnabled: false, | ||
}; | ||
|
||
validateClickCollectionConfig(config, logger); | ||
|
||
expect(logger.warn).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("handles undefined config values", () => { | ||
const config = { | ||
clickCollectionEnabled: false, | ||
onBeforeLinkClickSend: undefined, | ||
downloadLinkQualifier: undefined, | ||
}; | ||
|
||
validateClickCollectionConfig(config, logger); | ||
|
||
expect(logger.warn).not.toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(non-blocking nitpick) Will you remove this duplicated license header?