Skip to content

Commit

Permalink
chore(all): add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarsiBarsi committed Sep 28, 2020
1 parent a7746ae commit ae9b6ad
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
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 projects/cdk/components/portal-host/test/portal.service.spec.ts
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);
});
});
26 changes: 26 additions & 0 deletions projects/cdk/observables/test/watch.spec.ts
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);
}));
});

0 comments on commit ae9b6ad

Please sign in to comment.