2019-08-09 12:19:49 +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-11-16 14:35:14 +00:00
|
|
|
import { ProjectMembersApiMock } from '../../mock/api/projectMembers';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
import { appStateModule } from '@/store/modules/appState';
|
|
|
|
import { makeNotificationsModule } from '@/store/modules/notifications';
|
2019-09-09 11:33:39 +01:00
|
|
|
import { makeProjectMembersModule } from '@/store/modules/projectMembers';
|
2019-08-30 12:34:51 +01:00
|
|
|
import { ProjectMember, ProjectMemberHeaderState, ProjectMembersPage } from '@/types/projectMembers';
|
2022-09-08 15:11:09 +01:00
|
|
|
import { APP_STATE_MUTATIONS } from '@/store/mutationConstants';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2022-09-08 15:11:09 +01:00
|
|
|
import HeaderArea from '@/components/team/HeaderArea.vue';
|
2019-08-09 12:19:49 +01:00
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
2020-09-28 14:44:01 +01:00
|
|
|
const date = new Date(0);
|
2019-08-30 12:34:51 +01:00
|
|
|
const projectMembers: ProjectMember[] = [
|
2020-09-28 14:44:01 +01:00
|
|
|
new ProjectMember('f1', 's1', '1@example.com', date, '1'),
|
|
|
|
new ProjectMember('f2', 's2', '2@example.com', date, '2'),
|
|
|
|
new ProjectMember('f3', 's3', '3@example.com', date, '3'),
|
2019-08-30 12:34:51 +01:00
|
|
|
];
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const api = new ProjectMembersApiMock();
|
|
|
|
api.setMockPage(new ProjectMembersPage(projectMembers));
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const notificationsModule = makeNotificationsModule();
|
|
|
|
const projectMembersModule = makeProjectMembersModule(api);
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
localVue.use(Vuex);
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const store = new Vuex.Store({ modules: { appStateModule, projectMembersModule, notificationsModule } });
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
describe('Team HeaderArea', () => {
|
|
|
|
it('renders correctly', () => {
|
2022-04-07 12:04:24 +01:00
|
|
|
const wrapper = shallowMount<HeaderArea>(HeaderArea, {
|
2019-08-30 12:34:51 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
2019-08-09 12:19:49 +01:00
|
|
|
});
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const addNewTemMemberPopup = wrapper.findAll('adduserpopup-stub');
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
expect(addNewTemMemberPopup.length).toBe(0);
|
|
|
|
expect(wrapper.findAll('.header-default-state').length).toBe(1);
|
|
|
|
expect(wrapper.findAll('.blur-content').length).toBe(0);
|
|
|
|
expect(wrapper.findAll('.blur-search').length).toBe(0);
|
|
|
|
expect(wrapper.vm.isDeleteClicked).toBe(false);
|
2019-08-09 12:19:49 +01:00
|
|
|
});
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
it('renders correctly with opened Add team member popup', () => {
|
2022-08-03 14:29:58 +01:00
|
|
|
store.commit(APP_STATE_MUTATIONS.TOGGLE_ADD_TEAM_MEMBERS_MODAL);
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
const wrapper = shallowMount<HeaderArea>(HeaderArea, {
|
2019-08-09 12:19:49 +01:00
|
|
|
store,
|
2019-08-30 12:34:51 +01:00
|
|
|
localVue,
|
2019-08-29 16:06:17 +01:00
|
|
|
});
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
expect(wrapper.findAll('.header-default-state').length).toBe(1);
|
|
|
|
expect(wrapper.vm.isDeleteClicked).toBe(false);
|
|
|
|
expect(wrapper.findAll('.blur-content').length).toBe(0);
|
|
|
|
expect(wrapper.findAll('.blur-search').length).toBe(0);
|
2019-08-29 16:06:17 +01:00
|
|
|
|
2022-08-03 14:29:58 +01:00
|
|
|
store.commit(APP_STATE_MUTATIONS.TOGGLE_ADD_TEAM_MEMBERS_MODAL);
|
2019-08-09 12:19:49 +01:00
|
|
|
});
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
it('renders correctly with selected users', () => {
|
2022-08-03 14:29:58 +01:00
|
|
|
store.commit(APP_STATE_MUTATIONS.TOGGLE_ADD_TEAM_MEMBERS_MODAL);
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const selectedUsersCount = 2;
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
const wrapper = shallowMount<HeaderArea>(HeaderArea, {
|
2019-08-30 12:34:51 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
propsData: {
|
|
|
|
selectedProjectMembersCount: selectedUsersCount,
|
|
|
|
headerState: ProjectMemberHeaderState.ON_SELECT,
|
2019-08-29 16:06:17 +01:00
|
|
|
},
|
2019-08-09 12:19:49 +01:00
|
|
|
});
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(wrapper.findAll('.header-selected-members').length).toBe(1);
|
2019-08-29 16:06:17 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
expect(wrapper.vm.selectedProjectMembersCount).toBe(selectedUsersCount);
|
|
|
|
expect(wrapper.vm.isDeleteClicked).toBe(false);
|
|
|
|
expect(wrapper.findAll('.blur-content').length).toBe(0);
|
|
|
|
expect(wrapper.findAll('.blur-search').length).toBe(0);
|
2019-08-09 12:19:49 +01:00
|
|
|
});
|
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
it('renders correctly with 2 selected users and delete clicked once', async () => {
|
2022-08-03 14:29:58 +01:00
|
|
|
store.commit(APP_STATE_MUTATIONS.TOGGLE_ADD_TEAM_MEMBERS_MODAL);
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const selectedUsersCount = 2;
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
const wrapper = shallowMount<HeaderArea>(HeaderArea, {
|
2019-08-09 12:19:49 +01:00
|
|
|
store,
|
2019-08-30 12:34:51 +01:00
|
|
|
localVue,
|
|
|
|
propsData: {
|
|
|
|
selectedProjectMembersCount: selectedUsersCount,
|
|
|
|
headerState: ProjectMemberHeaderState.ON_SELECT,
|
|
|
|
},
|
2019-08-09 12:19:49 +01:00
|
|
|
});
|
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.vm.onFirstDeleteClick();
|
2019-08-09 12:19:49 +01:00
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(wrapper.vm.selectedProjectMembersCount).toBe(selectedUsersCount);
|
|
|
|
expect(wrapper.vm.userCountTitle).toBe('users');
|
|
|
|
expect(wrapper.vm.isDeleteClicked).toBe(true);
|
|
|
|
expect(wrapper.findAll('.blur-content').length).toBe(1);
|
|
|
|
expect(wrapper.findAll('.blur-search').length).toBe(1);
|
|
|
|
|
|
|
|
const expectedSectionRendered = wrapper.find('.header-after-delete-click');
|
|
|
|
expect(expectedSectionRendered.text()).toBe(`Are you sure you want to delete ${selectedUsersCount} users?`);
|
2019-08-09 12:19:49 +01:00
|
|
|
});
|
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
it('renders correctly with 1 selected user and delete clicked once', async () => {
|
2022-08-03 14:29:58 +01:00
|
|
|
store.commit(APP_STATE_MUTATIONS.TOGGLE_ADD_TEAM_MEMBERS_MODAL);
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const selectedUsersCount = 1;
|
2019-08-29 16:06:17 +01:00
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
const wrapper = shallowMount<HeaderArea>(HeaderArea, {
|
2019-08-30 12:34:51 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
propsData: {
|
|
|
|
selectedProjectMembersCount: selectedUsersCount,
|
|
|
|
headerState: ProjectMemberHeaderState.ON_SELECT,
|
|
|
|
},
|
|
|
|
});
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.vm.onFirstDeleteClick();
|
2019-08-09 12:19:49 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
expect(wrapper.vm.selectedProjectMembersCount).toBe(selectedUsersCount);
|
|
|
|
expect(wrapper.vm.userCountTitle).toBe('user');
|
|
|
|
expect(wrapper.vm.isDeleteClicked).toBe(true);
|
|
|
|
expect(wrapper.findAll('.blur-content').length).toBe(1);
|
|
|
|
expect(wrapper.findAll('.blur-search').length).toBe(1);
|
|
|
|
|
|
|
|
const expectedSectionRendered = wrapper.find('.header-after-delete-click');
|
|
|
|
expect(expectedSectionRendered.text()).toBe(`Are you sure you want to delete ${selectedUsersCount} user?`);
|
2019-08-09 12:19:49 +01:00
|
|
|
});
|
|
|
|
});
|