From 83d2d86a40a316eb332b9962f9fac2eae3259cc2 Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Mon, 30 Jul 2018 13:12:44 +0200 Subject: [PATCH] collection-creation-test Feature #13893 Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk --- .../collection-creator-reducer.test.ts | 44 ++++++++++++++++++- .../creator/collection-creator-reducer.ts | 8 ++-- src/store/project/project-reducer.test.ts | 13 +++--- src/store/project/project-reducer.ts | 4 +- .../dialog-collection-create.tsx | 4 +- .../dialog-create/dialog-project-create.tsx | 2 +- 6 files changed, 56 insertions(+), 19 deletions(-) diff --git a/src/store/collections/creator/collection-creator-reducer.test.ts b/src/store/collections/creator/collection-creator-reducer.test.ts index df2c3628..0da18c81 100644 --- a/src/store/collections/creator/collection-creator-reducer.test.ts +++ b/src/store/collections/creator/collection-creator-reducer.test.ts @@ -1,3 +1,45 @@ // 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 diff --git a/src/store/collections/creator/collection-creator-reducer.ts b/src/store/collections/creator/collection-creator-reducer.ts index c7854808..769766e1 100644 --- a/src/store/collections/creator/collection-creator-reducer.ts +++ b/src/store/collections/creator/collection-creator-reducer.ts @@ -10,11 +10,10 @@ export type CollectionCreatorState = { interface CollectionCreator { opened: boolean; - pending: boolean; ownerUuid: string; } -const updateCreator = (state: CollectionCreatorState, creator: Partial) => ({ +const updateCreator = (state: CollectionCreatorState, creator?: Partial) => ({ ...state, creator: { ...state.creator, @@ -25,16 +24,15 @@ const updateCreator = (state: CollectionCreatorState, creator: Partial { 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 }); diff --git a/src/store/project/project-reducer.test.ts b/src/store/project/project-reducer.test.ts index 0fc28960..92274b3d 100644 --- a/src/store/project/project-reducer.test.ts +++ b/src/store/project/project-reducer.test.ts @@ -35,7 +35,6 @@ describe('project-reducer', () => { creator: { opened: false, ownerUuid: "", - pending: false } }); }); @@ -50,7 +49,7 @@ describe('project-reducer', () => { status: TreeItemStatus.PENDING }], currentItemId: "1", - creator: { opened: false, pending: false, ownerUuid: "" }, + creator: { opened: false, ownerUuid: "" }, }; const project = { items: [{ @@ -61,7 +60,7 @@ describe('project-reducer', () => { 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)); @@ -78,7 +77,7 @@ describe('project-reducer', () => { status: TreeItemStatus.PENDING }], currentItemId: "1", - creator: { opened: false, pending: false, ownerUuid: "" } + creator: { opened: false, ownerUuid: "" } }; const project = { items: [{ @@ -89,7 +88,7 @@ describe('project-reducer', () => { 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)); @@ -107,7 +106,7 @@ describe('project-reducer', () => { status: TreeItemStatus.PENDING, }], currentItemId: "1", - creator: { opened: false, pending: false, ownerUuid: "" } + creator: { opened: false, ownerUuid: "" } }; const project = { items: [{ @@ -118,7 +117,7 @@ describe('project-reducer', () => { 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)); diff --git a/src/store/project/project-reducer.ts b/src/store/project/project-reducer.ts index 45e0e195..f5af23ab 100644 --- a/src/store/project/project-reducer.ts +++ b/src/store/project/project-reducer.ts @@ -16,7 +16,6 @@ export type ProjectState = { interface ProjectCreator { opened: boolean; - pending: boolean; ownerUuid: string; error?: string; } @@ -106,7 +105,6 @@ const initialState: ProjectState = { currentItemId: "", creator: { opened: false, - pending: false, ownerUuid: "" } }; @@ -114,7 +112,7 @@ const initialState: ProjectState = { 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: "" }), diff --git a/src/views-components/dialog-create/dialog-collection-create.tsx b/src/views-components/dialog-create/dialog-collection-create.tsx index 8ce0c5d2..d0f793bf 100644 --- a/src/views-components/dialog-create/dialog-collection-create.tsx +++ b/src/views-components/dialog-create/dialog-collection-create.tsx @@ -42,7 +42,7 @@ const styles: StyleRulesCallback = theme => ({ createProgress: { position: "absolute", minWidth: "20px", - right: "95px" + right: "110px" }, dialogActions: { marginBottom: "24px" @@ -102,7 +102,7 @@ export const DialogCollectionCreate = compose( diff --git a/src/views-components/dialog-create/dialog-project-create.tsx b/src/views-components/dialog-create/dialog-project-create.tsx index e05a3bd9..acfe3973 100644 --- a/src/views-components/dialog-create/dialog-project-create.tsx +++ b/src/views-components/dialog-create/dialog-project-create.tsx @@ -103,7 +103,7 @@ export const DialogProjectCreate = compose( -- 2.39.5