123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- /*
- * <<
- * Davinci
- * ==
- * Copyright (C) 2016 - 2017 EDP
- * ==
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * >>
- */
- import produce from 'immer'
- import reducer, { initialState } from 'app/containers/Organizations/reducer'
- import actions from 'app/containers/Organizations/actions'
- import { mockAnonymousAction } from 'test/utils/fixtures'
- import { mockStore } from './fixtures'
- describe('organizationReducer', () => {
- const {
- orgId,
- projects,
- orgProjects,
- organization,
- organizations,
- role,
- members,
- roles,
- memberId
- } = mockStore
- let state
- beforeEach(() => {
- state = initialState
- })
- it('should return the initial state', () => {
- expect(reducer(void 0, mockAnonymousAction)).toEqual(state)
- })
- it('should handle the organizationMemberDeleted action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- if (draft.currentOrganizationMembers) {
- draft.currentOrganizationMembers = draft.currentOrganizationMembers.filter(
- (d) => d.id !== orgId
- )
- }
- })
- expect(reducer(state, actions.organizationMemberDeleted(orgId))).toEqual(
- expectedResult
- )
- })
- it('should handle the organizationsProjectsLoaded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.currentOrganizationProjects = orgProjects.list
- draft.currentOrganizationProjectsDetail = orgProjects
- })
- expect(
- reducer(state, actions.organizationsProjectsLoaded(orgProjects))
- ).toEqual(expectedResult)
- })
- it('should handle the organizationsMembersLoaded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.currentOrganizationMembers = members.map((member) => {
- return {
- ...member,
- roles: 'loading'
- }
- })
- })
- expect(reducer(state, actions.organizationsMembersLoaded(members))).toEqual(
- expectedResult
- )
- })
- it('should handle the getRoleListByMemberIdFail action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- const mId = memberId
- if (draft.currentOrganizationMembers) {
- draft.currentOrganizationMembers = draft.currentOrganizationMembers.map(
- (member) =>
- member.user.id === mId ? { ...member, roles: undefined } : member
- )
- }
- })
- expect(
- reducer(state, actions.getRoleListByMemberIdFail('error', memberId))
- ).toEqual(expectedResult)
- })
- it('should handle the getRoleListByMemberIdSuccess action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- if (draft.currentOrganizationMembers) {
- draft.currentOrganizationMembers = draft.currentOrganizationMembers.map(
- (member) =>
- member.user.id === memberId ? { ...member, roles } : member
- )
- }
- })
- expect(
- reducer(state, actions.getRoleListByMemberIdSuccess(roles, memberId))
- ).toEqual(expectedResult)
- })
- it('should handle the organizationsRoleLoaded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.currentOrganizationRole = role
- })
- expect(reducer(state, actions.organizationsRoleLoaded(role))).toEqual(
- expectedResult
- )
- })
- it('should handle the organizationsLoaded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.organizations = organizations
- })
- expect(reducer(state, actions.organizationsLoaded(organizations))).toEqual(
- expectedResult
- )
- })
- it('should handle the organizationAdded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- if (draft.organizations) {
- draft.organizations.unshift(organization)
- } else {
- draft.organizations = [organization]
- }
- })
- expect(reducer(state, actions.organizationAdded(organization))).toEqual(
- expectedResult
- )
- })
- it('should handle the organizationEdited action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.organizations.splice(
- draft.organizations.findIndex((d) => d.id === organization.id),
- 1,
- organization
- )
- })
- expect(reducer(state, actions.organizationEdited(organization))).toEqual(
- expectedResult
- )
- })
- it('should handle the organizationDeleted action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.organizations = draft.organizations.filter((d) => d.id !== orgId)
- })
- expect(reducer(state, actions.organizationDeleted(orgId))).toEqual(
- expectedResult
- )
- })
- it('should handle the loadOrganizationDetail action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.currentOrganizationLoading = true
- })
- expect(reducer(state, actions.loadOrganizationDetail(orgId))).toEqual(
- expectedResult
- )
- })
- it('should handle the organizationDetailLoaded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.currentOrganizationLoading = false
- draft.currentOrganization = organization
- })
- expect(
- reducer(state, actions.organizationDetailLoaded(organization))
- ).toEqual(expectedResult)
- })
- it('should handle the roleAdded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.roleModalLoading = false
- })
- expect(reducer(state, actions.roleAdded(role))).toEqual(expectedResult)
- })
- it('should handle the addRoleFail action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.roleModalLoading = false
- })
- expect(reducer(state, actions.addRoleFail())).toEqual(expectedResult)
- })
- it('should handle the searchMember action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.inviteMemberfetching = true
- })
- expect(reducer(state, actions.searchMember('keyword'))).toEqual(
- expectedResult
- )
- })
- it('should handle the memberSearched action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.inviteMemberLists = members
- draft.inviteMemberfetching = false
- })
- expect(reducer(state, actions.memberSearched(members))).toEqual(
- expectedResult
- )
- })
- it('should handle the searchMemberFail action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.inviteMemberfetching = true
- })
- expect(reducer(state, actions.searchMemberFail())).toEqual(expectedResult)
- })
- it('should handle the setCurrentProject action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.projectDetail = orgProjects
- })
- expect(reducer(state, actions.setCurrentProject(orgProjects))).toEqual(
- expectedResult
- )
- })
- it('should handle the projectAdminLoaded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.projectAdmins = projects
- })
- expect(reducer(state, actions.projectAdminLoaded(projects))).toEqual(
- expectedResult
- )
- })
- it('should handle the projectRolesLoaded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.projectRoles = role
- })
- expect(reducer(state, actions.projectRolesLoaded(role))).toEqual(
- expectedResult
- )
- })
- })
|