Skip to content

Commit 79069d5

Browse files
author
Patricio Albizu
committed
fix: adding UT
1 parent 77bd6b5 commit 79069d5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

projects/components/src/paginator/paginator.component.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('Paginator component', () => {
3737
});
3838
});
3939

40-
test('should have the correct number of pages for the provided page size and total items', () => {
40+
test('should hide the pager when totalItems is less than the pageSizeOptions options', () => {
4141
const spectator = createHost(`<ht-paginator [totalItems]="totalItems"></ht-paginator>`, {
4242
hostProps: {
4343
totalItems: totalResults
@@ -110,4 +110,15 @@ describe('Paginator component', () => {
110110
expect(spectator.query(LabelComponent)?.label).toEqual('1-50 of 50');
111111
expect(spectator.component.hasNextPage()).toBe(false);
112112
});
113+
114+
test('should navigate to first page when totalItems is changed', () => {
115+
const spectator = createHost(`<ht-paginator [totalItems]="totalItems"></ht-paginator>`, {
116+
hostProps: {
117+
totalItems: 20
118+
}
119+
});
120+
121+
const paginator = spectator.query('.paginator')!;
122+
expect(paginator).toBeUndefined();
123+
});
113124
});

projects/components/src/paginator/paginator.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { PaginationProvider } from './paginator-api';
1919
styleUrls: ['./paginator.component.scss'],
2020
changeDetection: ChangeDetectionStrategy.OnPush,
2121
template: `
22-
<div class="paginator" *ngIf="this.totalItems && this.totalItems > this.pageSize">
22+
<div class="paginator" *ngIf="this.totalItems && this.totalItems > this.pageSizeOptions[0]">
2323
<ht-label
2424
class="label"
2525
label="{{ this.firstItemNumberForPage() }}-{{ this.lastItemNumberForPage() }} of {{ this.totalItems }}"
@@ -59,7 +59,7 @@ import { PaginationProvider } from './paginator-api';
5959
})
6060
export class PaginatorComponent implements OnChanges, PaginationProvider {
6161
@Input()
62-
public pageSizeOptions: number[] = [25, 50, 100];
62+
public pageSizeOptions: number[] = [];
6363

6464
@Input()
6565
public set pageIndex(pageIndex: number) {

0 commit comments

Comments
 (0)