test(click-block): fix click block test

This commit is contained in:
Adam Bradley
2016-12-07 11:31:25 -06:00
parent e210448e63
commit df52a410d3
2 changed files with 16 additions and 20 deletions

View File

@ -1,7 +1,8 @@
import { App } from '../app'; import { App } from '../app';
import { AppPortal } from '../app-root'; import { AppPortal } from '../app-root';
import { ClickBlock } from '../../../util/click-block';
import { Config } from '../../../config/config'; import { Config } from '../../../config/config';
import { mockApp, mockConfig, mockNavController, mockPlatform, mockTab, mockTabs, mockView, mockViews } from '../../../util/mock-providers'; import { mockApp, mockConfig, mockElementRef, mockNavController, mockPlatform, mockRenderer, mockTab, mockTabs, mockView, mockViews } from '../../../util/mock-providers';
import { OverlayPortal } from '../../nav/overlay-portal'; import { OverlayPortal } from '../../nav/overlay-portal';
import { Platform } from '../../../platform/platform'; import { Platform } from '../../../platform/platform';
@ -354,29 +355,22 @@ describe('App', () => {
}); });
describe('setEnabled', () => { describe('setEnabled', () => {
it('should disable click block when app is enabled', (done) => { it('should disable click block when app is enabled', (done) => {
// arrange app._clickBlock = new ClickBlock(app, mockConfig(), mockElementRef(), mockRenderer());
let mockClickBlock: any = {
activate: () => {}
};
spyOn(mockClickBlock, 'activate'); spyOn(app._clickBlock, '_activate');
app._clickBlock = mockClickBlock;
// act
app.setEnabled(true); app.setEnabled(true);
// assert expect(app._clickBlock._activate).not.toHaveBeenCalledWith();
expect(mockClickBlock.activate).not.toHaveBeenCalled();
setTimeout(() => { setTimeout(() => {
expect(mockClickBlock.activate).toHaveBeenCalledWith(false, 0); expect(app._clickBlock._activate).toHaveBeenCalledWith(false);
done(); done();
}, 120); }, 120);
}, 1000); }, 1000);
it('should enable click block when false is passed with duration', () => { it('should enable click block when false is passed with duration', () => {
// arrange // arrange
let mockClickBlock: any = { let mockClickBlock: any = {

View File

@ -12,7 +12,7 @@ import { Config } from '../config/config';
selector: '.click-block' selector: '.click-block'
}) })
export class ClickBlock { export class ClickBlock {
private _tmrId: number; private _tmr: number;
private _showing: boolean = false; private _showing: boolean = false;
isEnabled: boolean; isEnabled: boolean;
@ -23,30 +23,32 @@ export class ClickBlock {
private renderer: Renderer private renderer: Renderer
) { ) {
app._clickBlock = this; app._clickBlock = this;
let enabled = this.isEnabled = config.getBoolean('clickBlock', true);
const enabled = this.isEnabled = config.getBoolean('clickBlock', true);
if (enabled) { if (enabled) {
this.setElementClass('click-block-enabled', true); this._setElementClass('click-block-enabled', true);
} }
} }
activate(shouldShow: boolean, expire: number = 100) { activate(shouldShow: boolean, expire: number = 100) {
if (this.isEnabled) { if (this.isEnabled) {
clearNativeTimeout(this._tmrId); clearNativeTimeout(this._tmr);
if (shouldShow) { if (shouldShow) {
this._activate(true); this._activate(true);
} }
this._tmrId = nativeTimeout(this._activate.bind(this, false), expire); this._tmr = nativeTimeout(this._activate.bind(this, false), expire);
} }
} }
/** @internal */
_activate(shouldShow: boolean) { _activate(shouldShow: boolean) {
if (this._showing !== shouldShow) { if (this._showing !== shouldShow) {
this.setElementClass('click-block-active', shouldShow); this._setElementClass('click-block-active', shouldShow);
this._showing = shouldShow; this._showing = shouldShow;
} }
} }
setElementClass(className: string, add: boolean) { private _setElementClass(className: string, add: boolean) {
this.renderer.setElementClass(this.elementRef.nativeElement, className, add); this.renderer.setElementClass(this.elementRef.nativeElement, className, add);
} }