Skip to content

Commit 2f531ed

Browse files
committed
Improve automated tests.
1 parent edca719 commit 2f531ed

26 files changed

Lines changed: 399 additions & 390 deletions

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM nginx
22
ARG DAP_ENV='dev'
33
ENV DAP_ENV=${DAP_ENV}
4-
COPY test_site Universal-Federated-Analytics-Min.js Federated.js.map /usr/share/nginx/html/
4+
COPY test_site Universal-Federated-Analytics-Min.js Universal-Federated-Analytics.js Federated.js.map /usr/share/nginx/html/
55
COPY nginx-test.conf.template /etc/nginx/conf.d/
66
RUN envsubst '${DAP_ENV}' < /etc/nginx/conf.d/nginx-test.conf.template > /etc/nginx/conf.d/default.conf

features/404_tracking.feature

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ Feature: DAP modifies page_location for 404 pages
66

77
Scenario: Page title containing "404" sets page_location to a vpv404 path
88
When I load the test page "404.html"
9-
Then the config call for the DAP property has "page_location" containing "/vpv404/"
9+
Then DAP will set custom dimensions for the DAP property
10+
| page_location | http://dap-test-site.local/vpv404/404.html |
1011

1112
Scenario: Page title containing "not found" sets page_location to a vpv404 path
1213
When I load the test page "not-found.html"
13-
Then the config call for the DAP property has "page_location" containing "/vpv404/"
14-
15-
Scenario: 404 page without a referrer does not append a referrer to page_location
16-
When I load the test page "404.html"
17-
Then the config call for the DAP property has "page_location" containing "/vpv404/404.html"
14+
Then DAP will set custom dimensions for the DAP property
15+
| page_location | http://dap-test-site.local/vpv404/not-found.html |
1816

1917
Scenario: 404 page with a referrer appends the referrer to page_location
2018
When I load the test site
21-
And I load the test page "404.html"
22-
Then the config call for the DAP property has "page_location" containing "/vpv404/"
23-
And the config call for the DAP property has "page_location" containing "http://localhost:8080/"
19+
And I click on link with href "/404.html" and wait for new page to load
20+
Then DAP will set custom dimensions for the DAP property
21+
| page_location | http://dap-test-site.local/vpv404/404.html/http://dap-test-site.local/ |

features/autotracker.feature

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# DAP's GA4 property is configured to disable most enhanced measurement events.
2+
# The DAP code takes over responsibility for tracking these events, rather than relying on gtag's implementation.
3+
# This test feature verifies DAP's alternative implementation of outbound click and file download tracking.
4+
Feature: Downloads and outbound link clicks are tracked when autotracking is enabled
5+
6+
Background:
7+
Given I load an empty browser
8+
And DAP is configured for agency "GSA"
9+
10+
Scenario: Clicking an email link fires email_click when autotracking is enabled
11+
Given DAP is configured with autotracking enabled
12+
When I load the test site
13+
And I click on element with selector "a[href='mailto:test@domain.com']"
14+
Then a "email_click" event is sent to DAP with parameters
15+
| link_text | mailto:[REDACTED_EMAIL] |
16+
| link_domain | domain.com |
17+
| outbound | true |
18+
| interaction_type | Mouse Click |
19+
20+
Scenario: Clicking an email link does not fire email_click when autotracking is disabled
21+
Given DAP is configured with autotracking disabled
22+
When I load the test site
23+
And I click on element with selector "a[href='mailto:test@domain.com']"
24+
Then no "email_click" event is sent to DAP
25+
26+
Scenario: Clicking a telephone link fires telephone_click when autotracking is enabled
27+
Given DAP is configured with autotracking enabled
28+
When I load the test site
29+
And I click on element with selector "a[href='tel:+1437-925-1855']"
30+
Then a "telephone_click" event is sent to DAP with parameters
31+
| link_text | Telephone [REDACTED_TEL] |
32+
| interaction_type | Mouse Click |
33+
34+
Scenario: Clicking a telephone link does not fire telephone_click when autotracking is disabled
35+
Given DAP is configured with autotracking disabled
36+
When I load the test site
37+
And I click on element with selector "a[href='tel:+1437-925-1855']"
38+
Then no "telephone_click" event is sent to DAP
39+
40+
Scenario: Clicking an outbound link sends a click event when autotracking is enabled
41+
Given DAP is configured with autotracking enabled
42+
When I load the test site
43+
And I click on element with selector "a[href='http://www.gsa.gov/travelpolicy']"
44+
Then a "click" event is sent to DAP with parameters
45+
| link_url | http://gsa.gov/travelpolicy |
46+
| link_domain | gsa.gov |
47+
| link_text | http://gsa.gov/travelpolicy |
48+
| outbound | true |
49+
| interaction_type | Mouse Click |
50+
51+
Scenario: Clicking an outbound link does not fire event when autotracking is disabled
52+
Given DAP is configured with autotracking disabled
53+
When I load the test site
54+
And I click on element with selector "a[href='http://www.gsa.gov/travelpolicy']"
55+
Then no "click" event is sent to DAP
56+
57+
Scenario: Clicking a file download link reports the download when autotracking is enabled
58+
When I load the test site
59+
And I click on a file to download it
60+
Then a "file_download" event is sent to DAP with parameters
61+
| file_name | /about.zip |
62+
| file_extension | zip |
63+
| link_text | /about.zip |
64+
| link_id | internalDownload |
65+
| link_url | http://dap-test-site.local/about.zip |
66+
| link_domain | dap-test-site.local |
67+
| interaction_type | Mouse Click |
68+
69+
Scenario: Pressing Enter on a file download link reports the download when autotracking is enabled
70+
When I load the test site
71+
And I highlight and press Enter on a file to download it
72+
Then a "file_download" event is sent to DAP with parameters
73+
| file_name | /about.zip |
74+
| file_extension | zip |
75+
| link_text | /about.zip |
76+
| link_id | internalDownload |
77+
| link_url | http://dap-test-site.local/about.zip |
78+
| link_domain | dap-test-site.local |
79+
| interaction_type | Enter Key Keystroke |
80+
81+
Scenario: File downloads are not tracked when autotracking is disabled
82+
Given DAP is configured with autotracking disabled
83+
When I load the test site
84+
And I click on a file to download it
85+
Then no "file_download" event is sent to DAP

features/autotracker_download.feature

Lines changed: 0 additions & 23 deletions
This file was deleted.

features/banner_tracker.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Feature: DAP tracks clicks on any 'Official website of the US government' banner
2+
3+
Background:
4+
Given I load an empty browser
5+
And DAP is configured for agency "GSA"
6+
7+
Scenario: Clicking the USA banner button fires official_usa_site_banner_click
8+
When I load the test site
9+
And I click on element with selector "#banner-button"
10+
Then a "official_usa_site_banner_click" event is sent to DAP with parameters
11+
| link_text | Here's how you know |
12+
| section | header |

features/basic_page_load.feature

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ Feature: Test the outgoing requests sent by a basic page with DAP code loaded
88
Scenario: Loading the page with the DAP code without further action
99
When I load the test site
1010
And I wait 5 seconds
11-
Then there is a GA4 request
12-
But there are no unexpected requests
11+
Then there are no unexpected requests
1312

1413
Scenario: Loading the page with the DAP code and clicking a button
1514
When I load the test site
1615
And I click on element with selector "#banner-button"
1716
And I wait 5 seconds
18-
Then there is a GA4 request
19-
But there are no unexpected requests
17+
Then there are no unexpected requests

features/beacon_payload.feature

Lines changed: 0 additions & 21 deletions
This file was deleted.

features/configuration.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ Feature: A site can load the DAP code with varying levels of customization
2626
When I load the test site
2727
Then DAP will set custom dimensions for the DAP property
2828
| protocol | http: |
29-
| hostname_dimension | localhost |
29+
| hostname_dimension | dap-test-site.local |
3030
| using_parallel_tracker | no |
31-
And the DAP property config has script_source set to the DAP script URL
32-
And the DAP property config has version matching "\d{8} v\d+\.\d+ - ga4"
31+
And DAP will set the "script_source" dimension to a string matching "https?:\/\/.*\/universal-federated-analytics-min.js"
32+
And DAP will set the "version" dimension to a string matching "\d{8} v\d+\.\d+ - ga4"
3333

34-
Scenario: Setting cto configures the cookie expiration in the config call
34+
Scenario: Load a DAP-enabled page with a custom cookie timeout
3535
Given DAP is configured for agency "GSA"
3636
And DAP is configured with cookie timeout of 1 months
3737
When I load the test site

features/gapim.feature

Lines changed: 0 additions & 17 deletions
This file was deleted.

features/gas4_functions.feature

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ Feature: gas4() custom event API
44
Given I load an empty browser
55
And DAP is configured for agency "GSA"
66

7-
Scenario: gas4() with a page_view event name sends a page_view event
7+
Scenario: gas4() sends a virtual page_view event
88
When I load the test site
99
And I execute script "window.gas4('page_view', {page_location: '/virtual/page', page_title: 'Virtual Page'})"
1010
Then a "page_view" event is sent to DAP with parameters
11-
| page_location | http://localhost/virtual/page |
12-
| page_title | Virtual Page |
11+
| page_location | http://dap-test-site.local/virtual/page |
12+
| page_title | Virtual Page |
1313

14-
Scenario: gas4() with a valid GA4 event name sends the event
14+
Scenario: gas4() sends a virtual page_view event setting default page title
15+
When I load the test site
16+
And I execute script "window.gas4('page_view', {page_location: '/virtual/page'})"
17+
Then a "page_view" event is sent to DAP with parameters
18+
| page_location | http://dap-test-site.local/virtual/page |
19+
| page_title | DAP test site |
20+
21+
Scenario: gas4() sends a file_download event
1522
When I load the test site
1623
And I execute script "window.gas4('file_download', {file_name: '/test.pdf', file_extension: 'pdf', link_text: 'Download Test PDF', link_id: 'download-link', link_url: 'https://example.gov/test.pdf', link_domain: 'example.gov', interaction_type: 'Mouse Click'})"
1724
Then a "file_download" event is sent to DAP with parameters
@@ -23,12 +30,6 @@ Feature: gas4() custom event API
2330
| link_domain | example.gov |
2431
| interaction_type | Mouse Click |
2532

26-
Scenario: gas4() with an invalid event name falls back to dap_event
27-
When I load the test site
28-
And I execute script "window.gas4('not_a_valid_event', {some_param: 'value'})"
29-
Then a "dap_event" event is sent to DAP with parameters
30-
| some_param | value |
31-
3233
Scenario: gas4() sends a form_start event
3334
When I load the test site
3435
And I execute script "window.gas4('form_start', {form_id: 'contact-form', form_name: 'Contact Form', form_destination: '/thank-you', section: 'body'})"
@@ -47,13 +48,10 @@ Feature: gas4() custom event API
4748

4849
Scenario: gas4() sends a form_submit event
4950
When I load the test site
50-
And I click on element with selector ".column:first-child input[type=submit]"
51+
And I execute script "window.gas4('form_submit', {form_step: 3, form_submit_text: 'Submit'})"
5152
Then a "form_submit" event is sent to DAP with parameters
52-
| form_name | <form_name> |
53-
| form_id | <form_id> |
54-
| form_destination | <form_destination> |
55-
| section | <section> |
56-
| form_submit_text | <form_submit_text> |
53+
| form_step | 3 |
54+
| form_submit_text | Submit |
5755

5856
Scenario: gas4() sends a content_view event
5957
When I load the test site
@@ -96,18 +94,6 @@ Feature: gas4() custom event API
9694
| outbound | <outbound> |
9795
| section | <section> |
9896

99-
Scenario: gas4() falls back to dap_event when cta event name is invalid
100-
When I load the test site
101-
And I click on element with selector "button[onclick*=\"gas4('cta',\"]"
102-
Then a "dap_event" event is sent to DAP with parameters
103-
| link_text | <link_text> |
104-
| link_domain | <link_domain> |
105-
| link_url | <link_url> |
106-
| link_id | <link_id> |
107-
| link_classes | <link_classes> |
108-
| outbound | <outbound> |
109-
| section | <section> |
110-
11197
Scenario: gas4() sends a navigation_click event
11298
When I load the test site
11399
And I click on element with selector "a[href='#home']"
@@ -162,3 +148,9 @@ Feature: gas4() custom event API
162148
Then a "sort" event is sent to DAP with parameters
163149
| sort_selection | newest |
164150
| section | results |
151+
152+
Scenario: gas4() with an invalid event name falls back to dap_event
153+
When I load the test site
154+
And I execute script "window.gas4('not_a_valid_event', {some_param: 'value'})"
155+
Then a "dap_event" event is sent to DAP with parameters
156+
| some_param | value |

0 commit comments

Comments
 (0)