From ad1aaccfacff466b839ef5d5f27c969369076cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maren=20S=C3=BCwer?= Date: Tue, 17 Jul 2018 15:06:40 +0200 Subject: [PATCH] add tests for alert dialog --- .../users/containers/DeleteUserButton.test.js | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/scm-ui/src/users/containers/DeleteUserButton.test.js b/scm-ui/src/users/containers/DeleteUserButton.test.js index 937ee81172..944c739c35 100644 --- a/scm-ui/src/users/containers/DeleteUserButton.test.js +++ b/scm-ui/src/users/containers/DeleteUserButton.test.js @@ -3,6 +3,9 @@ import { configure, shallow } from "enzyme"; import DeleteUserButton from "./DeleteUserButton"; import Adapter from "enzyme-adapter-react-16"; +import { confirmAlert } from '../../components/ConfirmAlert'; +jest.mock('../../components/ConfirmAlert'); + import "raf/polyfill"; configure({ adapter: new Adapter() }); @@ -12,7 +15,7 @@ it("should render nothing, if the delete link is missing", () => { _links: {} }; - const button = shallow(); + const button = shallow( {}} />); expect(button.text()).toBe(""); }); @@ -25,11 +28,26 @@ it("should render the button", () => { } }; - const button = shallow(); + const button = shallow( {}} />); expect(button.text()).not.toBe(""); }); -//TODO: Fix wrong test! +it("should open the confirm dialog on button click", () => { + + const user = { + _links: { + delete: { + href: "/users" + } + } + }; + + const button = shallow( {}} />); + button.simulate("click"); + + expect(confirmAlert.mock.calls.length).toBe(1); +}); + it("should call the delete user function with delete url", () => { const user = { _links: { @@ -40,12 +58,11 @@ it("should call the delete user function with delete url", () => { }; let calledUrl = null; - function capture(url) { calledUrl = url; } - const button = shallow(); + const button = shallow(); button.simulate("click"); expect(calledUrl).toBe("/users");