This repository was archived by the owner on Feb 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 490
Add unit tests to demo project #1579
Merged
Merged
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b9103bc
fix: tests can't find DOM types
shanmukhateja bd280d2
feat: update AppComponent tests
shanmukhateja 1733d64
feat: Add tests for zero-config component
shanmukhateja ce29c29
feat: add tests for with-options component
shanmukhateja aced589
feat: tests for with-ajax component
shanmukhateja 8abac6a
WIP feat: server-side-angular-way test
shanmukhateja 6c3c243
feat(demo): Upgrade demo project to Angular v12
shanmukhateja 913f31d
fix(tests): fix up server-side-angular-way, with-ajax
shanmukhateja 7f68294
fix(tests): tsconfig.spec.json bug fixes
shanmukhateja 42ff9c0
feat: tests for angular-way component
shanmukhateja 7e23fcb
feat: add tests for custom-range-search component
shanmukhateja 9299f1d
feat: add tests for dt-instance component
shanmukhateja d434181
feat: add tests for individual column filter component
shanmukhateja 3d49d39
feat: add tests for load-dt-options-with-promise component
shanmukhateja 616e810
feat: add tests for multiple-tables component
shanmukhateja f586d1f
feat: add tests for rerender component
shanmukhateja 67e05cf
feat(demo): add unit tests for router-link.component
shanmukhateja 35c7632
feat(demo): add unit tests for row-click-event component
shanmukhateja b633d5b
feat(demo): add unit tests for using-ng-pipe component
shanmukhateja 9fd5e38
feat: UsingNgTemplateRef update
shanmukhateja d6fbd0b
fix(tests): remove redunant tslint comment
shanmukhateja 195209a
fix(tests): update comment in ng-template-ref component
shanmukhateja e880fd7
fix: remove tslint comment in spec files
shanmukhateja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
demo/src/app/advanced/custom-range-search.component.spec.ts
This file contains hidden or 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,96 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
|
||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { NO_ERRORS_SCHEMA, SecurityContext } from '@angular/core'; | ||
import { ComponentFixture, TestBed, tick, waitForAsync } from '@angular/core/testing'; | ||
import { DataTableDirective, DataTablesModule } from 'angular-datatables'; | ||
import { MarkdownModule } from 'ngx-markdown'; | ||
import { BaseDemoComponent } from '../base-demo/base-demo.component'; | ||
import { AppRoutingModule } from '../app.routing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { CustomRangeSearchComponent } from './custom-range-search.component'; | ||
import { FormsModule } from '@angular/forms'; | ||
|
||
|
||
let fixture: ComponentFixture<CustomRangeSearchComponent>, component: CustomRangeSearchComponent = null; | ||
|
||
describe('CustomRangeSearchComponent', () => { | ||
beforeEach(() => { | ||
fixture = TestBed.configureTestingModule({ | ||
declarations: [ | ||
BaseDemoComponent, | ||
CustomRangeSearchComponent, | ||
DataTableDirective | ||
], | ||
imports: [ | ||
AppRoutingModule, | ||
RouterTestingModule, | ||
DataTablesModule.forRoot(), | ||
HttpClientModule, | ||
MarkdownModule.forRoot( | ||
{ | ||
sanitize: SecurityContext.NONE | ||
} | ||
), | ||
FormsModule | ||
], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}).createComponent(CustomRangeSearchComponent); | ||
|
||
component = fixture.componentInstance; | ||
|
||
fixture.detectChanges(); // initial binding | ||
}); | ||
|
||
it('should create the app', waitForAsync(() => { | ||
const app = fixture.debugElement.componentInstance; | ||
expect(app).toBeTruthy(); | ||
})); | ||
|
||
it('should have title "Custom filtering - Range search"', waitForAsync(() => { | ||
const app = fixture.debugElement.componentInstance as CustomRangeSearchComponent; | ||
expect(app.pageTitle).toBe('Custom filtering - Range search'); | ||
})); | ||
|
||
it('should have data filtered when min, max values change', async () => { | ||
const app = fixture.componentInstance as CustomRangeSearchComponent; | ||
await fixture.whenStable(); | ||
|
||
const query = fixture.debugElement.query(By.directive(DataTableDirective)); | ||
const dir = query.injector.get(DataTableDirective); | ||
expect(dir).toBeTruthy(); | ||
const instance = await dir.dtInstance; | ||
|
||
const inputFieldMin: HTMLInputElement = fixture.nativeElement.querySelector('input[name="min"]'); | ||
const inputFieldMax: HTMLInputElement = fixture.nativeElement.querySelector('input[name="max"]'); | ||
|
||
// # Test 1 | ||
|
||
inputFieldMin.value = '1'; | ||
inputFieldMax.value = '5'; | ||
|
||
inputFieldMin.dispatchEvent(new Event('input')); | ||
inputFieldMax.dispatchEvent(new Event('input')); | ||
|
||
instance.draw(); | ||
fixture.detectChanges(); | ||
|
||
expect(instance.rows({ page: 'current' }).count()).toBe(1); | ||
|
||
// # Test 2 | ||
|
||
inputFieldMin.value = '1'; | ||
inputFieldMax.value = '15'; | ||
|
||
inputFieldMin.dispatchEvent(new Event('input')); | ||
inputFieldMax.dispatchEvent(new Event('input')); | ||
|
||
instance.draw(); | ||
fixture.detectChanges(); | ||
|
||
expect(instance.rows({ page: 'current' }).count()).toBe(3); | ||
|
||
}); | ||
|
||
}); |
This file contains hidden or 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,68 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
|
||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { NO_ERRORS_SCHEMA, SecurityContext } from '@angular/core'; | ||
import { ComponentFixture, TestBed, tick, waitForAsync } from '@angular/core/testing'; | ||
import { DataTableDirective, DataTablesModule } from 'angular-datatables'; | ||
import { MarkdownModule } from 'ngx-markdown'; | ||
import { BaseDemoComponent } from '../base-demo/base-demo.component'; | ||
import { AppRoutingModule } from '../app.routing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { DtInstanceComponent } from './dt-instance.component'; | ||
|
||
|
||
let fixture: ComponentFixture<DtInstanceComponent>, component: DtInstanceComponent = null; | ||
|
||
describe('DtInstanceComponent', () => { | ||
beforeEach(() => { | ||
fixture = TestBed.configureTestingModule({ | ||
declarations: [ | ||
BaseDemoComponent, | ||
DtInstanceComponent, | ||
DataTableDirective | ||
], | ||
imports: [ | ||
AppRoutingModule, | ||
RouterTestingModule, | ||
DataTablesModule.forRoot(), | ||
HttpClientModule, | ||
MarkdownModule.forRoot( | ||
{ | ||
sanitize: SecurityContext.NONE | ||
} | ||
), | ||
FormsModule | ||
], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}).createComponent(DtInstanceComponent); | ||
|
||
component = fixture.componentInstance; | ||
|
||
fixture.detectChanges(); // initial binding | ||
}); | ||
|
||
it('should create the app', waitForAsync(() => { | ||
const app = fixture.debugElement.componentInstance; | ||
expect(app).toBeTruthy(); | ||
})); | ||
|
||
it('should have title "Getting the DataTable instance"', waitForAsync(() => { | ||
const app = fixture.debugElement.componentInstance as DtInstanceComponent; | ||
expect(app.pageTitle).toBe('Getting the DataTable instance'); | ||
})); | ||
|
||
it('should retrieve Table instance', async () => { | ||
const app = fixture.componentInstance as DtInstanceComponent; | ||
await fixture.whenStable(); | ||
|
||
const query = fixture.debugElement.query(By.directive(DataTableDirective)); | ||
const dir = query.injector.get(DataTableDirective); | ||
expect(dir).toBeTruthy(); | ||
|
||
const instance = await dir.dtInstance; | ||
expect(instance).toBeTruthy(); | ||
}); | ||
|
||
}); |
99 changes: 99 additions & 0 deletions
99
demo/src/app/advanced/individual-column-filtering.component.spec.ts
This file contains hidden or 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,99 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
|
||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { NO_ERRORS_SCHEMA, SecurityContext } from '@angular/core'; | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { DataTableDirective, DataTablesModule } from 'angular-datatables'; | ||
import { MarkdownModule } from 'ngx-markdown'; | ||
import { BaseDemoComponent } from '../base-demo/base-demo.component'; | ||
import { AppRoutingModule } from '../app.routing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { IndividualColumnFilteringComponent } from './individual-column-filtering.component'; | ||
|
||
|
||
let fixture: ComponentFixture<IndividualColumnFilteringComponent>, component: IndividualColumnFilteringComponent = null; | ||
|
||
function applyValueToInput(inputElement: HTMLInputElement, value: string, table: DataTables.Api) { | ||
inputElement.value = value; | ||
inputElement.dispatchEvent(new Event('input')); | ||
inputElement.dispatchEvent(new Event('change')); | ||
table.draw(); | ||
} | ||
|
||
describe('IndividualColumnFilteringComponent', () => { | ||
beforeEach(() => { | ||
fixture = TestBed.configureTestingModule({ | ||
declarations: [ | ||
BaseDemoComponent, | ||
IndividualColumnFilteringComponent, | ||
DataTableDirective | ||
], | ||
imports: [ | ||
AppRoutingModule, | ||
RouterTestingModule, | ||
DataTablesModule.forRoot(), | ||
HttpClientModule, | ||
MarkdownModule.forRoot( | ||
{ | ||
sanitize: SecurityContext.NONE | ||
} | ||
), | ||
FormsModule | ||
], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}).createComponent(IndividualColumnFilteringComponent); | ||
|
||
component = fixture.componentInstance; | ||
|
||
fixture.detectChanges(); // initial binding | ||
}); | ||
|
||
it('should create the app', waitForAsync(() => { | ||
const app = fixture.debugElement.componentInstance; | ||
expect(app).toBeTruthy(); | ||
})); | ||
|
||
it('should have title "Individual column searching"', waitForAsync(() => { | ||
const app = fixture.debugElement.componentInstance as IndividualColumnFilteringComponent; | ||
expect(app.pageTitle).toBe('Individual column searching'); | ||
})); | ||
|
||
it('should filter contents acc. to column', async () => { | ||
const app = fixture.componentInstance as IndividualColumnFilteringComponent; | ||
app.dtOptions.paging = false; | ||
|
||
await fixture.whenStable(); | ||
|
||
const query = fixture.debugElement.query(By.directive(DataTableDirective)); | ||
const dir = query.injector.get(DataTableDirective); | ||
expect(dir).toBeTruthy(); | ||
|
||
const instance = await dir.dtInstance; | ||
|
||
const inputFields = Array.from(fixture.nativeElement.querySelectorAll('input')) as HTMLInputElement[]; | ||
const inputFieldID = inputFields.find(e => e.name == "search-id"); | ||
const inputFieldFirstName = inputFields.find(e => e.name == "search-first-name"); | ||
const inputFieldLastName = inputFields.find(e => e.name == "search-last-name"); | ||
|
||
// # Test 1 | ||
applyValueToInput(inputFieldID, '113', instance); | ||
expect(instance.rows({ page: 'current' }).count()).toBe(1); | ||
|
||
// # Test 2 | ||
|
||
// reset prev. field | ||
applyValueToInput(inputFieldID, '', instance); | ||
applyValueToInput(inputFieldFirstName, 'Batman', instance); | ||
expect(instance.rows({ page: 'current' }).count()).toBe(30); | ||
|
||
// # Test 3 | ||
// reset prev. field | ||
applyValueToInput(inputFieldFirstName, '', instance); | ||
applyValueToInput(inputFieldLastName, 'Titi', instance); | ||
expect(instance.rows({ page: 'current' }).count()).toBe(28); | ||
|
||
}); | ||
|
||
}); |
68 changes: 68 additions & 0 deletions
68
demo/src/app/advanced/load-dt-options-with-promise.component.spec.ts
This file contains hidden or 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,68 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
|
||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { NO_ERRORS_SCHEMA, SecurityContext } from '@angular/core'; | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { DataTableDirective, DataTablesModule } from 'angular-datatables'; | ||
import { MarkdownModule } from 'ngx-markdown'; | ||
import { BaseDemoComponent } from '../base-demo/base-demo.component'; | ||
import { AppRoutingModule } from '../app.routing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { LoadDtOptionsWithPromiseComponent } from './load-dt-options-with-promise.component'; | ||
|
||
|
||
let fixture: ComponentFixture<LoadDtOptionsWithPromiseComponent>, component: LoadDtOptionsWithPromiseComponent = null; | ||
|
||
describe('LoadDtOptionsWithPromiseComponent', () => { | ||
beforeEach(() => { | ||
fixture = TestBed.configureTestingModule({ | ||
declarations: [ | ||
BaseDemoComponent, | ||
LoadDtOptionsWithPromiseComponent, | ||
DataTableDirective | ||
], | ||
imports: [ | ||
AppRoutingModule, | ||
RouterTestingModule, | ||
DataTablesModule.forRoot(), | ||
HttpClientModule, | ||
MarkdownModule.forRoot( | ||
{ | ||
sanitize: SecurityContext.NONE | ||
} | ||
), | ||
FormsModule | ||
], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}).createComponent(LoadDtOptionsWithPromiseComponent); | ||
|
||
component = fixture.componentInstance; | ||
|
||
fixture.detectChanges(); // initial binding | ||
}); | ||
|
||
it('should create the app', waitForAsync(() => { | ||
const app = fixture.debugElement.componentInstance; | ||
expect(app).toBeTruthy(); | ||
})); | ||
|
||
it('should have title "Load DataTables Options with Promise"', waitForAsync(() => { | ||
const app = fixture.debugElement.componentInstance as LoadDtOptionsWithPromiseComponent; | ||
expect(app.pageTitle).toBe('Load DataTables Options with Promise'); | ||
})); | ||
|
||
it('should render table from dtOptions as a Promise', async () => { | ||
const app = fixture.componentInstance as LoadDtOptionsWithPromiseComponent; | ||
await fixture.whenStable(); | ||
|
||
const query = fixture.debugElement.query(By.directive(DataTableDirective)); | ||
const dir = query.injector.get(DataTableDirective); | ||
expect(dir).toBeTruthy(); | ||
|
||
const instance = await dir.dtInstance; | ||
expect(instance.rows().count()).toBeGreaterThan(0); | ||
}); | ||
|
||
}); |
This file contains hidden or 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,63 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
|
||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { NO_ERRORS_SCHEMA, QueryList, SecurityContext } from '@angular/core'; | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { DataTableDirective, DataTablesModule } from 'angular-datatables'; | ||
import { MarkdownModule } from 'ngx-markdown'; | ||
import { BaseDemoComponent } from '../base-demo/base-demo.component'; | ||
import { AppRoutingModule } from '../app.routing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { MultipleTablesComponent } from './multiple-tables.component'; | ||
|
||
|
||
let fixture: ComponentFixture<MultipleTablesComponent>, component: MultipleTablesComponent = null; | ||
|
||
describe('MultipleTablesComponent', () => { | ||
beforeEach(() => { | ||
fixture = TestBed.configureTestingModule({ | ||
declarations: [ | ||
BaseDemoComponent, | ||
MultipleTablesComponent, | ||
DataTableDirective | ||
], | ||
imports: [ | ||
AppRoutingModule, | ||
RouterTestingModule, | ||
DataTablesModule.forRoot(), | ||
HttpClientModule, | ||
MarkdownModule.forRoot( | ||
{ | ||
sanitize: SecurityContext.NONE | ||
} | ||
), | ||
FormsModule | ||
], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}).createComponent(MultipleTablesComponent); | ||
|
||
component = fixture.componentInstance; | ||
|
||
fixture.detectChanges(); // initial binding | ||
}); | ||
|
||
it('should create the app', waitForAsync(() => { | ||
const app = fixture.debugElement.componentInstance; | ||
expect(app).toBeTruthy(); | ||
})); | ||
|
||
it('should have title "Multiple DataTables in the same page"', waitForAsync(() => { | ||
const app = fixture.debugElement.componentInstance as MultipleTablesComponent; | ||
expect(app.pageTitle).toBe('Multiple DataTables in the same page'); | ||
})); | ||
|
||
it('should have two table instances in dtElements', async () => { | ||
const app = fixture.componentInstance as MultipleTablesComponent; | ||
await fixture.whenStable(); | ||
|
||
expect(app.dtElements.length).toBe(2); | ||
}); | ||
|
||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.