From b00916ac177a11c4f2fbd36ea374f06750839cbc Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Tue, 30 Oct 2018 14:17:23 -0700 Subject: [PATCH] Test coverage for resetPagination --- .../templates/components/list-pagination.hbs | 8 ++--- .../components/list-pagination/list-pager.hbs | 2 +- ui/tests/acceptance/jobs-list-test.js | 18 ++++++++++++ ui/tests/pages/jobs/list.js | 3 ++ ui/tests/unit/mixins/searchable-test.js | 29 +++++++++++++++++++ 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/ui/app/templates/components/list-pagination.hbs b/ui/app/templates/components/list-pagination.hbs index bb86e606a..e42c7fc62 100644 --- a/ui/app/templates/components/list-pagination.hbs +++ b/ui/app/templates/components/list-pagination.hbs @@ -1,9 +1,9 @@ {{#if source.length}} {{yield (hash - first=(component "list-pagination/list-pager" page=1 visible=(not (eq page 1))) - prev=(component "list-pagination/list-pager" page=(dec page) visible=(not (eq page 1))) - next=(component "list-pagination/list-pager" page=(inc page) visible=(not (eq page lastPage))) - last=(component "list-pagination/list-pager" page=lastPage visible=(not (eq page lastPage))) + first=(component "list-pagination/list-pager" test="first" page=1 visible=(not (eq page 1))) + prev=(component "list-pagination/list-pager" test="prev" page=(dec page) visible=(not (eq page 1))) + next=(component "list-pagination/list-pager" test="next" page=(inc page) visible=(not (eq page lastPage))) + last=(component "list-pagination/list-pager" test="last" page=lastPage visible=(not (eq page lastPage))) pageLinks=pageLinks currentPage=page totalPages=lastPage diff --git a/ui/app/templates/components/list-pagination/list-pager.hbs b/ui/app/templates/components/list-pagination/list-pager.hbs index cc3437927..4cf46f528 100644 --- a/ui/app/templates/components/list-pagination/list-pager.hbs +++ b/ui/app/templates/components/list-pagination/list-pager.hbs @@ -1,5 +1,5 @@ {{#if visible}} - {{#link-to (query-params currentPage=page) class=attrs.class}} + {{#link-to (query-params currentPage=page) class=attrs.class data-test-pager=test}} {{yield}} {{/link-to}} {{/if}} diff --git a/ui/tests/acceptance/jobs-list-test.js b/ui/tests/acceptance/jobs-list-test.js index 69c9eed71..f8b8bc92a 100644 --- a/ui/tests/acceptance/jobs-list-test.js +++ b/ui/tests/acceptance/jobs-list-test.js @@ -106,6 +106,24 @@ test('when there are jobs, but no matches for a search result, there is an empty }); }); +test('searching resets the current page', function(assert) { + server.createList('job', JobsList.pageSize + 1, { createAllocations: false }); + JobsList.visit(); + + andThen(() => { + JobsList.nextPage(); + }); + + andThen(() => { + assert.equal(currentURL(), '/jobs?page=2', 'Page query param captures page=2'); + JobsList.search('foobar'); + }); + + andThen(() => { + assert.equal(currentURL(), '/jobs?search=foobar', 'No page query param'); + }); +}); + test('when the namespace query param is set, only matching jobs are shown and the namespace value is forwarded to app state', function(assert) { server.createList('namespace', 2); const job1 = server.create('job', { namespaceId: server.db.namespaces[0].id }); diff --git a/ui/tests/pages/jobs/list.js b/ui/tests/pages/jobs/list.js index 252b92efc..37ebd6746 100644 --- a/ui/tests/pages/jobs/list.js +++ b/ui/tests/pages/jobs/list.js @@ -31,6 +31,9 @@ export default create({ clickName: clickable('[data-test-job-name] a'), }), + nextPage: clickable('[data-test-pager="next"]'), + prevPage: clickable('[data-test-pager="prev"]'), + isEmpty: isPresent('[data-test-empty-jobs-list]'), emptyState: { headline: text('[data-test-empty-jobs-list-headline]'), diff --git a/ui/tests/unit/mixins/searchable-test.js b/ui/tests/unit/mixins/searchable-test.js index 10396e749..00b749d94 100644 --- a/ui/tests/unit/mixins/searchable-test.js +++ b/ui/tests/unit/mixins/searchable-test.js @@ -176,3 +176,32 @@ test('each search mode has independent search props', function(assert) { 'Canada is not matched by the regex because only id is looked at for regex search' ); }); + +test('the resetPagination method is a no-op', function(assert) { + const subject = this.subject(); + assert.strictEqual(subject.get('currentPage'), undefined, 'No currentPage value set'); + subject.resetPagination(); + assert.strictEqual(subject.get('currentPage'), undefined, 'Still no currentPage value set'); +}); + +moduleFor('mixin:searchable', 'Unit | Mixin | Searchable (with pagination)', { + subject() { + const SearchablePaginatedObject = EmberObject.extend(Searchable, { + source: null, + searchProps: computed(() => ['id', 'name']), + listToSearch: alias('source'), + currentPage: 1, + }); + + this.register('test-container:searchable-paginated-object', SearchablePaginatedObject); + return getOwner(this).lookup('test-container:searchable-paginated-object'); + }, +}); + +test('the resetPagination method sets the currentPage to 1', function(assert) { + const subject = this.subject(); + subject.set('currentPage', 5); + assert.equal(subject.get('currentPage'), 5, 'Current page is something other than 1'); + subject.resetPagination(); + assert.equal(subject.get('currentPage'), 1, 'Current page gets reset to 1'); +});