1
1
import { Window } from "./window.class" ;
2
- import { NativeAdapter } from "./adapter/native.adapter.class" ;
3
- import providerRegistry from "./provider/provider-registry.class" ;
2
+ import { ProviderRegistry } from "./provider/provider-registry.class" ;
3
+ import { mockPartial } from "sneer" ;
4
+ import { WindowProviderInterface } from "./provider" ;
4
5
5
- jest . mock ( 'jimp' , ( ) => { } ) ;
6
- jest . mock ( "./adapter/native.adapter.class" ) ;
6
+ jest . mock ( 'jimp' , ( ) => {
7
+ } ) ;
7
8
8
9
describe ( "Window class" , ( ) => {
9
10
it ( "should retrieve the window region via its native adapter" , async ( ) => {
10
11
// GIVEN
11
- const nativeAdapterMock = new NativeAdapter ( providerRegistry ) ;
12
+ const windowMock = jest . fn ( ) ;
13
+ const providerRegistryMock = mockPartial < ProviderRegistry > ( {
14
+ getWindow ( ) : WindowProviderInterface {
15
+ return mockPartial < WindowProviderInterface > ( {
16
+ getWindowRegion : windowMock
17
+ } )
18
+ }
19
+ } )
12
20
const mockWindowHandle = 123 ;
13
- const SUT = new Window ( nativeAdapterMock , mockWindowHandle ) ;
21
+ const SUT = new Window ( providerRegistryMock , mockWindowHandle ) ;
14
22
15
23
// WHEN
16
24
await SUT . region
17
25
18
26
// THEN
19
- expect ( nativeAdapterMock . getWindowRegion ) . toBeCalledTimes ( 1 ) ;
20
- expect ( nativeAdapterMock . getWindowRegion ) . toBeCalledWith ( mockWindowHandle ) ;
27
+ expect ( windowMock ) . toBeCalledTimes ( 1 ) ;
28
+ expect ( windowMock ) . toBeCalledWith ( mockWindowHandle ) ;
21
29
} ) ;
22
30
23
31
it ( "should retrieve the window title via its native adapter" , async ( ) => {
24
32
// GIVEN
25
- const nativeAdapterMock = new NativeAdapter ( providerRegistry ) ;
33
+ const windowMock = jest . fn ( ) ;
34
+ const providerRegistryMock = mockPartial < ProviderRegistry > ( {
35
+ getWindow ( ) : WindowProviderInterface {
36
+ return mockPartial < WindowProviderInterface > ( {
37
+ getWindowTitle : windowMock
38
+ } )
39
+ }
40
+ } )
26
41
const mockWindowHandle = 123 ;
27
- const SUT = new Window ( nativeAdapterMock , mockWindowHandle ) ;
42
+ const SUT = new Window ( providerRegistryMock , mockWindowHandle ) ;
28
43
29
44
// WHEN
30
45
await SUT . title
31
46
32
47
// THEN
33
- expect ( nativeAdapterMock . getWindowTitle ) . toBeCalledTimes ( 1 ) ;
34
- expect ( nativeAdapterMock . getWindowTitle ) . toBeCalledWith ( mockWindowHandle ) ;
48
+ expect ( windowMock ) . toBeCalledTimes ( 1 ) ;
49
+ expect ( windowMock ) . toBeCalledWith ( mockWindowHandle ) ;
35
50
} ) ;
36
51
} ) ;
0 commit comments