storj/web/satellite/tests/unit/projectMembers/HeaderArea.spec.ts
Egon Elbre 8620532a05 web/satellite: bump dependencies
This contains also multiple fixes to make it work.
The following is a non-exhaustive list.

When @Prop default value is a callback, then it is called
instead of set verbatim. This means, when you want a default
value to be a callback, then it needs to be `default: () => () => X`.

jest does not yet properly support WebWorkers, hence the code introduces
an indirection to provide the worker URL.

This in turn required removing the global "store" dependency from
the tests. As a consequence the new NotificatorPlugin takes store
as a dependency. And many of the tests are adjusted to not import
store directly.

Moved StoreModule definition to avoid initializing the global store.

Some of the router code was moved into store. We can later figure out
how to structure it better and move it back.

bip39 needs explicit fallbacks for some of the dependencies.

Fixes to timer mocking. jest supports it natively.

Remove sinon dependency. jest provides all the functionality we need.

Change-Id: I7af3599390c63ce9f99dbd0b1e0870e9f8ca994d
2022-05-04 15:02:01 +00:00

149 lines
5.6 KiB
TypeScript

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
import Vuex from 'vuex';
import HeaderArea from '@/components/team/HeaderArea.vue';
import { appStateModule } from '@/store/modules/appState';
import { makeNotificationsModule } from '@/store/modules/notifications';
import { makeProjectMembersModule } from '@/store/modules/projectMembers';
import { ProjectMember, ProjectMemberHeaderState, ProjectMembersPage } from '@/types/projectMembers';
import { APP_STATE_ACTIONS } from '@/utils/constants/actionNames';
import { createLocalVue, shallowMount } from '@vue/test-utils';
import { ProjectMembersApiMock } from '../mock/api/projectMembers';
const localVue = createLocalVue();
const date = new Date(0);
const projectMembers: ProjectMember[] = [
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'),
];
const api = new ProjectMembersApiMock();
api.setMockPage(new ProjectMembersPage(projectMembers));
const notificationsModule = makeNotificationsModule();
const projectMembersModule = makeProjectMembersModule(api);
localVue.use(Vuex);
const store = new Vuex.Store({ modules: { appStateModule, projectMembersModule, notificationsModule } });
describe('Team HeaderArea', () => {
it('renders correctly', () => {
const wrapper = shallowMount<HeaderArea>(HeaderArea, {
store,
localVue,
});
const addNewTemMemberPopup = wrapper.findAll('adduserpopup-stub');
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);
});
it('renders correctly with opened Add team member popup', () => {
store.dispatch(APP_STATE_ACTIONS.TOGGLE_TEAM_MEMBERS);
const wrapper = shallowMount<HeaderArea>(HeaderArea, {
store,
localVue,
});
const addNewTemMemberPopup = wrapper.findAll('adduserpopup-stub');
expect(wrapper).toMatchSnapshot();
expect(addNewTemMemberPopup.length).toBe(1);
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);
store.dispatch(APP_STATE_ACTIONS.TOGGLE_TEAM_MEMBERS);
});
it('renders correctly with selected users', () => {
store.dispatch(APP_STATE_ACTIONS.TOGGLE_TEAM_MEMBERS);
const selectedUsersCount = 2;
const wrapper = shallowMount<HeaderArea>(HeaderArea, {
store,
localVue,
propsData: {
selectedProjectMembersCount: selectedUsersCount,
headerState: ProjectMemberHeaderState.ON_SELECT,
},
});
expect(wrapper.findAll('.header-selected-members').length).toBe(1);
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);
});
it('renders correctly with 2 selected users and delete clicked once', async () => {
store.dispatch(APP_STATE_ACTIONS.TOGGLE_TEAM_MEMBERS);
const selectedUsersCount = 2;
const wrapper = shallowMount<HeaderArea>(HeaderArea, {
store,
localVue,
propsData: {
selectedProjectMembersCount: selectedUsersCount,
headerState: ProjectMemberHeaderState.ON_SELECT,
},
});
await wrapper.vm.onFirstDeleteClick();
expect(wrapper).toMatchSnapshot();
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?`);
});
it('renders correctly with 1 selected user and delete clicked once', async () => {
store.dispatch(APP_STATE_ACTIONS.TOGGLE_TEAM_MEMBERS);
const selectedUsersCount = 1;
const wrapper = shallowMount<HeaderArea>(HeaderArea, {
store,
localVue,
propsData: {
selectedProjectMembersCount: selectedUsersCount,
headerState: ProjectMemberHeaderState.ON_SELECT,
},
});
await wrapper.vm.onFirstDeleteClick();
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?`);
});
});