2016-05-07 07:42:55 +08:00
|
|
|
/* eslint react/prefer-es6-class: "off" */
|
|
|
|
/* eslint react/prefer-stateless-function: "off" */
|
|
|
|
|
2015-12-30 01:15:18 +08:00
|
|
|
import {React, ComponentRegistry, NylasTestUtils} from 'nylas-exports';
|
|
|
|
import {InjectedComponentSet} from 'nylas-component-kit';
|
2016-10-18 08:59:33 +08:00
|
|
|
|
2015-12-30 01:15:18 +08:00
|
|
|
const {renderIntoDocument} = NylasTestUtils;
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
const reactStub = (displayName) => {
|
2016-05-07 07:42:55 +08:00
|
|
|
return React.createClass({
|
|
|
|
displayName,
|
2016-10-18 08:59:33 +08:00
|
|
|
render() { return <div className={displayName} /> },
|
2016-05-07 07:42:55 +08:00
|
|
|
});
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|