Skip to content

Commit

Permalink
Keep the search box around when a search yields no results
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Jul 30, 2018
1 parent 495a5a7 commit 0e76c5b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ui/app/templates/jobs/job/allocations.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{#gutter-menu class="page-body" onNamespaceChange=(action "gotoJobs")}}
{{partial "jobs/job/subnav"}}
<section class="section">
{{#if sortedAllocations.length}}
{{#if allocations.length}}
<div class="content">
<div>
{{search-box
Expand Down
39 changes: 32 additions & 7 deletions ui/tests/acceptance/job-allocations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import Allocations from 'nomad-ui/tests/pages/jobs/job/allocations';
let job;
let allocations;

const makeSearchAllocations = server => {
Array(10)
.fill(null)
.map((_, index) => {
server.create('allocation', {
id: index < 5 ? `ffffff-dddddd-${index}` : `111111-222222-${index}`,
});
});
};

moduleForAcceptance('Acceptance | job allocations', {
beforeEach() {
server.create('node');
Expand Down Expand Up @@ -64,13 +74,7 @@ test('allocations table is sortable', function(assert) {
});

test('allocations table is searchable', function(assert) {
Array(10)
.fill(null)
.map((_, index) => {
server.create('allocation', {
id: index < 5 ? `ffffff-dddddd-${index}` : `111111-222222-${index}`,
});
});
makeSearchAllocations(server);

allocations = server.schema.allocations.where({ jobId: job.id }).models;
Allocations.visit({ id: job.id });
Expand All @@ -83,3 +87,24 @@ test('allocations table is searchable', function(assert) {
assert.equal(Allocations.allocations.length, 5, 'List is filtered by search term');
});
});

test('when a search yields no results, the search box remains', function(assert) {
makeSearchAllocations(server);

allocations = server.schema.allocations.where({ jobId: job.id }).models;
Allocations.visit({ id: job.id });

andThen(() => {
Allocations.search('^nothing will ever match this long regex$');
});

andThen(() => {
assert.equal(
Allocations.emptyState.headline,
'No Matches',
'List is empty and the empty state is about search'
);

assert.ok(Allocations.hasSearchBox, 'Search box is still shown');
});
});
8 changes: 8 additions & 0 deletions ui/tests/pages/jobs/job/allocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
create,
collection,
fillable,
isPresent,
text,
visitable,
} from 'ember-cli-page-object';

Expand All @@ -14,10 +16,16 @@ export default create({

pageSize: 25,

hasSearchBox: isPresent('[data-test-allocations-search]'),
search: fillable('[data-test-allocations-search] input'),

...allocations(),

isEmpty: isPresent('[data-test-empty-allocations-list]'),
emptyState: {
headline: text('[data-test-empty-allocations-list-headline]'),
},

sortOptions: collection('[data-test-sort-by]', {
id: attribute('data-test-sort-by'),
sort: clickable(),
Expand Down

0 comments on commit 0e76c5b

Please sign in to comment.