2019-09-05 09:41:39 +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';
|
|
|
|
|
2022-12-19 15:38:18 +00:00
|
|
|
import { AccessGrantsMock } from '../../mock/api/accessGrants';
|
|
|
|
import { BucketsMock } from '../../mock/api/buckets';
|
|
|
|
import { PaymentsMock } from '../../mock/api/payments';
|
2023-03-24 05:55:48 +00:00
|
|
|
import { FrontendConfigApiMock } from '../../mock/api/config';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-10-28 13:27:12 +00:00
|
|
|
import { RouteConfig, router } from '@/router';
|
2020-12-06 23:32:35 +00:00
|
|
|
import { makeAccessGrantsModule } from '@/store/modules/accessGrants';
|
2023-03-24 05:55:48 +00:00
|
|
|
import { makeAppStateModule } 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-05 09:41:39 +01:00
|
|
|
import { APP_STATE_ACTIONS } from '@/utils/constants/actionNames';
|
2023-03-24 05:55:48 +00:00
|
|
|
import { FetchState } from '@/utils/constants/fetchStateEnum';
|
2020-01-08 15:58:28 +00:00
|
|
|
import { NotificatorPlugin } from '@/utils/plugins/notificator';
|
2022-12-08 12:10:25 +00:00
|
|
|
import { AnalyticsHttpApi } from '@/api/analytics';
|
2023-04-07 13:28:16 +01:00
|
|
|
import DashboardArea from '@/views/DashboardArea.vue';
|
2019-09-05 09:41:39 +01:00
|
|
|
|
2019-09-27 15:41:04 +01:00
|
|
|
const localVue = createLocalVue();
|
2019-09-05 09:41:39 +01:00
|
|
|
localVue.use(Vuex);
|
|
|
|
|
2023-03-24 05:55:48 +00:00
|
|
|
const appStateModule = makeAppStateModule(new FrontendConfigApiMock());
|
2020-12-06 23:32:35 +00:00
|
|
|
const accessGrantsModule = makeAccessGrantsModule(new AccessGrantsMock());
|
2019-09-27 15:41:04 +01:00
|
|
|
const bucketsModule = makeBucketsModule(new BucketsMock());
|
|
|
|
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,
|
|
|
|
bucketsModule,
|
2020-12-06 23:32:35 +00:00
|
|
|
accessGrantsModule,
|
2019-09-27 15:41:04 +01:00
|
|
|
appStateModule,
|
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
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
localVue.use(new NotificatorPlugin(store));
|
|
|
|
|
2019-09-05 09:41:39 +01:00
|
|
|
describe('Dashboard', () => {
|
2019-09-27 15:41:04 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
2022-12-08 12:10:25 +00:00
|
|
|
jest.spyOn(AnalyticsHttpApi.prototype, 'errorEventTriggered').mockImplementation(() => Promise.resolve());
|
2019-09-27 15:41:04 +01:00
|
|
|
});
|
|
|
|
|
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', () => {
|
2023-03-24 05:55:48 +00:00
|
|
|
store.dispatch(APP_STATE_ACTIONS.CHANGE_FETCH_STATE, FetchState.LOADED);
|
2019-09-05 09:41:39 +01:00
|
|
|
|
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);
|
2020-09-09 19:25:59 +01:00
|
|
|
expect(wrapper.findAll('.dashboard__wrap').length).toBe(1);
|
2019-09-05 09:41:39 +01:00
|
|
|
});
|
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,
|
2020-03-16 12:08:38 +00:00
|
|
|
RouteConfig.Account.with(RouteConfig.Settings).path,
|
2019-09-27 15:41:04 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
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 = [
|
2020-12-06 23:32:35 +00:00
|
|
|
RouteConfig.AccessGrants.path,
|
2020-09-09 19:25:59 +01:00
|
|
|
RouteConfig.Users.path,
|
2020-03-18 17:07:29 +00:00
|
|
|
RouteConfig.ProjectDashboard.path,
|
2019-09-27 15:41:04 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
for (let i = 0; i < unavailableWithoutProject.length; i++) {
|
|
|
|
await router.push(unavailableWithoutProject[i]);
|
|
|
|
|
|
|
|
const wrapper = await shallowMount(DashboardArea, {
|
|
|
|
localVue,
|
|
|
|
router,
|
|
|
|
store,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2020-03-18 17:07:29 +00:00
|
|
|
expect(wrapper.vm.$router.currentRoute.path).toBe(RouteConfig.ProjectDashboard.path);
|
2019-09-27 15:41:04 +01:00
|
|
|
}, 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
|
|
|
});
|