2020-06-25 22:43:26 +02:00
|
|
|
import {shallow} from "enzyme";
|
|
|
|
import React from "react";
|
|
|
|
import MovieSettings from "./MovieSettings";
|
|
|
|
|
|
|
|
function prepareFetchApi(response) {
|
|
|
|
const mockJsonPromise = Promise.resolve(response);
|
|
|
|
const mockFetchPromise = Promise.resolve({
|
|
|
|
json: () => mockJsonPromise,
|
|
|
|
});
|
|
|
|
return (jest.fn().mockImplementation(() => mockFetchPromise));
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('<MovieSettings/>', function () {
|
|
|
|
it('renders without crashing ', function () {
|
|
|
|
const wrapper = shallow(<MovieSettings/>);
|
|
|
|
wrapper.unmount();
|
|
|
|
});
|
|
|
|
|
2020-06-29 19:55:40 +02:00
|
|
|
it('received text renders into dom', function () {
|
|
|
|
const wrapper = shallow(<MovieSettings/>);
|
|
|
|
|
|
|
|
wrapper.setState({
|
|
|
|
text: [
|
|
|
|
"firstline",
|
|
|
|
"secline"
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find(".indextextarea").find(".textarea-element")).toHaveLength(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test simulate reindex', function () {
|
|
|
|
global.fetch = prepareFetchApi({});
|
|
|
|
const wrapper = shallow(<MovieSettings/>);
|
|
|
|
|
|
|
|
wrapper.find(".reindexbtn").simulate("click");
|
2020-06-25 22:43:26 +02:00
|
|
|
|
2020-06-29 19:55:40 +02:00
|
|
|
// initial send of reindex request to server
|
|
|
|
expect(global.fetch).toBeCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('content available received and in state', done => {
|
|
|
|
global.fetch = prepareFetchApi({
|
|
|
|
contentAvailable: true,
|
|
|
|
message: "firstline\nsecondline"
|
|
|
|
});
|
|
|
|
const wrapper = shallow(<MovieSettings/>);
|
|
|
|
wrapper.instance().updateStatus();
|
|
|
|
|
|
|
|
process.nextTick(() => {
|
|
|
|
expect(wrapper.state()).toMatchObject({
|
|
|
|
text: [
|
|
|
|
"firstline",
|
|
|
|
"secondline"
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
global.fetch.mockClear();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2020-06-25 22:43:26 +02:00
|
|
|
});
|