diff --git a/src/elements/Preview/Previw.test.js b/src/elements/Preview/Previw.test.js index 1631d94..1395a65 100644 --- a/src/elements/Preview/Previw.test.js +++ b/src/elements/Preview/Previw.test.js @@ -22,7 +22,7 @@ describe('', function () { const wrapper = shallow(); wrapper.setProps({ viewbinding: { - showVideo: () => { + changeRootElement: () => { func() } } diff --git a/src/elements/Tag/Tag.test.js b/src/elements/Tag/Tag.test.js index 4ee9886..183608d 100644 --- a/src/elements/Tag/Tag.test.js +++ b/src/elements/Tag/Tag.test.js @@ -5,6 +5,14 @@ import "@testing-library/jest-dom" import {shallow} from 'enzyme' describe('', function () { + function prepareFetchApi(response) { + const mockJsonPromise = Promise.resolve(response); + const mockFetchPromise = Promise.resolve({ + json: () => mockJsonPromise, + }); + return (jest.fn().mockImplementation(() => mockFetchPromise)); + } + it('renders without crashing ', function () { const wrapper = shallow(test); wrapper.unmount(); @@ -14,4 +22,22 @@ describe('', function () { const wrapper = shallow(test); expect(wrapper.children().text()).toBe("test"); }); + + it('click event triggered and setvideo callback called', done => { + global.fetch = prepareFetchApi({}); + const func = jest.fn(); + + const wrapper = shallow(test); + + wrapper.simulate("click"); + + process.nextTick(() => { + // state to be set correctly with response + expect(func).toBeCalledTimes(1); + + global.fetch.mockClear(); + done(); + }); + }); }); diff --git a/src/pages/HomePage/HomePage.test.js b/src/pages/HomePage/HomePage.test.js index 5e23abb..0ba8447 100644 --- a/src/pages/HomePage/HomePage.test.js +++ b/src/pages/HomePage/HomePage.test.js @@ -1,4 +1,4 @@ -import {shallow} from "enzyme"; +import {shallow, mount} from "enzyme"; import React from "react"; import HomePage from "./HomePage"; import VideoContainer from "../../elements/VideoContainer/VideoContainer"; @@ -23,7 +23,8 @@ describe('', function () { }); it('ckeck default tag click events', function () { - const wrapper = shallow(); + // todo mount bad here maybe delete this test + const wrapper = mount(); global.fetch = prepareFetchApi({}); expect(global.fetch).toBeCalledTimes(0); diff --git a/src/pages/Player/Player.test.js b/src/pages/Player/Player.test.js index ec21940..2ac02e2 100644 --- a/src/pages/Player/Player.test.js +++ b/src/pages/Player/Player.test.js @@ -99,7 +99,7 @@ describe('', function () { wrapper.setProps({ viewbinding: { - hideVideo: () => { + returnToLastElement: () => { func() } }