1
1
import React from 'react' ;
2
+ import type { ReactWrapper } from 'enzyme' ;
2
3
import { mount } from 'enzyme' ;
3
- import { EventEmitter } from 'events' ;
4
4
import { expect } from 'chai' ;
5
5
6
6
import { CompassShell } from './components/compass-shell' ;
7
- import createPlugin from './plugin' ;
8
- import CompassShellStore from './stores' ;
7
+ import { CompassShellPlugin } from './index' ;
8
+ import { AppRegistryProvider , globalAppRegistry } from 'hadron-app-registry' ;
9
+ import { DataServiceProvider } from 'mongodb-data-service/provider' ;
9
10
10
11
// Wait until a component is present that is rendered in a limited number
11
12
// of microtask queue iterations. In particular, this does *not* wait for the
@@ -26,35 +27,51 @@ async function waitForAsyncComponent(wrapper, Component, attempts = 10) {
26
27
}
27
28
28
29
describe ( 'CompassShellPlugin' , function ( ) {
29
- it ( 'returns a renderable plugin' , async function ( ) {
30
- const { Plugin } = createPlugin ( ) ;
30
+ const fakeDataService = {
31
+ getMongoClientConnectionOptions ( ) { } ,
32
+ } as any ;
33
+ let wrapper : ReactWrapper | null ;
31
34
32
- const wrapper = mount ( < Plugin /> ) ;
35
+ afterEach ( ( ) => {
36
+ wrapper ?. unmount ( ) ;
37
+ wrapper = null ;
38
+ } ) ;
39
+ it ( 'returns a renderable plugin' , async function ( ) {
40
+ wrapper = mount (
41
+ < AppRegistryProvider >
42
+ { /* global */ }
43
+ < AppRegistryProvider >
44
+ { /* local */ }
45
+ < DataServiceProvider value = { fakeDataService } >
46
+ < CompassShellPlugin />
47
+ </ DataServiceProvider >
48
+ </ AppRegistryProvider >
49
+ </ AppRegistryProvider >
50
+ ) ;
33
51
34
52
const component = await waitForAsyncComponent ( wrapper , CompassShell ) ;
35
53
36
54
expect ( component . exists ( ) ) . to . equal ( true ) ;
37
55
} ) ;
38
56
39
- it ( 'returns a CompassShellStore store' , function ( ) {
40
- const { store } = createPlugin ( ) ;
41
- const appRegistry = new EventEmitter ( ) ;
42
- store . onActivated ( appRegistry ) ;
43
- expect ( store ) . to . be . instanceOf ( CompassShellStore ) ;
44
- } ) ;
45
-
46
57
it ( 'emits an event on the app registry when it is expanded' , async function ( ) {
47
- const { store, Plugin } = createPlugin ( ) ;
48
-
49
- const appRegistry = new EventEmitter ( ) ;
50
58
let eventOccured = false ;
51
- appRegistry . on ( 'compass:compass-shell:opened' , ( ) => {
59
+ globalAppRegistry . on ( 'compass:compass-shell:opened' , ( ) => {
52
60
eventOccured = true ;
53
61
} ) ;
54
62
55
- store . onActivated ( appRegistry ) ;
63
+ wrapper = mount (
64
+ < AppRegistryProvider >
65
+ { /* global */ }
66
+ < AppRegistryProvider >
67
+ { /* local */ }
68
+ < DataServiceProvider value = { fakeDataService } >
69
+ < CompassShellPlugin />
70
+ </ DataServiceProvider >
71
+ </ AppRegistryProvider >
72
+ </ AppRegistryProvider >
73
+ ) ;
56
74
57
- const wrapper = mount ( < Plugin /> ) ;
58
75
const shellComponentWrapper = await waitForAsyncComponent (
59
76
wrapper ,
60
77
CompassShell
0 commit comments