Skip to content

Commit

Permalink
fix(Paginator): simple mode no longer shows total count
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #2031
  • Loading branch information
benjamincharity committed Feb 18, 2020
1 parent 8fd1294 commit e8421d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
19 changes: 18 additions & 1 deletion terminus-ui/paginator/src/paginator.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ describe(`TsPaginatorComponent`, function() {

const titleEl = fixture.debugElement.query(By.css('.qa-paginator-current-page-menu .c-button__content')).nativeElement as HTMLElement;
expect(titleEl.textContent).toContain('1 - 20 of 100');

});

test(`should be hidden when set`, () => {
Expand Down Expand Up @@ -342,6 +341,24 @@ describe(`TsPaginatorComponent`, function() {

});

describe(`simple mode`, () => {
let fixture: ComponentFixture<TestComponents.SimpleMode>;
let hostComponent: TestComponents.SimpleMode;

beforeEach(() => {
fixture = createComponent(TestComponents.SimpleMode);
hostComponent = fixture.componentInstance;
fixture.detectChanges();
});

test(`should output the correct, shortened, current page message`, fakeAsync(() => {
tick(1000);
fixture.detectChanges();
const titleEl = fixture.debugElement.query(By.css('.c-paginator__current-page')).nativeElement as HTMLElement;
expect(titleEl.textContent).toContain('1 - 10');
}));
});

});


Expand Down
4 changes: 4 additions & 0 deletions terminus-ui/paginator/src/paginator.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ export class TsPaginatorComponent implements OnChanges, AfterViewInit {
const destinationIsValid: boolean = destinationPage >= this.firstPageIndex && destinationPage <= pages.length;
const notAlreadyOnPage: boolean = destinationPage !== currentPage;

// istanbul ignore else
if (destinationIsValid && notAlreadyOnPage) {
const foundPage: TsPaginatorMenuItem | undefined = pages.find((page: TsPaginatorMenuItem): boolean => page.value === destinationPage);

Expand Down Expand Up @@ -492,6 +493,9 @@ export class TsPaginatorComponent implements OnChanges, AfterViewInit {
}

// '1 - 10 of 243'
if (this.isSimpleMode) {
return `${foundPage.name}`;
}
return `${foundPage.name} of ${totalRecords}`;
}

Expand Down
2 changes: 1 addition & 1 deletion terminus-ui/paginator/testing/src/test-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class ZeroBased {
`,
})
export class SimpleMode {
public isSimple = false;
public isSimple = true;
public totalRecords = 100;
}

Expand Down

0 comments on commit e8421d5

Please sign in to comment.