Skip to content

Commit

Permalink
jobs list updateFilter initial test
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Apr 19, 2024
1 parent db5d382 commit d1ecb92
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ui/app/components/job-search-box.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: BUSL-1.1
~}}

<Hds::Form::TextInput::Base
@type="search"
@value=""
Expand All @@ -11,4 +16,5 @@
pattern=(array "Shift+F")
action=(action this.focus)
}}
data-test-job-search
/>
5 changes: 5 additions & 0 deletions ui/app/components/job-search-box.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

// @ts-check

import Component from '@glimmer/component';
Expand Down
2 changes: 1 addition & 1 deletion ui/app/controllers/jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
}

Expand Down
32 changes: 32 additions & 0 deletions ui/tests/acceptance/jobs-list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
});

/**
Expand Down
8 changes: 8 additions & 0 deletions ui/tests/integration/components/job-search-box-test.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -19,6 +25,8 @@ module('Integration | Component | job-search-box', function (hooks) {
});

await render(hbs`<JobSearchBox @onFilterChange={{this.externalAction}} />`);
await componentA11yAudit(this.element, assert);

const element = find('input');
await fillIn('input', 'test1');
assert.equal(message, 'test1', 'Initial typing');
Expand Down

0 comments on commit d1ecb92

Please sign in to comment.