<commit_before>import storeConnectBehaviour from '../connect';
const {renderIntoDocument, Simulate} = TestUtils;
import {store, dispatcher} from 'focus-core';
const {CoreStore} = store;


describe('The store connect behaviour', () => {
    describe('when called without storeConf', () => {
        it('should throw an error', () => {
            expect(() => storeConnectBehaviour()).to.throw('connectToStores: you need to provide an array of store config.');
        });
    });
    describe('when called without getState', () => {
        it('should throw an error', () => {
            expect(() => storeConnectBehaviour([])).to.throw('connectToStores: you need to provide function to read state from store.');
        });
    });
    describe('when called with correct argument', () => {
        it('should return a function', () => {
            expect(() => storeConnectBehaviour([], () => {})).to.be.a.function;
        });
    });
    describe('when called with a store', () => {
        let renderComponent;
        const storeChangeSpy = sinon.spy();
        const conectedComponentRenderSpy = sinon.spy();
        const newStore = new CoreStore({definition: {papa: 'papa', lopez: 'lopez'}});
        const connector = storeConnectBehaviour(
            [{store: newStore, properties: ['papa', 'lopez']}],
            (props) => {const storeValue = newStore.getValue(); storeChangeSpy(storeValue); return storeValue; }
        );
        const Component = (props) => { console.log(props); conectedComponentRenderSpy(props); return <div>{JSON.stringify(props)}</div>;};
        const ConnectedComponent = connector(Component);
        before(
            () => {
                renderComponent = renderIntoDocument(<ConnectedComponent testProps='testPropsValue'/>);
            }
        );
        it('should call the getState method on mounting', () => {
            expect(storeChangeSpy).to.have.been.called.once;
            expect(storeChangeSpy).to.have.been.calledWith({});
            expect(conectedComponentRenderSpy).to.have.been.called.once;
            expect(conectedComponentRenderSpy).to.have.been.calledWith({testProps: 'testPropsValue'});
        });
        describe('when a value is dispatched' , () => {
            before(() => {
                dispatcher.handleViewAction({
                    data: {
                        lopez: 'joe',
                        papa: 'singe'
                    },
                    type: 'update'
                });
            });
            it('should render the component with the state value', () => {
                expect(storeChangeSpy).to.have.been.called.thrice; //Mounting, joe, singe
                //expect(storeChangeSpy.getCall(0)).to.equal({ lopez: 'joe', papa: 'singe'});
                // expect(storeChangeSpy).to.have.been.calledWith({ lopez: 'joe', papa: 'singe'});//
                expect(conectedComponentRenderSpy).to.have.been.called.twice;
            });
            it('should render the component with the state value', () => {
                expect(storeChangeSpy).to.have.been.called.thrice; //Mounting, joe, singe
                expect(conectedComponentRenderSpy).to.have.been.called.twice;
            });
            it('should render the component with the state value', () => {
                const domNode = ReactDOM.findDOMNode(renderComponent);
                expect(JSON.parse(domNode.innerHTML)).to.deep.equal({lopez: 'joe', papa: 'singe', testProps: 'testPropsValue'});
            });
        });

    });
});
<commit_msg>[connect] Rewrite the tests desc.<commit_after>import storeConnectBehaviour from '../connect';
const {renderIntoDocument, Simulate} = TestUtils;
import {store, dispatcher} from 'focus-core';
const {CoreStore} = store;


describe('The store connect behaviour', () => {
    describe('when called without storeConf', () => {
        it('should throw an error', () => {
            expect(() => storeConnectBehaviour()).to.throw('connectToStores: you need to provide an array of store config.');
        });
    });
    describe('when called without getState', () => {
        it('should throw an error', () => {
            expect(() => storeConnectBehaviour([])).to.throw('connectToStores: you need to provide function to read state from store.');
        });
    });
    describe('when called with correct argument', () => {
        it('should return a function', () => {
            expect(() => storeConnectBehaviour([], () => {})).to.be.a.function;
        });
    });
    describe('when called with a store', () => {
        let renderComponent;
        const storeChangeSpy = sinon.spy();
        const conectedComponentRenderSpy = sinon.spy();
        const newStore = new CoreStore({definition: {papa: 'papa', lopez: 'lopez'}});
        const connector = storeConnectBehaviour(
            [{store: newStore, properties: ['papa', 'lopez']}],
            (props) => {const storeValue = newStore.getValue(); storeChangeSpy(storeValue); return storeValue; }
        );
        const Component = (props) => { console.log(props); conectedComponentRenderSpy(props); return <div>{JSON.stringify(props)}</div>;};
        const ConnectedComponent = connector(Component);
        before(
            () => {
                renderComponent = renderIntoDocument(<ConnectedComponent testProps='testPropsValue'/>);
            }
        );
        it('should call the getState method on mounting', () => {
            expect(storeChangeSpy).to.have.been.called.once;
            expect(storeChangeSpy).to.have.been.calledWith({});
            expect(conectedComponentRenderSpy).to.have.been.called.once;
            expect(conectedComponentRenderSpy).to.have.been.calledWith({testProps: 'testPropsValue'});
        });
        describe('when a value with two nodes is dispatched' , () => {
            before(() => {
                dispatcher.handleViewAction({
                    data: {
                        lopez: 'joe',
                        papa: 'singe'
                    },
                    type: 'update'
                });
            });
            it('the store change spy should have been called twice', () => {
                expect(storeChangeSpy).to.have.been.called.thrice; //Mounting, joe, singe
            });
            it('the component shoud have been rendered twice', () => {
                expect(conectedComponentRenderSpy).to.have.been.called.twice;
            });
            it('the html generated by the component should contains props and state', () => {
                const domNode = ReactDOM.findDOMNode(renderComponent);
                expect(JSON.parse(domNode.innerHTML)).to.deep.equal({lopez: 'joe', papa: 'singe', testProps: 'testPropsValue'});
            });
        });

    });
});

{'fraction_non_alphanumeric': 0.14797347089167281, 'fraction_numerical': 0.00014738393515106854, 'mean_word_length': 2.295774647887324, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4925188', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1781, 'n_words': 395}