2019-09-05 09:41:39 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2022-09-08 15:11:09 +01:00
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
|
|
|
2019-10-28 13:27:12 +00:00
|
|
|
import { RouteConfig, router } from '@/router';
|
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();
|
2023-04-13 13:04:26 +01:00
|
|
|
localVue.use(new NotificatorPlugin());
|
2022-04-07 12:04:24 +01:00
|
|
|
|
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
|
|
|
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', () => {
|
2019-09-26 14:36:12 +01:00
|
|
|
const wrapper = shallowMount(DashboardArea, {
|
2019-09-05 09:41:39 +01:00
|
|
|
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,
|
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
2023-04-20 08:39:59 +01:00
|
|
|
RouteConfig.Team.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,
|
|
|
|
});
|
|
|
|
|
|
|
|
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, {
|
|
|
|
localVue,
|
|
|
|
router,
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(wrapper.vm.$router.currentRoute.path).toBe(RouteConfig.Login.path);
|
|
|
|
}, 50);
|
|
|
|
});
|
2019-09-05 09:41:39 +01:00
|
|
|
});
|