2016-05-07 07:42:55 +08:00
|
|
|
/* eslint react/prefer-es6-class: "off" */
|
|
|
|
/* eslint react/prefer-stateless-function: "off" */
|
|
|
|
|
2017-09-27 02:55:33 +08:00
|
|
|
import { React, ComponentRegistry, MailspringTestUtils } from 'mailspring-exports';
|
|
|
|
import { InjectedComponentSet } from 'mailspring-component-kit';
|
2016-10-18 08:59:33 +08:00
|
|
|
|
2017-09-27 02:55:33 +08:00
|
|
|
const { renderIntoDocument } = MailspringTestUtils;
|
2015-12-30 01:15:18 +08:00
|
|
|
|
2017-09-27 02:55:33 +08:00
|
|
|
const reactStub = displayName => {
|
2017-09-27 03:03:04 +08:00
|
|
|
class StubWithName extends React.Component {
|
|
|
|
static displayName = displayName;
|
2017-09-27 02:55:33 +08:00
|
|
|
render() {
|
|
|
|
return <div className={displayName} />;
|
2017-09-27 03:03:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return StubWithName;
|
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(
|
2017-09-27 02:55:33 +08:00
|
|
|
<InjectedComponentSet matching={{}} onComponentsDidRender={onComponentsDidRender} />
|
2015-12-30 01:15:18 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
waitsFor(
|
2017-09-27 02:55:33 +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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|