-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pager-tests): added tests for pager component (#1279)
- Loading branch information
1 parent
d813946
commit 3970521
Showing
1 changed file
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; | ||
import { PagerComponent } from '../pagination/pager.component'; | ||
|
||
describe('Component: Pager:', () => { | ||
|
||
let fixture: ComponentFixture<PagerComponent>; | ||
let context: any; | ||
let element: any; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [PagerComponent] | ||
}); | ||
fixture = TestBed.createComponent(PagerComponent); | ||
context = fixture.debugElement.componentInstance; | ||
|
||
element = fixture.nativeElement; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('checking of working with default values', () => { | ||
const listItems = element.querySelectorAll('li'); | ||
|
||
expect(listItems.length).toEqual(2); | ||
expect(listItems[0].classList).toContain('disabled'); | ||
expect(listItems[1].classList).toContain('disabled'); | ||
|
||
const links = element.querySelectorAll('a'); | ||
|
||
expect(links[0].innerHTML).toEqual('Previous'); | ||
expect(links[1].innerHTML).toEqual('Next'); | ||
|
||
expect(context._totalPages).toEqual(1); | ||
}); | ||
|
||
it('checking of working with custom values', () => { | ||
context.totalItems = 10; | ||
context.itemsPerPage = 4; | ||
context.previousText = 'Prev'; | ||
context.nextText = 'New next'; | ||
context.pageBtnClass = 'btn'; | ||
context.align = true; | ||
|
||
context.ngOnInit(); | ||
fixture.detectChanges(); | ||
|
||
const listItems = element.querySelectorAll('li'); | ||
|
||
expect(listItems[0].classList).toContain('disabled'); | ||
expect(listItems[0].classList).toContain('pull-right'); | ||
expect(listItems[0].classList).toContain('previous'); | ||
expect(listItems[0].classList).toContain('btn'); | ||
expect(listItems[1].classList).not.toContain('disabled'); | ||
expect(listItems[1].classList).toContain('pull-right'); | ||
expect(listItems[1].classList).toContain('next'); | ||
expect(listItems[1].classList).toContain('btn'); | ||
|
||
const links = element.querySelectorAll('a'); | ||
|
||
expect(links[0].innerHTML).toEqual('Prev'); | ||
expect(links[1].innerHTML).toEqual('New next'); | ||
|
||
expect(context._totalPages).toEqual(3); | ||
}); | ||
|
||
it('check NgModel through click', fakeAsync(() => { | ||
|
||
context.totalItems = 10; | ||
context.itemsPerPage = 4; | ||
fixture.detectChanges(); | ||
|
||
const links = element.querySelectorAll('a'); | ||
const listItems = element.querySelectorAll('li'); | ||
|
||
expect(listItems[0].classList).toContain('disabled'); | ||
expect(listItems[1].classList).not.toContain('disabled'); | ||
expect(context._page).toEqual(1); | ||
|
||
links[1].click(); | ||
tick(200); | ||
fixture.detectChanges(); | ||
|
||
expect(listItems[0].classList).not.toContain('disabled'); | ||
expect(listItems[1].classList).not.toContain('disabled'); | ||
expect(context._page).toEqual(2); | ||
|
||
links[1].click(); | ||
tick(200); | ||
fixture.detectChanges(); | ||
|
||
expect(listItems[0].classList).not.toContain('disabled'); | ||
expect(listItems[1].classList).toContain('disabled'); | ||
expect(context._page).toEqual(3); | ||
|
||
expect(context._totalPages).toEqual(3); | ||
})); | ||
|
||
it('check NgModel through event', () => { | ||
|
||
context.totalItems = 10; | ||
context.itemsPerPage = 4; | ||
fixture.detectChanges(); | ||
|
||
const listItems = element.querySelectorAll('li'); | ||
|
||
expect(listItems[0].classList).toContain('disabled'); | ||
expect(listItems[1].classList).not.toContain('disabled'); | ||
|
||
context.page = 2; | ||
fixture.detectChanges(); | ||
element.dispatchEvent(new Event('input')); | ||
fixture.detectChanges(); | ||
|
||
fixture.whenStable().then(() => { | ||
fixture.detectChanges(); | ||
expect(listItems[0].classList).not.toContain('disabled'); | ||
expect(listItems[1].classList).not.toContain('disabled'); | ||
expect(context._page).toEqual(2); | ||
|
||
expect(context._totalPages).toEqual(3); | ||
}); | ||
}); | ||
}); |