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
146 lines
4.9 KiB
TypeScript
146 lines
4.9 KiB
TypeScript
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
import { RouteConfig, router } from '@/router';
|
|
import { makeAccessGrantsModule } from '@/store/modules/accessGrants';
|
|
import { appStateModule } from '@/store/modules/appState';
|
|
import { makeBucketsModule } from '@/store/modules/buckets';
|
|
import { makeNotificationsModule } from '@/store/modules/notifications';
|
|
import { makePaymentsModule } from '@/store/modules/payments';
|
|
import { makeProjectMembersModule } from '@/store/modules/projectMembers';
|
|
import { makeProjectsModule } from '@/store/modules/projects';
|
|
import { makeUsersModule } from '@/store/modules/users';
|
|
import { User } from '@/types/users';
|
|
import { APP_STATE_ACTIONS } from '@/utils/constants/actionNames';
|
|
import { AppState } from '@/utils/constants/appStateEnum';
|
|
import { NotificatorPlugin } from '@/utils/plugins/notificator';
|
|
import DashboardArea from '@/views/DashboardArea.vue';
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
|
|
import { AccessGrantsMock } from '../mock/api/accessGrants';
|
|
import { BucketsMock } from '../mock/api/buckets';
|
|
import { PaymentsMock } from '../mock/api/payments';
|
|
import { ProjectMembersApiMock } from '../mock/api/projectMembers';
|
|
import { ProjectsApiMock } from '../mock/api/projects';
|
|
import { UsersApiMock } from '../mock/api/users';
|
|
|
|
const localVue = createLocalVue();
|
|
localVue.use(Vuex);
|
|
|
|
const usersApi = new UsersApiMock();
|
|
const projectsApi = new ProjectsApiMock();
|
|
|
|
usersApi.setMockUser(new User('1', '2', '3', '4', '5', '6', '7', 1));
|
|
projectsApi.setMockProjects([]);
|
|
|
|
const usersModule = makeUsersModule(usersApi);
|
|
const projectsModule = makeProjectsModule(projectsApi);
|
|
const accessGrantsModule = makeAccessGrantsModule(new AccessGrantsMock());
|
|
const teamMembersModule = makeProjectMembersModule(new ProjectMembersApiMock());
|
|
const bucketsModule = makeBucketsModule(new BucketsMock());
|
|
const notificationsModule = makeNotificationsModule();
|
|
const paymentsModule = makePaymentsModule(new PaymentsMock());
|
|
|
|
const store = new Vuex.Store({
|
|
modules: {
|
|
notificationsModule,
|
|
bucketsModule,
|
|
accessGrantsModule,
|
|
usersModule,
|
|
projectsModule,
|
|
appStateModule,
|
|
teamMembersModule,
|
|
paymentsModule,
|
|
},
|
|
});
|
|
|
|
localVue.use(new NotificatorPlugin(store));
|
|
|
|
describe('Dashboard', () => {
|
|
beforeEach(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
it('renders correctly when data is loading', () => {
|
|
const wrapper = shallowMount(DashboardArea, {
|
|
store,
|
|
localVue,
|
|
router,
|
|
});
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
expect(wrapper.findAll('.loading-overlay.active').length).toBe(1);
|
|
expect(wrapper.findAll('.dashboard-container__wrap').length).toBe(0);
|
|
});
|
|
|
|
it('renders correctly when data is loaded', () => {
|
|
store.dispatch(APP_STATE_ACTIONS.CHANGE_STATE, AppState.LOADED);
|
|
|
|
const wrapper = shallowMount(DashboardArea, {
|
|
store,
|
|
localVue,
|
|
router,
|
|
});
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
expect(wrapper.findAll('.loading-overlay active').length).toBe(0);
|
|
expect(wrapper.findAll('.dashboard__wrap').length).toBe(1);
|
|
});
|
|
|
|
it('loads routes correctly when authorithed without project with available routes', async () => {
|
|
const availableWithoutProject = [
|
|
RouteConfig.Account.with(RouteConfig.Billing).path,
|
|
RouteConfig.Account.with(RouteConfig.Settings).path,
|
|
];
|
|
|
|
for (let i = 0; i < availableWithoutProject.length; i++) {
|
|
const wrapper = await shallowMount(DashboardArea, {
|
|
localVue,
|
|
router,
|
|
store,
|
|
});
|
|
|
|
setTimeout(() => {
|
|
expect(wrapper.vm.$router.currentRoute.path).toBe(availableWithoutProject[i]);
|
|
}, 50);
|
|
}
|
|
});
|
|
|
|
it('loads routes correctly when authorithed without project with unavailable routes', async () => {
|
|
const unavailableWithoutProject = [
|
|
RouteConfig.AccessGrants.path,
|
|
RouteConfig.Users.path,
|
|
RouteConfig.ProjectDashboard.path,
|
|
];
|
|
|
|
for (let i = 0; i < unavailableWithoutProject.length; i++) {
|
|
await router.push(unavailableWithoutProject[i]);
|
|
|
|
const wrapper = await shallowMount(DashboardArea, {
|
|
localVue,
|
|
router,
|
|
store,
|
|
});
|
|
|
|
setTimeout(() => {
|
|
expect(wrapper.vm.$router.currentRoute.path).toBe(RouteConfig.ProjectDashboard.path);
|
|
}, 50);
|
|
}
|
|
|
|
});
|
|
|
|
it('loads routes correctly when not authorithed', () => {
|
|
const wrapper = shallowMount(DashboardArea, {
|
|
store,
|
|
localVue,
|
|
router,
|
|
});
|
|
|
|
setTimeout(() => {
|
|
expect(wrapper.vm.$router.currentRoute.path).toBe(RouteConfig.Login.path);
|
|
}, 50);
|
|
});
|
|
});
|