diff options
Diffstat (limited to 'spec/frontend/jobs')
-rw-r--r-- | spec/frontend/jobs/components/job_log_controllers_spec.js | 148 | ||||
-rw-r--r-- | spec/frontend/jobs/components/sidebar_detail_row_spec.js | 2 |
2 files changed, 112 insertions, 38 deletions
diff --git a/spec/frontend/jobs/components/job_log_controllers_spec.js b/spec/frontend/jobs/components/job_log_controllers_spec.js index cc97d111c06..aa85253a177 100644 --- a/spec/frontend/jobs/components/job_log_controllers_spec.js +++ b/spec/frontend/jobs/components/job_log_controllers_spec.js @@ -1,8 +1,9 @@ import { GlSearchBoxByClick } from '@gitlab/ui'; import { mount } from '@vue/test-utils'; -import { nextTick } from 'vue'; import JobLogControllers from '~/jobs/components/job_log_controllers.vue'; import HelpPopover from '~/vue_shared/components/help_popover.vue'; +import { backoffMockImplementation } from 'helpers/backoff_helper'; +import * as commonUtils from '~/lib/utils/common_utils'; import { mockJobLog } from '../mock_data'; const mockToastShow = jest.fn(); @@ -10,10 +11,15 @@ const mockToastShow = jest.fn(); describe('Job log controllers', () => { let wrapper; + beforeEach(() => { + jest.spyOn(commonUtils, 'backOff').mockImplementation(backoffMockImplementation); + }); + afterEach(() => { if (wrapper?.destroy) { wrapper.destroy(); } + commonUtils.backOff.mockReset(); }); const defaultProps = { @@ -24,10 +30,11 @@ describe('Job log controllers', () => { isScrollBottomDisabled: false, isScrollingDown: true, isJobLogSizeVisible: true, + isComplete: true, jobLog: mockJobLog, }; - const createWrapper = (props, jobLogSearch = false) => { + const createWrapper = (props, { jobLogJumpToFailures = false } = {}) => { wrapper = mount(JobLogControllers, { propsData: { ...defaultProps, @@ -35,7 +42,7 @@ describe('Job log controllers', () => { }, provide: { glFeatures: { - jobLogSearch, + jobLogJumpToFailures, }, }, data() { @@ -58,6 +65,7 @@ describe('Job log controllers', () => { const findScrollBottom = () => wrapper.find('[data-testid="job-controller-scroll-bottom"]'); const findJobLogSearch = () => wrapper.findComponent(GlSearchBoxByClick); const findSearchHelp = () => wrapper.findComponent(HelpPopover); + const findScrollFailure = () => wrapper.find('[data-testid="job-controller-scroll-to-failure"]'); describe('Truncate information', () => { describe('with isJobLogSizeVisible', () => { @@ -109,9 +117,7 @@ describe('Job log controllers', () => { }); it('emits scrollJobLogTop event on click', async () => { - findScrollTop().trigger('click'); - - await nextTick(); + await findScrollTop().trigger('click'); expect(wrapper.emitted().scrollJobLogTop).toHaveLength(1); }); @@ -131,9 +137,7 @@ describe('Job log controllers', () => { }); it('does not emit scrollJobLogTop event on click', async () => { - findScrollTop().trigger('click'); - - await nextTick(); + await findScrollTop().trigger('click'); expect(wrapper.emitted().scrollJobLogTop).toBeUndefined(); }); @@ -147,9 +151,7 @@ describe('Job log controllers', () => { }); it('emits scrollJobLogBottom event on click', async () => { - findScrollBottom().trigger('click'); - - await nextTick(); + await findScrollBottom().trigger('click'); expect(wrapper.emitted().scrollJobLogBottom).toHaveLength(1); }); @@ -169,9 +171,7 @@ describe('Job log controllers', () => { }); it('does not emit scrollJobLogBottom event on click', async () => { - findScrollBottom().trigger('click'); - - await nextTick(); + await findScrollBottom().trigger('click'); expect(wrapper.emitted().scrollJobLogBottom).toBeUndefined(); }); @@ -201,41 +201,115 @@ describe('Job log controllers', () => { }); }); }); - }); - describe('Job log search', () => { - describe('with feature flag off', () => { - it('does not display job log search', () => { - createWrapper(); + describe('scroll to failure button', () => { + describe('with feature flag disabled', () => { + it('does not display button', () => { + createWrapper(); - expect(findJobLogSearch().exists()).toBe(false); - expect(findSearchHelp().exists()).toBe(false); + expect(findScrollFailure().exists()).toBe(false); + }); }); - }); - describe('with feature flag on', () => { - beforeEach(() => { - createWrapper({}, { jobLogSearch: true }); - }); + describe('with red text failures on the page', () => { + let firstFailure; + let secondFailure; + + beforeEach(() => { + jest.spyOn(document, 'querySelectorAll').mockReturnValueOnce(['mock-element']); + + createWrapper({}, { jobLogJumpToFailures: true }); + + firstFailure = document.createElement('div'); + firstFailure.className = 'term-fg-l-red'; + document.body.appendChild(firstFailure); + + secondFailure = document.createElement('div'); + secondFailure.className = 'term-fg-l-red'; + document.body.appendChild(secondFailure); + }); + + afterEach(() => { + if (firstFailure) { + firstFailure.remove(); + firstFailure = null; + } + + if (secondFailure) { + secondFailure.remove(); + secondFailure = null; + } + }); + + it('is enabled', () => { + expect(findScrollFailure().props('disabled')).toBe(false); + }); + + it('scrolls to each failure', async () => { + jest.spyOn(firstFailure, 'scrollIntoView'); - it('displays job log search', () => { - expect(findJobLogSearch().exists()).toBe(true); - expect(findSearchHelp().exists()).toBe(true); + await findScrollFailure().trigger('click'); + + expect(firstFailure.scrollIntoView).toHaveBeenCalled(); + + await findScrollFailure().trigger('click'); + + expect(secondFailure.scrollIntoView).toHaveBeenCalled(); + + await findScrollFailure().trigger('click'); + + expect(firstFailure.scrollIntoView).toHaveBeenCalled(); + }); }); - it('emits search results', () => { - const expectedSearchResults = [[[mockJobLog[6].lines[1], mockJobLog[6].lines[2]]]]; + describe('with no red text failures on the page', () => { + beforeEach(() => { + jest.spyOn(document, 'querySelectorAll').mockReturnValueOnce([]); - findJobLogSearch().vm.$emit('submit'); + createWrapper({}, { jobLogJumpToFailures: true }); + }); - expect(wrapper.emitted('searchResults')).toEqual(expectedSearchResults); + it('is disabled', () => { + expect(findScrollFailure().props('disabled')).toBe(true); + }); }); - it('clears search results', () => { - findJobLogSearch().vm.$emit('clear'); + describe('when the job log is not complete', () => { + beforeEach(() => { + jest.spyOn(document, 'querySelectorAll').mockReturnValueOnce(['mock-element']); + + createWrapper({ isComplete: false }, { jobLogJumpToFailures: true }); + }); - expect(wrapper.emitted('searchResults')).toEqual([[[]]]); + it('is enabled', () => { + expect(findScrollFailure().props('disabled')).toBe(false); + }); }); }); }); + + describe('Job log search', () => { + beforeEach(() => { + createWrapper(); + }); + + it('displays job log search', () => { + expect(findJobLogSearch().exists()).toBe(true); + expect(findSearchHelp().exists()).toBe(true); + }); + + it('emits search results', () => { + const expectedSearchResults = [[[mockJobLog[6].lines[1], mockJobLog[6].lines[2]]]]; + + findJobLogSearch().vm.$emit('submit'); + + expect(wrapper.emitted('searchResults')).toEqual(expectedSearchResults); + }); + + it('clears search results', () => { + findJobLogSearch().vm.$emit('clear'); + + expect(wrapper.emitted('searchResults')).toEqual([[[]]]); + }); + }); }); diff --git a/spec/frontend/jobs/components/sidebar_detail_row_spec.js b/spec/frontend/jobs/components/sidebar_detail_row_spec.js index 43f2e022dd8..8d2680608ab 100644 --- a/spec/frontend/jobs/components/sidebar_detail_row_spec.js +++ b/spec/frontend/jobs/components/sidebar_detail_row_spec.js @@ -7,7 +7,7 @@ describe('Sidebar detail row', () => { const title = 'this is the title'; const value = 'this is the value'; - const helpUrl = '/help/ci/runners/index.html'; + const helpUrl = 'https://docs.gitlab.com/runner/register/index.html'; const findHelpLink = () => wrapper.findComponent(GlLink); |