Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nnixaa committed Jan 17, 2019
1 parent 73d73e4 commit b46f50d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export class NbMockDynamicOverlay {
this._componentType = componentType;
}

setContentAndContext(content: NbOverlayContent, context: Object) {
this._content = content;
this._context = context;
}

setPositionStrategy(positionStrategy: NbAdjustableConnectedPositionStrategy) {
this._positionStrategy = positionStrategy;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestBed } from '@angular/core/testing';
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { Component, ComponentFactoryResolver, Input } from '@angular/core';
import { Subject } from 'rxjs';
import { ScrollStrategy } from '@angular/cdk/overlay';
Expand Down Expand Up @@ -227,47 +227,51 @@ describe('dynamic-overlay', () => {
expect(dynamicOverlay.getContainer()).toBe(container as any);
});

it('should set content when shown', () => {
it('should set content when shown', fakeAsync(() => {
const renderContentSpy = spyOn(instance, 'renderContent').and.callThrough();
const updatePositionSpy = spyOn(ref, 'updatePosition').and.callThrough();

dynamicOverlay.show();
const newContent = 'new content';
dynamicOverlay.setContent(newContent);
tick(); // we have setTimeout here

expect(instance.content).toBe(newContent);
expect(renderContentSpy).toHaveBeenCalledTimes(2);
expect(updatePositionSpy).toHaveBeenCalledTimes(1);
});
}));

it('should set context when shown', () => {
it('should set context when shown', fakeAsync(() => {
const renderContentSpy = spyOn(instance, 'renderContent').and.callThrough();
const updatePositionSpy = spyOn(ref, 'updatePosition').and.callThrough();

dynamicOverlay.show();
const newContext = { some: 'thing' };
dynamicOverlay.setContext(newContext);
tick(); // we have setTimeout here

expect(instance.context).toBe(newContext);
expect(renderContentSpy).toHaveBeenCalledTimes(2);
expect(updatePositionSpy).toHaveBeenCalledTimes(1);
});
}));

it('should set context & content when shown', () => {
it('should set context & content when shown', fakeAsync(() => {
const renderContentSpy = spyOn(instance, 'renderContent').and.callThrough();
const updatePositionSpy = spyOn(ref, 'updatePosition').and.callThrough();

dynamicOverlay.show();
const newContext = { some: 'thing' };
const newContent = 'new content';
dynamicOverlay.setContent(newContent);
tick(); // we have setTimeout here
dynamicOverlay.setContext(newContext);
tick(); // we have setTimeout here

expect(instance.context).toBe(newContext);
expect(instance.content).toBe(newContent);
expect(renderContentSpy).toHaveBeenCalledTimes(3);
expect(updatePositionSpy).toHaveBeenCalledTimes(2);
});
}));

it('should set component', () => {
const detachSpy = spyOn(ref, 'detach').and.callThrough();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ export class NbDynamicOverlay {
context: Object,
positionStrategy: NbAdjustableConnectedPositionStrategy) {

this.setContext(context);
this.setContent(content);
this.setContentAndContext(content, context);
this.setComponent(componentType);
this.setPositionStrategy(positionStrategy);

Expand All @@ -70,7 +69,6 @@ export class NbDynamicOverlay {
setContentAndContext(content: NbOverlayContent, context: Object) {
this.content = content;
this.context = context;

if (this.container) {
this.updateContext();
}
Expand Down

0 comments on commit b46f50d

Please sign in to comment.