2021-03-11 19:13:27 +05:30
|
|
|
import { GlSkeletonLoading } from '@gitlab/ui';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import Vue, { nextTick } from 'vue';
|
2021-01-03 14:25:43 +05:30
|
|
|
import Vuex from 'vuex';
|
2021-01-29 00:20:46 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-03-11 19:13:27 +05:30
|
|
|
import IdeReview from '~/ide/components/ide_review.vue';
|
2021-01-03 14:25:43 +05:30
|
|
|
import IdeSidebar from '~/ide/components/ide_side_bar.vue';
|
|
|
|
import IdeTree from '~/ide/components/ide_tree.vue';
|
|
|
|
import RepoCommitSection from '~/ide/components/repo_commit_section.vue';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { leftSidebarViews } from '~/ide/constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { createStore } from '~/ide/stores';
|
2018-10-15 14:42:47 +05:30
|
|
|
import { projectData } from '../mock_data';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
Vue.use(Vuex);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
describe('IdeSidebar', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
let wrapper;
|
2020-10-24 23:57:45 +05:30
|
|
|
let store;
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
function createComponent({ view = leftSidebarViews.edit.name } = {}) {
|
2020-10-24 23:57:45 +05:30
|
|
|
store = createStore();
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
store.state.currentProjectId = 'abcproject';
|
|
|
|
store.state.projects.abcproject = projectData;
|
2021-01-29 00:20:46 +05:30
|
|
|
store.state.currentActivityView = view;
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
return mount(IdeSidebar, {
|
|
|
|
store,
|
|
|
|
});
|
|
|
|
}
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
2021-01-03 14:25:43 +05:30
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a sidebar', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
wrapper = createComponent();
|
|
|
|
|
|
|
|
expect(wrapper.find('[data-testid="ide-side-bar-inner"]').exists()).toBe(true);
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('renders loading components', async () => {
|
|
|
|
wrapper = createComponent();
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
store.state.loading = true;
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
expect(wrapper.findAll(GlSkeletonLoading)).toHaveLength(3);
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('deferred rendering components', () => {
|
|
|
|
it('fetches components on demand', async () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
wrapper = createComponent();
|
|
|
|
|
|
|
|
expect(wrapper.find(IdeTree).exists()).toBe(true);
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(wrapper.find(IdeReview).exists()).toBe(false);
|
|
|
|
expect(wrapper.find(RepoCommitSection).exists()).toBe(false);
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
store.state.currentActivityView = leftSidebarViews.review.name;
|
|
|
|
await waitForPromises();
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(wrapper.find(IdeTree).exists()).toBe(false);
|
|
|
|
expect(wrapper.find(IdeReview).exists()).toBe(true);
|
|
|
|
expect(wrapper.find(RepoCommitSection).exists()).toBe(false);
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
store.state.currentActivityView = leftSidebarViews.commit.name;
|
|
|
|
await waitForPromises();
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(wrapper.find(IdeTree).exists()).toBe(false);
|
|
|
|
expect(wrapper.find(IdeReview).exists()).toBe(false);
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(wrapper.find(RepoCommitSection).exists()).toBe(true);
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
it.each`
|
|
|
|
view | tree | review | commit
|
|
|
|
${leftSidebarViews.edit.name} | ${true} | ${false} | ${false}
|
|
|
|
${leftSidebarViews.review.name} | ${false} | ${true} | ${false}
|
|
|
|
${leftSidebarViews.commit.name} | ${false} | ${false} | ${true}
|
|
|
|
`('renders correct panels for $view', async ({ view, tree, review, commit } = {}) => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
view,
|
|
|
|
});
|
|
|
|
await waitForPromises();
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
expect(wrapper.find(IdeTree).exists()).toBe(tree);
|
|
|
|
expect(wrapper.find(IdeReview).exists()).toBe(review);
|
|
|
|
expect(wrapper.find(RepoCommitSection).exists()).toBe(commit);
|
|
|
|
});
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
it('keeps the current activity view components alive', async () => {
|
|
|
|
wrapper = createComponent();
|
|
|
|
|
|
|
|
const ideTreeComponent = wrapper.find(IdeTree).element;
|
|
|
|
|
|
|
|
store.state.currentActivityView = leftSidebarViews.commit.name;
|
2021-01-29 00:20:46 +05:30
|
|
|
await waitForPromises();
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
expect(wrapper.find(IdeTree).exists()).toBe(false);
|
|
|
|
expect(wrapper.find(RepoCommitSection).exists()).toBe(true);
|
|
|
|
|
|
|
|
store.state.currentActivityView = leftSidebarViews.edit.name;
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
await waitForPromises();
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
// reference to the elements remains the same, meaning the components were kept alive
|
|
|
|
expect(wrapper.find(IdeTree).element).toEqual(ideTreeComponent);
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|