2019-08-30 12:34:51 +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-08-30 12:34:51 +01:00
|
|
|
import NavigationArea from '@/components/navigation/NavigationArea.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';
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
const store = new Vuex.Store({ modules: { projectsModule } });
|
|
|
|
|
|
|
|
const expectedLinks: NavigationLink[] = [
|
2019-09-09 17:29:19 +01:00
|
|
|
RouteConfig.ProjectOverview,
|
2019-08-30 12:34:51 +01:00
|
|
|
RouteConfig.Team,
|
|
|
|
RouteConfig.ApiKeys,
|
|
|
|
RouteConfig.Buckets,
|
|
|
|
];
|
|
|
|
|
|
|
|
describe('NavigationArea', () => {
|
|
|
|
it('snapshot not changed without project', () => {
|
|
|
|
const wrapper = shallowMount(NavigationArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
const navigationElements = wrapper.findAll('.navigation-area__item-container');
|
|
|
|
const disabledElements = wrapper.findAll('.navigation-area__item-container.disabled');
|
2019-09-09 17:29:19 +01:00
|
|
|
const resourcesButton = wrapper.findAll('.navigation-area__resources-title__button');
|
|
|
|
const accountButton = wrapper.findAll('.navigation-area__account-title__button');
|
2019-08-30 12:34:51 +01:00
|
|
|
|
2020-01-22 11:16:27 +00:00
|
|
|
expect(navigationElements.length).toBe(8);
|
2020-02-28 16:33:11 +00:00
|
|
|
expect(disabledElements.length).toBe(4);
|
2019-09-09 17:29:19 +01:00
|
|
|
expect(resourcesButton.length).toBe(0);
|
|
|
|
expect(accountButton.length).toBe(0);
|
|
|
|
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
const wrapper = shallowMount(NavigationArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
const navigationElements = wrapper.findAll('.navigation-area__item-container');
|
|
|
|
const disabledElements = wrapper.findAll('.navigation-area__item-container.disabled');
|
2019-09-09 17:29:19 +01:00
|
|
|
const resourcesButton = wrapper.findAll('.navigation-area__resources-title__button');
|
|
|
|
const accountButton = wrapper.findAll('.navigation-area__account-title__button');
|
2019-08-30 12:34:51 +01:00
|
|
|
|
2020-01-22 11:16:27 +00:00
|
|
|
expect(navigationElements.length).toBe(8);
|
2019-08-30 12:34:51 +01:00
|
|
|
expect(disabledElements.length).toBe(0);
|
2019-09-09 17:29:19 +01:00
|
|
|
expect(resourcesButton.length).toBe(0);
|
|
|
|
expect(accountButton.length).toBe(0);
|
2019-08-30 12:34:51 +01:00
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('navigation links are correct', () => {
|
|
|
|
const wrapper = shallowMount(NavigationArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2019-09-09 17:29:19 +01:00
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
it('trigger show/hide events works correctly', async () => {
|
2019-09-09 17:29:19 +01:00
|
|
|
const wrapper = shallowMount(NavigationArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.find('.navigation-area__resources-title').trigger('mouseenter');
|
|
|
|
await wrapper.find('.navigation-area__account-title').trigger('mouseenter');
|
2019-09-09 17:29:19 +01:00
|
|
|
|
2019-09-11 11:21:45 +01:00
|
|
|
expect(wrapper.find('.navigation-area__resources-title__button').text()).toMatch('Hide');
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.find('.navigation-area__resources-title__button').trigger('click');
|
2019-09-09 17:29:19 +01:00
|
|
|
|
2019-09-11 11:21:45 +01:00
|
|
|
expect(wrapper.find('.navigation-area__account-title__button').text()).toMatch('Hide');
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.find('.navigation-area__account-title__button').trigger('click');
|
2019-09-09 17:29:19 +01:00
|
|
|
|
2019-09-11 11:21:45 +01:00
|
|
|
expect(wrapper.find('.navigation-area__resources-title__button').text()).toMatch('Show');
|
|
|
|
expect(wrapper.find('.navigation-area__account-title__button').text()).toMatch('Show');
|
2019-09-09 17:29:19 +01:00
|
|
|
|
2019-09-11 11:21:45 +01:00
|
|
|
expect(wrapper.findAll('.navigation-area__item-container').length).toBe(4);
|
2019-09-09 17:29:19 +01:00
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.find('.navigation-area__resources-title__button').trigger('click');
|
|
|
|
await wrapper.find('.navigation-area__account-title__button').trigger('click');
|
2019-09-09 17:29:19 +01:00
|
|
|
|
2020-01-22 11:16:27 +00:00
|
|
|
expect(wrapper.findAll('.navigation-area__item-container').length).toBe(8);
|
2019-09-09 17:29:19 +01:00
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.find('.navigation-area__resources-title').trigger('mouseleave');
|
|
|
|
await wrapper.find('.navigation-area__account-title').trigger('mouseleave');
|
2019-09-09 17:29:19 +01:00
|
|
|
|
|
|
|
expect(wrapper.findAll('.navigation-area__resources-title__button').length).toBe(0);
|
|
|
|
expect(wrapper.findAll('.navigation-area__account-title__button').length).toBe(0);
|
|
|
|
|
2020-01-22 11:16:27 +00:00
|
|
|
expect(wrapper.findAll('.navigation-area__item-container').length).toBe(8);
|
2019-09-09 17:29:19 +01:00
|
|
|
});
|
2019-08-30 12:34:51 +01:00
|
|
|
});
|