Skip to content

Commit 69e3e75

Browse files
authored
suppress form submission on segment page (#24341)
* suppress form submission on segment page * simplify approach
1 parent 3bf5873 commit 69e3e75

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

plugins/SegmentEditor/templates/manageSegments.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<h2 class="card-title">{{ 'SegmentEditor_SegmentPageTitle'|translate }}</h2>
99
<div>
1010
<p class="card-introduction">{{ 'SegmentEditor_SegmentPageDescription'|translate }}</p>
11-
<form name="manageSegmentSearchFilter">
11+
<form name="manageSegmentSearchFilter" onsubmit="return false;">
1212
<div class="form-group row matomo-form-field" style="">
1313
<div class="col s12 input-field m6">
1414
<input class="control_text" type="text" id="manageSegmentSearch" name="manageSegmentSearch">

plugins/SegmentEditor/tests/UI/SegmentManagementPage_spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,35 @@ describe("SegmentManagementPageTest", function () {
506506
expect(alertCount).to.equal(0);
507507
});
508508

509+
it("should keep the manage segments search term when pressing Enter", async function() {
510+
await openPage();
511+
512+
await page.type('#manageSegmentSearch', 'site');
513+
await page.waitForTimeout(600);
514+
515+
const urlBeforeEnter = await page.url();
516+
await page.keyboard.press('Enter');
517+
await page.waitForTimeout(300);
518+
519+
const searchState = await page.evaluate(() => {
520+
const input = document.querySelector('#manageSegmentSearch');
521+
const visibleRows = Array.from(document.querySelectorAll('tr[data-segment-name]')).filter((row) => {
522+
return $(row).is(':visible');
523+
});
524+
525+
return {
526+
value: input ? input.value : '',
527+
visibleRowNames: visibleRows.map((row) => row.getAttribute('data-segment-name') || ''),
528+
url: window.location.href,
529+
};
530+
});
531+
532+
expect(searchState.url).to.equal(urlBeforeEnter);
533+
expect(searchState.value).to.equal('site');
534+
expect(searchState.visibleRowNames).to.include(siteSegment.name);
535+
expect(searchState.visibleRowNames).to.not.include(globalSegment.name);
536+
});
537+
509538
function assignSegmentIdsFromApiResponse(response) {
510539
const segments = normalizeSegmentsResponse(response);
511540

0 commit comments

Comments
 (0)