diff --git a/sveltejs/public/build/bundle.js b/sveltejs/public/build/bundle.js index 2a93e4b8b8538dea08efe7e3120d78c771fd9695..86164c2f79e64779de5091ca5fa7fb7410e9da42 100644 Binary files a/sveltejs/public/build/bundle.js and b/sveltejs/public/build/bundle.js differ diff --git a/sveltejs/public/build/bundle.js.map b/sveltejs/public/build/bundle.js.map index 37ecd7fc50b9a3e1fd7f6bff53eddac000c8be60..e2cb7317713d25d6380d7e3b939502e3c0dd10e5 100644 Binary files a/sveltejs/public/build/bundle.js.map and b/sveltejs/public/build/bundle.js.map differ diff --git a/sveltejs/src/QueryManager.js b/sveltejs/src/QueryManager.js index 5267398b5067102d6a2e5dac778b87decfad54c5..6ae9ff5f260c84062cc0d0868a2f61d6d7fed861 100644 --- a/sveltejs/src/QueryManager.js +++ b/sveltejs/src/QueryManager.js @@ -87,9 +87,6 @@ export default class { * @return {Promise<Object>} - The list of project objects. */ async load(filters, page, pageSize, sort, source) { - this.list = []; - this.count = 0; - // Encode the current filter values as URL parameters. const searchParams = new URLSearchParams(); Object.entries(filters).forEach(([key, value]) => { @@ -108,8 +105,11 @@ export default class { if (this.lastQueryParams === queryString) { return; } - + // We're going to query the backend, so reinitialize our internal state. + this.list = []; + this.count = 0; this.lastQueryParams = queryString; + const res = await fetch( `${BASE_URL}project-browser/data/project?${queryString}`, ); diff --git a/tests/modules/project_browser_test/src/Plugin/ProjectBrowserSource/ProjectBrowserTestMock.php b/tests/modules/project_browser_test/src/Plugin/ProjectBrowserSource/ProjectBrowserTestMock.php index ec7a7c0aa5faaf8217bfa99a2e8357c9fffe2878..9fd99b719c873039b8befc609c3a01be8d4e0168 100644 --- a/tests/modules/project_browser_test/src/Plugin/ProjectBrowserSource/ProjectBrowserTestMock.php +++ b/tests/modules/project_browser_test/src/Plugin/ProjectBrowserSource/ProjectBrowserTestMock.php @@ -263,6 +263,11 @@ final class ProjectBrowserTestMock extends ProjectBrowserSourceBase { * {@inheritdoc} */ public function getFilterDefinitions(): array { + $filters_to_define = $this->state->get('filters_to_define'); + if ($filters_to_define !== NULL) { + return $filters_to_define; + } + $filters = [ 'search' => new TextFilter('', $this->t('Search'), NULL), ]; @@ -295,17 +300,6 @@ final class ProjectBrowserTestMock extends ProjectBrowserSourceBase { $this->t('Development status'), NULL, ); - - $filters_to_define = $this->state->get('filters_to_define'); - if ($filters_to_define !== NULL) { - // Only keep those filters which needs to be defined according to - // $filters_to_define. - foreach ($filters as $filter_key => $filter_value) { - if (!in_array($filter_key, $filters_to_define, TRUE)) { - unset($filters[$filter_key]); - } - } - } return $filters; } diff --git a/tests/src/FunctionalJavascript/ProjectBrowserUiTest.php b/tests/src/FunctionalJavascript/ProjectBrowserUiTest.php index a2f3d3c1bbfcab7d08dfbd0e39b5fd0665a08078..e58480323b00bd5d89daafe92bdb471383f0013a 100644 --- a/tests/src/FunctionalJavascript/ProjectBrowserUiTest.php +++ b/tests/src/FunctionalJavascript/ProjectBrowserUiTest.php @@ -8,6 +8,7 @@ use Behat\Mink\Element\DocumentElement; use Behat\Mink\Element\NodeElement; use Drupal\Core\Extension\MissingDependencyException; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\project_browser\ProjectBrowser\Filter\TextFilter; // cspell:ignore coverageall doomer eggman quiznos statusactive statusmaintained // cspell:ignore vetica @@ -1159,6 +1160,18 @@ class ProjectBrowserUiTest extends WebDriverTestBase { // Click Clear Filters button and make sure search empty again. $this->pressWithWait('Clear filters', '25 Results'); $this->assertEquals($search_field->getValue(), ''); + + // Ensure that clearing filters will preserve the result count, even if + // all the initial filter values are falsy. + \Drupal::state()->set('filters_to_define', [ + 'search' => new TextFilter('', 'Search', NULL), + ]); + $this->getSession()->reload(); + $this->assertElementIsVisible('named', ['button', 'Clear filters'])->press(); + // Ensure that the result count remains even after we wait a sec for + // Svelte to re-render. + sleep(1); + $this->assertElementIsVisible('css', '.pb-search-results'); } /** diff --git a/tests/src/FunctionalJavascript/ProjectBrowserUiTestJsonApi.php b/tests/src/FunctionalJavascript/ProjectBrowserUiTestJsonApi.php index e262762c655a50e707f3dfaa821fc1f79c8cfe81..4a28a01c24602e7f21e6a6775cab8b8979d43373 100644 --- a/tests/src/FunctionalJavascript/ProjectBrowserUiTestJsonApi.php +++ b/tests/src/FunctionalJavascript/ProjectBrowserUiTestJsonApi.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Drupal\Tests\project_browser\FunctionalJavascript; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\project_browser\ProjectBrowser\Filter\BooleanFilter; // cspell:ignore cashpresso Adnuntius Paypage Redsys ZURB Superfish TMGMT Toki // cspell:ignore Webtheme Pitchburgh Gotem Webform Bsecurity Bstatus Cardless @@ -343,11 +344,23 @@ class ProjectBrowserUiTestJsonApi extends WebDriverTestBase { $this->drupalGet('admin/modules/browse/project_browser_test_mock'); $this->assertNull($assert_session->waitForElementVisible('css', '.search__form-filters-container')); - // Set the names of filters which will be defined by the test mock. + // Set the filters which will be defined by the test mock. // @see \Drupal\project_browser_test\Plugin\ProjectBrowserSource\ProjectBrowserTestMock::getFilterDefinitions() \Drupal::state()->set('filters_to_define', [ - 'maintenance_status', - 'security_advisory_coverage', + 'maintenance_status' => new BooleanFilter( + TRUE, + 'Show actively maintained projects', + 'Show all', + 'Maintenance status', + NULL, + ), + 'security_advisory_coverage' => new BooleanFilter( + TRUE, + 'Show projects covered by a security policy', + 'Show all', + 'Security advisory coverage', + NULL, + ), ]); $this->getSession()->reload(); // Drupal.org test mock defines only two filters (actively maintained filter