Skip to content

Commit

Permalink
feat: basic tests for metrics class
Browse files Browse the repository at this point in the history
  • Loading branch information
rushtong committed Nov 13, 2024
1 parent 058918e commit c020243
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
42 changes: 42 additions & 0 deletions cypress/component/utils/metrics.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable no-undef */
import {Metrics} from '../../../src/libs/ajax/Metrics';
import eventList from '../../../src/libs/events';

describe('Metrics Tests', function () {

// Intercept configuration calls
beforeEach(() => {
cy.intercept({
method: 'GET',
url: '/config.json',
hostname: 'localhost',
}, {'env': 'ci'});
});

Cypress._.each(Object.keys(eventList), (eventType) => {
it(`Captures ${eventType} Event`, function () {
cy.intercept('**/event').as('event');
Metrics.captureEvent(eventType);
cy.wait('@event').then(interception => {
expect(interception).to.exist;
});
});
});

it(`Sync Profile`, function () {
cy.intercept('**/syncProfile').as('sync');
Metrics.syncProfile();
cy.wait('@sync').then(interception => {
expect(interception).to.exist;
});
});

it(`Identify`, function () {
cy.intercept('**/identify').as('identify');
Metrics.identify('anonymousId');
cy.wait('@identify').then(interception => {
expect(interception).to.exist;
});
});

});
5 changes: 4 additions & 1 deletion cypress/support/component-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<script src="https://accounts.google.com/gsi/client" async defer id="gsiClient"></script>
<title>Components App</title>
<!-- AppCues Requirements -->
<script type="text/javascript">
window.AppcuesSettings = { enableURLDetection: true };
</script>
</head>

<body>
Expand Down

0 comments on commit c020243

Please sign in to comment.