diff options
Diffstat (limited to 'spec/frontend/ci/job_details')
14 files changed, 145 insertions, 165 deletions
diff --git a/spec/frontend/ci/job_details/components/job_header_spec.js b/spec/frontend/ci/job_details/components/job_header_spec.js index 6fc55732353..609369316f5 100644 --- a/spec/frontend/ci/job_details/components/job_header_spec.js +++ b/spec/frontend/ci/job_details/components/job_header_spec.js @@ -16,7 +16,7 @@ describe('Header CI Component', () => { text: 'failed', details_path: 'path', }, - name: 'Job build_job', + name: 'build_job', time: '2017-05-08T14:57:39.781Z', user: { id: 1234, @@ -34,17 +34,15 @@ describe('Header CI Component', () => { const findUserLink = () => wrapper.findComponent(GlAvatarLink); const findSidebarToggleBtn = () => wrapper.findComponent(GlButton); const findStatusTooltip = () => wrapper.findComponent(GlTooltip); - const findActionButtons = () => wrapper.findByTestId('job-header-action-buttons'); const findJobName = () => wrapper.findByTestId('job-name'); - const createComponent = (props, slots) => { + const createComponent = (props) => { wrapper = extendedWrapper( shallowMount(JobHeader, { propsData: { ...defaultProps, ...props, }, - ...slots, }), ); }; @@ -54,6 +52,10 @@ describe('Header CI Component', () => { createComponent(); }); + it('renders the correct job name', () => { + expect(findJobName().text()).toBe(defaultProps.name); + }); + it('should render status badge', () => { expect(findCiBadgeLink().exists()).toBe(true); }); @@ -65,10 +67,6 @@ describe('Header CI Component', () => { it('should render sidebar toggle button', () => { expect(findSidebarToggleBtn().exists()).toBe(true); }); - - it('should not render header action buttons when slot is empty', () => { - expect(findActionButtons().exists()).toBe(false); - }); }); describe('user avatar', () => { @@ -124,31 +122,12 @@ describe('Header CI Component', () => { }); }); - describe('job name', () => { - beforeEach(() => { - createComponent(); - }); - - it('should render the job name', () => { - expect(findJobName().text()).toBe('Job build_job'); - }); - }); - - describe('slot', () => { - it('should render header action buttons', () => { - createComponent({}, { slots: { default: 'Test Actions' } }); - - expect(findActionButtons().exists()).toBe(true); - expect(findActionButtons().text()).toBe('Test Actions'); - }); - }); - describe('shouldRenderTriggeredLabel', () => { it('should render created keyword when the shouldRenderTriggeredLabel is false', () => { createComponent({ shouldRenderTriggeredLabel: false }); - expect(wrapper.text()).toContain('created'); - expect(wrapper.text()).not.toContain('started'); + expect(wrapper.text()).toContain('Created'); + expect(wrapper.text()).not.toContain('Started'); }); }); }); diff --git a/spec/frontend/ci/job_details/components/log/collapsible_section_spec.js b/spec/frontend/ci/job_details/components/log/collapsible_section_spec.js index e3d5c448338..5abf2a5ce53 100644 --- a/spec/frontend/ci/job_details/components/log/collapsible_section_spec.js +++ b/spec/frontend/ci/job_details/components/log/collapsible_section_spec.js @@ -1,6 +1,7 @@ import { mount } from '@vue/test-utils'; import { nextTick } from 'vue'; import CollapsibleSection from '~/ci/job_details/components/log/collapsible_section.vue'; +import LogLine from '~/ci/job_details/components/log/line.vue'; import LogLineHeader from '~/ci/job_details/components/log/line_header.vue'; import { collapsibleSectionClosed, collapsibleSectionOpened } from './mock_data'; @@ -9,9 +10,9 @@ describe('Job Log Collapsible Section', () => { const jobLogEndpoint = 'jobs/335'; - const findCollapsibleLine = () => wrapper.find('.collapsible-line'); - const findCollapsibleLineSvg = () => wrapper.find('.collapsible-line svg'); const findLogLineHeader = () => wrapper.findComponent(LogLineHeader); + const findLogLineHeaderSvg = () => findLogLineHeader().find('svg'); + const findLogLines = () => wrapper.findAllComponents(LogLine); const createComponent = (props = {}) => { wrapper = mount(CollapsibleSection, { @@ -30,11 +31,16 @@ describe('Job Log Collapsible Section', () => { }); it('renders clickable header line', () => { - expect(findCollapsibleLine().attributes('role')).toBe('button'); + expect(findLogLineHeader().text()).toBe('1 foo'); + expect(findLogLineHeader().attributes('role')).toBe('button'); }); - it('renders an icon with the closed state', () => { - expect(findCollapsibleLineSvg().attributes('data-testid')).toBe('chevron-lg-right-icon'); + it('renders an icon with a closed state', () => { + expect(findLogLineHeaderSvg().attributes('data-testid')).toBe('chevron-lg-right-icon'); + }); + + it('does not render collapsed lines', () => { + expect(findLogLines()).toHaveLength(0); }); }); @@ -47,15 +53,17 @@ describe('Job Log Collapsible Section', () => { }); it('renders clickable header line', () => { - expect(findCollapsibleLine().attributes('role')).toBe('button'); + expect(findLogLineHeader().text()).toContain('foo'); + expect(findLogLineHeader().attributes('role')).toBe('button'); }); it('renders an icon with the open state', () => { - expect(findCollapsibleLineSvg().attributes('data-testid')).toBe('chevron-lg-down-icon'); + expect(findLogLineHeaderSvg().attributes('data-testid')).toBe('chevron-lg-down-icon'); }); - it('renders collapsible lines content', () => { - expect(wrapper.findAll('.js-line').length).toEqual(collapsibleSectionOpened.lines.length); + it('renders collapsible lines', () => { + expect(findLogLines().at(0).text()).toContain('this is a collapsible nested section'); + expect(findLogLines()).toHaveLength(collapsibleSectionOpened.lines.length); }); }); @@ -65,7 +73,7 @@ describe('Job Log Collapsible Section', () => { jobLogEndpoint, }); - findCollapsibleLine().trigger('click'); + findLogLineHeader().trigger('click'); await nextTick(); expect(wrapper.emitted('onClickCollapsibleLine').length).toBe(1); diff --git a/spec/frontend/ci/job_details/components/log/line_header_spec.js b/spec/frontend/ci/job_details/components/log/line_header_spec.js index 7d1b05346f2..45296e4b6c2 100644 --- a/spec/frontend/ci/job_details/components/log/line_header_spec.js +++ b/spec/frontend/ci/job_details/components/log/line_header_spec.js @@ -16,7 +16,7 @@ describe('Job Log Header Line', () => { style: 'term-fg-l-green', }, ], - lineNumber: 76, + lineNumber: 77, }, isClosed: true, path: '/jashkenas/underscore/-/jobs/335', diff --git a/spec/frontend/ci/job_details/components/log/line_number_spec.js b/spec/frontend/ci/job_details/components/log/line_number_spec.js index d5c1d0fd985..db964e341b7 100644 --- a/spec/frontend/ci/job_details/components/log/line_number_spec.js +++ b/spec/frontend/ci/job_details/components/log/line_number_spec.js @@ -5,7 +5,7 @@ describe('Job Log Line Number', () => { let wrapper; const data = { - lineNumber: 0, + lineNumber: 1, path: '/jashkenas/underscore/-/jobs/335', }; diff --git a/spec/frontend/ci/job_details/components/log/line_spec.js b/spec/frontend/ci/job_details/components/log/line_spec.js index b6f3a2b68df..dad41d0cd7f 100644 --- a/spec/frontend/ci/job_details/components/log/line_spec.js +++ b/spec/frontend/ci/job_details/components/log/line_spec.js @@ -224,7 +224,7 @@ describe('Job Log Line', () => { offset: 24526, content: [{ text: 'job log content' }], section: 'custom-section', - lineNumber: 76, + lineNumber: 77, }, path: '/root/ci-project/-/jobs/6353', }); diff --git a/spec/frontend/ci/job_details/components/log/log_spec.js b/spec/frontend/ci/job_details/components/log/log_spec.js index cc1621b87d6..1931d5046dc 100644 --- a/spec/frontend/ci/job_details/components/log/log_spec.js +++ b/spec/frontend/ci/job_details/components/log/log_spec.js @@ -7,7 +7,7 @@ import { scrollToElement } from '~/lib/utils/common_utils'; import Log from '~/ci/job_details/components/log/log.vue'; import LogLineHeader from '~/ci/job_details/components/log/line_header.vue'; import { logLinesParser } from '~/ci/job_details/store/utils'; -import { jobLog } from './mock_data'; +import { mockJobLog, mockJobLogLineCount } from './mock_data'; jest.mock('~/lib/utils/common_utils', () => ({ ...jest.requireActual('~/lib/utils/common_utils'), @@ -39,7 +39,7 @@ describe('Job Log', () => { }; state = { - jobLog: logLinesParser(jobLog), + jobLog: logLinesParser(mockJobLog), jobLogEndpoint: 'jobs/id', }; @@ -57,15 +57,18 @@ describe('Job Log', () => { createComponent(); }); - it('renders a line number for each open line', () => { - expect(wrapper.find('#L1').text()).toBe('1'); - expect(wrapper.find('#L2').text()).toBe('2'); - expect(wrapper.find('#L3').text()).toBe('3'); - }); + it.each([...Array(mockJobLogLineCount).keys()])( + 'renders a line number for each line %d', + (index) => { + const lineNumber = wrapper + .findAll('.js-log-line') + .at(index) + .find(`#L${index + 1}`); - it('links to the provided path and correct line number', () => { - expect(wrapper.find('#L1').attributes('href')).toBe(`${state.jobLogEndpoint}#L1`); - }); + expect(lineNumber.text()).toBe(`${index + 1}`); + expect(lineNumber.attributes('href')).toBe(`${state.jobLogEndpoint}#L${index + 1}`); + }, + ); }); describe('collapsible sections', () => { @@ -103,7 +106,7 @@ describe('Job Log', () => { await waitForPromises(); - expect(wrapper.find('#L6').exists()).toBe(false); + expect(wrapper.find('#L9').exists()).toBe(false); expect(scrollToElement).not.toHaveBeenCalled(); }); }); @@ -116,19 +119,19 @@ describe('Job Log', () => { it('scrolls to line number', async () => { createComponent(); - state.jobLog = logLinesParser(jobLog, [], '#L6'); + state.jobLog = logLinesParser(mockJobLog, [], '#L6'); await waitForPromises(); expect(scrollToElement).toHaveBeenCalledTimes(1); - state.jobLog = logLinesParser(jobLog, [], '#L7'); + state.jobLog = logLinesParser(mockJobLog, [], '#L7'); await waitForPromises(); expect(scrollToElement).toHaveBeenCalledTimes(1); }); it('line number within collapsed section is visible', () => { - state.jobLog = logLinesParser(jobLog, [], '#L6'); + state.jobLog = logLinesParser(mockJobLog, [], '#L6'); createComponent(); @@ -148,7 +151,7 @@ describe('Job Log', () => { ], section: 'prepare-executor', section_header: true, - lineNumber: 2, + lineNumber: 3, }, ]; diff --git a/spec/frontend/ci/job_details/components/log/mock_data.js b/spec/frontend/ci/job_details/components/log/mock_data.js index fa51b92a044..14669872cc1 100644 --- a/spec/frontend/ci/job_details/components/log/mock_data.js +++ b/spec/frontend/ci/job_details/components/log/mock_data.js @@ -1,4 +1,4 @@ -export const jobLog = [ +export const mockJobLog = [ { offset: 1000, content: [{ text: 'Running with gitlab-runner 12.1.0 (de7731dd)' }], @@ -19,69 +19,50 @@ export const jobLog = [ }, { offset: 1003, - content: [{ text: 'Starting service postgres:9.6.14 ...', style: 'text-green' }], + content: [{ text: 'Docker executor with image registry.gitlab.com ...' }], section: 'prepare-executor', }, { offset: 1004, - content: [ - { - text: 'Restore cache', - style: 'term-fg-l-cyan term-bold', - }, - ], - section: 'restore-cache', - section_header: true, - section_options: { - collapsed: 'true', - }, + content: [{ text: 'Starting service ...', style: 'term-fg-l-green' }], + section: 'prepare-executor', }, { offset: 1005, - content: [ - { - text: 'Checking cache for ruby-gems-debian-bullseye-ruby-3.0-16...', - style: 'term-fg-l-green term-bold', - }, - ], - section: 'restore-cache', - }, -]; - -export const utilsMockData = [ - { - offset: 1001, - content: [{ text: ' on docker-auto-scale-com 8a6210b8' }], + content: [], + section: 'prepare-executor', + section_duration: '00:09', }, { - offset: 1002, + offset: 1006, content: [ { - text: - 'Using Docker executor with image dev.gitlab.org:5005/gitlab/gitlab-build-images:ruby-2.6.6-golang-1.14-git-2.28-lfs-2.9-chrome-84-node-12.x-yarn-1.21-postgresql-11-graphicsmagick-1.3.34', + text: 'Getting source from Git repository', }, ], - section: 'prepare-executor', + section: 'get-sources', section_header: true, }, { - offset: 1003, - content: [{ text: 'Starting service postgres:9.6.14 ...' }], - section: 'prepare-executor', + offset: 1007, + content: [{ text: 'Fetching changes with git depth set to 20...' }], + section: 'get-sources', }, { - offset: 1004, - content: [{ text: 'Pulling docker image postgres:9.6.14 ...', style: 'term-fg-l-green' }], - section: 'prepare-executor', + offset: 1008, + content: [{ text: 'Initialized empty Git repository', style: 'term-fg-l-green' }], + section: 'get-sources', }, { - offset: 1005, + offset: 1009, content: [], - section: 'prepare-executor', - section_duration: '10:00', + section: 'get-sources', + section_duration: '00:19', }, ]; +export const mockJobLogLineCount = 8; // `text` entries in mockJobLog + export const originalTrace = [ { offset: 1, @@ -191,7 +172,7 @@ export const collapsibleSectionClosed = { offset: 80, content: [{ text: 'this is a collapsible nested section' }], section: 'prepare-script', - lineNumber: 3, + lineNumber: 2, }, ], }; @@ -212,7 +193,7 @@ export const collapsibleSectionOpened = { offset: 80, content: [{ text: 'this is a collapsible nested section' }], section: 'prepare-script', - lineNumber: 3, + lineNumber: 2, }, ], }; diff --git a/spec/frontend/ci/job_details/components/sidebar/artifacts_block_spec.js b/spec/frontend/ci/job_details/components/sidebar/artifacts_block_spec.js index 1d61bf3243f..e539be2b220 100644 --- a/spec/frontend/ci/job_details/components/sidebar/artifacts_block_spec.js +++ b/spec/frontend/ci/job_details/components/sidebar/artifacts_block_spec.js @@ -30,31 +30,31 @@ describe('Artifacts block', () => { 'These artifacts are the latest. They will not be deleted (even if expired) until newer artifacts are available.'; const expiredArtifact = { - expire_at: expireAt, + expireAt, expired: true, locked: false, }; const nonExpiredArtifact = { - download_path: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/download', - browse_path: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/browse', - keep_path: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/keep', - expire_at: expireAt, + downloadPath: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/download', + browsePath: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/browse', + keepPath: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/keep', + expireAt, expired: false, locked: false, }; const lockedExpiredArtifact = { ...expiredArtifact, - download_path: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/download', - browse_path: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/browse', + downloadPath: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/download', + browsePath: '/gitlab-org/gitlab-foss/-/jobs/98314558/artifacts/browse', expired: true, locked: true, }; const lockedNonExpiredArtifact = { ...nonExpiredArtifact, - keep_path: undefined, + keepPath: undefined, locked: true, }; diff --git a/spec/frontend/ci/job_details/components/sidebar/sidebar_header_spec.js b/spec/frontend/ci/job_details/components/sidebar/sidebar_header_spec.js index 1063bec6f3b..81181fc71b2 100644 --- a/spec/frontend/ci/job_details/components/sidebar/sidebar_header_spec.js +++ b/spec/frontend/ci/job_details/components/sidebar/sidebar_header_spec.js @@ -55,15 +55,9 @@ describe('Sidebar Header', () => { const findEraseButton = () => wrapper.findByTestId('job-log-erase-link'); const findNewIssueButton = () => wrapper.findByTestId('job-new-issue'); const findTerminalLink = () => wrapper.findByTestId('terminal-link'); - const findJobName = () => wrapper.findByTestId('job-name'); const findRetryButton = () => wrapper.findComponent(JobRetryButton); describe('when rendering contents', () => { - it('renders the correct job name', async () => { - await createComponentWithApollo(); - expect(findJobName().text()).toBe(mockJobResponse.data.project.job.name); - }); - it('does not render buttons with no paths', async () => { await createComponentWithApollo(); expect(findCancelButton().exists()).toBe(false); diff --git a/spec/frontend/ci/job_details/components/sidebar/sidebar_job_details_container_spec.js b/spec/frontend/ci/job_details/components/sidebar/sidebar_job_details_container_spec.js index e188d99b8b1..37a2ca75df0 100644 --- a/spec/frontend/ci/job_details/components/sidebar/sidebar_job_details_container_spec.js +++ b/spec/frontend/ci/job_details/components/sidebar/sidebar_job_details_container_spec.js @@ -53,7 +53,6 @@ describe('Job Sidebar Details Container', () => { ['erased_at', 'Erased: 3 weeks ago'], ['finished_at', 'Finished: 3 weeks ago'], ['queued_duration', 'Queued: 9 seconds'], - ['id', 'Job ID: #4757'], ['runner', 'Runner: #1 (ABCDEFGH) local ci runner'], ['coverage', 'Coverage: 20%'], ])('uses %s to render job-%s', async (detail, value) => { @@ -78,7 +77,7 @@ describe('Job Sidebar Details Container', () => { createWrapper(); await store.dispatch('receiveJobSuccess', job); - expect(findAllDetailsRow()).toHaveLength(8); + expect(findAllDetailsRow()).toHaveLength(7); }); describe('duration row', () => { diff --git a/spec/frontend/ci/job_details/job_app_spec.js b/spec/frontend/ci/job_details/job_app_spec.js index c2d91771495..ff84b2d0283 100644 --- a/spec/frontend/ci/job_details/job_app_spec.js +++ b/spec/frontend/ci/job_details/job_app_spec.js @@ -31,8 +31,6 @@ describe('Job App', () => { const initSettings = { endpoint: `${TEST_HOST}jobs/123.json`, pagePath: `${TEST_HOST}jobs/123`, - logState: - 'eyJvZmZzZXQiOjE3NDUxLCJuX29wZW5fdGFncyI6MCwiZmdfY29sb3IiOm51bGwsImJnX2NvbG9yIjpudWxsLCJzdHlsZV9tYXNrIjowfQ%3D%3D', }; const props = { diff --git a/spec/frontend/ci/job_details/store/actions_spec.js b/spec/frontend/ci/job_details/store/actions_spec.js index bb5c1fe32bd..2799bc9578c 100644 --- a/spec/frontend/ci/job_details/store/actions_spec.js +++ b/spec/frontend/ci/job_details/store/actions_spec.js @@ -2,7 +2,6 @@ import MockAdapter from 'axios-mock-adapter'; import { TEST_HOST } from 'helpers/test_constants'; import testAction from 'helpers/vuex_action_helper'; import { - setJobEndpoint, setJobLogOptions, clearEtagPoll, stopPolling, @@ -39,25 +38,21 @@ describe('Job State actions', () => { mockedState = state(); }); - describe('setJobEndpoint', () => { - it('should commit SET_JOB_ENDPOINT mutation', () => { - return testAction( - setJobEndpoint, - 'job/872324.json', - mockedState, - [{ type: types.SET_JOB_ENDPOINT, payload: 'job/872324.json' }], - [], - ); - }); - }); - describe('setJobLogOptions', () => { it('should commit SET_JOB_LOG_OPTIONS mutation', () => { return testAction( setJobLogOptions, - { pagePath: 'job/872324/trace.json' }, + { endpoint: '/group1/project1/-/jobs/99.json', pagePath: '/group1/project1/-/jobs/99' }, mockedState, - [{ type: types.SET_JOB_LOG_OPTIONS, payload: { pagePath: 'job/872324/trace.json' } }], + [ + { + type: types.SET_JOB_LOG_OPTIONS, + payload: { + endpoint: '/group1/project1/-/jobs/99.json', + pagePath: '/group1/project1/-/jobs/99', + }, + }, + ], [], ); }); diff --git a/spec/frontend/ci/job_details/store/mutations_spec.js b/spec/frontend/ci/job_details/store/mutations_spec.js index 0835c534fb9..78b29efed68 100644 --- a/spec/frontend/ci/job_details/store/mutations_spec.js +++ b/spec/frontend/ci/job_details/store/mutations_spec.js @@ -12,11 +12,17 @@ describe('Jobs Store Mutations', () => { stateCopy = state(); }); - describe('SET_JOB_ENDPOINT', () => { + describe('SET_JOB_LOG_OPTIONS', () => { it('should set jobEndpoint', () => { - mutations[types.SET_JOB_ENDPOINT](stateCopy, 'job/21312321.json'); + mutations[types.SET_JOB_LOG_OPTIONS](stateCopy, { + endpoint: '/group1/project1/-/jobs/99.json', + pagePath: '/group1/project1/-/jobs/99', + }); - expect(stateCopy.jobEndpoint).toEqual('job/21312321.json'); + expect(stateCopy).toMatchObject({ + jobLogEndpoint: '/group1/project1/-/jobs/99', + jobEndpoint: '/group1/project1/-/jobs/99.json', + }); }); }); @@ -39,13 +45,13 @@ describe('Jobs Store Mutations', () => { describe('RECEIVE_JOB_LOG_SUCCESS', () => { describe('when job log has state', () => { it('sets jobLogState', () => { - const stateLog = + const logState = 'eyJvZmZzZXQiOjczNDQ1MSwibl9vcGVuX3RhZ3MiOjAsImZnX2NvbG9yIjpudWxsLCJiZ19jb2xvciI6bnVsbCwic3R5bGVfbWFzayI6MH0='; mutations[types.RECEIVE_JOB_LOG_SUCCESS](stateCopy, { - state: stateLog, + state: logState, }); - expect(stateCopy.jobLogState).toEqual(stateLog); + expect(stateCopy.jobLogState).toEqual(logState); }); }); @@ -100,7 +106,7 @@ describe('Jobs Store Mutations', () => { { offset: 1, content: [{ text: 'Running with gitlab-runner 11.12.1 (5a147c92)' }], - lineNumber: 0, + lineNumber: 1, }, ]); }); @@ -121,7 +127,7 @@ describe('Jobs Store Mutations', () => { { offset: 0, content: [{ text: 'Running with gitlab-runner 11.11.1 (5a147c92)' }], - lineNumber: 0, + lineNumber: 1, }, ]); }); diff --git a/spec/frontend/ci/job_details/store/utils_spec.js b/spec/frontend/ci/job_details/store/utils_spec.js index 4ffba35761e..394ce0ab737 100644 --- a/spec/frontend/ci/job_details/store/utils_spec.js +++ b/spec/frontend/ci/job_details/store/utils_spec.js @@ -6,10 +6,10 @@ import { addDurationToHeader, isCollapsibleSection, findOffsetAndRemove, - getIncrementalLineNumber, + getNextLineNumber, } from '~/ci/job_details/store/utils'; import { - utilsMockData, + mockJobLog, originalTrace, regularIncremental, regularIncrementalRepeated, @@ -187,39 +187,49 @@ describe('Jobs Store Utils', () => { let result; beforeEach(() => { - result = logLinesParser(utilsMockData); + result = logLinesParser(mockJobLog); }); describe('regular line', () => { it('adds a lineNumber property with correct index', () => { - expect(result[0].lineNumber).toEqual(0); - expect(result[1].line.lineNumber).toEqual(1); + expect(result[0].lineNumber).toEqual(1); + expect(result[1].lineNumber).toEqual(2); + expect(result[2].line.lineNumber).toEqual(3); + expect(result[2].lines[0].lineNumber).toEqual(4); + expect(result[2].lines[1].lineNumber).toEqual(5); + expect(result[3].line.lineNumber).toEqual(6); + expect(result[3].lines[0].lineNumber).toEqual(7); + expect(result[3].lines[1].lineNumber).toEqual(8); }); }); describe('collapsible section', () => { it('adds a `isClosed` property', () => { - expect(result[1].isClosed).toEqual(false); + expect(result[2].isClosed).toEqual(false); + expect(result[3].isClosed).toEqual(false); }); it('adds a `isHeader` property', () => { - expect(result[1].isHeader).toEqual(true); + expect(result[2].isHeader).toEqual(true); + expect(result[3].isHeader).toEqual(true); }); it('creates a lines array property with the content of the collapsible section', () => { - expect(result[1].lines.length).toEqual(2); - expect(result[1].lines[0].content).toEqual(utilsMockData[2].content); - expect(result[1].lines[1].content).toEqual(utilsMockData[3].content); + expect(result[2].lines.length).toEqual(2); + expect(result[2].lines[0].content).toEqual(mockJobLog[3].content); + expect(result[2].lines[1].content).toEqual(mockJobLog[4].content); }); }); describe('section duration', () => { it('adds the section information to the header section', () => { - expect(result[1].line.section_duration).toEqual(utilsMockData[4].section_duration); + expect(result[2].line.section_duration).toEqual(mockJobLog[5].section_duration); + expect(result[3].line.section_duration).toEqual(mockJobLog[9].section_duration); }); it('does not add section duration as a line', () => { - expect(result[1].lines.includes(utilsMockData[4])).toEqual(false); + expect(result[2].lines.includes(mockJobLog[5])).toEqual(false); + expect(result[3].lines.includes(mockJobLog[9])).toEqual(false); }); }); }); @@ -316,17 +326,24 @@ describe('Jobs Store Utils', () => { }); }); - describe('getIncrementalLineNumber', () => { - describe('when last line is 0', () => { + describe('getNextLineNumber', () => { + describe('when there is no previous log', () => { + it('returns 1', () => { + expect(getNextLineNumber([])).toEqual(1); + expect(getNextLineNumber(undefined)).toEqual(1); + }); + }); + + describe('when last line is 1', () => { it('returns 1', () => { const log = [ { content: [], - lineNumber: 0, + lineNumber: 1, }, ]; - expect(getIncrementalLineNumber(log)).toEqual(1); + expect(getNextLineNumber(log)).toEqual(2); }); }); @@ -343,7 +360,7 @@ describe('Jobs Store Utils', () => { }, ]; - expect(getIncrementalLineNumber(log)).toEqual(102); + expect(getNextLineNumber(log)).toEqual(102); }); }); @@ -364,7 +381,7 @@ describe('Jobs Store Utils', () => { }, ]; - expect(getIncrementalLineNumber(log)).toEqual(102); + expect(getNextLineNumber(log)).toEqual(102); }); }); @@ -391,7 +408,7 @@ describe('Jobs Store Utils', () => { }, ]; - expect(getIncrementalLineNumber(log)).toEqual(104); + expect(getNextLineNumber(log)).toEqual(104); }); }); }); @@ -410,7 +427,7 @@ describe('Jobs Store Utils', () => { text: 'Downloading', }, ], - lineNumber: 0, + lineNumber: 1, }, { offset: 2, @@ -419,7 +436,7 @@ describe('Jobs Store Utils', () => { text: 'log line', }, ], - lineNumber: 1, + lineNumber: 2, }, ]); }); @@ -438,7 +455,7 @@ describe('Jobs Store Utils', () => { text: 'log line', }, ], - lineNumber: 0, + lineNumber: 1, }, ]); }); @@ -462,7 +479,7 @@ describe('Jobs Store Utils', () => { }, ], section: 'section', - lineNumber: 0, + lineNumber: 1, }, lines: [], }, @@ -488,7 +505,7 @@ describe('Jobs Store Utils', () => { }, ], section: 'section', - lineNumber: 0, + lineNumber: 1, }, lines: [ { @@ -499,7 +516,7 @@ describe('Jobs Store Utils', () => { }, ], section: 'section', - lineNumber: 1, + lineNumber: 2, }, ], }, |