File: cypress/integration/views.js

Recommend this page to a friend!
  Classes of Arturs Sosins  >  Countly Web SDK  >  cypress/integration/views.js  >  Download  
File: cypress/integration/views.js
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Countly Web SDK
Track site accesses and errors the Countly API
Author: By
Last change:
Date: 2 months ago
Size: 2,327 bytes
 

Contents

Class file image Download
/* eslint-disable cypress/no-unnecessary-waiting */
/* eslint-disable require-jsdoc */
var Countly = require("../../lib/countly");
var hp = require("../support/helper");

function initMain() {
    Countly.init({
        app_key: "YOUR_APP_KEY",
        url: "https://try.count.ly",
        max_events: -1,
        tests: true
    });
}

var pageNameOne = "test view page name1";
var pageNameTwo = "test view page name2";

describe("Views tests ", () => {
    it("Checks if recording page view works", () => {
        hp.haltAndClearStorage(() => {
            initMain();
            Countly.track_view(pageNameOne);
            cy.fetch_local_event_queue().then((eq) => {
                expect(eq.length).to.equal(1);
                cy.check_view_event(eq[0], pageNameOne);
            });
        });
    });
    it("Checks if recording timed page views with same name works", () => {
        hp.haltAndClearStorage(() => {
            initMain();
            Countly.track_view(pageNameOne);
            cy.wait(3000).then(() => {
                Countly.track_view(pageNameOne);
                cy.fetch_local_event_queue().then((eq) => {
                    expect(eq.length).to.equal(3);
                    cy.check_view_event(eq[0], pageNameOne);
                    cy.check_view_event(eq[1], pageNameOne, 3);
                    cy.check_view_event(eq[2], pageNameOne);
                });
            });
        });
    });
    it("Checks if recording timed page views with different name works", () => {
        hp.haltAndClearStorage(() => {
            initMain();
            Countly.track_view(pageNameOne);
            var expectedDur = 4000;
            hp.waitFunction(hp.getTimestampMs(), expectedDur, 500, ()=>{
                // cy.wait(4000).then(() => {
                Countly.track_view(pageNameTwo);
                cy.fetch_local_event_queue().then((eq) => {
                    expect(eq.length).to.equal(3);
                    cy.check_view_event(eq[0], pageNameOne);
                    // this test is flaky we are expecting 3 and +1 (4) to make test more reliable 
                    cy.check_view_event(eq[1], pageNameOne, expectedDur / 1000);
                    cy.check_view_event(eq[2], pageNameTwo);
                });
                // });
            });
        });
    });
});