diff options
Diffstat (limited to 'spec/frontend/jobs/store')
-rw-r--r-- | spec/frontend/jobs/store/mutations_spec.js | 94 | ||||
-rw-r--r-- | spec/frontend/jobs/store/utils_spec.js | 95 |
2 files changed, 183 insertions, 6 deletions
diff --git a/spec/frontend/jobs/store/mutations_spec.js b/spec/frontend/jobs/store/mutations_spec.js index 1c7e45dfb3d..159315330e4 100644 --- a/spec/frontend/jobs/store/mutations_spec.js +++ b/spec/frontend/jobs/store/mutations_spec.js @@ -4,12 +4,21 @@ import state from '~/jobs/store/state'; describe('Jobs Store Mutations', () => { let stateCopy; + let origGon; const html = 'I, [2018-08-17T22:57:45.707325 #1841] INFO -- : Writing /builds/ab89e95b0fa0b9272ea0c797b76908f24d36992630e9325273a4ce3.png<br>I'; beforeEach(() => { stateCopy = state(); + + origGon = window.gon; + + window.gon = { features: { infinitelyCollapsibleSections: false } }; + }); + + afterEach(() => { + window.gon = origGon; }); describe('SET_JOB_ENDPOINT', () => { @@ -267,3 +276,88 @@ describe('Jobs Store Mutations', () => { }); }); }); + +describe('Job Store mutations, feature flag ON', () => { + let stateCopy; + let origGon; + + const html = + 'I, [2018-08-17T22:57:45.707325 #1841] INFO -- : Writing /builds/ab89e95b0fa0b9272ea0c797b76908f24d36992630e9325273a4ce3.png<br>I'; + + beforeEach(() => { + stateCopy = state(); + + origGon = window.gon; + + window.gon = { features: { infinitelyCollapsibleSections: true } }; + }); + + afterEach(() => { + window.gon = origGon; + }); + + describe('RECEIVE_TRACE_SUCCESS', () => { + describe('with new job log', () => { + describe('log.lines', () => { + describe('when append is true', () => { + it('sets the parsed log ', () => { + mutations[types.RECEIVE_TRACE_SUCCESS](stateCopy, { + append: true, + size: 511846, + complete: true, + lines: [ + { + offset: 1, + content: [{ text: 'Running with gitlab-runner 11.12.1 (5a147c92)' }], + }, + ], + }); + + expect(stateCopy.trace).toEqual([ + { + offset: 1, + content: [{ text: 'Running with gitlab-runner 11.12.1 (5a147c92)' }], + lineNumber: 1, + }, + ]); + }); + }); + + describe('when lines are defined', () => { + it('sets the parsed log ', () => { + mutations[types.RECEIVE_TRACE_SUCCESS](stateCopy, { + append: false, + size: 511846, + complete: true, + lines: [ + { offset: 0, content: [{ text: 'Running with gitlab-runner 11.11.1 (5a147c92)' }] }, + ], + }); + + expect(stateCopy.trace).toEqual([ + { + offset: 0, + content: [{ text: 'Running with gitlab-runner 11.11.1 (5a147c92)' }], + lineNumber: 1, + }, + ]); + }); + }); + + describe('when lines are null', () => { + it('sets the default value', () => { + mutations[types.RECEIVE_TRACE_SUCCESS](stateCopy, { + append: true, + html, + size: 511846, + complete: false, + lines: null, + }); + + expect(stateCopy.trace).toEqual([]); + }); + }); + }); + }); + }); +}); diff --git a/spec/frontend/jobs/store/utils_spec.js b/spec/frontend/jobs/store/utils_spec.js index e50d304bb08..35ac2945ab5 100644 --- a/spec/frontend/jobs/store/utils_spec.js +++ b/spec/frontend/jobs/store/utils_spec.js @@ -1,5 +1,6 @@ import { logLinesParser, + logLinesParserLegacy, updateIncrementalTrace, parseHeaderLine, parseLine, @@ -17,6 +18,7 @@ import { headerTraceIncremental, collapsibleTrace, collapsibleTraceIncremental, + multipleCollapsibleSectionsMockData, } from '../components/log/mock_data'; describe('Jobs Store Utils', () => { @@ -175,11 +177,11 @@ describe('Jobs Store Utils', () => { expect(isCollapsibleSection()).toEqual(false); }); }); - describe('logLinesParser', () => { + describe('logLinesParserLegacy', () => { let result; beforeEach(() => { - result = logLinesParser(utilsMockData); + result = logLinesParserLegacy(utilsMockData); }); describe('regular line', () => { @@ -216,6 +218,87 @@ describe('Jobs Store Utils', () => { }); }); + describe('logLinesParser', () => { + let result; + + beforeEach(() => { + result = logLinesParser(utilsMockData); + }); + + describe('regular line', () => { + it('adds a lineNumber property with correct index', () => { + expect(result.parsedLines[0].lineNumber).toEqual(1); + expect(result.parsedLines[1].line.lineNumber).toEqual(2); + }); + }); + + describe('collapsible section', () => { + it('adds a `isClosed` property', () => { + expect(result.parsedLines[1].isClosed).toEqual(false); + }); + + it('adds a `isHeader` property', () => { + expect(result.parsedLines[1].isHeader).toEqual(true); + }); + + it('creates a lines array property with the content of the collapsible section', () => { + expect(result.parsedLines[1].lines.length).toEqual(2); + expect(result.parsedLines[1].lines[0].content).toEqual(utilsMockData[2].content); + expect(result.parsedLines[1].lines[1].content).toEqual(utilsMockData[3].content); + }); + }); + + describe('section duration', () => { + it('adds the section information to the header section', () => { + expect(result.parsedLines[1].line.section_duration).toEqual( + utilsMockData[4].section_duration, + ); + }); + + it('does not add section duration as a line', () => { + expect(result.parsedLines[1].lines.includes(utilsMockData[4])).toEqual(false); + }); + }); + + describe('multiple collapsible sections', () => { + beforeEach(() => { + result = logLinesParser(multipleCollapsibleSectionsMockData); + }); + + it('should contain a section inside another section', () => { + const innerSection = [ + { + isClosed: false, + isHeader: true, + line: { + content: [{ text: '1st collapsible section' }], + lineNumber: 6, + offset: 1006, + section: 'collapsible-1', + section_duration: '01:00', + section_header: true, + }, + lines: [ + { + content: [ + { + text: + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam lorem dolor, congue ac condimentum vitae', + }, + ], + lineNumber: 7, + offset: 1007, + section: 'collapsible-1', + }, + ], + }, + ]; + + expect(result.parsedLines[1].lines).toEqual(expect.arrayContaining(innerSection)); + }); + }); + }); + describe('findOffsetAndRemove', () => { describe('when last item is header', () => { const existingLog = [ @@ -391,7 +474,7 @@ describe('Jobs Store Utils', () => { describe('updateIncrementalTrace', () => { describe('without repeated section', () => { it('concats and parses both arrays', () => { - const oldLog = logLinesParser(originalTrace); + const oldLog = logLinesParserLegacy(originalTrace); const result = updateIncrementalTrace(regularIncremental, oldLog); expect(result).toEqual([ @@ -419,7 +502,7 @@ describe('Jobs Store Utils', () => { describe('with regular line repeated offset', () => { it('updates the last line and formats with the incremental part', () => { - const oldLog = logLinesParser(originalTrace); + const oldLog = logLinesParserLegacy(originalTrace); const result = updateIncrementalTrace(regularIncrementalRepeated, oldLog); expect(result).toEqual([ @@ -438,7 +521,7 @@ describe('Jobs Store Utils', () => { describe('with header line repeated', () => { it('updates the header line and formats with the incremental part', () => { - const oldLog = logLinesParser(headerTrace); + const oldLog = logLinesParserLegacy(headerTrace); const result = updateIncrementalTrace(headerTraceIncremental, oldLog); expect(result).toEqual([ @@ -464,7 +547,7 @@ describe('Jobs Store Utils', () => { describe('with collapsible line repeated', () => { it('updates the collapsible line and formats with the incremental part', () => { - const oldLog = logLinesParser(collapsibleTrace); + const oldLog = logLinesParserLegacy(collapsibleTrace); const result = updateIncrementalTrace(collapsibleTraceIncremental, oldLog); expect(result).toEqual([ |