Skip to content
Snippets Groups Projects
Verified Commit d251a98e authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3100826 by ilya.no, mwilbur, nikita_tt, smustgrave, quietone: AJAX...

Issue #3100826 by ilya.no, mwilbur, nikita_tt, smustgrave, quietone: AJAX pager doesn't work with exposed filter which has a default value
parent 08f6d675
Branches
Tags
42 merge requests!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3546refactored dialog.pcss file,!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3502Issue #3335308: Confusing behavior with FormState::setFormState and FormState::setMethod,!3452Issue #3332701: Refactor Claro's tablesort-indicator stylesheet,!3451Issue #2410579: Allows setting the current language programmatically.,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3147Issue #3328457: Replace most substr($a, $i) where $i is negative with str_ends_with(),!3146Issue #3328456: Replace substr($a, 0, $i) with str_starts_with(),!3133core/modules/system/css/components/hidden.module.css,!31312878513-10.1.x,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2614Issue #2981326: Replace non-test usages of \Drupal::logger() with IoC injection,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!844Resolve #3036010 "Updaters",!673Issue #3214208: FinishResponseSubscriber could create duplicate headers,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
...@@ -29,9 +29,13 @@ ...@@ -29,9 +29,13 @@
for (let i = 0; i < pairs.length; i++) { for (let i = 0; i < pairs.length; i++) {
pair = pairs[i].split('='); pair = pairs[i].split('=');
// Ignore the 'q' path argument, if present. // Ignore the 'q' path argument, if present.
if (pair[0] !== 'q' && pair[1]) { if (pair[0] !== 'q') {
args[decodeURIComponent(pair[0].replace(/\+/g, ' '))] = if (pair[1]) {
decodeURIComponent(pair[1].replace(/\+/g, ' ')); args[decodeURIComponent(pair[0].replace(/\+/g, ' '))] =
decodeURIComponent(pair[1].replace(/\+/g, ' '));
} else {
args[decodeURIComponent(pair[0].replace(/\+/g, ' '))] = '';
}
} }
} }
return args; return args;
......
...@@ -46,7 +46,11 @@ protected function setUp(): void { ...@@ -46,7 +46,11 @@ protected function setUp(): void {
// Create a Content type and eleven test nodes. // Create a Content type and eleven test nodes.
$this->createContentType(['type' => 'page']); $this->createContentType(['type' => 'page']);
for ($i = 1; $i <= 11; $i++) { for ($i = 1; $i <= 11; $i++) {
$this->createNode(['title' => 'Node ' . $i . ' content', 'changed' => $i * 1000]); $fields = [
'title' => $i > 6 ? 'Node ' . $i . ' content' : 'Node ' . $i . ' content default_value',
'changed' => $i * 1000,
];
$this->createNode($fields);
} }
// Create a user privileged enough to view content. // Create a user privileged enough to view content.
...@@ -90,18 +94,18 @@ public function testBasicPagination() { ...@@ -90,18 +94,18 @@ public function testBasicPagination() {
/** @var \Behat\Mink\Element\NodeElement[] $rows */ /** @var \Behat\Mink\Element\NodeElement[] $rows */
$rows = $page->findAll('css', 'tbody tr'); $rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows); $this->assertCount(5, $rows);
$this->assertStringContainsString('Node 1 content', $rows[0]->getHtml()); $this->assertStringContainsString('Node 1 content default_value', $rows[0]->getHtml());
$this->clickLink('Go to page 2'); $this->clickLink('Go to page 2');
$session_assert->assertWaitOnAjaxRequest(); $session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr'); $rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows); $this->assertCount(5, $rows);
$this->assertStringContainsString('Node 6 content', $rows[0]->getHtml()); $this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
$link = $page->findLink('Go to page 3'); $link = $page->findLink('Go to page 3');
$this->assertNoDuplicateAssetsOnPage(); $this->assertNoDuplicateAssetsOnPage();
// Test that no unwanted parameters are added to the URL. // Test that no unwanted parameters are added to the URL.
$this->assertEquals('?status=All&type=All&langcode=All&items_per_page=5&order=changed&sort=asc&page=2', $link->getAttribute('href')); $this->assertEquals('?status=All&type=All&title=&langcode=All&items_per_page=5&order=changed&sort=asc&page=2', $link->getAttribute('href'));
$this->clickLink('Go to page 3'); $this->clickLink('Go to page 3');
$session_assert->assertWaitOnAjaxRequest(); $session_assert->assertWaitOnAjaxRequest();
...@@ -114,14 +118,14 @@ public function testBasicPagination() { ...@@ -114,14 +118,14 @@ public function testBasicPagination() {
$session_assert->assertWaitOnAjaxRequest(); $session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr'); $rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows); $this->assertCount(5, $rows);
$this->assertStringContainsString('Node 1 content', $rows[0]->getHtml()); $this->assertStringContainsString('Node 1 content default_value', $rows[0]->getHtml());
// Navigate using the 'next' link. // Navigate using the 'next' link.
$this->clickLink('Go to next page'); $this->clickLink('Go to next page');
$session_assert->assertWaitOnAjaxRequest(); $session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr'); $rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows); $this->assertCount(5, $rows);
$this->assertStringContainsString('Node 6 content', $rows[0]->getHtml()); $this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
// Navigate using the 'last' link. // Navigate using the 'last' link.
$this->clickLink('Go to last page'); $this->clickLink('Go to last page');
...@@ -135,6 +139,104 @@ public function testBasicPagination() { ...@@ -135,6 +139,104 @@ public function testBasicPagination() {
$this->assertEquals($expected_view_path, current($settings['views']['ajaxViews'])['view_path']); $this->assertEquals($expected_view_path, current($settings['views']['ajaxViews'])['view_path']);
} }
/**
* Tests if pagination via AJAX works for the filter with default value.
*/
public function testDefaultFilterPagination() {
// Add default value to the title filter.
$view = \Drupal::configFactory()->getEditable('views.view.test_content_ajax');
$display = $view->get('display');
$display['default']['display_options']['filters']['title']['value'] = 'default_value';
$view->set('display', $display);
$view->save();
// Visit the content page.
$this->drupalGet('test-content-ajax');
$session_assert = $this->assertSession();
$page = $this->getSession()->getPage();
$settings = $this->getDrupalSettings();
// Make sure that the view_path is set correctly.
$expected_view_path = '/test-content-ajax';
$this->assertEquals($expected_view_path, current($settings['views']['ajaxViews'])['view_path']);
// Set the number of items displayed per page to 5 using the exposed pager.
$page->selectFieldOption('edit-items-per-page', 5);
$page->pressButton('Filter');
$session_assert->assertWaitOnAjaxRequest();
// Change 'Updated' sorting from descending to ascending.
$page->clickLink('Updated');
$session_assert->assertWaitOnAjaxRequest();
// Use the pager by clicking on the links and test if we see the expected
// number of rows on each page. For easy targeting the titles of the pager
// links are used.
/** @var \Behat\Mink\Element\NodeElement[] $rows */
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 1 content default_value', $rows[0]->getHtml());
$this->clickLink('Go to page 2');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(1, $rows);
$this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
$link = $page->findLink('Go to page 1');
$this->assertNoDuplicateAssetsOnPage();
// Test that no unwanted parameters are added to the URL.
$this->assertEquals('?status=All&type=All&title=default_value&langcode=All&items_per_page=5&order=changed&sort=asc&page=0', $link->getAttribute('href'));
// Set the title filter to empty string using the exposed pager.
$page->fillField('title', '');
$page->pressButton('Filter');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 11 content', $rows[0]->getHtml());
// Navigate to the second page.
$this->clickLink('Go to page 2');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
$link = $page->findLink('Go to page 1');
$this->assertNoDuplicateAssetsOnPage();
// Test that no unwanted parameters are added to the URL.
$this->assertEquals('?status=All&type=All&title=&langcode=All&items_per_page=5&page=0', $link->getAttribute('href'));
// Navigate back to the first page.
$this->clickLink('Go to first page');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 11 content', $rows[0]->getHtml());
// Navigate using the 'next' link.
$this->clickLink('Go to next page');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
// Navigate using the 'last' link.
$this->clickLink('Go to last page');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(1, $rows);
$this->assertStringContainsString('Node 1 content default_value', $rows[0]->getHtml());
// Make sure the AJAX calls don't change the view_path.
$settings = $this->getDrupalSettings();
$this->assertEquals($expected_view_path, current($settings['views']['ajaxViews'])['view_path']);
}
/** /**
* Assert that assets are not loaded twice on a page. * Assert that assets are not loaded twice on a page.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment