2019-08-19 12:20:38 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import Vuex from 'vuex';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
import ProjectMembersArea from '@/components/team/ProjectMembersArea.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
|
|
|
import { ProjectMembersApiGql } from '@/api/projectMembers';
|
|
|
|
import { appStateModule } from '@/store/modules/appState';
|
2019-08-20 13:57:43 +01:00
|
|
|
import { makeProjectMembersModule, PROJECT_MEMBER_MUTATIONS } from '@/store/modules/projectMembers';
|
2019-08-19 12:20:38 +01:00
|
|
|
import { ProjectMember, ProjectMembersPage } from '@/types/projectMembers';
|
2019-09-09 11:33:39 +01:00
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
2019-08-19 12:20:38 +01:00
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
const projectMember1 = new ProjectMember('testFullName1', 'testShortName1', 'test1@example.com', 'now1', '1');
|
|
|
|
const projectMember2 = new ProjectMember('testFullName2', 'testShortName2', 'test2@example.com', 'now2', '2');
|
|
|
|
|
|
|
|
describe('ProjectMembersArea.vue', () => {
|
2019-08-20 13:57:43 +01:00
|
|
|
const pmApi = new ProjectMembersApiGql();
|
|
|
|
const projectMembersModule = makeProjectMembersModule(pmApi);
|
2019-08-19 12:20:38 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const store = new Vuex.Store({modules: { projectMembersModule, appStateModule }});
|
2019-08-19 12:20:38 +01:00
|
|
|
|
|
|
|
it('renders correctly', () => {
|
|
|
|
const wrapper = shallowMount(ProjectMembersArea, {
|
|
|
|
store,
|
2019-09-13 15:58:18 +01:00
|
|
|
localVue,
|
2019-08-19 12:20:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
it('empty search result area render correctly', function () {
|
|
|
|
const wrapper = shallowMount(ProjectMembersArea, {
|
|
|
|
store,
|
2019-09-13 15:58:18 +01:00
|
|
|
localVue,
|
2019-08-30 12:34:51 +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
|
|
|
it('function fetchProjectMembers works correctly', () => {
|
|
|
|
const testProjectMembersPage = new ProjectMembersPage();
|
|
|
|
testProjectMembersPage.projectMembers = [projectMember1];
|
|
|
|
testProjectMembersPage.totalCount = 1;
|
|
|
|
testProjectMembersPage.pageCount = 1;
|
|
|
|
|
|
|
|
store.commit(PROJECT_MEMBER_MUTATIONS.FETCH, testProjectMembersPage);
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const wrapper = shallowMount(ProjectMembersArea, {
|
2019-08-19 12:20:38 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.projectMembers.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
it('team area renders correctly', function () {
|
|
|
|
const wrapper = shallowMount(ProjectMembersArea, {
|
|
|
|
store,
|
2019-09-13 15:58:18 +01:00
|
|
|
localVue,
|
2019-08-30 12:34:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
const emptySearchResultArea = wrapper.findAll('.team-area__empty-search-result-area');
|
|
|
|
expect(emptySearchResultArea.length).toBe(0);
|
|
|
|
|
|
|
|
const teamContainer = wrapper.findAll('.team-area__container');
|
|
|
|
expect(teamContainer.length).toBe(1);
|
|
|
|
|
|
|
|
const sortingListHeaderStub = wrapper.findAll('sortinglistheader-stub');
|
|
|
|
expect(sortingListHeaderStub.length).toBe(1);
|
|
|
|
|
2019-09-26 14:36:12 +01:00
|
|
|
const listStub = wrapper.findAll('vlist-stub');
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(listStub.length).toBe(1);
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
it('action on toggle works correctly', () => {
|
2019-08-30 12:34:51 +01:00
|
|
|
const wrapper = shallowMount(ProjectMembersArea, {
|
2019-08-19 12:20:38 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.onMemberClick(projectMember1);
|
|
|
|
|
|
|
|
expect(store.getters.selectedProjectMembers.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('clear selection works correctly', () => {
|
2019-08-30 12:34:51 +01:00
|
|
|
const wrapper = shallowMount(ProjectMembersArea, {
|
2019-08-19 12:20:38 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.onMemberClick(projectMember1);
|
|
|
|
|
|
|
|
expect(store.getters.selectedProjectMembers.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Reversing list order triggers rerender', () => {
|
|
|
|
const testProjectMembersPage = new ProjectMembersPage();
|
|
|
|
testProjectMembersPage.projectMembers = [projectMember1, projectMember2];
|
|
|
|
testProjectMembersPage.totalCount = 2;
|
|
|
|
testProjectMembersPage.pageCount = 1;
|
|
|
|
|
|
|
|
store.commit(PROJECT_MEMBER_MUTATIONS.FETCH, testProjectMembersPage);
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const wrapper = shallowMount(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];
|
|
|
|
|
|
|
|
store.commit(PROJECT_MEMBER_MUTATIONS.FETCH, testProjectMembersPage);
|
|
|
|
|
|
|
|
expect(wrapper.vm.projectMembers[0].user.id).toBe(projectMember2.user.id);
|
|
|
|
});
|
|
|
|
});
|