Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
import { PaginationComponent } from './pagination.component';
import { PaginationSettings } from './pagination-settings';
describe('PaginationComponent', () => {
let component: PaginationComponent;
beforeEach(() => {
component = new PaginationComponent();
});
it('should be created', () => {
expect(component).toBeTruthy();
});
it('test ngOnInit method', () => {
component.ngOnInit();
expect(component.paginationSettings).toEqual(undefined);
expect(component.pages).toEqual(undefined);
expect(component.dropdownValue).toEqual([10, 15, 25]);
expect(component.notify).not.toEqual(undefined);
expect(component.notify).not.toEqual(null);
});
it('test setPage method', () => {
component.paginationSettings = new PaginationSettings();
expect(component.paginationSettings.currentPage).toEqual(1);
spyOn(component.notify, 'emit');
component.setPage(5);
expect(component.paginationSettings.currentPage).toEqual(5);
expect(component.notify.emit).toHaveBeenCalled();
});
it('test setPageSize method', () => {
component.paginationSettings = new PaginationSettings();
expect(component.paginationSettings.pageSize).toEqual(10);
component.paginationSettings.currentPage = 10;
spyOn(component.notify, 'emit');
component.setPageSize(5);
expect(component.paginationSettings.pageSize).toEqual(5);
expect(component.paginationSettings.currentPage).toEqual(1);
expect(component.notify.emit).toHaveBeenCalled();
});
it('test prevPage method: "component.paginationSettings.currentPage" is equal to 1', () => {
component.paginationSettings = new PaginationSettings();
expect(component.paginationSettings.currentPage).toEqual(1);
expect(component.paginationSettings.totalPages).toEqual(undefined);
spyOn(component.notify, 'emit');
component.prevPage();
expect(component.paginationSettings.currentPage).toEqual(1);
expect(component.paginationSettings.totalPages).toEqual(undefined);
expect(component.notify.emit).not.toHaveBeenCalled();
});
it('test nextPage method: "component.paginationSettings.currentPage" is greater than "component.paginationSettings.totalPages"', () => {
component.paginationSettings = new PaginationSettings();
component.paginationSettings.currentPage = 3;
component.paginationSettings.totalPages = 2;
spyOn(component.notify, 'emit');
component.nextPage();
// New behavior is to reset component.paginationSettings.currentPage
// and call emit to get back on track
expect(component.paginationSettings.currentPage).toEqual(2);
expect(component.paginationSettings.totalPages).toEqual(2);
expect(component.notify.emit).toHaveBeenCalled();
});
// Could use some tests of pageRange()
});