2015-12-30 01:15:18 +08:00
|
|
|
import {React, ComponentRegistry, NylasTestUtils} from 'nylas-exports';
|
|
|
|
import {InjectedComponentSet} from 'nylas-component-kit';
|
|
|
|
const {renderIntoDocument} = NylasTestUtils;
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
const reactStub = (displayName) => {
|
2016-05-07 05:10:28 +08:00
|
|
|
return <div className={displayName}></div>;
|
2015-12-30 01:15:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-05-05 05:03:15 +08:00
|
|
|
describe('InjectedComponentSet', function injectedComponentSet() {
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('render', () => {
|
|
|
|
beforeEach(() => {
|
2015-12-30 01:15:18 +08:00
|
|
|
const components = [reactStub('comp1'), reactStub('comp2')];
|
|
|
|
spyOn(ComponentRegistry, 'findComponentsMatching').andReturn(components);
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('calls `onComponentsDidRender` when all child comps have actually been rendered to the dom', () => {
|
2015-12-30 01:15:18 +08:00
|
|
|
let rendered;
|
2016-05-06 13:30:34 +08:00
|
|
|
const onComponentsDidRender = () => {
|
2015-12-30 01:15:18 +08:00
|
|
|
rendered = true;
|
|
|
|
};
|
2016-05-06 13:30:34 +08:00
|
|
|
runs(() => {
|
2015-12-30 01:15:18 +08:00
|
|
|
renderIntoDocument(
|
|
|
|
<InjectedComponentSet
|
|
|
|
matching={{}}
|
2016-05-07 05:10:28 +08:00
|
|
|
onComponentsDidRender={onComponentsDidRender}
|
|
|
|
/>
|
2015-12-30 01:15:18 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(
|
2016-05-06 13:30:34 +08:00
|
|
|
() => { return rendered; },
|
2015-12-30 01:15:18 +08:00
|
|
|
'`onComponentsDidMount` should be called',
|
|
|
|
100
|
|
|
|
);
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
runs(() => {
|
2015-12-30 01:15:18 +08:00
|
|
|
expect(rendered).toBe(true);
|
|
|
|
expect(document.querySelectorAll('.comp1').length).toEqual(1);
|
|
|
|
expect(document.querySelectorAll('.comp2').length).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|