import React from 'react';
import {mount, shallow} from 'enzyme';
import {Client} from 'app/api';
import AsyncComponent from 'app/components/asyncComponent';
describe('AsyncComponent', function() {
class TestAsyncComponent extends AsyncComponent {
shouldRenderBadRequests = true;
constructor(props) {
super(props);
this.state = {};
}
getEndpoints() {
return [['data', '/some/path/to/something/']];
}
renderBody() {
return
{this.state.data.message}
;
}
}
it('renders on successful request', function() {
Client.clearMockResponses();
Client.addMockResponse({
url: '/some/path/to/something/',
method: 'GET',
body: {
message: 'hi',
},
});
let wrapper = shallow();
expect(wrapper.find('div')).toHaveLength(1);
expect(wrapper.find('div').text()).toEqual('hi');
});
it('renders error message', function() {
Client.clearMockResponses();
Client.addMockResponse({
url: '/some/path/to/something/',
method: 'GET',
body: {
detail: 'oops there was a problem',
},
statusCode: 400,
});
let wrapper = mount();
expect(wrapper.find('LoadingError')).toHaveLength(1);
expect(
wrapper
.find('LoadingError')
.find('p')
.text()
).toEqual('oops there was a problem');
});
});