mirror of
https://github.com/kemko/nomad.git
synced 2026-01-08 19:35:41 +03:00
Test coverage for resetPagination
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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]'),
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user