import { shallow } from 'enzyme';
import { Component } from 'react';
import { RepositorySearch } from 'bitbucket/internal/feature/dashboard/components/repository-search';
import webFragments from 'bitbucket/internal/impl/web-fragments'

class DummySearch extends Component { // eslint-disable-line react/prefer-stateless-function
    render() {
        return <p>Search me?!</p>;
    }
}

QUnit.module('dashboard-repository-search', {
    beforeEach: function () {
        this.getWebPanelsStub = sinon.stub(webFragments, 'getWebPanels');
    },
    afterEach: function () {
        this.getWebPanelsStub.restore();
    },
});

QUnit.test('Renders nothing if nothing in fragment', function (assert) {
    this.getWebPanelsStub.returns([]);
    const wrapper = shallow(<RepositorySearch />);
    assert.ok(!wrapper.get(0));
});

QUnit.test('Renders returned component from fragment', function (assert) {
    this.getWebPanelsStub.returns([{
        html: DummySearch
    }]);
    const wrapper = shallow(<RepositorySearch />);
    assert.equal(wrapper.find(DummySearch).length, 1);
});
