From 3206e9706471c8e6296d1e946ccedc321788ae4e Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Mon, 9 Nov 2020 11:47:54 -0600 Subject: [PATCH] =?UTF-8?q?Add=20check=20that=20active=20summary=20isn?= =?UTF-8?q?=E2=80=99t=20filtered=20out?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/app/controllers/optimize.js | 14 ++++++++++++++ ui/app/templates/optimize.hbs | 1 + ui/tests/acceptance/optimize-test.js | 18 +++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ui/app/controllers/optimize.js b/ui/app/controllers/optimize.js index 1fd4d9960..e96d5a63f 100644 --- a/ui/app/controllers/optimize.js +++ b/ui/app/controllers/optimize.js @@ -179,6 +179,20 @@ export default class OptimizeController extends Controller { @action setFacetQueryParam(queryParam, selection) { this[queryParam] = serialize(selection); + this.ensureActiveSummaryIsNotExcluded(); + } + + @action + ensureActiveSummaryIsNotExcluded() { + scheduleOnce('actions', () => { + if (!this.filteredSummaries.includes(this.activeRecommendationSummary)) { + const firstFilteredSummary = this.filteredSummaries.objectAt(0); + + if (firstFilteredSummary) { + this.transitionToSummary(firstFilteredSummary); + } + } + }); } } diff --git a/ui/app/templates/optimize.hbs b/ui/app/templates/optimize.hbs index a08e92d4a..ddd89206b 100644 --- a/ui/app/templates/optimize.hbs +++ b/ui/app/templates/optimize.hbs @@ -6,6 +6,7 @@ {{#if @model}} {{/if}} diff --git a/ui/tests/acceptance/optimize-test.js b/ui/tests/acceptance/optimize-test.js index 3b5d90334..b927bcad8 100644 --- a/ui/tests/acceptance/optimize-test.js +++ b/ui/tests/acceptance/optimize-test.js @@ -366,7 +366,18 @@ module('Acceptance | optimize search and facets', function(hooks) { window.localStorage.nomadTokenSecret = managementToken.secretId; }); - test('search field narrows summary table results and displays a no matches message when there are none', async function(assert) { + test('search field narrows summary table results, changes the active summary if it no longer matches, and displays a no matches message when there are none', async function(assert) { + server.createList('job', 1, { + name: 'zzzzzz', + createRecommendations: true, + groupsCount: 1, + groupTaskCount: 6, + }); + + // Ensure this job’s recommendations are sorted to the top of the table + const futureSubmitTime = (Date.now() + 10000) * 1000000; + server.db.recommendations.update({ submitTime: futureSubmitTime }); + server.createList('job', 1, { name: 'oooooo', createRecommendations: true, @@ -383,6 +394,8 @@ module('Acceptance | optimize search and facets', function(hooks) { await Optimize.visit(); + assert.equal(Optimize.card.slug.jobName, 'zzzzzz'); + assert.equal(Optimize.search.placeholder, `Search ${Optimize.recommendationSummaries.length} recommendations...`); await Optimize.search.fillIn('ooo'); @@ -390,6 +403,9 @@ module('Acceptance | optimize search and facets', function(hooks) { assert.equal(Optimize.recommendationSummaries.length, 2); assert.ok(Optimize.recommendationSummaries[0].slug.startsWith('oooooo')); + assert.equal(Optimize.card.slug.jobName, 'oooooo'); + assert.ok(currentURL().includes('oooooo')); + await Optimize.search.fillIn('qqq'); assert.notOk(Optimize.card.isPresent);