Skip to content

Commit 02fbada

Browse files
committed
fix(platform): add missing methods to platform
platform mock is breaking slides as it's missing some hidden methods BREAKING CHANGE: registerCallBackButtonAction has been changed
1 parent 5978785 commit 02fbada

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

src/angular/platform.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {PlatformMock} from './platform';
2+
3+
describe('PlatformMock', () => {
4+
let classUnderTest;
5+
6+
beforeEach(() => {
7+
classUnderTest = PlatformMock.instance();
8+
});
9+
10+
describe('dir', () => {
11+
it('should return empty string', () => {
12+
expect(classUnderTest.dir()).toEqual('');
13+
});
14+
});
15+
16+
describe('hasFocus', () => {
17+
it('should return true', () => {
18+
expect(classUnderTest.hasFocus()).toBeTruthy();
19+
});
20+
});
21+
22+
describe('registerListener', () => {
23+
let callback = () => 'foo';
24+
25+
it('should return function that was passed in', () => {
26+
expect(classUnderTest.registerListener(callback).call()).toEqual('foo');
27+
});
28+
});
29+
});

src/angular/platform.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export class PlatformMock {
2626
'registerListener',
2727
'win',
2828
'getActiveElement',
29-
'raf'
29+
'raf',
30+
'hasFocus',
31+
'getElementComputedStyle',
32+
'timeout'
3033
]);
3134

3235
instance.dir.and.returnValue('');
@@ -38,16 +41,23 @@ export class PlatformMock {
3841
instance.lang.and.returnValue('en');
3942
instance.platforms.and.returnValue([]);
4043
instance.ready.and.returnValue(Promise.resolve());
41-
instance.registerBackButtonAction.and.returnValue(() => {
42-
});
44+
instance.registerBackButtonAction.and.callFake(callback => callback);
45+
instance.registerListener.and.callFake(callback => callback);
4346
instance.url.and.returnValue('');
4447
instance.version.and.returnValue([]);
4548
instance.width.and.returnValue(0);
4649
instance.doc.and.returnValue(document);
4750
instance.win.and.returnValue(window);
4851
instance.getActiveElement.and.returnValue(document['activeElement']);
4952
instance.raf.and.returnValue(1);
50-
53+
instance.hasFocus.and.returnValue(true);
54+
instance.getElementComputedStyle.and.returnValue({
55+
paddingLeft: '10',
56+
paddingTop: '10',
57+
paddingRight: '10',
58+
paddingBottom: '10'
59+
});
60+
instance.timeout.and.callFake((callback: any, timer: number) => setTimeout(callback, timer));
5161
return instance;
5262
}
5363
}

0 commit comments

Comments
 (0)