// Copyright (C) The Arvados Authors. All rights reserved.
//
-// SPDX-License-Identifier: AGPL-3.0
\ No newline at end of file
+// SPDX-License-Identifier: AGPL-3.0
+
+import { collectionCreationReducer } from "./collection-creator-reducer";
+import { collectionCreateActions } from "./collection-creator-action";
+
+describe('collection-reducer', () => {
+
+ it('should open collection creator dialog', () => {
+ const initialState = {
+ creator: { opened: false, ownerUuid: "" }
+ };
+ const collection = {
+ creator: { opened: true, ownerUuid: "" },
+ };
+
+ const state = collectionCreationReducer(initialState, collectionCreateActions.OPEN_COLLECTION_CREATOR(initialState.creator));
+ expect(state).toEqual(collection);
+ });
+
+ it('should close collection creator dialog', () => {
+ const initialState = {
+ creator: { opened: true, ownerUuid: "" }
+ };
+ const collection = {
+ creator: { opened: false, ownerUuid: "" },
+ };
+
+ const state = collectionCreationReducer(initialState, collectionCreateActions.CLOSE_COLLECTION_CREATOR());
+ expect(state).toEqual(collection);
+ });
+
+ it('should reset collection creator dialog props', () => {
+ const initialState = {
+ creator: { opened: true, ownerUuid: "test" }
+ };
+ const collection = {
+ creator: { opened: false, ownerUuid: "" },
+ };
+
+ const state = collectionCreationReducer(initialState, collectionCreateActions.CREATE_COLLECTION_SUCCESS());
+ expect(state).toEqual(collection);
+ });
+});
\ No newline at end of file
interface CollectionCreator {
opened: boolean;
- pending: boolean;
ownerUuid: string;
}
-const updateCreator = (state: CollectionCreatorState, creator: Partial<CollectionCreator>) => ({
+const updateCreator = (state: CollectionCreatorState, creator?: Partial<CollectionCreator>) => ({
...state,
creator: {
...state.creator,
const initialState: CollectionCreatorState = {
creator: {
opened: false,
- pending: false,
ownerUuid: ""
}
};
export const collectionCreationReducer = (state: CollectionCreatorState = initialState, action: CollectionCreateAction) => {
return collectionCreateActions.match(action, {
- OPEN_COLLECTION_CREATOR: ({ ownerUuid }) => updateCreator(state, { ownerUuid, opened: true, pending: false }),
+ OPEN_COLLECTION_CREATOR: ({ ownerUuid }) => updateCreator(state, { ownerUuid, opened: true }),
CLOSE_COLLECTION_CREATOR: () => updateCreator(state, { opened: false }),
- CREATE_COLLECTION: () => updateCreator(state, { opened: true }),
+ CREATE_COLLECTION: () => updateCreator(state),
CREATE_COLLECTION_SUCCESS: () => updateCreator(state, { opened: false, ownerUuid: "" }),
default: () => state
});
creator: {
opened: false,
ownerUuid: "",
- pending: false
}
});
});
status: TreeItemStatus.PENDING
}],
currentItemId: "1",
- creator: { opened: false, pending: false, ownerUuid: "" },
+ creator: { opened: false, ownerUuid: "" },
};
const project = {
items: [{
status: TreeItemStatus.PENDING
}],
currentItemId: "",
- creator: { opened: false, pending: false, ownerUuid: "" },
+ creator: { opened: false, ownerUuid: "" },
};
const state = projectsReducer(initialState, projectActions.RESET_PROJECT_TREE_ACTIVITY(initialState.items[0].id));
status: TreeItemStatus.PENDING
}],
currentItemId: "1",
- creator: { opened: false, pending: false, ownerUuid: "" }
+ creator: { opened: false, ownerUuid: "" }
};
const project = {
items: [{
status: TreeItemStatus.PENDING,
}],
currentItemId: "1",
- creator: { opened: false, pending: false, ownerUuid: "" },
+ creator: { opened: false, ownerUuid: "" },
};
const state = projectsReducer(initialState, projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(initialState.items[0].id));
status: TreeItemStatus.PENDING,
}],
currentItemId: "1",
- creator: { opened: false, pending: false, ownerUuid: "" }
+ creator: { opened: false, ownerUuid: "" }
};
const project = {
items: [{
status: TreeItemStatus.PENDING,
}],
currentItemId: "1",
- creator: { opened: false, pending: false, ownerUuid: "" },
+ creator: { opened: false, ownerUuid: "" },
};
const state = projectsReducer(initialState, projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(initialState.items[0].id));
interface ProjectCreator {
opened: boolean;
- pending: boolean;
ownerUuid: string;
error?: string;
}
currentItemId: "",
creator: {
opened: false,
- pending: false,
ownerUuid: ""
}
};
export const projectsReducer = (state: ProjectState = initialState, action: ProjectAction) => {
return projectActions.match(action, {
- OPEN_PROJECT_CREATOR: ({ ownerUuid }) => updateCreator(state, { ownerUuid, opened: true, pending: false }),
+ OPEN_PROJECT_CREATOR: ({ ownerUuid }) => updateCreator(state, { ownerUuid, opened: true }),
CLOSE_PROJECT_CREATOR: () => updateCreator(state, { opened: false }),
CREATE_PROJECT: () => updateCreator(state, { error: undefined }),
CREATE_PROJECT_SUCCESS: () => updateCreator(state, { opened: false, ownerUuid: "" }),
createProgress: {
position: "absolute",
minWidth: "20px",
- right: "95px"
+ right: "110px"
},
dialogActions: {
marginBottom: "24px"
<Button type="submit"
className={classes.lastButton}
color="primary"
- disabled={invalid|| submitting || pristine}
+ disabled={invalid || submitting || pristine}
variant="contained">
CREATE A COLLECTION
</Button>
<Button type="submit"
className={classes.lastButton}
color="primary"
- disabled={invalid|| submitting || pristine}
+ disabled={invalid || submitting || pristine}
variant="contained">
CREATE A PROJECT
</Button>