Skip to content

Commit 3f53fad

Browse files
committed
Add step definitions to set DAP parameters individually.
1 parent 35e20c7 commit 3f53fad

7 files changed

Lines changed: 74 additions & 71 deletions

File tree

features/autotracker_download.feature

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@ Feature: Downloads are reported to DAP when autotracking is enabled
22

33
Background:
44
Given I load an empty browser
5+
And DAP is configured for agency "GSA"
56

67
Scenario: User clicks to download file with autotracker on
7-
When I load the test site with autotracker enabled
8+
Given DAP is configured with autotracking enabled
9+
When I load the test site
810
And I click on a file to download it
911
Then the file download is reported to DAP with interaction type "mouse click"
1012

1113
Scenario: User presses Enter to download file with autotracker on
12-
When I load the test site with autotracker enabled
14+
Given DAP is configured with autotracking enabled
15+
When I load the test site
1316
And I highlight and press Enter on a file to download it
1417
Then the file download is reported to DAP with interaction type "enter key keystroke"
1518

1619
Scenario: User clicks to download file with autotracker off
17-
When I load the test site with autotracker disabled
20+
Given DAP is configured with autotracking disabled
21+
When I load the test site
1822
And I click on a file to download it
1923
Then the file download is not reported to DAP

features/basic_page_load.feature

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ Feature: Test the outgoing requests sent by a basic page with DAP code loaded
33
Background:
44
Given I load an empty browser
55
And I set the browser to intercept outbound requests
6+
And DAP is configured for agency "GSA"
67

78
Scenario: Loading the page with the DAP code without further action
8-
When I load the test site with default DAP parameters
9+
When I load the test site
910
And I wait 5 seconds
1011
Then there is a GA4 request
1112
But there are no unexpected requests
1213

1314
Scenario: Loading the page with the DAP code and clicking a button
14-
When I load the test site with default DAP parameters
15+
When I load the test site
1516
And I click on element with selector "#banner-button"
1617
And I wait 5 seconds
1718
Then there is a GA4 request

features/configuration.feature

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@ Feature: A site can load the DAP code with varying levels of customization
33
Background:
44
Given I load an empty browser
55

6-
Scenario: Load a DAP-enabled page with no customization
7-
When I load the test site with default DAP parameters
8-
Then DAP is configured with default parameters
6+
Scenario: Load a DAP-enabled page with agency and subagency
7+
Given DAP is configured for agency "HHS"
8+
And DAP is configured for subagency "CDC"
9+
When I load the test site
10+
Then DAP will set custom dimensions
11+
| agency | HHS |
12+
| subagency | CDC |
913

10-
Scenario: Load a DAP-enabled page with customization
11-
When I load the test site with custom DAP parameters
12-
Then DAP is configured with custom parameters
14+
Scenario: Load a DAP-enabled page with agency and site topic and site platform
15+
Given DAP is configured for agency "GSA"
16+
And DAP is configured with site topic "Analytics"
17+
And DAP is configured with site platform "Cloud.gov"
18+
When I load the test site
19+
Then DAP will set custom dimensions
20+
| agency | GSA |
21+
| site_topic | analytics |
22+
| site_platform | cloud.gov |

features/support/dapconfig.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class DAPConfig {
2+
agency;
3+
subagency;
4+
sitetopic;
5+
siteplatform;
6+
autotracker;
7+
cto;
8+
9+
constructor(agency) {
10+
this.agency = agency;
11+
}
12+
13+
toQueryParams() {
14+
const configuredFields = Object.entries(this).filter(entry => entry[1] !== undefined);
15+
return new URLSearchParams(configuredFields).toString();
16+
}
17+
}
18+
19+
export default DAPConfig;

features/support/step_definitions/dataLayer_steps.js

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,14 @@
1-
import { Then } from "@cucumber/cucumber";
1+
import {Given, Then} from "@cucumber/cucumber";
22
import * as chai from 'chai'
33
const expect = chai.expect;
44

5-
Then("DAP is configured with default parameters", async function () {
6-
const config = await this.page.evaluate(() => {
5+
Given("DAP will set custom dimensions", async function (table) {
6+
const configCommand = await this.page.evaluate(() => {
77
return window.dataLayer.find(item => item[0] === 'config');
88
});
9-
expect(config).to.deep.equal(
10-
{
11-
"0": "config",
12-
"1": "G-9TNNMGP8WJ",
13-
"2": {
14-
"cookie_expires": "63072000",
15-
"page_location": "http://localhost:8080/",
16-
"page_title": "DAP test site",
17-
"agency": "HHS",
18-
"site_platform": "unspecified:localhost",
19-
"site_topic": "unspecified:localhost",
20-
"subagency": "LOCALHOST",
21-
"script_source": "http://localhost:8080/universal-federated-analytics-min.js",
22-
"version": "20240712 v8.2 - ga4",
23-
"protocol": "http:",
24-
"using_parallel_tracker": "no"
25-
}
26-
}
27-
);
28-
});
29-
30-
Then("DAP is configured with custom parameters", async function () {
31-
const config = await this.page.evaluate(() => {
32-
return window.dataLayer.find(item => item[0] === 'config');
33-
});
34-
expect(config).to.deep.equal(
35-
{
36-
"0": "config",
37-
"1": "G-9TNNMGP8WJ",
38-
"2": {
39-
"cookie_expires": "15768000",
40-
"page_location": "http://localhost:8080/",
41-
"page_title": "DAP test site",
42-
"agency": "GSA",
43-
"site_platform": "standard-site",
44-
"site_topic": "comp,educ,soc|sm|2023-12-04+(ai+education+and+ai+in+education)",
45-
"subagency": "TTS",
46-
"script_source": "http://localhost:8080/universal-federated-analytics-min.js",
47-
"version": "20240712 v8.2 - ga4",
48-
"protocol": "http:",
49-
"using_parallel_tracker": "no"
50-
}
51-
}
52-
);
9+
expect(configCommand["0"]).to.equal("config");
10+
expect(configCommand["1"]).to.equal("G-9TNNMGP8WJ");
11+
expect(configCommand["2"]).to.include(table.rowsHash());
5312
});
5413

5514
Then("the file download is reported to DAP with interaction type {string}", async function (interactionType) {
Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
1-
import {When} from "@cucumber/cucumber";
1+
import { Given, When } from "@cucumber/cucumber";
22

3-
When("I load the test site with default DAP parameters", async function () {
4-
await this.page.goto("http://localhost:8080?agency=HHS");
3+
import DAPConfig from "../dapconfig.js";
4+
5+
Given("DAP is configured for agency {string}", function (agency) {
6+
this.dapConfig = new DAPConfig(agency);
7+
});
8+
9+
Given("DAP is configured for subagency {string}", function (subagency) {
10+
this.dapConfig.subagency = subagency;
11+
});
12+
13+
Given("DAP is configured with site topic {string}", function (sitetopic) {
14+
this.dapConfig.sitetopic = sitetopic;
15+
});
16+
17+
Given("DAP is configured with site platform {string}", function (siteplatform) {
18+
this.dapConfig.siteplatform = siteplatform;
519
});
620

7-
When("I load the test site with custom DAP parameters", async function () {
8-
await this.page.goto("http://localhost:8080?agency=GSA&Subagency=TTS&sitetopic=comp,educ,soc|sm|2023-12-04 (AI education and AI in education)&siteplatform=standard-site&cto=6");
21+
Given("DAP is configured with autotracking enabled", function () {
22+
this.dapConfig.autotracker = true;
923
});
1024

11-
When("I load the test site with autotracker enabled", async function () {
12-
// autotracker enabled by default
13-
await this.page.goto("http://localhost:8080");
25+
Given("DAP is configured with autotracking disabled", function () {
26+
this.dapConfig.autotracker = false;
1427
});
1528

16-
When("I load the test site with autotracker disabled", async function () {
17-
await this.page.goto("http://localhost:8080?autotracker=false");
29+
When("I load the test site", async function () {
30+
await this.page.goto(`http://localhost:8080?${this.dapConfig.toQueryParams()}`);
1831
});

test_site/index.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
<script>
99
(function() {
1010
const queryParams = new URLSearchParams(window.location.search);
11-
if (!queryParams.has("agency")) {
12-
queryParams.set("agency", "GSA");
13-
}
1411
const dapScriptTag = document.createElement("script");
1512
dapScriptTag.id = "_fed_an_ua_tag";
1613
dapScriptTag.async = true;

0 commit comments

Comments
 (0)