import React        from 'react/addons';
const { TestUtils } = React.addons;
import { expect }   from 'chai';
import sinon        from 'sinon';
import mockery      from 'mockery';

var TopCommitter;
var topCommitter;

describe('Github — TopCommitter', () => {

    let sandbox;

    before(() => {
        mockery.enable({ useCleanCache: true });
        mockery.warnOnUnregistered(false);
        mockery.registerMock('mozaik/browser', {
            Mixin: { ApiConsumer: {} }
        });

        TopCommitter = require('./../components/TopCommitter.jsx');
    });

    beforeEach(() => {
        sandbox = sinon.sandbox.create();
        topCommitter = TestUtils.renderIntoDocument(<TopCommitter repository="plouc/mozaik" />);
    });

    afterEach(() => {
        sandbox.restore();
    });

    after(() => {
        mockery.deregisterMock('mozaik/browser');
        mockery.disable();
    });


    it('should return correct api request', () => {
        expect(topCommitter.getApiRequest()).to.eql({
            id:     'github.repositoryCommits.plouc/mozaik',
            params: {
                repository: 'plouc/mozaik'
            }
        });
    });

    it('should display repository name in header', () => {
        let count = TestUtils.findRenderedDOMComponentWithClass(topCommitter, 'widget__header');
        expect(count.getDOMNode().textContent).to.equal('plouc/mozaik top committer');
    });

    it('should display top committer info and commit count', () => {
        topCommitter.setState({
            topCommitter: {
                login:      'plouc',
                avatar_url: 'http://avatar.io/plouc'
            }
        });

        let img = TestUtils.scryRenderedDOMComponentsWithTag(topCommitter, 'img');
        expect(img).to.have.length(1);
        img = img[0];
        expect(img.props).to.have.property('src');
        expect(img.props.src).to.equal('http://avatar.io/plouc');

        let username = TestUtils.findRenderedDOMComponentWithClass(topCommitter, 'github__top-committer__info');
        expect(username.getDOMNode().textContent).to.contain('plouc');
    });
});
@@ -172,16 +172,51 @@
 ockery';
+%0Aimport moment       from 'moment';
 %0A%0Avar To
@@ -974,32 +974,139 @@
 quest', () =%3E %7B%0A
+        let since = moment().startOf('day').format();%0A        let until = moment().endOf('day').format();%0A%0A
         expect(t
@@ -1163,17 +1163,17 @@
 id:     
-'
+%60
 github.r
@@ -1201,17 +1201,39 @@
 c/mozaik
-'
+.$%7B since %7D.$%7B until %7D%60
 ,%0A      
@@ -1290,16 +1290,86 @@
 /mozaik'
+,%0A                since:      since,%0A                until:      until
 %0A       
@@ -2351,8 +2351,9 @@
  %7D);%0A%7D);
+%0A

fix TopCommitter component test