Skip to content

refactor(material/paginator): refactor tests for paginator texts #23516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 61 additions & 41 deletions src/material-experimental/mdc-paginator/paginator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,72 @@ describe('MDC-based MatPaginator', () => {
}

describe('with the default internationalization provider', () => {
it('should show the right range text', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-mdc-paginator-range-label');

// View second page of list of 100, each page contains 10 items.
component.length = 100;
component.pageSize = 10;
component.pageIndex = 1;
fixture.detectChanges();
expect(rangeElement.innerText.trim()).toBe('11 – 20 of 100');
describe('showing the right range text', () => {
it('should show second page of list of 100, each page contains 10 items', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-mdc-paginator-range-label');
component.length = 100;
component.pageSize = 10;
component.pageIndex = 1;
fixture.detectChanges();
expect(rangeElement.textContent!.trim()).toBe('11 – 20 of 100');
});

// View third page of list of 200, each page contains 20 items.
component.length = 200;
component.pageSize = 20;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.innerText.trim()).toBe('41 – 60 of 200');
it('should show third page of list of 200, each page contains 20 items', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-mdc-paginator-range-label');
component.length = 200;
component.pageSize = 20;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.textContent!.trim()).toBe('41 – 60 of 200');
});

// View first page of list of 0, each page contains 5 items.
component.length = 0;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.innerText.trim()).toBe('0 of 0');
it('should show first page of list of 0, each page contains 5 items', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-mdc-paginator-range-label');
component.length = 0;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.textContent!.trim()).toBe('0 of 0');
});

// View third page of list of 12, each page contains 5 items.
component.length = 12;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.innerText.trim()).toBe('11 – 12 of 12');
it('should show third page of list of 12, each page contains 5 items', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-mdc-paginator-range-label');
component.length = 12;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.textContent!.trim()).toBe('11 – 12 of 12');
});

// View third page of list of 10, each page contains 5 items.
component.length = 10;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.innerText.trim()).toBe('11 – 15 of 10');
it('should show third page of list of 10, each page contains 5 items', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-mdc-paginator-range-label');
component.length = 10;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.textContent!.trim()).toBe('11 – 15 of 10');
});

// View third page of list of -5, each page contains 5 items.
component.length = -5;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.innerText.trim()).toBe('11 – 15 of 0');
it('should show third page of list of -5, each page contains 5 items', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-mdc-paginator-range-label');
component.length = -5;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.textContent!.trim()).toBe('11 – 15 of 0');
});
});

it('should show right aria-labels for select and buttons', () => {
Expand Down
118 changes: 69 additions & 49 deletions src/material/paginator/paginator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {ComponentFixture, TestBed, tick, fakeAsync} from '@angular/core/testing';
import {Component, ViewChild, Type, Provider} from '@angular/core';
import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {Component, Provider, Type, ViewChild} from '@angular/core';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {dispatchMouseEvent} from '../../cdk/testing/private';
import {ThemePalette} from '@angular/material/core';
import {MatSelect} from '@angular/material/select';
import {By} from '@angular/platform-browser';
import {MatPaginatorModule, MatPaginator, MatPaginatorIntl} from './index';
import {MatPaginator, MatPaginatorIntl, MatPaginatorModule} from './index';
import {MAT_PAGINATOR_DEFAULT_OPTIONS, MatPaginatorDefaultOptions} from './paginator';


Expand All @@ -23,52 +23,72 @@ describe('MatPaginator', () => {
}

describe('with the default internationalization provider', () => {
it('should show the right range text', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-paginator-range-label');

// View second page of list of 100, each page contains 10 items.
component.length = 100;
component.pageSize = 10;
component.pageIndex = 1;
fixture.detectChanges();
expect(rangeElement.innerText.trim()).toBe('11 – 20 of 100');

// View third page of list of 200, each page contains 20 items.
component.length = 200;
component.pageSize = 20;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.innerText.trim()).toBe('41 – 60 of 200');

// View first page of list of 0, each page contains 5 items.
component.length = 0;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.innerText.trim()).toBe('0 of 0');

// View third page of list of 12, each page contains 5 items.
component.length = 12;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.innerText.trim()).toBe('11 – 12 of 12');

// View third page of list of 10, each page contains 5 items.
component.length = 10;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.innerText.trim()).toBe('11 – 15 of 10');

// View third page of list of -5, each page contains 5 items.
component.length = -5;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.innerText.trim()).toBe('11 – 15 of 0');
describe('showing the right range text', () => {
it('should show second page of list of 100, each page contains 10 items', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-paginator-range-label');
component.length = 100;
component.pageSize = 10;
component.pageIndex = 1;
fixture.detectChanges();
expect(rangeElement.textContent!.trim()).toBe('11 – 20 of 100');
});

it('should show third page of list of 200, each page contains 20 items', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-paginator-range-label');
component.length = 200;
component.pageSize = 20;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.textContent!.trim()).toBe('41 – 60 of 200');
});

it('should show first page of list of 0, each page contains 5 items', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-paginator-range-label');
component.length = 0;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.textContent!.trim()).toBe('0 of 0');
});

it('should show third page of list of 12, each page contains 5 items', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-paginator-range-label');
component.length = 12;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.textContent!.trim()).toBe('11 – 12 of 12');
});

it('should show third page of list of 10, each page contains 5 items', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-paginator-range-label');
component.length = 10;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.textContent!.trim()).toBe('11 – 15 of 10');
});

it('should show third page of list of -5, each page contains 5 items', () => {
const fixture = createComponent(MatPaginatorApp);
const component = fixture.componentInstance;
const rangeElement = fixture.nativeElement.querySelector('.mat-paginator-range-label');
component.length = -5;
component.pageSize = 5;
component.pageIndex = 2;
fixture.detectChanges();
expect(rangeElement.textContent!.trim()).toBe('11 – 15 of 0');
});
});

it('should show right aria-labels for select and buttons', () => {
Expand Down