OpenMediaCenter/src/pages/RandomPage/RandomPage.test.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-06-12 15:57:30 +00:00
import {shallow} from "enzyme";
import React from "react";
import RandomPage from "./RandomPage";
function prepareFetchApi(response) {
const mockJsonPromise = Promise.resolve(response);
const mockFetchPromise = Promise.resolve({
json: () => mockJsonPromise,
});
return (jest.fn().mockImplementation(() => mockFetchPromise));
}
describe('<RandomPage/>', function () {
it('renders without crashing ', function () {
const wrapper = shallow(<RandomPage/>);
wrapper.unmount();
});
it('test shuffleload fetch', function () {
global.fetch = prepareFetchApi({});
const wrapper = shallow(<RandomPage/>);
expect(global.fetch).toBeCalledTimes(1);
});
it('btnshuffle click test', function () {
global.fetch = prepareFetchApi({});
const wrapper = shallow(<RandomPage/>);
wrapper.find(".btnshuffle").simulate("click");
expect(global.fetch).toBeCalledTimes(2);
});
it('test tags in random selection', function () {
const wrapper = shallow(<RandomPage/>);
wrapper.setState({
tags: [
{tag_name: "test1"},
{tag_name: "test2"}
]
});
expect(wrapper.find("Tag")).toHaveLength(2);
});
});