Skip to content

Commit 7e6dd00

Browse files
authored
Fix flaky segment editor test (#23905)
* trying to fix failing test for segment editor * putting back commented out code for faster testing * removed unused code * put back touched code. removing unnecessary timeout and log * adding check that list is closed before the loop starts * adding a console log to see if the check is actually working and adding a test screenshot to see what happens * changing how we check if segment is checked if it is expanded or not * moved the test a little bit on top to prevent issues caused by side effect from previous tests * moved the new test to its own suite to test if this works w/ a new test state * adding missing parameters * trying to add back the test but making sure to close the panel at the end of the last test * removing the test from old test suite and putting it on its own suite so that there are no issues with test state * removed console log * trying out resetting the compared segments before testing the limits * removing test solution because it did not work
1 parent 4ef59e8 commit 7e6dd00

File tree

2 files changed

+70
-50
lines changed

2 files changed

+70
-50
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*!
2+
* Matomo - free/libre analytics platform
3+
*
4+
* SegmentEditor Compare tests.
5+
*
6+
* @link https://matomo.org
7+
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8+
*/
9+
10+
describe('SegmentComparison', () => {
11+
var generalParams = 'idSite=1&period=year&date=2012-08-09';
12+
it('should not allow comparing segments more than the limit set', async function() {
13+
const configLimit = 2;
14+
const maxSegments = configLimit + 1;
15+
testEnvironment.overrideConfig('General', 'data_comparison_segment_limit', configLimit);
16+
await testEnvironment.save();
17+
const dashUrl = '?module=CoreHome&action=index&' + generalParams + '#?' + generalParams + '&category=Dashboard_Dashboard&subcategory=1'
18+
// Need to reload here since overrideConfig above does not really
19+
// reflect well when the config is used in javascript
20+
// start a fresh navigation so the new config is injected
21+
await page.goto('about:blank');
22+
await page.waitForNetworkIdle();
23+
await page.goto(dashUrl);
24+
await page.waitForNetworkIdle();
25+
// We grab the max limit message
26+
const maxLimitMessage = await page.evaluate(
27+
(limit) => _pk_translate('General_MaximumNumberOfSegmentsComparedIs', [limit]),
28+
maxSegments);
29+
30+
// We check that the title attribute is still not the max limit message
31+
let title = await page.$eval('.segmentationContainer .segmentList li:last-child', (el) => el.getAttribute('title'));
32+
expect(title).to.not.equal(maxLimitMessage);
33+
34+
await page.waitForSelector('.segmentationContainer');
35+
// We check that the number of <li> elements is greater than the limit we set
36+
const liElemLength = await page.$$eval('.segmentListContainer .segmentList li', (e) => e.length);
37+
expect(liElemLength).to.be.greaterThan(maxSegments);
38+
39+
// We check that the number of segments compared is 1 at the start
40+
let comparedCount = await page.$$eval(
41+
'.segmentListContainer .segmentList li.comparedSegment',
42+
(nodes) => nodes.length,
43+
);
44+
expect(comparedCount).to.equal(1);
45+
46+
// Making sure that the list is closed initially before the loop starts
47+
const segmentListIsExpanded = await page.evaluate(() => !!document.querySelector('.segmentEditorPanel.expanded'));
48+
if (segmentListIsExpanded) {
49+
await page.click('.segmentationContainer .title');
50+
await page.waitForTimeout(100);
51+
}
52+
53+
// We want to click all the segments so that we can check that it stops at the limit
54+
for (let i=0; i<liElemLength; i++) {
55+
await page.click('.segmentationContainer .title');
56+
await page.waitForTimeout(100);
57+
const elements = await page.$$('.segmentListContainer .segmentList li button.compareSegment');
58+
if (!elements[i]) break;
59+
await elements[i].click();
60+
await page.waitForTimeout(100);
61+
}
62+
63+
// We check that the number of segments compared is now equal to the limit we set
64+
comparedCount = await page.$$eval(
65+
'.segmentListContainer .segmentList li.comparedSegment',
66+
(nodes) => nodes.length,
67+
);
68+
expect(comparedCount).to.equal(maxSegments);
69+
});
70+
});

plugins/SegmentEditor/tests/UI/SegmentSelectorEditor_spec.js

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -404,54 +404,4 @@ describe("SegmentSelectorEditorTest", function () {
404404
await page.click('.segmentationContainer .title');
405405
expect(await page.screenshotSelector(selectorsToCapture)).to.matchImage('enabled_create_realtime_segments_saved');
406406
});
407-
408-
it('should not allow comparing segments more than the limit set', async function() {
409-
const configLimit = 2;
410-
const maxSegments = configLimit + 1;
411-
testEnvironment.overrideConfig('General', 'data_comparison_segment_limit', configLimit);
412-
testEnvironment.save();
413-
// Need to reload here since overrideConfig above does not really
414-
// reflect well when the config is used in javascript
415-
await page.reload();
416-
await page.waitForNetworkIdle();
417-
// We grab the max limit message
418-
const maxLimitMessage = await page.evaluate(
419-
(limit) => _pk_translate('General_MaximumNumberOfSegmentsComparedIs', [limit]),
420-
maxSegments);
421-
422-
// We check that the title attribute is still not the max limit message
423-
let title = await page.$eval('.segmentationContainer .segmentList li:last-child', (el) => el.getAttribute('title'));
424-
expect(title).to.not.equal(maxLimitMessage);
425-
426-
await page.waitForSelector('.segmentationContainer');
427-
// We check that the number of <li> elements is greater than the limit we set
428-
const liElemLength = await page.$$eval('.segmentListContainer .segmentList li', (e) => e.length);
429-
expect(liElemLength).to.be.greaterThan(maxSegments);
430-
431-
// We check that the number of segments compared is 1 at the start
432-
let comparedCount = await page.$$eval(
433-
'.segmentListContainer .segmentList li.comparedSegment',
434-
(nodes) => nodes.length,
435-
);
436-
expect(comparedCount).to.equal(1);
437-
438-
// We want to click all the segments so that we can check that it stops at the limit
439-
for (let i=0; i<liElemLength; i++) {
440-
await page.click('.segmentationContainer .title');
441-
const segments = await page.$$('.segmentListContainer .segmentList li span.compareSegment');
442-
await segments[i].click();
443-
await page.waitForTimeout(50);
444-
}
445-
446-
// We check that the number of segments compared is now equal to the limit we set
447-
comparedCount = await page.$$eval(
448-
'.segmentListContainer .segmentList li.comparedSegment',
449-
(nodes) => nodes.length,
450-
);
451-
expect(comparedCount).to.equal(maxSegments);
452-
453-
// Last we check that the title attribute has changed to reflect the limit has been reached
454-
title = await page.$eval('.segmentationContainer .segmentList li:last-child', (el) => el.getAttribute('title'));
455-
expect(title).to.equal(maxLimitMessage);
456-
});
457407
});

0 commit comments

Comments
 (0)