use index resources for groups

This commit is contained in:
Maren Süwer
2018-10-09 16:17:25 +02:00
parent ff5e7e6dbb
commit b93da611cd
9 changed files with 112 additions and 69 deletions

View File

@@ -14,18 +14,20 @@ import {
modifyConfigReset modifyConfigReset
} from "../modules/config"; } from "../modules/config";
import { connect } from "react-redux"; import { connect } from "react-redux";
import type { Config } from "@scm-manager/ui-types"; import type { Config, Link } from "@scm-manager/ui-types";
import ConfigForm from "../components/form/ConfigForm"; import ConfigForm from "../components/form/ConfigForm";
import { getConfigLink } from "../../modules/indexResource";
type Props = { type Props = {
loading: boolean, loading: boolean,
error: Error, error: Error,
config: Config, config: Config,
configUpdatePermission: boolean, configUpdatePermission: boolean,
configLink: string,
// dispatch functions // dispatch functions
modifyConfig: (config: Config, callback?: () => void) => void, modifyConfig: (config: Config, callback?: () => void) => void,
fetchConfig: void => void, fetchConfig: (link: string) => void,
configReset: void => void, configReset: void => void,
// context objects // context objects
@@ -35,7 +37,7 @@ type Props = {
class GlobalConfig extends React.Component<Props> { class GlobalConfig extends React.Component<Props> {
componentDidMount() { componentDidMount() {
this.props.configReset(); this.props.configReset();
this.props.fetchConfig(); this.props.fetchConfig(this.props.configLink);
} }
modifyConfig = (config: Config) => { modifyConfig = (config: Config) => {
@@ -75,8 +77,8 @@ class GlobalConfig extends React.Component<Props> {
const mapDispatchToProps = dispatch => { const mapDispatchToProps = dispatch => {
return { return {
fetchConfig: () => { fetchConfig: (link: string) => {
dispatch(fetchConfig()); dispatch(fetchConfig(link));
}, },
modifyConfig: (config: Config, callback?: () => void) => { modifyConfig: (config: Config, callback?: () => void) => {
dispatch(modifyConfig(config, callback)); dispatch(modifyConfig(config, callback));
@@ -92,12 +94,14 @@ const mapStateToProps = state => {
const error = getFetchConfigFailure(state) || getModifyConfigFailure(state); const error = getFetchConfigFailure(state) || getModifyConfigFailure(state);
const config = getConfig(state); const config = getConfig(state);
const configUpdatePermission = getConfigUpdatePermission(state); const configUpdatePermission = getConfigUpdatePermission(state);
const configLink = getConfigLink(state);
return { return {
loading, loading,
error, error,
config, config,
configUpdatePermission configUpdatePermission,
configLink
}; };
}; };

View File

@@ -6,7 +6,6 @@ import { isPending } from "../../modules/pending";
import { getFailure } from "../../modules/failure"; import { getFailure } from "../../modules/failure";
import { Dispatch } from "redux"; import { Dispatch } from "redux";
import type { Config } from "@scm-manager/ui-types"; import type { Config } from "@scm-manager/ui-types";
import { getConfigLink } from "../../modules/indexResource";
export const FETCH_CONFIG = "scm/config/FETCH_CONFIG"; export const FETCH_CONFIG = "scm/config/FETCH_CONFIG";
export const FETCH_CONFIG_PENDING = `${FETCH_CONFIG}_${types.PENDING_SUFFIX}`; export const FETCH_CONFIG_PENDING = `${FETCH_CONFIG}_${types.PENDING_SUFFIX}`;
@@ -22,11 +21,11 @@ export const MODIFY_CONFIG_RESET = `${MODIFY_CONFIG}_${types.RESET_SUFFIX}`;
const CONTENT_TYPE_CONFIG = "application/vnd.scmm-config+json;v=2"; const CONTENT_TYPE_CONFIG = "application/vnd.scmm-config+json;v=2";
//fetch config //fetch config
export function fetchConfig() { export function fetchConfig(link: string) {
return function(dispatch: any, getState: any) { return function(dispatch: any) {
dispatch(fetchConfigPending()); dispatch(fetchConfigPending());
return apiClient return apiClient
.get(getConfigLink(getState())) .get(link)
.then(response => { .then(response => {
return response.json(); return response.json();
}) })

View File

@@ -125,7 +125,7 @@ describe("config fetch()", () => {
} }
}); });
return store.dispatch(fetchConfig()).then(() => { return store.dispatch(fetchConfig(CONFIG_URL)).then(() => {
expect(store.getActions()).toEqual(expectedActions); expect(store.getActions()).toEqual(expectedActions);
}); });
}); });
@@ -144,7 +144,7 @@ describe("config fetch()", () => {
} }
} }
}); });
return store.dispatch(fetchConfig()).then(() => { return store.dispatch(fetchConfig(CONFIG_URL)).then(() => {
const actions = store.getActions(); const actions = store.getActions();
expect(actions[0].type).toEqual(FETCH_CONFIG_PENDING); expect(actions[0].type).toEqual(FETCH_CONFIG_PENDING);
expect(actions[1].type).toEqual(FETCH_CONFIG_FAILURE); expect(actions[1].type).toEqual(FETCH_CONFIG_FAILURE);

View File

@@ -18,6 +18,7 @@ import {
Image Image
} from "@scm-manager/ui-components"; } from "@scm-manager/ui-components";
import classNames from "classnames"; import classNames from "classnames";
import { fetchIndexResources } from "../modules/indexResource";
const styles = { const styles = {
avatar: { avatar: {
@@ -44,6 +45,7 @@ type Props = {
// dispatcher props // dispatcher props
login: (username: string, password: string) => void, login: (username: string, password: string) => void,
fetchIndexResources: () => void,
// context props // context props
t: string => string, t: string => string,
@@ -87,6 +89,7 @@ class Login extends React.Component<Props, State> {
} }
renderRedirect = () => { renderRedirect = () => {
this.props.fetchIndexResources();
const { from } = this.props.location.state || { from: { pathname: "/" } }; const { from } = this.props.location.state || { from: { pathname: "/" } };
return <Redirect to={from} />; return <Redirect to={from} />;
}; };
@@ -155,7 +158,8 @@ const mapStateToProps = state => {
const mapDispatchToProps = dispatch => { const mapDispatchToProps = dispatch => {
return { return {
login: (username: string, password: string) => login: (username: string, password: string) =>
dispatch(login(username, password)) dispatch(login(username, password)),
fetchIndexResources: () => dispatch(fetchIndexResources())
}; };
}; };

View File

@@ -9,18 +9,21 @@ import {
createGroup, createGroup,
isCreateGroupPending, isCreateGroupPending,
getCreateGroupFailure, getCreateGroupFailure,
createGroupReset createGroupReset,
getCreateGroupLink
} from "../modules/groups"; } from "../modules/groups";
import type { Group } from "@scm-manager/ui-types"; import type { Group } from "@scm-manager/ui-types";
import type { History } from "history"; import type { History } from "history";
import { getGroupsLink } from "../../modules/indexResource";
type Props = { type Props = {
t: string => string, t: string => string,
createGroup: (group: Group, callback?: () => void) => void, createGroup: (link: string, group: Group, callback?: () => void) => void,
history: History, history: History,
loading?: boolean, loading?: boolean,
error?: Error, error?: Error,
resetForm: () => void resetForm: () => void,
createLink: string
}; };
type State = {}; type State = {};
@@ -51,14 +54,14 @@ class AddGroup extends React.Component<Props, State> {
this.props.history.push("/groups"); this.props.history.push("/groups");
}; };
createGroup = (group: Group) => { createGroup = (group: Group) => {
this.props.createGroup(group, this.groupCreated); this.props.createGroup(this.props.createLink, group, this.groupCreated);
}; };
} }
const mapDispatchToProps = dispatch => { const mapDispatchToProps = dispatch => {
return { return {
createGroup: (group: Group, callback?: () => void) => createGroup: (link: string, group: Group, callback?: () => void) =>
dispatch(createGroup(group, callback)), dispatch(createGroup(link, group, callback)),
resetForm: () => { resetForm: () => {
dispatch(createGroupReset()); dispatch(createGroupReset());
} }
@@ -68,7 +71,9 @@ const mapDispatchToProps = dispatch => {
const mapStateToProps = state => { const mapStateToProps = state => {
const loading = isCreateGroupPending(state); const loading = isCreateGroupPending(state);
const error = getCreateGroupFailure(state); const error = getCreateGroupFailure(state);
const createLink = getGroupsLink(state);
return { return {
createLink,
loading, loading,
error error
}; };

View File

@@ -18,6 +18,7 @@ import {
isPermittedToCreateGroups, isPermittedToCreateGroups,
selectListAsCollection selectListAsCollection
} from "../modules/groups"; } from "../modules/groups";
import { getGroupsLink } from "../../modules/indexResource";
type Props = { type Props = {
groups: Group[], groups: Group[],
@@ -26,19 +27,20 @@ type Props = {
canAddGroups: boolean, canAddGroups: boolean,
list: PagedCollection, list: PagedCollection,
page: number, page: number,
groupLink: string,
// context objects // context objects
t: string => string, t: string => string,
history: History, history: History,
// dispatch functions // dispatch functions
fetchGroupsByPage: (page: number) => void, fetchGroupsByPage: (link: string, page: number) => void,
fetchGroupsByLink: (link: string) => void fetchGroupsByLink: (link: string) => void
}; };
class Groups extends React.Component<Props> { class Groups extends React.Component<Props> {
componentDidMount() { componentDidMount() {
this.props.fetchGroupsByPage(this.props.page); this.props.fetchGroupsByPage(this.props.groupLink, this.props.page);
} }
onPageChange = (link: string) => { onPageChange = (link: string) => {
@@ -111,20 +113,23 @@ const mapStateToProps = (state, ownProps) => {
const canAddGroups = isPermittedToCreateGroups(state); const canAddGroups = isPermittedToCreateGroups(state);
const list = selectListAsCollection(state); const list = selectListAsCollection(state);
const groupLink = getGroupsLink(state);
return { return {
groups, groups,
loading, loading,
error, error,
canAddGroups, canAddGroups,
list, list,
page page,
groupLink
}; };
}; };
const mapDispatchToProps = dispatch => { const mapDispatchToProps = dispatch => {
return { return {
fetchGroupsByPage: (page: number) => { fetchGroupsByPage: (link: string, page: number) => {
dispatch(fetchGroupsByPage(page)); dispatch(fetchGroupsByPage(link, page));
}, },
fetchGroupsByLink: (link: string) => { fetchGroupsByLink: (link: string) => {
dispatch(fetchGroupsByLink(link)); dispatch(fetchGroupsByLink(link));

View File

@@ -26,16 +26,18 @@ import {
import { translate } from "react-i18next"; import { translate } from "react-i18next";
import EditGroup from "./EditGroup"; import EditGroup from "./EditGroup";
import { getGroupsLink } from "../../modules/indexResource";
type Props = { type Props = {
name: string, name: string,
group: Group, group: Group,
loading: boolean, loading: boolean,
error: Error, error: Error,
groupLink: string,
// dispatcher functions // dispatcher functions
deleteGroup: (group: Group, callback?: () => void) => void, deleteGroup: (group: Group, callback?: () => void) => void,
fetchGroup: string => void, fetchGroup: (string, string) => void,
// context objects // context objects
t: string => string, t: string => string,
@@ -45,7 +47,7 @@ type Props = {
class SingleGroup extends React.Component<Props> { class SingleGroup extends React.Component<Props> {
componentDidMount() { componentDidMount() {
this.props.fetchGroup(this.props.name); this.props.fetchGroup(this.props.groupLink, this.props.name);
} }
stripEndingSlash = (url: string) => { stripEndingSlash = (url: string) => {
@@ -132,19 +134,21 @@ const mapStateToProps = (state, ownProps) => {
isFetchGroupPending(state, name) || isDeleteGroupPending(state, name); isFetchGroupPending(state, name) || isDeleteGroupPending(state, name);
const error = const error =
getFetchGroupFailure(state, name) || getDeleteGroupFailure(state, name); getFetchGroupFailure(state, name) || getDeleteGroupFailure(state, name);
const groupLink = getGroupsLink(state);
return { return {
name, name,
group, group,
loading, loading,
error error,
groupLink
}; };
}; };
const mapDispatchToProps = dispatch => { const mapDispatchToProps = dispatch => {
return { return {
fetchGroup: (name: string) => { fetchGroup: (link: string, name: string) => {
dispatch(fetchGroup(name)); dispatch(fetchGroup(link, name));
}, },
deleteGroup: (group: Group, callback?: () => void) => { deleteGroup: (group: Group, callback?: () => void) => {
dispatch(deleteGroup(group, callback)); dispatch(deleteGroup(group, callback));

View File

@@ -32,17 +32,16 @@ export const DELETE_GROUP_PENDING = `${DELETE_GROUP}_${types.PENDING_SUFFIX}`;
export const DELETE_GROUP_SUCCESS = `${DELETE_GROUP}_${types.SUCCESS_SUFFIX}`; export const DELETE_GROUP_SUCCESS = `${DELETE_GROUP}_${types.SUCCESS_SUFFIX}`;
export const DELETE_GROUP_FAILURE = `${DELETE_GROUP}_${types.FAILURE_SUFFIX}`; export const DELETE_GROUP_FAILURE = `${DELETE_GROUP}_${types.FAILURE_SUFFIX}`;
const GROUPS_URL = "groups";
const CONTENT_TYPE_GROUP = "application/vnd.scmm-group+json;v=2"; const CONTENT_TYPE_GROUP = "application/vnd.scmm-group+json;v=2";
// fetch groups // fetch groups
export function fetchGroups() { export function fetchGroups(link: string) {
return fetchGroupsByLink(GROUPS_URL); return fetchGroupsByLink(link);
} }
export function fetchGroupsByPage(page: number) { export function fetchGroupsByPage(link: string, page: number) {
// backend start counting by 0 // backend start counting by 0
return fetchGroupsByLink(GROUPS_URL + "?page=" + (page - 1)); return fetchGroupsByLink(link + "?page=" + (page - 1));
} }
export function fetchGroupsByLink(link: string) { export function fetchGroupsByLink(link: string) {
@@ -56,7 +55,7 @@ export function fetchGroupsByLink(link: string) {
}) })
.catch(cause => { .catch(cause => {
const error = new Error(`could not fetch groups: ${cause.message}`); const error = new Error(`could not fetch groups: ${cause.message}`);
dispatch(fetchGroupsFailure(GROUPS_URL, error)); dispatch(fetchGroupsFailure(link, error));
}); });
}; };
} }
@@ -85,8 +84,8 @@ export function fetchGroupsFailure(url: string, error: Error): Action {
} }
//fetch group //fetch group
export function fetchGroup(name: string) { export function fetchGroup(link: string, name: string) {
const groupUrl = GROUPS_URL + "/" + name; const groupUrl = link.endsWith("/") ? link + name : link + "/" + name;
return function(dispatch: any) { return function(dispatch: any) {
dispatch(fetchGroupPending(name)); dispatch(fetchGroupPending(name));
return apiClient return apiClient
@@ -132,11 +131,11 @@ export function fetchGroupFailure(name: string, error: Error): Action {
} }
//create group //create group
export function createGroup(group: Group, callback?: () => void) { export function createGroup(link: string, group: Group, callback?: () => void) {
return function(dispatch: Dispatch) { return function(dispatch: Dispatch) {
dispatch(createGroupPending()); dispatch(createGroupPending());
return apiClient return apiClient
.post(GROUPS_URL, group, CONTENT_TYPE_GROUP) .post(link, group, CONTENT_TYPE_GROUP)
.then(() => { .then(() => {
dispatch(createGroupSuccess()); dispatch(createGroupSuccess());
if (callback) { if (callback) {
@@ -410,6 +409,12 @@ export const isPermittedToCreateGroups = (state: Object): boolean => {
return false; return false;
}; };
export function getCreateGroupLink(state: Object) {
if (state.groups.list.entry && state.groups.list.entry._links)
return state.groups.list.entry._links.create.href;
return undefined;
}
export function getGroupsFromState(state: Object) { export function getGroupsFromState(state: Object) {
const groupNames = selectList(state).entries; const groupNames = selectList(state).entries;
if (!groupNames) { if (!groupNames) {

View File

@@ -42,9 +42,11 @@ import reducer, {
modifyGroup, modifyGroup,
MODIFY_GROUP_PENDING, MODIFY_GROUP_PENDING,
MODIFY_GROUP_SUCCESS, MODIFY_GROUP_SUCCESS,
MODIFY_GROUP_FAILURE MODIFY_GROUP_FAILURE,
getCreateGroupLink
} from "./groups"; } from "./groups";
const GROUPS_URL = "/api/v2/groups"; const GROUPS_URL = "/api/v2/groups";
const URL = "/groups";
const error = new Error("You have an error!"); const error = new Error("You have an error!");
@@ -63,7 +65,7 @@ const humanGroup = {
href: "http://localhost:8081/api/v2/groups/humanGroup" href: "http://localhost:8081/api/v2/groups/humanGroup"
}, },
update: { update: {
href:"http://localhost:8081/api/v2/groups/humanGroup" href: "http://localhost:8081/api/v2/groups/humanGroup"
} }
}, },
_embedded: { _embedded: {
@@ -95,7 +97,7 @@ const emptyGroup = {
href: "http://localhost:8081/api/v2/groups/emptyGroup" href: "http://localhost:8081/api/v2/groups/emptyGroup"
}, },
update: { update: {
href:"http://localhost:8081/api/v2/groups/emptyGroup" href: "http://localhost:8081/api/v2/groups/emptyGroup"
} }
}, },
_embedded: { _embedded: {
@@ -150,7 +152,7 @@ describe("groups fetch()", () => {
const store = mockStore({}); const store = mockStore({});
return store.dispatch(fetchGroups()).then(() => { return store.dispatch(fetchGroups(URL)).then(() => {
expect(store.getActions()).toEqual(expectedActions); expect(store.getActions()).toEqual(expectedActions);
}); });
}); });
@@ -161,7 +163,7 @@ describe("groups fetch()", () => {
}); });
const store = mockStore({}); const store = mockStore({});
return store.dispatch(fetchGroups()).then(() => { return store.dispatch(fetchGroups(URL)).then(() => {
const actions = store.getActions(); const actions = store.getActions();
expect(actions[0].type).toEqual(FETCH_GROUPS_PENDING); expect(actions[0].type).toEqual(FETCH_GROUPS_PENDING);
expect(actions[1].type).toEqual(FETCH_GROUPS_FAILURE); expect(actions[1].type).toEqual(FETCH_GROUPS_FAILURE);
@@ -173,7 +175,7 @@ describe("groups fetch()", () => {
fetchMock.getOnce(GROUPS_URL + "/humanGroup", humanGroup); fetchMock.getOnce(GROUPS_URL + "/humanGroup", humanGroup);
const store = mockStore({}); const store = mockStore({});
return store.dispatch(fetchGroup("humanGroup")).then(() => { return store.dispatch(fetchGroup(URL, "humanGroup")).then(() => {
const actions = store.getActions(); const actions = store.getActions();
expect(actions[0].type).toEqual(FETCH_GROUP_PENDING); expect(actions[0].type).toEqual(FETCH_GROUP_PENDING);
expect(actions[1].type).toEqual(FETCH_GROUP_SUCCESS); expect(actions[1].type).toEqual(FETCH_GROUP_SUCCESS);
@@ -187,7 +189,7 @@ describe("groups fetch()", () => {
}); });
const store = mockStore({}); const store = mockStore({});
return store.dispatch(fetchGroup("humanGroup")).then(() => { return store.dispatch(fetchGroup(URL, "humanGroup")).then(() => {
const actions = store.getActions(); const actions = store.getActions();
expect(actions[0].type).toEqual(FETCH_GROUP_PENDING); expect(actions[0].type).toEqual(FETCH_GROUP_PENDING);
expect(actions[1].type).toEqual(FETCH_GROUP_FAILURE); expect(actions[1].type).toEqual(FETCH_GROUP_FAILURE);
@@ -195,14 +197,13 @@ describe("groups fetch()", () => {
}); });
}); });
it("should successfully create group", () => { it("should successfully create group", () => {
fetchMock.postOnce(GROUPS_URL, { fetchMock.postOnce(GROUPS_URL, {
status: 201 status: 201
}); });
const store = mockStore({}); const store = mockStore({});
return store.dispatch(createGroup(humanGroup)).then(() => { return store.dispatch(createGroup(URL, humanGroup)).then(() => {
const actions = store.getActions(); const actions = store.getActions();
expect(actions[0].type).toEqual(CREATE_GROUP_PENDING); expect(actions[0].type).toEqual(CREATE_GROUP_PENDING);
expect(actions[1].type).toEqual(CREATE_GROUP_SUCCESS); expect(actions[1].type).toEqual(CREATE_GROUP_SUCCESS);
@@ -219,14 +220,13 @@ describe("groups fetch()", () => {
called = true; called = true;
}; };
const store = mockStore({}); const store = mockStore({});
return store.dispatch(createGroup(humanGroup, callMe)).then(() => { return store.dispatch(createGroup(URL, humanGroup, callMe)).then(() => {
const actions = store.getActions(); const actions = store.getActions();
expect(actions[0].type).toEqual(CREATE_GROUP_PENDING); expect(actions[0].type).toEqual(CREATE_GROUP_PENDING);
expect(actions[1].type).toEqual(CREATE_GROUP_SUCCESS); expect(actions[1].type).toEqual(CREATE_GROUP_SUCCESS);
expect(called).toEqual(true); expect(called).toEqual(true);
}); });
}); });
it("should fail creating group on HTTP 500", () => { it("should fail creating group on HTTP 500", () => {
fetchMock.postOnce(GROUPS_URL, { fetchMock.postOnce(GROUPS_URL, {
@@ -234,7 +234,7 @@ describe("groups fetch()", () => {
}); });
const store = mockStore({}); const store = mockStore({});
return store.dispatch(createGroup(humanGroup)).then(() => { return store.dispatch(createGroup(URL, humanGroup)).then(() => {
const actions = store.getActions(); const actions = store.getActions();
expect(actions[0].type).toEqual(CREATE_GROUP_PENDING); expect(actions[0].type).toEqual(CREATE_GROUP_PENDING);
expect(actions[1].type).toEqual(CREATE_GROUP_FAILURE); expect(actions[1].type).toEqual(CREATE_GROUP_FAILURE);
@@ -248,7 +248,7 @@ describe("groups fetch()", () => {
status: 204 status: 204
}); });
const store = mockStore({}); const store = mockStore({});
return store.dispatch(modifyGroup(humanGroup)).then(() => { return store.dispatch(modifyGroup(humanGroup)).then(() => {
const actions = store.getActions(); const actions = store.getActions();
@@ -267,7 +267,7 @@ describe("groups fetch()", () => {
const callback = () => { const callback = () => {
called = true; called = true;
}; };
const store = mockStore({}); const store = mockStore({});
return store.dispatch(modifyGroup(humanGroup, callback)).then(() => { return store.dispatch(modifyGroup(humanGroup, callback)).then(() => {
const actions = store.getActions(); const actions = store.getActions();
@@ -282,7 +282,7 @@ describe("groups fetch()", () => {
status: 500 status: 500
}); });
const store = mockStore({}); const store = mockStore({});
return store.dispatch(modifyGroup(humanGroup)).then(() => { return store.dispatch(modifyGroup(humanGroup)).then(() => {
const actions = store.getActions(); const actions = store.getActions();
@@ -337,13 +337,10 @@ describe("groups fetch()", () => {
expect(actions[1].payload).toBeDefined(); expect(actions[1].payload).toBeDefined();
}); });
}); });
}); });
describe("groups reducer", () => { describe("groups reducer", () => {
it("should update state correctly according to FETCH_GROUPS_SUCCESS action", () => { it("should update state correctly according to FETCH_GROUPS_SUCCESS action", () => {
const newState = reducer({}, fetchGroupsSuccess(responseBody)); const newState = reducer({}, fetchGroupsSuccess(responseBody));
expect(newState.list).toEqual({ expect(newState.list).toEqual({
@@ -391,7 +388,6 @@ describe("groups reducer", () => {
expect(newState.byNames["humanGroup"]).toBeTruthy(); expect(newState.byNames["humanGroup"]).toBeTruthy();
}); });
it("should update state according to FETCH_GROUP_SUCCESS action", () => { it("should update state according to FETCH_GROUP_SUCCESS action", () => {
const newState = reducer({}, fetchGroupSuccess(emptyGroup)); const newState = reducer({}, fetchGroupSuccess(emptyGroup));
expect(newState.byNames["emptyGroup"]).toBe(emptyGroup); expect(newState.byNames["emptyGroup"]).toBe(emptyGroup);
@@ -426,7 +422,6 @@ describe("groups reducer", () => {
expect(newState.byNames["emptyGroup"]).toBeFalsy(); expect(newState.byNames["emptyGroup"]).toBeFalsy();
expect(newState.list.entries).toEqual(["humanGroup"]); expect(newState.list.entries).toEqual(["humanGroup"]);
}); });
}); });
describe("selector tests", () => { describe("selector tests", () => {
@@ -476,6 +471,23 @@ describe("selector tests", () => {
expect(isPermittedToCreateGroups(state)).toBe(true); expect(isPermittedToCreateGroups(state)).toBe(true);
}); });
it("should return create Group link", () => {
const state = {
groups: {
list: {
entry: {
_links: {
create: {
href: "/create"
}
}
}
}
}
};
expect(getCreateGroupLink(state)).toBe("/create");
});
it("should get groups from state", () => { it("should get groups from state", () => {
const state = { const state = {
groups: { groups: {
@@ -488,7 +500,7 @@ describe("selector tests", () => {
} }
} }
}; };
expect(getGroupsFromState(state)).toEqual([{ name: "a" }, { name: "b" }]); expect(getGroupsFromState(state)).toEqual([{ name: "a" }, { name: "b" }]);
}); });
@@ -560,9 +572,13 @@ describe("selector tests", () => {
}); });
it("should return true if create group is pending", () => { it("should return true if create group is pending", () => {
expect(isCreateGroupPending({pending: { expect(
[CREATE_GROUP]: true isCreateGroupPending({
}})).toBeTruthy(); pending: {
[CREATE_GROUP]: true
}
})
).toBeTruthy();
}); });
it("should return false if create group is not pending", () => { it("should return false if create group is not pending", () => {
@@ -570,18 +586,19 @@ describe("selector tests", () => {
}); });
it("should return error if creating group failed", () => { it("should return error if creating group failed", () => {
expect(getCreateGroupFailure({ expect(
failure: { getCreateGroupFailure({
[CREATE_GROUP]: error failure: {
} [CREATE_GROUP]: error
})).toEqual(error); }
})
).toEqual(error);
}); });
it("should return undefined if creating group did not fail", () => { it("should return undefined if creating group did not fail", () => {
expect(getCreateGroupFailure({})).toBeUndefined(); expect(getCreateGroupFailure({})).toBeUndefined();
}); });
it("should return true, when delete group humanGroup is pending", () => { it("should return true, when delete group humanGroup is pending", () => {
const state = { const state = {
pending: { pending: {