2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2019-01-08 15:14:00 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import { projectMembersModule } from '@/store/modules/projectMembers';
|
2019-01-28 14:39:51 +00:00
|
|
|
import { createLocalVue } from '@vue/test-utils';
|
2019-01-08 15:14:00 +00:00
|
|
|
import { PROJECT_MEMBER_MUTATIONS } from '@/store/mutationConstants';
|
2019-01-28 14:39:51 +00:00
|
|
|
import Vuex from 'vuex';
|
2019-08-19 12:20:38 +01:00
|
|
|
import { ProjectMember, ProjectMemberCursor, ProjectMembersPage } from '@/types/projectMembers';
|
2019-01-28 14:39:51 +00:00
|
|
|
|
|
|
|
const mutations = projectMembersModule.mutations;
|
2019-01-08 15:14:00 +00:00
|
|
|
|
|
|
|
describe('mutations', () => {
|
2019-02-20 13:33:56 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
createLocalVue().use(Vuex);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('success delete project members', () => {
|
|
|
|
const state = {
|
2019-08-19 12:20:38 +01:00
|
|
|
cursor: new ProjectMemberCursor(),
|
|
|
|
page: {
|
|
|
|
projectMembers: [{user: {email: '1'}}, {user: {email: '2'}}]
|
|
|
|
} as ProjectMembersPage,
|
2019-02-20 13:33:56 +00:00
|
|
|
};
|
|
|
|
const store = new Vuex.Store({state, mutations});
|
|
|
|
|
|
|
|
const membersToDelete = ['1', '2'];
|
|
|
|
|
|
|
|
store.commit(PROJECT_MEMBER_MUTATIONS.DELETE, membersToDelete);
|
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
expect(state.page.projectMembers.length).toBe(0);
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('error delete project members', () => {
|
|
|
|
const state = {
|
2019-08-19 12:20:38 +01:00
|
|
|
cursor: new ProjectMemberCursor(),
|
|
|
|
page: {
|
|
|
|
projectMembers: [{user: {email: '1'}}, {user: {email: '2'}}]
|
|
|
|
} as ProjectMembersPage,
|
2019-02-20 13:33:56 +00:00
|
|
|
};
|
|
|
|
const store = new Vuex.Store({state, mutations});
|
|
|
|
|
|
|
|
const membersToDelete = ['3', '4'];
|
|
|
|
|
|
|
|
store.commit(PROJECT_MEMBER_MUTATIONS.DELETE, membersToDelete);
|
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
expect(state.page.projectMembers.length).toBe(2);
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('toggle selection', () => {
|
|
|
|
const state = {
|
2019-08-19 12:20:38 +01:00
|
|
|
cursor: new ProjectMemberCursor(),
|
|
|
|
page: {
|
|
|
|
projectMembers: [{
|
|
|
|
user: {id: '1'},
|
|
|
|
isSelected: false
|
|
|
|
}, {
|
|
|
|
user: {id: '2'},
|
|
|
|
isSelected: false
|
|
|
|
}]
|
|
|
|
} as ProjectMembersPage,
|
2019-02-20 13:33:56 +00:00
|
|
|
};
|
|
|
|
const store = new Vuex.Store({state, mutations});
|
|
|
|
|
|
|
|
const memberId = '1';
|
|
|
|
|
|
|
|
store.commit(PROJECT_MEMBER_MUTATIONS.TOGGLE_SELECTION, memberId);
|
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
expect(state.page.projectMembers[0].isSelected).toBeTruthy();
|
|
|
|
expect(state.page.projectMembers[1].isSelected).toBeFalsy();
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('clear selection', () => {
|
|
|
|
const state = {
|
2019-08-19 12:20:38 +01:00
|
|
|
cursor: new ProjectMemberCursor(),
|
|
|
|
page: {
|
|
|
|
projectMembers: [{
|
|
|
|
user: {id: '1'},
|
|
|
|
isSelected: true
|
|
|
|
}, {
|
|
|
|
user: {id: '2'},
|
|
|
|
isSelected: true
|
|
|
|
}]
|
|
|
|
} as ProjectMembersPage,
|
2019-02-20 13:33:56 +00:00
|
|
|
};
|
|
|
|
const store = new Vuex.Store({state, mutations});
|
|
|
|
|
|
|
|
store.commit(PROJECT_MEMBER_MUTATIONS.CLEAR_SELECTION);
|
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
expect(state.page.projectMembers[0].isSelected).toBeFalsy();
|
|
|
|
expect(state.page.projectMembers[1].isSelected).toBeFalsy();
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
it('fetch projectMembers members', () => {
|
2019-02-20 13:33:56 +00:00
|
|
|
const state = {
|
2019-08-19 12:20:38 +01:00
|
|
|
cursor: new ProjectMemberCursor(),
|
|
|
|
page: new ProjectMembersPage(),
|
2019-02-20 13:33:56 +00:00
|
|
|
};
|
|
|
|
const store = new Vuex.Store({state, mutations});
|
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
const teamMembers = new ProjectMembersPage();
|
|
|
|
teamMembers.projectMembers = [
|
|
|
|
new ProjectMember('', '', '', '', '1'),
|
|
|
|
];
|
2019-02-20 13:33:56 +00:00
|
|
|
|
|
|
|
store.commit(PROJECT_MEMBER_MUTATIONS.FETCH, teamMembers);
|
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
expect(state.page.projectMembers.length).toBe(1);
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
2019-01-08 15:14:00 +00:00
|
|
|
});
|
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
// describe('actions', () => {
|
|
|
|
// beforeEach(() => {
|
|
|
|
// jest.resetAllMocks();
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// it('success add project members', async function () {
|
|
|
|
// const rootGetters = {
|
|
|
|
// selectedProject: {
|
|
|
|
// id: '1'
|
|
|
|
// },
|
|
|
|
// searchParameters: {},
|
|
|
|
// pagination: {limit: 20, offset: 0}
|
|
|
|
// };
|
|
|
|
// jest.spyOn(api, 'addProjectMembersRequest').mockReturnValue(Promise.resolve(<RequestResponse<null>>{isSuccess: true}));
|
|
|
|
//
|
|
|
|
// const emails = ['1', '2'];
|
|
|
|
//
|
|
|
|
// const dispatchResponse = await projectMembersModule.actions.addProjectMembers({rootGetters}, emails);
|
|
|
|
//
|
|
|
|
// expect(dispatchResponse.isSuccess).toBeTruthy();
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// it('error add project members', async function () {
|
|
|
|
// const rootGetters = {
|
|
|
|
// selectedProject: {
|
|
|
|
// id: '1'
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// jest.spyOn(api, 'addProjectMembersRequest').mockReturnValue(Promise.resolve(<RequestResponse<null>>{isSuccess: false}));
|
|
|
|
//
|
|
|
|
// const emails = ['1', '2'];
|
|
|
|
//
|
|
|
|
// const dispatchResponse = await projectMembersModule.actions.addProjectMembers({rootGetters}, emails);
|
|
|
|
//
|
|
|
|
// expect(dispatchResponse.isSuccess).toBeFalsy();
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// it('success delete project members', async () => {
|
|
|
|
// const rootGetters = {
|
|
|
|
// selectedProject: {
|
|
|
|
// id: '1'
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// jest.spyOn(api, 'deleteProjectMembersRequest').mockReturnValue(Promise.resolve(<RequestResponse<null>>{isSuccess: true}));
|
|
|
|
//
|
|
|
|
// const commit = jest.fn();
|
|
|
|
// const emails = ['1', '2'];
|
|
|
|
//
|
|
|
|
// const dispatchResponse = await projectMembersModule.actions.deleteProjectMembers({commit, rootGetters}, emails);
|
|
|
|
//
|
|
|
|
// expect(dispatchResponse.isSuccess).toBeTruthy();
|
|
|
|
// expect(commit).toHaveBeenCalledWith(PROJECT_MEMBER_MUTATIONS.DELETE, emails);
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// it('error delete project members', async () => {
|
|
|
|
// const rootGetters = {
|
|
|
|
// selectedProject: {
|
|
|
|
// id: '1'
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// jest.spyOn(api, 'deleteProjectMembersRequest').mockReturnValue(Promise.resolve(<RequestResponse<null>>{isSuccess: false}));
|
|
|
|
//
|
|
|
|
// const commit = jest.fn();
|
|
|
|
// const emails = ['1', '2'];
|
|
|
|
//
|
|
|
|
// const dispatchResponse = await projectMembersModule.actions.deleteProjectMembers({commit, rootGetters}, emails);
|
|
|
|
//
|
|
|
|
// expect(dispatchResponse.isSuccess).toBeFalsy();
|
|
|
|
// expect(commit).toHaveBeenCalledTimes(0);
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// it('toggle selection', function () {
|
|
|
|
// const commit = jest.fn();
|
|
|
|
// const projectMemberId = '1';
|
|
|
|
//
|
|
|
|
// projectMembersModule.actions.toggleProjectMemberSelection({commit}, projectMemberId);
|
|
|
|
//
|
|
|
|
// expect(commit).toHaveBeenCalledWith(PROJECT_MEMBER_MUTATIONS.TOGGLE_SELECTION, projectMemberId);
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// it('clear selection', function () {
|
|
|
|
// const commit = jest.fn();
|
|
|
|
//
|
|
|
|
// projectMembersModule.actions.clearProjectMemberSelection({commit});
|
|
|
|
//
|
|
|
|
// expect(commit).toHaveBeenCalledTimes(1);
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// it('success fetch project members', async function () {
|
|
|
|
// const rootGetters = {
|
|
|
|
// selectedProject: {
|
|
|
|
// id: '1'
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// const state = {
|
|
|
|
// pagination: {
|
|
|
|
// limit: 20,
|
|
|
|
// offset: 0
|
|
|
|
// },
|
|
|
|
// searchParameters: {
|
|
|
|
// searchQuery: ''
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// const commit = jest.fn();
|
|
|
|
// const projectMemberMockModel: ProjectMember = new ProjectMember('1', '1', '1', '1', '1');
|
|
|
|
// jest.spyOn(api, 'fetchProjectMembersRequest').mockReturnValue(
|
|
|
|
// Promise.resolve(<RequestResponse<ProjectMember[]>>{
|
|
|
|
// isSuccess: true,
|
|
|
|
// data: [projectMemberMockModel]
|
|
|
|
// }));
|
|
|
|
//
|
|
|
|
// const dispatchResponse = await projectMembersModule.actions.fetchProjectMembers({
|
|
|
|
// state,
|
|
|
|
// commit,
|
|
|
|
// rootGetters
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// expect(dispatchResponse.isSuccess).toBeTruthy();
|
|
|
|
// expect(commit).toHaveBeenCalledWith(PROJECT_MEMBER_MUTATIONS.FETCH, [projectMemberMockModel]);
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// it('error fetch project members', async function () {
|
|
|
|
// const rootGetters = {
|
|
|
|
// selectedProject: {
|
|
|
|
// id: '1'
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// const state = {
|
|
|
|
// pagination: {
|
|
|
|
// limit: 20,
|
|
|
|
// offset: 0
|
|
|
|
// },
|
|
|
|
// searchParameters: {
|
|
|
|
// searchQuery: ''
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// const commit = jest.fn();
|
|
|
|
// jest.spyOn(api, 'fetchProjectMembersRequest').mockReturnValue(
|
|
|
|
// Promise.resolve(<RequestResponse<ProjectMember[]>>{
|
|
|
|
// isSuccess: false,
|
|
|
|
// })
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// const dispatchResponse = await projectMembersModule.actions.fetchProjectMembers({
|
|
|
|
// state,
|
|
|
|
// commit,
|
|
|
|
// rootGetters
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// expect(dispatchResponse.isSuccess).toBeFalsy();
|
|
|
|
// expect(commit).toHaveBeenCalledTimes(0);
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
// describe('getters', () => {
|
|
|
|
// it('project members', function () {
|
|
|
|
// const state = {
|
|
|
|
// projectMembers: [{user: {email: '1'}}]
|
|
|
|
// };
|
|
|
|
// const retrievedProjectMembers = projectMembersModule.getters.projectMembers(state);
|
|
|
|
//
|
|
|
|
// expect(retrievedProjectMembers.length).toBe(1);
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// it('selected project members', function () {
|
|
|
|
// const state = {
|
|
|
|
// projectMembers: [
|
|
|
|
// {isSelected: false},
|
|
|
|
// {isSelected: true},
|
|
|
|
// {isSelected: true},
|
|
|
|
// {isSelected: true},
|
|
|
|
// {isSelected: false},
|
|
|
|
// ]
|
|
|
|
// };
|
|
|
|
// const retrievedSelectedProjectMembers = projectMembersModule.getters.selectedProjectMembers(state);
|
|
|
|
// expect(retrievedSelectedProjectMembers.length).toBe(3);
|
|
|
|
// });
|
|
|
|
// });
|