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

SegmentSelectorEditor_spec.js « specs « UI « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d144a9be54b934ef403c850edd8455e2c85d1820 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*!
 * Piwik - free/libre analytics platform
 * 
 * ViewDataTable screenshot tests.
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

describe("SegmentSelectorEditorTest", function () {
    var selectorsToCapture = ".segmentEditorPanel,.segmentEditorPanel .dropdown-body,.segment-element";
    
    this.timeout(0);

    var generalParams = 'idSite=1&period=year&date=2012-08-09';
    var url = '?module=CoreHome&action=index&' + generalParams + '#?' + generalParams + '&category=General_Actions&subcategory=General_Pages';

    it("should load correctly", function (done) {
        expect.screenshot("0_initial").to.be.captureSelector(selectorsToCapture, function (page) {
            page.load(url);
        }, done);
    });

    it("should open selector when control clicked", function (done) {
        expect.screenshot("1_selector_open").to.be.captureSelector(selectorsToCapture, function (page) {
            page.click('.segmentationContainer .title');
        }, done);
    });

    it("should open segment editor when edit link clicked for existing segment", function (done) {
        expect.screenshot("2_segment_editor_update").to.be.captureSelector(selectorsToCapture, function (page) {
            page.evaluate(function() {
                $('.segmentList .editSegment:first').click()
            }, 200);
        }, done);
    });

    it("should start editing segment name when segment name edit link clicked", function (done) {
        expect.screenshot("3_segment_editor_edit_name").to.be.captureSelector(selectorsToCapture, function (page) {
            page.click('.segmentEditorPanel .editSegmentName');
        }, done);
    });

    it("should expand segment dimension category when category name clicked in segment editor", function (done) {
        expect.screenshot("4_segment_editor_expanded_dimensions").to.be.captureSelector(selectorsToCapture, function (page) {
            page.click('.segmentEditorPanel .metric_category:contains(Actions)');
        }, done);
    });

    it("should search segment dimensions when text entered in dimension search input", function (done) {
        expect.screenshot("5_segment_editor_search_dimensions").to.be.captureSelector(selectorsToCapture, function (page) {
            page.sendKeys('.segmentEditorPanel .segmentSearch', 'page title');
        }, done);
    });

    it("should show the egment editor's available segments dropdown", function (done) {
        expect.screenshot("6_segment_editor_droplist").to.be.captureSelector(selectorsToCapture, function (page) {
            page.mouseMove('.available_segments a.dropList');
            page.click('.available_segments a.dropList');
        }, done);
    });

    it("should change segment when another available segment clicked in segment editor's available segments dropdown", function (done) {
        expect.screenshot("6_segment_editor_different").to.be.captureSelector(selectorsToCapture, function (page) {
            page.click('.ui-menu-item a:contains(Add new segment)');
        }, done);
    });

    it("should close the segment editor when the close link is clicked", function (done) {
        expect.screenshot("7_segment_editor_closed").to.be.captureSelector(selectorsToCapture, function (page) {
            page.evaluate(function () {
                $('.segmentEditorPanel .segment-footer .close').click();
            });
        }, done);
    });

    it("should open blank segment editor when create new segment link is clicked", function (done) {
        expect.screenshot("8_segment_editor_create").to.be.captureSelector(selectorsToCapture, function (page) {
            page.click('.segmentationContainer .title');
            page.click('.add_new_segment');
        }, done);
    });

    it("should add new segment expression when segment dimension drag dropped", function (done) {
        expect.screenshot("dimension_drag_drop").to.be.captureSelector(selectorsToCapture, function (page) {
            page.click('.segmentEditorPanel .metric_category:contains(Actions)');
            page.dragDrop('.segmentEditorPanel li[data-metric=actionUrl]', '.segmentEditorPanel .ui-droppable');
        }, done);
    });

    // phantomjs won't take screenshots of dropdown windows, so skip this test
    it.skip("should show suggested segment values when a segment value input is focused", function (done) {
        expect.screenshot("suggested_values").to.be.captureSelector(selectorsToCapture, function (page) {
            page.click('.segmentEditorPanel .ui-autocomplete-input');
        }, done);
    });

    it("should add an OR condition when a segment dimension is dragged to the OR placeholder section", function (done) {
        expect.screenshot("drag_or_condition").to.be.captureSelector(selectorsToCapture, function (page) {
            page.dragDrop('.segmentEditorPanel li[data-metric=outlinkUrl]', '.segmentEditorPanel .segment-add-or .ui-droppable');
        }, done);
    });

    it("should add an AND condition when a segment dimension is dragged to the AND placeholder section", function (done) {
        expect.screenshot("drag_and_condition").to.be.captureSelector(selectorsToCapture, function (page) {
            page.dragDrop('.segmentEditorPanel li[data-metric=outlinkUrl]', '.segmentEditorPanel .segment-add-row .ui-droppable');
        }, done);
    });

    it("should save a new segment and add it to the segment list when the form is filled out and the save button is clicked", function (done) {
        expect.screenshot("saved").to.be.captureSelector(selectorsToCapture, function (page) {
            page.evaluate(function () {
                $('.metricMatchBlock>select').each(function () {
                    $(this).val('==');
                });

                $('.metricValueBlock>input').each(function (index) {
                    $(this).val('value ' + index);
                });
            });

            page.sendKeys('input.edit_segment_name', 'new segment');
            page.click('.segmentEditorPanel .metric_category:contains(Actions)'); // click somewhere else to save new name

            page.evaluate(function () {
                $('button.saveAndApply').click();
            });

            page.click('.segmentationContainer');
        }, done);
    });

    it("should show the new segment after page reload", function (done) {
        expect.screenshot("saved").to.be.captureSelector("saved_reload", selectorsToCapture, function (page) {
            page.reload();
            page.click('.segmentationContainer .title');
        }, done);
    });

    it("should correctly load the new segment's details when the new segment is edited", function (done) {
        expect.screenshot("saved_details").to.be.captureSelector(selectorsToCapture, function (page) {
            page.click('.segmentList li[data-idsegment=4] .editSegment');
        }, done);
    });

    it("should correctly should show a confirmation when changing segment definition", function (done) {
        expect.screenshot("update_confirmation").to.be.captureSelector('.modal.open', function (page) {
            page.click('.segmentEditorPanel .editSegmentName');
            page.evaluate(function () {
                $('input.edit_segment_name').val('');
            });
            page.sendKeys('input.edit_segment_name', 'edited segment');
            page.click('.segmentEditorPanel .metric_category:contains(Actions)'); // click somewhere else to save new name

            page.evaluate(function () {
                $('.metricMatchBlock>select').each(function () {
                    $(this).val('!=');
                });

                $('.metricValueBlock>input').each(function (index) {
                    $(this).val('new value ' + index);
                });
            });

            page.evaluate(function () {
                $('button.saveAndApply').click();
            });
        }, done);
    });

    it("should correctly update the segment when saving confirmed", function (done) {
        expect.screenshot("updated").to.be.captureSelector(selectorsToCapture, function (page) {
            page.click('.modal.open .modal-footer a:contains(Yes):visible');
            page.click('.segmentationContainer');
        }, done);
    });

    it("should show the updated segment after page reload", function (done) {
        expect.screenshot("updated_reload").to.be.captureSelector("updated_reload", selectorsToCapture, function (page) {
            page.reload();
            page.click('.segmentationContainer .title');
        }, done);
    });

    it("should correctly load the updated segment's details when the updated segment is edited", function (done) {
        expect.screenshot("updated_details").to.be.captureSelector(selectorsToCapture, function (page) {
            page.click('.segmentList li[data-idsegment=4] .editSegment');
        }, done);
    });

    it("should correctly show delete dialog when the delete link is clicked", function (done) {
        expect.screenshot('deleted_dialog').to.be.captureSelector('.modal.open', function (page) {
            page.evaluate(function () {
                $('.segmentEditorPanel a.delete').click();
            });
        }, done);
    });

    it("should correctly remove the segment when the delete dialog is confirmed", function (done) {
        expect.screenshot('deleted').to.be.captureSelector(selectorsToCapture + ',.modal.open', function (page) {
            page.click('.modal.open .modal-footer a:contains(Yes):visible');

            page.click('.segmentationContainer .title');
        }, done);
    });

    it("should not show the deleted segment after page reload", function (done) {
        expect.screenshot('deleted').to.be.captureSelector('deleted_reload', selectorsToCapture, function (page) {
            page.reload();
            page.click('.segmentationContainer .title');
        }, done);
    });
});