import { shallow } from 'enzyme';
import RepositoryList from 'bitbucket/internal/feature/dashboard/components/repository-list';
import RepositorySearch from 'bitbucket/internal/feature/dashboard/components/repository-search';
import { Repositories } from 'bitbucket/internal/feature/dashboard/repositories';

QUnit.module('dashboard-repositories-test');

QUnit.test('Repositories renders', function (assert) {
    const loadRecentRepositoriesSpy = sinon.spy();
    const wrapper = shallow(<Repositories
        loadRecentRepositories={loadRecentRepositoriesSpy}
    />);
    assert.equal(wrapper.find(RepositorySearch).length, 1);
    assert.equal(wrapper.find(RepositoryList).length, 1);
    assert.equal(wrapper.find('Spinner').length, 0);
    sinon.assert.calledOnce(loadRecentRepositoriesSpy);
});

QUnit.test('Repositories has spinner if loading', function (assert) {
    const wrapper = shallow(<Repositories
        loadRecentRepositories={() => {}}
        isLoading
    />);
    assert.equal(wrapper.find('Spinner').length, 1);
});

QUnit.test('Repositories triggers load ', function (assert) {
    const loadMoreSpy = sinon.spy();
    const loadRecentRepositoriesSpy = sinon.spy();
    const wrapper = shallow(<Repositories
        loadRecentRepositories={loadRecentRepositoriesSpy}
        isLoading
        loadMore={loadMoreSpy}
    />);
    wrapper.instance().onMoreClick();
    sinon.assert.calledOnce(loadMoreSpy);
    sinon.assert.calledOnce(loadRecentRepositoriesSpy);
});
