8620532a05
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
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
// Copyright (C) 2020 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
import { VNode } from 'vue';
|
|
import { DirectiveBinding } from 'vue/types/options';
|
|
import Vuex from 'vuex';
|
|
|
|
import EditProjectDropdown from '@/components/navigation/EditProjectDropdown.vue';
|
|
|
|
import { router } from '@/router';
|
|
import { appStateModule } from '@/store/modules/appState';
|
|
import { makeProjectsModule, PROJECTS_MUTATIONS } from '@/store/modules/projects';
|
|
import { Project } from '@/types/projects';
|
|
import { createLocalVue, mount } from '@vue/test-utils';
|
|
|
|
import { ProjectsApiMock } from '../mock/api/projects';
|
|
import { makeNotificationsModule } from "@/store/modules/notifications";
|
|
import { NotificatorPlugin } from "@/utils/plugins/notificator";
|
|
|
|
const localVue = createLocalVue();
|
|
localVue.use(Vuex);
|
|
|
|
const projectsApi = new ProjectsApiMock();
|
|
const projectsModule = makeProjectsModule(projectsApi);
|
|
const notificationsModule = makeNotificationsModule();
|
|
const store = new Vuex.Store({ modules: { projectsModule, appStateModule, notificationsModule }});
|
|
const project = new Project('id', 'test', 'test', 'test', 'ownedId', false);
|
|
|
|
localVue.use(new NotificatorPlugin(store));
|
|
|
|
let clickOutsideEvent: EventListener;
|
|
|
|
localVue.directive('cli' +
|
|
'ck-outside', {
|
|
bind: function (el: HTMLElement, binding: DirectiveBinding, vnode: VNode) {
|
|
clickOutsideEvent = function(event: Event): void {
|
|
if (el === event.target) {
|
|
return;
|
|
}
|
|
|
|
if (vnode.context && binding.expression) {
|
|
vnode.context[binding.expression](event);
|
|
}
|
|
};
|
|
|
|
document.body.addEventListener('click', clickOutsideEvent);
|
|
},
|
|
unbind: function(): void {
|
|
document.body.removeEventListener('click', clickOutsideEvent);
|
|
},
|
|
});
|
|
|
|
|
|
store.commit(PROJECTS_MUTATIONS.ADD, project);
|
|
store.commit(PROJECTS_MUTATIONS.SELECT_PROJECT, project.id);
|
|
|
|
describe('EditProjectDropdown', () => {
|
|
it('renders correctly', (): void => {
|
|
const wrapper = mount(EditProjectDropdown, {
|
|
store,
|
|
localVue,
|
|
router,
|
|
});
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
it('dropdown opens correctly', async (): Promise<void> => {
|
|
const wrapper = mount(EditProjectDropdown, {
|
|
store,
|
|
localVue,
|
|
router,
|
|
});
|
|
|
|
await wrapper.find('.edit-project__selection-area').trigger('click');
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
});
|