2019-09-05 09:41:39 +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-10-28 13:27:12 +00:00
|
|
|
import { RouteConfig, router } from '@/router';
|
2019-09-27 15:41:04 +01:00
|
|
|
import { makeApiKeysModule } from '@/store/modules/apiKeys';
|
2019-09-05 09:41:39 +01:00
|
|
|
import { appStateModule } from '@/store/modules/appState';
|
2019-09-27 15:41:04 +01:00
|
|
|
import { makeBucketsModule } from '@/store/modules/buckets';
|
|
|
|
import { makeNotificationsModule } from '@/store/modules/notifications';
|
2019-11-27 14:57:56 +00:00
|
|
|
import { makePaymentsModule } from '@/store/modules/payments';
|
2019-09-27 15:41:04 +01:00
|
|
|
import { makeProjectMembersModule } from '@/store/modules/projectMembers';
|
|
|
|
import { makeProjectsModule } from '@/store/modules/projects';
|
|
|
|
import { makeUsageModule } from '@/store/modules/usage';
|
|
|
|
import { makeUsersModule } from '@/store/modules/users';
|
|
|
|
import { User } from '@/types/users';
|
2019-09-05 09:41:39 +01:00
|
|
|
import { APP_STATE_ACTIONS } from '@/utils/constants/actionNames';
|
|
|
|
import { AppState } from '@/utils/constants/appStateEnum';
|
2020-01-08 15:58:28 +00:00
|
|
|
import { NotificatorPlugin } from '@/utils/plugins/notificator';
|
|
|
|
import { SegmentioPlugin } from '@/utils/plugins/segment';
|
2019-09-26 14:36:12 +01:00
|
|
|
import DashboardArea from '@/views/DashboardArea.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
|
|
|
2019-09-27 15:41:04 +01:00
|
|
|
import { ApiKeysMock } from '../mock/api/apiKeys';
|
|
|
|
import { BucketsMock } from '../mock/api/buckets';
|
2019-11-27 14:57:56 +00:00
|
|
|
import { PaymentsMock } from '../mock/api/payments';
|
2019-09-27 15:41:04 +01:00
|
|
|
import { ProjectMembersApiMock } from '../mock/api/projectMembers';
|
|
|
|
import { ProjectsApiMock } from '../mock/api/projects';
|
|
|
|
import { ProjectUsageMock } from '../mock/api/usage';
|
|
|
|
import { UsersApiMock } from '../mock/api/users';
|
2019-09-05 09:41:39 +01:00
|
|
|
|
2019-09-27 15:41:04 +01:00
|
|
|
const localVue = createLocalVue();
|
2020-01-08 15:58:28 +00:00
|
|
|
const segmentioPlugin = new SegmentioPlugin();
|
|
|
|
const notificationPlugin = new NotificatorPlugin();
|
2019-09-05 09:41:39 +01:00
|
|
|
localVue.use(Vuex);
|
2020-01-08 15:58:28 +00:00
|
|
|
localVue.use(segmentioPlugin);
|
|
|
|
localVue.use(notificationPlugin);
|
2019-09-05 09:41:39 +01:00
|
|
|
|
2019-09-27 15:41:04 +01:00
|
|
|
const usersApi = new UsersApiMock();
|
|
|
|
const projectsApi = new ProjectsApiMock();
|
|
|
|
|
|
|
|
usersApi.setMockUser(new User('1', '2', '3', '4', '5'));
|
|
|
|
projectsApi.setMockProjects([]);
|
|
|
|
|
|
|
|
const usersModule = makeUsersModule(usersApi);
|
|
|
|
const projectsModule = makeProjectsModule(projectsApi);
|
|
|
|
const apiKeysModule = makeApiKeysModule(new ApiKeysMock());
|
|
|
|
const teamMembersModule = makeProjectMembersModule(new ProjectMembersApiMock());
|
|
|
|
const bucketsModule = makeBucketsModule(new BucketsMock());
|
|
|
|
const usageModule = makeUsageModule(new ProjectUsageMock());
|
|
|
|
const notificationsModule = makeNotificationsModule();
|
2019-11-27 14:57:56 +00:00
|
|
|
const paymentsModule = makePaymentsModule(new PaymentsMock());
|
2019-09-27 15:41:04 +01:00
|
|
|
|
|
|
|
const store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
notificationsModule,
|
|
|
|
usageModule,
|
|
|
|
bucketsModule,
|
|
|
|
apiKeysModule,
|
|
|
|
usersModule,
|
|
|
|
projectsModule,
|
|
|
|
appStateModule,
|
|
|
|
teamMembersModule,
|
2019-11-27 14:57:56 +00:00
|
|
|
paymentsModule,
|
2019-09-27 15:41:04 +01:00
|
|
|
},
|
|
|
|
});
|
2019-09-05 09:41:39 +01:00
|
|
|
|
|
|
|
describe('Dashboard', () => {
|
2019-09-27 15:41:04 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
|
2019-09-05 09:41:39 +01:00
|
|
|
it('renders correctly when data is loading', () => {
|
2019-09-26 14:36:12 +01:00
|
|
|
const wrapper = shallowMount(DashboardArea, {
|
2019-09-05 09:41:39 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
2019-09-27 15:41:04 +01:00
|
|
|
router,
|
2019-09-05 09:41:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-09-26 14:36:12 +01:00
|
|
|
const wrapper = shallowMount(DashboardArea, {
|
2019-09-05 09:41:39 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
2019-09-27 15:41:04 +01:00
|
|
|
router,
|
2019-09-05 09:41:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
expect(wrapper.findAll('.loading-overlay active').length).toBe(0);
|
|
|
|
expect(wrapper.findAll('.dashboard-container__wrap').length).toBe(1);
|
|
|
|
});
|
2019-09-27 15:41:04 +01:00
|
|
|
|
|
|
|
it('loads routes correctly when authorithed without project with available routes', async () => {
|
|
|
|
const availableWithoutProject = [
|
|
|
|
RouteConfig.Account.with(RouteConfig.Billing).path,
|
|
|
|
RouteConfig.Account.with(RouteConfig.Profile).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.ApiKeys.path,
|
|
|
|
RouteConfig.Buckets.path,
|
|
|
|
RouteConfig.Team.path,
|
|
|
|
RouteConfig.ProjectOverview.with(RouteConfig.UsageReport).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.ProjectOverview.with(RouteConfig.ProjectDetails).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);
|
|
|
|
});
|
2019-09-05 09:41:39 +01:00
|
|
|
});
|