-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7746ae
commit ae9b6ad
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
projects/cdk/components/portal-host/test/portal-host.component.spec.ts
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,47 @@ | ||
import {Component, ViewChild} from '@angular/core'; | ||
import {ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {NoopAnimationsModule} from '@angular/platform-browser/animations'; | ||
import {PolymorpheusModule} from '@tinkoff/ng-polymorpheus'; | ||
import {configureTestSuite} from 'ng-bullet'; | ||
import {TuiPortalHostComponent} from '../portal-host.component'; | ||
import {TuiPortalHostModule} from '../portal-host.module'; | ||
|
||
describe('PortalHost', () => { | ||
@Component({ | ||
template: ` | ||
<tui-portal-host> | ||
<button>Content</button> | ||
</tui-portal-host> | ||
`, | ||
}) | ||
class TestComponent { | ||
@ViewChild(TuiPortalHostComponent) | ||
portalHost?: TuiPortalHostComponent; | ||
} | ||
|
||
let fixture: ComponentFixture<TestComponent>; | ||
let testComponent: TestComponent; | ||
|
||
configureTestSuite(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [NoopAnimationsModule, PolymorpheusModule, TuiPortalHostModule], | ||
declarations: [TestComponent], | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TestComponent); | ||
testComponent = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('calculates clientRect', () => { | ||
expect(testComponent.portalHost!.clientRect.top).toBeGreaterThanOrEqual(0); | ||
}); | ||
|
||
it('calculates fixedPositionOffset', () => { | ||
expect( | ||
testComponent.portalHost!.fixedPositionOffset().top, | ||
).toBeGreaterThanOrEqual(0); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
projects/cdk/components/portal-host/test/portal.service.spec.ts
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,47 @@ | ||
import {TuiPortalService} from '../portal.service'; | ||
|
||
describe('PortalService', () => { | ||
let service: TuiPortalService; | ||
|
||
beforeEach(() => { | ||
service = new TuiPortalService(); | ||
}); | ||
|
||
it('Template removing', () => { | ||
let called = 0; | ||
const viewRefStub: any = {destroy: () => called++}; | ||
|
||
service.removeTemplate(viewRefStub); | ||
}); | ||
|
||
it('HostView removing', () => { | ||
let called = 0; | ||
const componentRefStub: any = {hostView: {destroy: () => called++}}; | ||
|
||
service.remove(componentRefStub); | ||
}); | ||
|
||
it('throws an error with no host', () => { | ||
const a: any = null; | ||
const b: any = null; | ||
|
||
try { | ||
service.add(a, b); | ||
fail(); | ||
} catch (e) { | ||
expect(e).toBeTruthy(); | ||
} | ||
}); | ||
|
||
it('addTemplateChild with host attached', () => { | ||
const a: any = null; | ||
const result = {}; | ||
const componentPortalStub: any = { | ||
addTemplateChild: () => result, | ||
}; | ||
|
||
service.attach(componentPortalStub); | ||
|
||
expect(service.addTemplate(a)).toBe(result as any); | ||
}); | ||
}); |
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,26 @@ | ||
import {fakeAsync, tick} from '@angular/core/testing'; | ||
import {Subject} from 'rxjs'; | ||
import {watch} from '../watch'; | ||
|
||
describe('Watch operator function', () => { | ||
let $: Subject<any>; | ||
let called = 0; | ||
|
||
const chrStub: any = { | ||
markForCheck: () => called++, | ||
}; | ||
|
||
beforeEach(() => { | ||
$ = new Subject<any>(); | ||
called = 0; | ||
}); | ||
|
||
it('initially emits nothing, after event emits "true" and after a tick emits "false"', fakeAsync(() => { | ||
$.pipe(watch(chrStub)).subscribe(); | ||
|
||
$.next(); | ||
tick(); | ||
|
||
expect(called).toBe(1); | ||
})); | ||
}); |