2019-08-19 12:20:38 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import Vuex from 'vuex';
|
2022-09-08 15:11:09 +01:00
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2022-09-08 15:11:09 +01:00
|
|
|
import { ProjectMembersApiMock } from '../mock/api/projectMembers';
|
|
|
|
import { ProjectsApiMock } from '../mock/api/projects';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
|
|
|
import { appStateModule } from '@/store/modules/appState';
|
2019-08-20 13:57:43 +01:00
|
|
|
import { makeProjectMembersModule, PROJECT_MEMBER_MUTATIONS } from '@/store/modules/projectMembers';
|
2019-10-17 11:34:45 +01:00
|
|
|
import { makeProjectsModule } from '@/store/modules/projects';
|
2019-08-19 12:20:38 +01:00
|
|
|
import { ProjectMember, ProjectMembersPage } from '@/types/projectMembers';
|
2019-10-17 11:34:45 +01:00
|
|
|
import { Project } from '@/types/projects';
|
2019-08-19 12:20:38 +01:00
|
|
|
|
2022-09-08 15:11:09 +01:00
|
|
|
import ProjectMembersArea from '@/components/team/ProjectMembersArea.vue';
|
2019-08-19 12:20:38 +01:00
|
|
|
|
2019-10-17 11:34:45 +01:00
|
|
|
const localVue = createLocalVue();
|
2019-08-19 12:20:38 +01:00
|
|
|
localVue.use(Vuex);
|
|
|
|
|
2019-10-17 11:34:45 +01:00
|
|
|
const pmApi = new ProjectMembersApiMock();
|
|
|
|
const projectMembersModule = makeProjectMembersModule(pmApi);
|
|
|
|
const projectsApi = new ProjectsApiMock();
|
|
|
|
const projectsModule = makeProjectsModule(projectsApi);
|
|
|
|
const { FETCH } = PROJECT_MEMBER_MUTATIONS;
|
2022-09-08 15:11:09 +01:00
|
|
|
const store = new Vuex.Store({ modules: { projectsModule, projectMembersModule, appStateModule } });
|
2019-08-19 12:20:38 +01:00
|
|
|
|
|
|
|
describe('ProjectMembersArea.vue', () => {
|
2019-10-22 12:12:49 +01:00
|
|
|
const project = new Project('id', 'projectName', 'projectDescription', 'test', 'testOwnerId', true);
|
2019-10-17 11:34:45 +01:00
|
|
|
projectsApi.setMockProjects([project]);
|
2020-09-28 14:44:01 +01:00
|
|
|
const date = new Date(0);
|
|
|
|
const projectMember1 = new ProjectMember('testFullName1', 'testShortName1', 'test1@example.com', date, '1');
|
|
|
|
const projectMember2 = new ProjectMember('testFullName2', 'testShortName2', 'test2@example.com', date, '2');
|
2019-08-19 12:20:38 +01:00
|
|
|
|
2019-10-17 11:34:45 +01:00
|
|
|
const testProjectMembersPage = new ProjectMembersPage();
|
|
|
|
testProjectMembersPage.projectMembers = [projectMember1];
|
|
|
|
testProjectMembersPage.totalCount = 1;
|
|
|
|
testProjectMembersPage.pageCount = 1;
|
2019-08-19 12:20:38 +01:00
|
|
|
|
2019-10-17 11:34:45 +01:00
|
|
|
pmApi.setMockPage(testProjectMembersPage);
|
2019-08-19 12:20:38 +01:00
|
|
|
|
2021-06-09 16:13:19 +01:00
|
|
|
it('renders correctly', async (): Promise<void> => {
|
2022-04-07 12:04:24 +01:00
|
|
|
const wrapper = shallowMount<ProjectMembersArea>(ProjectMembersArea, {
|
2019-08-30 12:34:51 +01:00
|
|
|
store,
|
2019-09-13 15:58:18 +01:00
|
|
|
localVue,
|
2019-08-30 12:34:51 +01:00
|
|
|
});
|
|
|
|
|
2021-06-09 16:13:19 +01:00
|
|
|
await wrapper.setData({ areMembersFetching: false });
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
it('function fetchProjectMembers works correctly', () => {
|
2019-10-17 11:34:45 +01:00
|
|
|
store.commit(FETCH, testProjectMembersPage);
|
2019-08-19 12:20:38 +01:00
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
const wrapper = shallowMount<ProjectMembersArea>(ProjectMembersArea, {
|
2019-08-19 12:20:38 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2019-10-17 11:34:45 +01:00
|
|
|
expect(wrapper.vm.projectMembers).toEqual([projectMember1]);
|
2019-08-19 12:20:38 +01:00
|
|
|
});
|
|
|
|
|
2021-06-09 16:13:19 +01:00
|
|
|
it('team area renders correctly', async (): Promise<void> => {
|
2019-10-17 11:34:45 +01:00
|
|
|
store.commit(FETCH, testProjectMembersPage);
|
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
const wrapper = shallowMount<ProjectMembersArea>(ProjectMembersArea, {
|
2019-08-30 12:34:51 +01:00
|
|
|
store,
|
2019-09-13 15:58:18 +01:00
|
|
|
localVue,
|
2019-08-30 12:34:51 +01:00
|
|
|
});
|
|
|
|
|
2021-06-09 16:13:19 +01:00
|
|
|
await wrapper.setData({ areMembersFetching: false });
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const emptySearchResultArea = wrapper.findAll('.team-area__empty-search-result-area');
|
|
|
|
expect(emptySearchResultArea.length).toBe(0);
|
|
|
|
|
2022-07-22 18:09:30 +01:00
|
|
|
const teamContainer = wrapper.findAll('.team-area__table');
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(teamContainer.length).toBe(1);
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
it('action on toggle works correctly', () => {
|
2019-10-17 11:34:45 +01:00
|
|
|
store.commit(FETCH, testProjectMembersPage);
|
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
const wrapper = shallowMount<ProjectMembersArea>(ProjectMembersArea, {
|
2019-08-19 12:20:38 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2022-07-22 18:09:30 +01:00
|
|
|
wrapper.vm.onMemberCheckChange(projectMember1);
|
2019-08-19 12:20:38 +01:00
|
|
|
|
|
|
|
expect(store.getters.selectedProjectMembers.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('clear selection works correctly', () => {
|
2020-09-28 14:44:01 +01:00
|
|
|
const date = new Date(0);
|
|
|
|
const projectMember3 = new ProjectMember('testFullName1', 'testShortName1', 'test1@example.com', date, '1');
|
2019-10-17 11:34:45 +01:00
|
|
|
projectMember3.isSelected = true;
|
|
|
|
const testProjectMembersPage = new ProjectMembersPage();
|
|
|
|
testProjectMembersPage.projectMembers = [projectMember3];
|
|
|
|
testProjectMembersPage.totalCount = 1;
|
|
|
|
testProjectMembersPage.pageCount = 1;
|
|
|
|
store.commit(FETCH, testProjectMembersPage);
|
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
const wrapper = shallowMount<ProjectMembersArea>(ProjectMembersArea, {
|
2019-08-19 12:20:38 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2022-07-22 18:09:30 +01:00
|
|
|
wrapper.vm.onMemberCheckChange(projectMember3);
|
2019-08-19 12:20:38 +01:00
|
|
|
|
|
|
|
expect(store.getters.selectedProjectMembers.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Reversing list order triggers rerender', () => {
|
2019-10-17 11:34:45 +01:00
|
|
|
const testPage = new ProjectMembersPage();
|
|
|
|
testPage.projectMembers = [projectMember1, projectMember2];
|
|
|
|
testPage.totalCount = 2;
|
|
|
|
testPage.pageCount = 1;
|
|
|
|
pmApi.setMockPage(testPage);
|
2019-08-19 12:20:38 +01:00
|
|
|
|
2019-10-17 11:34:45 +01:00
|
|
|
store.commit(FETCH, testPage);
|
2019-08-19 12:20:38 +01:00
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
const wrapper = shallowMount<ProjectMembersArea>(ProjectMembersArea, {
|
2019-08-19 12:20:38 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.projectMembers[0].user.id).toBe(projectMember1.user.id);
|
|
|
|
|
|
|
|
testProjectMembersPage.projectMembers = [projectMember2, projectMember1];
|
|
|
|
|
2019-10-17 11:34:45 +01:00
|
|
|
store.commit(FETCH, testProjectMembersPage);
|
2019-08-19 12:20:38 +01:00
|
|
|
|
|
|
|
expect(wrapper.vm.projectMembers[0].user.id).toBe(projectMember2.user.id);
|
|
|
|
});
|
2019-10-17 11:34:45 +01:00
|
|
|
|
2021-06-09 16:13:19 +01:00
|
|
|
it('empty search result area render correctly', async (): Promise<void> => {
|
2019-10-17 11:34:45 +01:00
|
|
|
const testPage1 = new ProjectMembersPage();
|
|
|
|
testPage1.projectMembers = [];
|
|
|
|
testPage1.totalCount = 0;
|
|
|
|
testPage1.pageCount = 0;
|
|
|
|
testPage1.search = 'testSearch';
|
|
|
|
pmApi.setMockPage(testPage1);
|
|
|
|
|
|
|
|
store.commit(FETCH, testPage1);
|
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
const wrapper = shallowMount<ProjectMembersArea>(ProjectMembersArea, {
|
2019-10-17 11:34:45 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2021-06-09 16:13:19 +01:00
|
|
|
await wrapper.setData({ areMembersFetching: false });
|
|
|
|
|
2019-10-17 11:34:45 +01:00
|
|
|
const emptySearchResultArea = wrapper.findAll('.team-area__empty-search-result-area');
|
|
|
|
expect(emptySearchResultArea.length).toBe(1);
|
|
|
|
|
|
|
|
const teamContainer = wrapper.findAll('.team-area__container');
|
|
|
|
expect(teamContainer.length).toBe(0);
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2019-08-19 12:20:38 +01:00
|
|
|
});
|