2019-08-30 12:34:51 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2020-04-22 17:21:12 +01:00
|
|
|
import Router from 'vue-router';
|
2019-08-30 12:34:51 +01:00
|
|
|
import Vuex from 'vuex';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
import NavigationArea from '@/components/navigation/NavigationArea.vue';
|
2020-04-22 17:21:12 +01:00
|
|
|
import OnboardingTourArea from '@/components/onboardingTour/OnboardingTourArea.vue';
|
|
|
|
import ProjectDashboard from '@/components/project/ProjectDashboard.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
|
|
|
import { RouteConfig } from '@/router';
|
2019-12-12 16:25:38 +00:00
|
|
|
import { makeProjectsModule, PROJECTS_MUTATIONS } from '@/store/modules/projects';
|
2019-08-30 12:34:51 +01:00
|
|
|
import { NavigationLink } from '@/types/navigation';
|
2019-09-09 11:33:39 +01:00
|
|
|
import { Project } from '@/types/projects';
|
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
|
|
|
2020-09-09 19:25:59 +01:00
|
|
|
import { ProjectsApiMock } from '../mock/api/projects';
|
2019-08-30 12:34:51 +01:00
|
|
|
|
|
|
|
const api = new ProjectsApiMock();
|
2019-09-27 15:41:04 +01:00
|
|
|
api.setMockProjects([new Project('1')]);
|
2019-08-30 12:34:51 +01:00
|
|
|
const projectsModule = makeProjectsModule(api);
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
|
|
|
|
localVue.use(Vuex);
|
2020-04-22 17:21:12 +01:00
|
|
|
localVue.use(Router);
|
2019-08-30 12:34:51 +01:00
|
|
|
|
|
|
|
const store = new Vuex.Store({ modules: { projectsModule } });
|
|
|
|
|
|
|
|
const expectedLinks: NavigationLink[] = [
|
2020-03-16 12:08:38 +00:00
|
|
|
RouteConfig.ProjectDashboard,
|
2019-08-30 12:34:51 +01:00
|
|
|
RouteConfig.ApiKeys,
|
2020-09-09 19:25:59 +01:00
|
|
|
RouteConfig.Users,
|
2019-08-30 12:34:51 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
describe('NavigationArea', () => {
|
2020-09-09 19:25:59 +01:00
|
|
|
it('snapshot not changed during onboarding tour', (): void => {
|
2020-04-22 17:21:12 +01:00
|
|
|
const router = new Router({
|
|
|
|
mode: 'history',
|
|
|
|
routes: [{
|
2020-12-01 16:53:57 +00:00
|
|
|
path: '/onboarding-tour',
|
2020-04-22 17:21:12 +01:00
|
|
|
name: RouteConfig.OnboardingTour.name,
|
|
|
|
component: OnboardingTourArea,
|
|
|
|
}],
|
|
|
|
});
|
2020-12-01 16:53:57 +00:00
|
|
|
|
|
|
|
router.push('/onboarding-tour');
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const wrapper = shallowMount(NavigationArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
2020-04-22 17:21:12 +01:00
|
|
|
router,
|
2019-08-30 12:34:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
const navigationElements = wrapper.findAll('.navigation-area__item-container');
|
2019-09-09 17:29:19 +01:00
|
|
|
|
2020-09-09 19:25:59 +01:00
|
|
|
expect(navigationElements.length).toBe(0);
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-04-22 17:21:12 +01:00
|
|
|
const router = new Router({
|
|
|
|
mode: 'history',
|
|
|
|
routes: [{
|
|
|
|
path: '/',
|
|
|
|
name: RouteConfig.ProjectDashboard.name,
|
|
|
|
component: ProjectDashboard,
|
|
|
|
}],
|
|
|
|
});
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
it('snapshot not changed with project', async () => {
|
|
|
|
const projects = await store.dispatch('fetchProjects');
|
2019-12-12 16:25:38 +00:00
|
|
|
store.commit(PROJECTS_MUTATIONS.SELECT_PROJECT, projects[0].id);
|
2019-08-30 12:34:51 +01:00
|
|
|
|
2020-12-01 16:53:57 +00:00
|
|
|
router.push('/');
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
const wrapper = shallowMount(NavigationArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
2020-04-22 17:21:12 +01:00
|
|
|
router,
|
2019-08-30 12:34:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
const navigationElements = wrapper.findAll('.navigation-area__item-container');
|
|
|
|
|
2020-09-09 19:25:59 +01:00
|
|
|
expect(navigationElements.length).toBe(3);
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('navigation links are correct', () => {
|
|
|
|
const wrapper = shallowMount(NavigationArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
2020-04-22 17:21:12 +01:00
|
|
|
router,
|
2019-08-30 12:34:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
const navigationLinks = (wrapper.vm as any).navigation;
|
|
|
|
|
|
|
|
expect(navigationLinks.length).toBe(expectedLinks.length);
|
|
|
|
|
|
|
|
expectedLinks.forEach((link, i) => {
|
|
|
|
expect(navigationLinks[i].name).toBe(expectedLinks[i].name);
|
|
|
|
expect(navigationLinks[i].path).toBe(expectedLinks[i].path);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|