From d1ecb9282740116c567d0220e658e58d38f4c8d6 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Fri, 19 Apr 2024 13:45:51 -0400 Subject: [PATCH] jobs list updateFilter initial test --- ui/app/components/job-search-box.hbs | 6 ++++ ui/app/components/job-search-box.js | 5 +++ ui/app/controllers/jobs/index.js | 2 +- ui/tests/acceptance/jobs-list-test.js | 32 +++++++++++++++++++ .../components/job-search-box-test.js | 8 +++++ 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/ui/app/components/job-search-box.hbs b/ui/app/components/job-search-box.hbs index f59f308cea1..dca147f5c3d 100644 --- a/ui/app/components/job-search-box.hbs +++ b/ui/app/components/job-search-box.hbs @@ -1,3 +1,8 @@ +{{! + Copyright (c) HashiCorp, Inc. + SPDX-License-Identifier: BUSL-1.1 +~}} + diff --git a/ui/app/components/job-search-box.js b/ui/app/components/job-search-box.js index 290ba1429ad..292735e2a08 100644 --- a/ui/app/components/job-search-box.js +++ b/ui/app/components/job-search-box.js @@ -1,3 +1,8 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: BUSL-1.1 + */ + // @ts-check import Component from '@glimmer/component'; diff --git a/ui/app/controllers/jobs/index.js b/ui/app/controllers/jobs/index.js index 60261e6bf11..c9fe19150a1 100644 --- a/ui/app/controllers/jobs/index.js +++ b/ui/app/controllers/jobs/index.js @@ -384,7 +384,7 @@ export default class JobsIndexController extends Controller { this.filter = newFilter; } else { // If it's a string without a filter operator, assume the user is trying to look up a job name - this.filter = `Name contains "${newFilter}"`; + this.filter = `Name contains ${newFilter}`; } } diff --git a/ui/tests/acceptance/jobs-list-test.js b/ui/tests/acceptance/jobs-list-test.js index 02aa6d52ebc..b7534dbb228 100644 --- a/ui/tests/acceptance/jobs-list-test.js +++ b/ui/tests/acceptance/jobs-list-test.js @@ -1190,6 +1190,38 @@ module('Acceptance | jobs list', function (hooks) { }); }); }); + + module('Searching and Filtering', function () { + module('Search', function () { + test('Searching reasons about whether you intended a job name or a filter expression', async function (assert) { + localStorage.setItem('nomadPageSize', '10'); + createJobs(server, 10); + await JobsList.visit(); + + await JobsList.search.fillIn('something-that-surely-doesnt-exist'); + // check to see that we fired off a request; check handledRequests to find one with a ?filter in it + assert.ok( + server.pretender.handledRequests.find((req) => + req.url.includes( + '?filter=Name%20contains%20something-that-surely-doesnt-exist' + ) + ), + 'A request was made with a filter query param that assumed job name' + ); + + await JobsList.search.fillIn('Namespace == ns-2'); + + assert.ok( + server.pretender.handledRequests.find((req) => + req.url.includes('?filter=Namespace%20==%20ns-2') + ), + 'A request was made with a filter query param for a filter expression as typed' + ); + + localStorage.removeItem('nomadPageSize'); + }); + }); + }); }); /** diff --git a/ui/tests/integration/components/job-search-box-test.js b/ui/tests/integration/components/job-search-box-test.js index 4082d2ffecc..6b4a38112e6 100644 --- a/ui/tests/integration/components/job-search-box-test.js +++ b/ui/tests/integration/components/job-search-box-test.js @@ -1,8 +1,14 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: BUSL-1.1 + */ + import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import { render } from '@ember/test-helpers'; import { hbs } from 'ember-cli-htmlbars'; import { fillIn, find, triggerEvent } from '@ember/test-helpers'; +import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit'; const DEBOUNCE_MS = 500; @@ -19,6 +25,8 @@ module('Integration | Component | job-search-box', function (hooks) { }); await render(hbs``); + await componentA11yAudit(this.element, assert); + const element = find('input'); await fillIn('input', 'test1'); assert.equal(message, 'test1', 'Initial typing');