mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-08 05:10:20 +01:00
fixed tests
This commit is contained in:
@@ -1,30 +1,41 @@
|
||||
import React from "react";
|
||||
import { mount, shallow } from "enzyme";
|
||||
import { mount } from "enzyme";
|
||||
import ReactRouterEnzymeContext from "react-router-enzyme-context";
|
||||
import configureStore from "redux-mock-store";
|
||||
|
||||
import "../../tests/enzyme";
|
||||
import "../../tests/i18n";
|
||||
import DeleteGroup from "./DeleteGroup";
|
||||
|
||||
import { confirmAlert } from "@scm-manager/ui-components";
|
||||
|
||||
jest.mock("@scm-manager/ui-components", () => ({
|
||||
confirmAlert: jest.fn(),
|
||||
Subtitle: require.requireActual("@scm-manager/ui-components").Subtitle,
|
||||
DeleteButton: require.requireActual("@scm-manager/ui-components").DeleteButton
|
||||
DeleteButton: require.requireActual("@scm-manager/ui-components").DeleteButton,
|
||||
ErrorNotification: ({err}) => err ? err.message : null
|
||||
}));
|
||||
|
||||
const options = new ReactRouterEnzymeContext();
|
||||
|
||||
describe("DeleteGroupNavLink", () => {
|
||||
|
||||
let store;
|
||||
|
||||
beforeEach(() => {
|
||||
store = configureStore()({});
|
||||
});
|
||||
|
||||
it("should render nothing, if the delete link is missing", () => {
|
||||
const group = {
|
||||
_links: {}
|
||||
};
|
||||
|
||||
const navLink = shallow(
|
||||
<DeleteGroup group={group} deleteGroup={() => {}} />
|
||||
const navLink = mount(
|
||||
<DeleteGroup group={group} store={store} />,
|
||||
options.get()
|
||||
);
|
||||
expect(navLink.text()).toBe("");
|
||||
expect(navLink.text()).toBeNull();
|
||||
});
|
||||
|
||||
it("should render the navLink", () => {
|
||||
@@ -37,7 +48,7 @@ describe("DeleteGroupNavLink", () => {
|
||||
};
|
||||
|
||||
const navLink = mount(
|
||||
<DeleteGroup group={group} deleteGroup={() => {}} />,
|
||||
<DeleteGroup group={group} store={store} />,
|
||||
options.get()
|
||||
);
|
||||
expect(navLink.text()).not.toBe("");
|
||||
@@ -53,7 +64,7 @@ describe("DeleteGroupNavLink", () => {
|
||||
};
|
||||
|
||||
const navLink = mount(
|
||||
<DeleteGroup group={group} deleteGroup={() => {}} />,
|
||||
<DeleteGroup group={group} store={store} />,
|
||||
options.get()
|
||||
);
|
||||
navLink.find("button").simulate("click");
|
||||
@@ -70,21 +81,18 @@ describe("DeleteGroupNavLink", () => {
|
||||
}
|
||||
};
|
||||
|
||||
let calledUrl = null;
|
||||
function capture(group) {
|
||||
calledUrl = group._links.delete.href;
|
||||
}
|
||||
store.dispatch = jest.fn();
|
||||
|
||||
const navLink = mount(
|
||||
<DeleteGroup
|
||||
group={group}
|
||||
confirmDialog={false}
|
||||
deleteGroup={capture}
|
||||
store={store}
|
||||
/>,
|
||||
options.get()
|
||||
);
|
||||
navLink.find("button").simulate("click");
|
||||
|
||||
expect(calledUrl).toBe("/groups");
|
||||
expect(store.dispatch.mock.calls.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,7 +32,8 @@ describe("DeleteRepo", () => {
|
||||
};
|
||||
|
||||
const navLink = mount(
|
||||
<DeleteRepo repository={repository} store={store} />
|
||||
<DeleteRepo repository={repository} store={store} />,
|
||||
options.get()
|
||||
);
|
||||
expect(navLink.text()).toBeNull();
|
||||
});
|
||||
@@ -80,6 +81,8 @@ describe("DeleteRepo", () => {
|
||||
}
|
||||
};
|
||||
|
||||
store.dispatch = jest.fn();
|
||||
|
||||
const navLink = mount(
|
||||
<DeleteRepo
|
||||
repository={repository}
|
||||
@@ -90,6 +93,6 @@ describe("DeleteRepo", () => {
|
||||
);
|
||||
navLink.find("button").simulate("click");
|
||||
|
||||
expect(calledUrl).toBe("/repos");
|
||||
expect(store.dispatch.mock.calls.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,30 +1,41 @@
|
||||
import React from "react";
|
||||
import { mount, shallow } from "enzyme";
|
||||
import { mount } from "enzyme";
|
||||
import ReactRouterEnzymeContext from "react-router-enzyme-context";
|
||||
import configureStore from "redux-mock-store";
|
||||
|
||||
import "../../tests/enzyme";
|
||||
import "../../tests/i18n";
|
||||
import DeleteUser from "./DeleteUser";
|
||||
|
||||
import { confirmAlert } from "@scm-manager/ui-components";
|
||||
|
||||
jest.mock("@scm-manager/ui-components", () => ({
|
||||
confirmAlert: jest.fn(),
|
||||
Subtitle: require.requireActual("@scm-manager/ui-components").Subtitle,
|
||||
DeleteButton: require.requireActual("@scm-manager/ui-components").DeleteButton
|
||||
DeleteButton: require.requireActual("@scm-manager/ui-components").DeleteButton,
|
||||
ErrorNotification: ({err}) => err ? err.message : null
|
||||
}));
|
||||
|
||||
const options = new ReactRouterEnzymeContext();
|
||||
|
||||
describe("DeleteUser", () => {
|
||||
|
||||
let store;
|
||||
|
||||
beforeEach(() => {
|
||||
store = configureStore()({});
|
||||
});
|
||||
|
||||
it("should render nothing, if the delete link is missing", () => {
|
||||
const user = {
|
||||
_links: {}
|
||||
};
|
||||
|
||||
const navLink = shallow(
|
||||
<DeleteUser user={user} deleteUser={() => {}} />
|
||||
const navLink = mount(
|
||||
<DeleteUser user={user} store={store} />,
|
||||
options.get()
|
||||
);
|
||||
expect(navLink.text()).toBe("");
|
||||
expect(navLink.text()).toBeNull();
|
||||
});
|
||||
|
||||
it("should render the navLink", () => {
|
||||
@@ -37,7 +48,7 @@ describe("DeleteUser", () => {
|
||||
};
|
||||
|
||||
const navLink = mount(
|
||||
<DeleteUser user={user} deleteUser={() => {}} />,
|
||||
<DeleteUser user={user} store={store} />,
|
||||
options.get()
|
||||
);
|
||||
expect(navLink.text()).not.toBe("");
|
||||
@@ -53,7 +64,7 @@ describe("DeleteUser", () => {
|
||||
};
|
||||
|
||||
const navLink = mount(
|
||||
<DeleteUser user={user} deleteUser={() => {}} />,
|
||||
<DeleteUser user={user} store={store} />,
|
||||
options.get()
|
||||
);
|
||||
navLink.find("button").simulate("click");
|
||||
@@ -70,21 +81,18 @@ describe("DeleteUser", () => {
|
||||
}
|
||||
};
|
||||
|
||||
let calledUrl = null;
|
||||
function capture(user) {
|
||||
calledUrl = user._links.delete.href;
|
||||
}
|
||||
store.dispatch = jest.fn();
|
||||
|
||||
const navLink = mount(
|
||||
<DeleteUser
|
||||
user={user}
|
||||
confirmDialog={false}
|
||||
deleteUser={capture}
|
||||
store={store}
|
||||
/>,
|
||||
options.get()
|
||||
);
|
||||
navLink.find("button").simulate("click");
|
||||
|
||||
expect(calledUrl).toBe("/users");
|
||||
expect(store.dispatch.mock.calls.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user