mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
add tests for alert dialog
This commit is contained in:
@@ -3,6 +3,9 @@ import { configure, shallow } from "enzyme";
|
|||||||
import DeleteUserButton from "./DeleteUserButton";
|
import DeleteUserButton from "./DeleteUserButton";
|
||||||
import Adapter from "enzyme-adapter-react-16";
|
import Adapter from "enzyme-adapter-react-16";
|
||||||
|
|
||||||
|
import { confirmAlert } from '../../components/ConfirmAlert';
|
||||||
|
jest.mock('../../components/ConfirmAlert');
|
||||||
|
|
||||||
import "raf/polyfill";
|
import "raf/polyfill";
|
||||||
|
|
||||||
configure({ adapter: new Adapter() });
|
configure({ adapter: new Adapter() });
|
||||||
@@ -12,7 +15,7 @@ it("should render nothing, if the delete link is missing", () => {
|
|||||||
_links: {}
|
_links: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const button = shallow(<DeleteUserButton user={user} />);
|
const button = shallow(<DeleteUserButton user={user} deleteUser={() => {}} />);
|
||||||
expect(button.text()).toBe("");
|
expect(button.text()).toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -25,11 +28,26 @@ it("should render the button", () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const button = shallow(<DeleteUserButton user={user} />);
|
const button = shallow(<DeleteUserButton user={user} deleteUser={() => {}} />);
|
||||||
expect(button.text()).not.toBe("");
|
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(<DeleteUserButton user={user} deleteUser={() => {}} />);
|
||||||
|
button.simulate("click");
|
||||||
|
|
||||||
|
expect(confirmAlert.mock.calls.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
it("should call the delete user function with delete url", () => {
|
it("should call the delete user function with delete url", () => {
|
||||||
const user = {
|
const user = {
|
||||||
_links: {
|
_links: {
|
||||||
@@ -40,12 +58,11 @@ it("should call the delete user function with delete url", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let calledUrl = null;
|
let calledUrl = null;
|
||||||
|
|
||||||
function capture(url) {
|
function capture(url) {
|
||||||
calledUrl = url;
|
calledUrl = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
const button = shallow(<DeleteUserButton user={user} deleteUser={capture} />);
|
const button = shallow(<DeleteUserButton user={user} confirmDialog={false} deleteUser={capture} />);
|
||||||
button.simulate("click");
|
button.simulate("click");
|
||||||
|
|
||||||
expect(calledUrl).toBe("/users");
|
expect(calledUrl).toBe("/users");
|
||||||
|
|||||||
Reference in New Issue
Block a user