Welcome to mirror list, hosted at ThFree Co, Russian Federation.

OptOutForm_spec.js « specs « UI « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 97f64d2885f382926875ca3ffbc05c22be339e1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*!
 * Piwik - free/libre analytics platform
 *
 * Opt-out form tests
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

describe("OptOutForm", function () {
    const siteUrl = "/tests/resources/overlay-test-site-real/index.html",
        safariUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A",
        chromeUserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";

    function expandIframe() {
        return page.evaluate(() => {
            const $iframe = $('iframe#optOutIframe');
            $iframe.contents().find('#textError_https').hide();
            $iframe.width(350);
            $iframe.height($iframe.contents().outerHeight());
        });
    }

    after(async () => {
        await page.clearCookies();
    });

    it("should display correctly when embedded in another site", async function () {
        await page.clearCookies();

        page.setUserAgent(chromeUserAgent);
        await page.goto(siteUrl);

        await expandIframe();

        const element = await page.jQuery('iframe#optOutIframe');
        expect(await element.screenshot()).to.matchImage('loaded');
    });

    it("should reload the iframe when clicking the opt out checkbox and display an empty checkbox", async function () {
        await page.evaluate(function () {
            $('iframe#optOutIframe').contents().find('input#trackVisits').click();
        });

        await page.waitFor(5000); // opt out iframe creates a new page, so we can't wait on it that easily
        await page.waitForNetworkIdle(); // safety

        await expandIframe();

        const element = await page.jQuery('iframe#optOutIframe');
        expect(await element.screenshot()).to.matchImage('opted-out');
    });

    it("should correctly show the checkbox unchecked after reloading after opting-out", async function () {
        page.setUserAgent(chromeUserAgent);
        await page.goto(siteUrl);

        await expandIframe();

        const element = await page.jQuery('iframe#optOutIframe');
        expect(await element.screenshot()).to.matchImage('opted-out_reloaded');
    });

    it("using opt out twice should work correctly", async function () {
        page.setUserAgent(chromeUserAgent);
        await page.goto(siteUrl);

        await page.evaluate(function () {
            $('iframe#optOutIframe').contents().find('input#trackVisits').click();
        });

        await page.waitFor(5000);

        await expandIframe();

        // check the box has opted in state after clicking once
        var element = await page.jQuery('iframe#optOutIframe');
        expect(await element.screenshot()).to.matchImage('clicked_once');

        await page.evaluate(function () {
            $('iframe#optOutIframe').contents().find('input#trackVisits').click();
        });

        await page.waitFor(5000);

        // check the box has outed out state after click another time
        await page.reload();

        await expandIframe();

        var element = await page.jQuery('iframe#optOutIframe');
        expect(await element.screenshot()).to.matchImage('clicked_twice');
    });

    it("should correctly show display opted-in form when cookies are cleared", async function () {
        await page.clearCookies();

        page.setUserAgent(safariUserAgent);
        await page.goto(siteUrl);

        await expandIframe();

        const element = await page.jQuery('iframe#optOutIframe');
        expect(await element.screenshot()).to.matchImage('safari-loaded');
    });

    it("should correctly set opt-out cookie on safari", async function () {
        await page.evaluate(function () {
            $('iframe#optOutIframe').contents().find('input#trackVisits').click();
        });

        await page.waitFor(5000); // opt out iframe creates a new page, so we can't wait on it that easily
        await page.waitForNetworkIdle(); // safety

        await page.goto(siteUrl); // reload to check that cookie was set

        await expandIframe();

        const element = await page.jQuery('iframe#optOutIframe');
        expect(await element.screenshot()).to.matchImage('safari-opted-out');
    });
});