diff options
Diffstat (limited to 'spec/frontend/pipelines/components/pipelines_list')
-rw-r--r-- | spec/frontend/pipelines/components/pipelines_list/pipeline_mini_graph_spec.js | 83 | ||||
-rw-r--r-- | spec/frontend/pipelines/components/pipelines_list/pipeline_stage_spec.js | 259 |
2 files changed, 0 insertions, 342 deletions
diff --git a/spec/frontend/pipelines/components/pipelines_list/pipeline_mini_graph_spec.js b/spec/frontend/pipelines/components/pipelines_list/pipeline_mini_graph_spec.js deleted file mode 100644 index 1cb43c199aa..00000000000 --- a/spec/frontend/pipelines/components/pipelines_list/pipeline_mini_graph_spec.js +++ /dev/null @@ -1,83 +0,0 @@ -import { shallowMount } from '@vue/test-utils'; -import { pipelines } from 'test_fixtures/pipelines/pipelines.json'; -import PipelineMiniGraph from '~/pipelines/components/pipelines_list/pipeline_mini_graph.vue'; -import PipelineStage from '~/pipelines/components/pipelines_list/pipeline_stage.vue'; - -const mockStages = pipelines[0].details.stages; - -describe('Pipeline Mini Graph', () => { - let wrapper; - - const findPipelineStages = () => wrapper.findAll(PipelineStage); - const findPipelineStagesAt = (i) => findPipelineStages().at(i); - - const createComponent = (props = {}) => { - wrapper = shallowMount(PipelineMiniGraph, { - propsData: { - stages: mockStages, - ...props, - }, - }); - }; - - it('renders stages', () => { - createComponent(); - - expect(findPipelineStages()).toHaveLength(mockStages.length); - }); - - it('renders stages with a custom class', () => { - createComponent({ stagesClass: 'my-class' }); - - expect(wrapper.findAll('.my-class')).toHaveLength(mockStages.length); - }); - - it('does not fail when stages are empty', () => { - createComponent({ stages: [] }); - - expect(wrapper.exists()).toBe(true); - expect(findPipelineStages()).toHaveLength(0); - }); - - it('triggers events in "action request complete" in stages', () => { - createComponent(); - - findPipelineStagesAt(0).vm.$emit('pipelineActionRequestComplete'); - findPipelineStagesAt(1).vm.$emit('pipelineActionRequestComplete'); - - expect(wrapper.emitted('pipelineActionRequestComplete')).toHaveLength(2); - }); - - it('update dropdown is false by default', () => { - createComponent(); - - expect(findPipelineStagesAt(0).props('updateDropdown')).toBe(false); - expect(findPipelineStagesAt(1).props('updateDropdown')).toBe(false); - }); - - it('update dropdown is set to true', () => { - createComponent({ updateDropdown: true }); - - expect(findPipelineStagesAt(0).props('updateDropdown')).toBe(true); - expect(findPipelineStagesAt(1).props('updateDropdown')).toBe(true); - }); - - it('is merge train is false by default', () => { - createComponent(); - - expect(findPipelineStagesAt(0).props('isMergeTrain')).toBe(false); - expect(findPipelineStagesAt(1).props('isMergeTrain')).toBe(false); - }); - - it('is merge train is set to true', () => { - createComponent({ isMergeTrain: true }); - - expect(findPipelineStagesAt(0).props('isMergeTrain')).toBe(true); - expect(findPipelineStagesAt(1).props('isMergeTrain')).toBe(true); - }); - - afterEach(() => { - wrapper.destroy(); - wrapper = null; - }); -}); diff --git a/spec/frontend/pipelines/components/pipelines_list/pipeline_stage_spec.js b/spec/frontend/pipelines/components/pipelines_list/pipeline_stage_spec.js deleted file mode 100644 index e712cdeaea2..00000000000 --- a/spec/frontend/pipelines/components/pipelines_list/pipeline_stage_spec.js +++ /dev/null @@ -1,259 +0,0 @@ -import { GlDropdown } from '@gitlab/ui'; -import { nextTick } from 'vue'; -import { mount } from '@vue/test-utils'; -import MockAdapter from 'axios-mock-adapter'; -import CiIcon from '~/vue_shared/components/ci_icon.vue'; -import axios from '~/lib/utils/axios_utils'; -import PipelineStage from '~/pipelines/components/pipelines_list/pipeline_stage.vue'; -import eventHub from '~/pipelines/event_hub'; -import waitForPromises from 'helpers/wait_for_promises'; -import { stageReply } from '../../mock_data'; - -const dropdownPath = 'path.json'; - -describe('Pipelines stage component', () => { - let wrapper; - let mock; - let glTooltipDirectiveMock; - - const createComponent = (props = {}) => { - glTooltipDirectiveMock = jest.fn(); - wrapper = mount(PipelineStage, { - attachTo: document.body, - directives: { - GlTooltip: glTooltipDirectiveMock, - }, - propsData: { - stage: { - status: { - group: 'success', - icon: 'status_success', - title: 'success', - }, - dropdown_path: dropdownPath, - }, - updateDropdown: false, - ...props, - }, - }); - }; - - beforeEach(() => { - mock = new MockAdapter(axios); - jest.spyOn(eventHub, '$emit'); - }); - - afterEach(() => { - wrapper.destroy(); - wrapper = null; - - eventHub.$emit.mockRestore(); - mock.restore(); - }); - - const findCiActionBtn = () => wrapper.find('.js-ci-action'); - const findCiIcon = () => wrapper.findComponent(CiIcon); - const findDropdown = () => wrapper.findComponent(GlDropdown); - const findDropdownToggle = () => wrapper.find('button.dropdown-toggle'); - const findDropdownMenu = () => - wrapper.find('[data-testid="mini-pipeline-graph-dropdown-menu-list"]'); - const findDropdownMenuTitle = () => - wrapper.find('[data-testid="pipeline-stage-dropdown-menu-title"]'); - const findMergeTrainWarning = () => wrapper.find('[data-testid="warning-message-merge-trains"]'); - const findLoadingState = () => wrapper.find('[data-testid="pipeline-stage-loading-state"]'); - - const openStageDropdown = async () => { - await findDropdownToggle().trigger('click'); - await waitForPromises(); - await nextTick(); - }; - - describe('loading state', () => { - beforeEach(async () => { - createComponent({ updateDropdown: true }); - - mock.onGet(dropdownPath).reply(200, stageReply); - - await openStageDropdown(); - }); - - it('displays loading state while jobs are being fetched', async () => { - jest.runOnlyPendingTimers(); - await nextTick(); - - expect(findLoadingState().exists()).toBe(true); - expect(findLoadingState().text()).toBe(PipelineStage.i18n.loadingText); - }); - - it('does not display loading state after jobs have been fetched', async () => { - await waitForPromises(); - - expect(findLoadingState().exists()).toBe(false); - }); - }); - - describe('default appearance', () => { - beforeEach(() => { - createComponent(); - }); - - it('sets up the tooltip to not have a show delay animation', () => { - expect(glTooltipDirectiveMock.mock.calls[0][1].modifiers.ds0).toBe(true); - }); - - it('renders a dropdown with the status icon', () => { - expect(findDropdown().exists()).toBe(true); - expect(findDropdownToggle().exists()).toBe(true); - expect(findCiIcon().exists()).toBe(true); - }); - - it('renders a borderless ci-icon', () => { - expect(findCiIcon().exists()).toBe(true); - expect(findCiIcon().props('isBorderless')).toBe(true); - expect(findCiIcon().classes('borderless')).toBe(true); - }); - - it('renders a ci-icon with a custom border class', () => { - expect(findCiIcon().exists()).toBe(true); - expect(findCiIcon().classes('gl-border')).toBe(true); - }); - }); - - describe('when user opens dropdown and stage request is successful', () => { - beforeEach(async () => { - mock.onGet(dropdownPath).reply(200, stageReply); - createComponent(); - - await openStageDropdown(); - await jest.runAllTimers(); - await axios.waitForAll(); - }); - - it('renders the received data and emit `clickedDropdown` event', async () => { - expect(findDropdownMenu().text()).toContain(stageReply.latest_statuses[0].name); - expect(findDropdownMenuTitle().text()).toContain(stageReply.name); - expect(eventHub.$emit).toHaveBeenCalledWith('clickedDropdown'); - }); - - it('refreshes when updateDropdown is set to true', async () => { - expect(mock.history.get).toHaveLength(1); - - wrapper.setProps({ updateDropdown: true }); - await axios.waitForAll(); - - expect(mock.history.get).toHaveLength(2); - }); - }); - - describe('when user opens dropdown and stage request fails', () => { - it('should close the dropdown', async () => { - mock.onGet(dropdownPath).reply(500); - createComponent(); - - await openStageDropdown(); - await axios.waitForAll(); - await waitForPromises(); - - expect(findDropdown().classes('show')).toBe(false); - }); - }); - - describe('update endpoint correctly', () => { - beforeEach(async () => { - const copyStage = { ...stageReply }; - copyStage.latest_statuses[0].name = 'this is the updated content'; - mock.onGet('bar.json').reply(200, copyStage); - createComponent({ - stage: { - status: { - group: 'running', - icon: 'status_running', - title: 'running', - }, - dropdown_path: 'bar.json', - }, - }); - await axios.waitForAll(); - }); - - it('should update the stage to request the new endpoint provided', async () => { - await openStageDropdown(); - jest.runOnlyPendingTimers(); - await waitForPromises(); - - expect(findDropdownMenu().text()).toContain('this is the updated content'); - }); - }); - - describe('pipelineActionRequestComplete', () => { - beforeEach(async () => { - mock.onGet(dropdownPath).reply(200, stageReply); - mock.onPost(`${stageReply.latest_statuses[0].status.action.path}.json`).reply(200); - - createComponent(); - await waitForPromises(); - await nextTick(); - }); - - const clickCiAction = async () => { - await openStageDropdown(); - jest.runOnlyPendingTimers(); - await waitForPromises(); - - await findCiActionBtn().trigger('click'); - }; - - it('closes dropdown when job item action is clicked', async () => { - const hidden = jest.fn(); - - wrapper.vm.$root.$on('bv::dropdown::hide', hidden); - - expect(hidden).toHaveBeenCalledTimes(0); - - await clickCiAction(); - await waitForPromises(); - - expect(hidden).toHaveBeenCalledTimes(1); - }); - - it('emits `pipelineActionRequestComplete` when job item action is clicked', async () => { - await clickCiAction(); - await waitForPromises(); - - expect(wrapper.emitted('pipelineActionRequestComplete')).toHaveLength(1); - }); - }); - - describe('With merge trains enabled', () => { - it('shows a warning on the dropdown', async () => { - mock.onGet(dropdownPath).reply(200, stageReply); - createComponent({ - isMergeTrain: true, - }); - - await openStageDropdown(); - jest.runOnlyPendingTimers(); - await waitForPromises(); - - const warning = findMergeTrainWarning(); - - expect(warning.text()).toBe('Merge train pipeline jobs can not be retried'); - }); - }); - - describe('With merge trains disabled', () => { - beforeEach(async () => { - mock.onGet(dropdownPath).reply(200, stageReply); - createComponent(); - - await openStageDropdown(); - await axios.waitForAll(); - }); - - it('does not show a warning on the dropdown', () => { - const warning = findMergeTrainWarning(); - - expect(warning.exists()).toBe(false); - }); - }); -}); |