debian-mirror-gitlab/spec/frontend/pipeline_editor/pipeline_editor_home_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

331 lines
10 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
2022-06-21 17:19:12 +05:30
import { GlButton, GlDrawer, GlModal } from '@gitlab/ui';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
2022-07-23 23:45:48 +05:30
import setWindowLocation from 'helpers/set_window_location_helper';
2022-06-21 17:19:12 +05:30
import CiEditorHeader from '~/pipeline_editor/components/editor/ci_editor_header.vue';
2021-03-11 19:13:27 +05:30
import CommitSection from '~/pipeline_editor/components/commit/commit_section.vue';
2021-06-08 01:23:25 +05:30
import PipelineEditorDrawer from '~/pipeline_editor/components/drawer/pipeline_editor_drawer.vue';
2021-04-29 21:17:54 +05:30
import PipelineEditorFileNav from '~/pipeline_editor/components/file_nav/pipeline_editor_file_nav.vue';
2022-07-16 23:28:13 +05:30
import PipelineEditorFileTree from '~/pipeline_editor/components/file_tree/container.vue';
2021-12-11 22:18:48 +05:30
import BranchSwitcher from '~/pipeline_editor/components/file_nav/branch_switcher.vue';
2021-03-11 19:13:27 +05:30
import PipelineEditorHeader from '~/pipeline_editor/components/header/pipeline_editor_header.vue';
import PipelineEditorTabs from '~/pipeline_editor/components/pipeline_editor_tabs.vue';
2022-07-16 23:28:13 +05:30
import {
CREATE_TAB,
FILE_TREE_DISPLAY_KEY,
2022-08-27 11:52:29 +05:30
VALIDATE_TAB,
2022-07-23 23:45:48 +05:30
MERGED_TAB,
TABS_INDEX,
VISUALIZE_TAB,
2022-07-16 23:28:13 +05:30
} from '~/pipeline_editor/constants';
2021-03-11 19:13:27 +05:30
import PipelineEditorHome from '~/pipeline_editor/pipeline_editor_home.vue';
import { mockLintResponse, mockCiYml } from './mock_data';
2021-12-11 22:18:48 +05:30
jest.mock('~/lib/utils/common_utils');
2021-03-11 19:13:27 +05:30
describe('Pipeline editor home wrapper', () => {
let wrapper;
2021-12-11 22:18:48 +05:30
const createComponent = ({ props = {}, glFeatures = {}, data = {}, stubs = {} } = {}) => {
2022-06-21 17:19:12 +05:30
wrapper = extendedWrapper(
shallowMount(PipelineEditorHome, {
data: () => data,
propsData: {
ciConfigData: mockLintResponse,
ciFileContent: mockCiYml,
isCiConfigDataLoading: false,
isNewCiConfigFile: false,
...props,
2021-06-08 01:23:25 +05:30
},
2022-06-21 17:19:12 +05:30
provide: {
projectFullPath: '',
totalBranches: 19,
glFeatures: {
...glFeatures,
},
},
stubs,
}),
);
2021-03-11 19:13:27 +05:30
};
2021-12-11 22:18:48 +05:30
const findBranchSwitcher = () => wrapper.findComponent(BranchSwitcher);
2021-03-11 19:13:27 +05:30
const findCommitSection = () => wrapper.findComponent(CommitSection);
2021-04-29 21:17:54 +05:30
const findFileNav = () => wrapper.findComponent(PipelineEditorFileNav);
2021-12-11 22:18:48 +05:30
const findModal = () => wrapper.findComponent(GlModal);
2021-06-08 01:23:25 +05:30
const findPipelineEditorDrawer = () => wrapper.findComponent(PipelineEditorDrawer);
2022-07-16 23:28:13 +05:30
const findPipelineEditorFileTree = () => wrapper.findComponent(PipelineEditorFileTree);
2021-06-08 01:23:25 +05:30
const findPipelineEditorHeader = () => wrapper.findComponent(PipelineEditorHeader);
const findPipelineEditorTabs = () => wrapper.findComponent(PipelineEditorTabs);
2022-07-16 23:28:13 +05:30
const findFileTreeBtn = () => wrapper.findByTestId('file-tree-toggle');
2022-06-21 17:19:12 +05:30
const findHelpBtn = () => wrapper.findByTestId('drawer-toggle');
2021-03-11 19:13:27 +05:30
afterEach(() => {
2022-07-16 23:28:13 +05:30
localStorage.clear();
2021-03-11 19:13:27 +05:30
wrapper.destroy();
});
describe('renders', () => {
beforeEach(() => {
createComponent();
});
2021-04-29 21:17:54 +05:30
it('shows the file nav', () => {
expect(findFileNav().exists()).toBe(true);
});
2021-03-11 19:13:27 +05:30
it('shows the pipeline editor header', () => {
expect(findPipelineEditorHeader().exists()).toBe(true);
});
it('shows the pipeline editor tabs', () => {
expect(findPipelineEditorTabs().exists()).toBe(true);
});
it('shows the commit section by default', () => {
expect(findCommitSection().exists()).toBe(true);
});
});
2021-12-11 22:18:48 +05:30
describe('modal when switching branch', () => {
describe('when `showSwitchBranchModal` value is false', () => {
beforeEach(() => {
createComponent();
});
it('is not visible', () => {
expect(findModal().exists()).toBe(false);
});
});
describe('when `showSwitchBranchModal` value is true', () => {
beforeEach(() => {
createComponent({
data: { showSwitchBranchModal: true },
stubs: { PipelineEditorFileNav },
});
});
it('is visible', () => {
expect(findModal().exists()).toBe(true);
});
it('pass down `shouldLoadNewBranch` to the branch switcher when primary is selected', async () => {
expect(findBranchSwitcher().props('shouldLoadNewBranch')).toBe(false);
await findModal().vm.$emit('primary');
expect(findBranchSwitcher().props('shouldLoadNewBranch')).toBe(true);
});
it('closes the modal when secondary action is selected', async () => {
expect(findModal().exists()).toBe(true);
await findModal().vm.$emit('secondary');
expect(findModal().exists()).toBe(false);
});
});
});
2021-03-11 19:13:27 +05:30
describe('commit form toggle', () => {
beforeEach(() => {
createComponent();
});
2021-12-11 22:18:48 +05:30
it.each`
tab | shouldShow
${MERGED_TAB} | ${false}
${VISUALIZE_TAB} | ${false}
2022-08-27 11:52:29 +05:30
${VALIDATE_TAB} | ${false}
2021-12-11 22:18:48 +05:30
${CREATE_TAB} | ${true}
`(
'when the active tab is $tab the commit form is shown: $shouldShow',
async ({ tab, shouldShow }) => {
expect(findCommitSection().exists()).toBe(true);
2021-03-11 19:13:27 +05:30
2021-12-11 22:18:48 +05:30
findPipelineEditorTabs().vm.$emit('set-current-tab', tab);
await nextTick();
2021-03-11 19:13:27 +05:30
2022-11-25 23:54:43 +05:30
expect(findCommitSection().isVisible()).toBe(shouldShow);
2021-12-11 22:18:48 +05:30
},
);
it('shows the commit form again when coming back to the create tab', async () => {
2022-11-25 23:54:43 +05:30
expect(findCommitSection().isVisible()).toBe(true);
2021-03-11 19:13:27 +05:30
findPipelineEditorTabs().vm.$emit('set-current-tab', MERGED_TAB);
await nextTick();
2022-11-25 23:54:43 +05:30
expect(findCommitSection().isVisible()).toBe(false);
2021-03-11 19:13:27 +05:30
2021-12-11 22:18:48 +05:30
findPipelineEditorTabs().vm.$emit('set-current-tab', CREATE_TAB);
2021-03-11 19:13:27 +05:30
await nextTick();
2022-11-25 23:54:43 +05:30
expect(findCommitSection().isVisible()).toBe(true);
2021-03-11 19:13:27 +05:30
});
2022-07-23 23:45:48 +05:30
describe('rendering with tab params', () => {
it.each`
tab | shouldShow
${MERGED_TAB} | ${false}
${VISUALIZE_TAB} | ${false}
2022-08-27 11:52:29 +05:30
${VALIDATE_TAB} | ${false}
2022-07-23 23:45:48 +05:30
${CREATE_TAB} | ${true}
`(
'when the tab query param is $tab the commit form is shown: $shouldShow',
async ({ tab, shouldShow }) => {
setWindowLocation(`https://gitlab.test/ci/editor/?tab=${TABS_INDEX[tab]}`);
await createComponent({ stubs: { PipelineEditorTabs } });
2022-11-25 23:54:43 +05:30
expect(findCommitSection().isVisible()).toBe(shouldShow);
2022-07-23 23:45:48 +05:30
},
);
});
2021-03-11 19:13:27 +05:30
});
2021-12-11 22:18:48 +05:30
describe('WalkthroughPopover events', () => {
beforeEach(() => {
createComponent();
});
describe('when "walkthrough-popover-cta-clicked" is emitted from pipeline editor tabs', () => {
it('passes down `scrollToCommitForm=true` to commit section', async () => {
expect(findCommitSection().props('scrollToCommitForm')).toBe(false);
await findPipelineEditorTabs().vm.$emit('walkthrough-popover-cta-clicked');
expect(findCommitSection().props('scrollToCommitForm')).toBe(true);
});
});
describe('when "scrolled-to-commit-form" is emitted from commit section', () => {
it('passes down `scrollToCommitForm=false` to commit section', async () => {
await findPipelineEditorTabs().vm.$emit('walkthrough-popover-cta-clicked');
expect(findCommitSection().props('scrollToCommitForm')).toBe(true);
await findCommitSection().vm.$emit('scrolled-to-commit-form');
expect(findCommitSection().props('scrollToCommitForm')).toBe(false);
});
});
});
2022-06-21 17:19:12 +05:30
describe('help drawer', () => {
const clickHelpBtn = async () => {
findHelpBtn().vm.$emit('click');
await nextTick();
};
it('hides the drawer by default', () => {
createComponent();
expect(findPipelineEditorDrawer().props('isVisible')).toBe(false);
});
it('toggles the drawer on button click', async () => {
createComponent({
stubs: {
CiEditorHeader,
GlButton,
GlDrawer,
PipelineEditorTabs,
PipelineEditorDrawer,
},
});
await clickHelpBtn();
expect(findPipelineEditorDrawer().props('isVisible')).toBe(true);
await clickHelpBtn();
expect(findPipelineEditorDrawer().props('isVisible')).toBe(false);
});
it("closes the drawer through the drawer's close button", async () => {
createComponent({
stubs: {
CiEditorHeader,
GlButton,
GlDrawer,
PipelineEditorTabs,
PipelineEditorDrawer,
},
});
await clickHelpBtn();
expect(findPipelineEditorDrawer().props('isVisible')).toBe(true);
2022-10-11 01:57:18 +05:30
findPipelineEditorDrawer().findComponent(GlDrawer).vm.$emit('close');
2022-06-21 17:19:12 +05:30
await nextTick();
expect(findPipelineEditorDrawer().props('isVisible')).toBe(false);
});
});
2022-07-16 23:28:13 +05:30
describe('file tree', () => {
const toggleFileTree = async () => {
findFileTreeBtn().vm.$emit('click');
await nextTick();
};
2022-07-23 23:45:48 +05:30
describe('button toggle', () => {
2022-07-16 23:28:13 +05:30
beforeEach(() => {
2022-07-23 23:45:48 +05:30
createComponent({
stubs: {
GlButton,
PipelineEditorFileNav,
},
});
2022-07-16 23:28:13 +05:30
});
2022-07-23 23:45:48 +05:30
it('shows button toggle', () => {
expect(findFileTreeBtn().exists()).toBe(true);
2022-07-16 23:28:13 +05:30
});
2022-07-23 23:45:48 +05:30
it('toggles the drawer on button click', async () => {
await toggleFileTree();
2022-07-16 23:28:13 +05:30
2022-07-23 23:45:48 +05:30
expect(findPipelineEditorFileTree().exists()).toBe(true);
2022-07-16 23:28:13 +05:30
2022-07-23 23:45:48 +05:30
await toggleFileTree();
2022-07-16 23:28:13 +05:30
2022-07-23 23:45:48 +05:30
expect(findPipelineEditorFileTree().exists()).toBe(false);
});
2022-07-16 23:28:13 +05:30
2022-07-23 23:45:48 +05:30
it('sets the display state in local storage', async () => {
await toggleFileTree();
2022-07-16 23:28:13 +05:30
2022-07-23 23:45:48 +05:30
expect(localStorage.getItem(FILE_TREE_DISPLAY_KEY)).toBe('true');
2022-07-16 23:28:13 +05:30
2022-07-23 23:45:48 +05:30
await toggleFileTree();
2022-07-16 23:28:13 +05:30
2022-07-23 23:45:48 +05:30
expect(localStorage.getItem(FILE_TREE_DISPLAY_KEY)).toBe('false');
2022-07-16 23:28:13 +05:30
});
2022-07-23 23:45:48 +05:30
});
2022-07-16 23:28:13 +05:30
2022-07-23 23:45:48 +05:30
describe('when file tree display state is saved in local storage', () => {
beforeEach(() => {
localStorage.setItem(FILE_TREE_DISPLAY_KEY, 'true');
createComponent({
stubs: { PipelineEditorFileNav },
2022-07-16 23:28:13 +05:30
});
2022-07-23 23:45:48 +05:30
});
2022-07-16 23:28:13 +05:30
2022-07-23 23:45:48 +05:30
it('shows the file tree by default', () => {
expect(findPipelineEditorFileTree().exists()).toBe(true);
2022-07-16 23:28:13 +05:30
});
2022-07-23 23:45:48 +05:30
});
2022-07-16 23:28:13 +05:30
2022-07-23 23:45:48 +05:30
describe('when file tree display state is not saved in local storage', () => {
beforeEach(() => {
createComponent({
stubs: { PipelineEditorFileNav },
2022-07-16 23:28:13 +05:30
});
2022-07-23 23:45:48 +05:30
});
2022-07-16 23:28:13 +05:30
2022-07-23 23:45:48 +05:30
it('hides the file tree by default', () => {
expect(findPipelineEditorFileTree().exists()).toBe(false);
2022-07-16 23:28:13 +05:30
});
});
});
2021-03-11 19:13:27 +05:30
});