Commit 15d46b49 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '31162-utilities' into 'master'

Splits functions in store utility - part 1

See merge request gitlab-org/gitlab!17494
parents 64274626 75ed9964
......@@ -8,6 +8,21 @@ export const parseLine = (line = {}, lineNumber) => ({
lineNumber,
});
/**
* When a line has `section_header` set to true, we create a new
* structure to allow to nest the lines that belong to the
* collpasible section
*
* @param Object line
* @param Number lineNumber
*/
export const parseHeaderLine = (line = {}, lineNumber) => ({
isClosed: true,
isHeader: true,
line: parseLine(line, lineNumber),
lines: [],
});
/**
* Parses the job log content into a structure usable by the template
*
......@@ -28,12 +43,7 @@ export const logLinesParser = (lines = [], lineNumberStart) =>
const last = acc[acc.length - 1];
if (line.section_header) {
acc.push({
isClosed: true,
isHeader: true,
line: parseLine(line, lineNumber),
lines: [],
});
acc.push(parseHeaderLine(line, lineNumber));
} else if (acc.length && last.isHeader && !line.section_duration && line.content.length) {
last.lines.push(parseLine(line, lineNumber));
} else if (acc.length && last.isHeader && line.section_duration) {
......
import { logLinesParser, updateIncrementalTrace } from '~/jobs/store/utils';
import {
logLinesParser,
updateIncrementalTrace,
parseHeaderLine,
parseLine,
} from '~/jobs/store/utils';
import {
utilsMockData,
originalTrace,
......@@ -11,6 +16,32 @@ import {
} from '../components/log/mock_data';
describe('Jobs Store Utils', () => {
describe('parseHeaderLine', () => {
it('returns a new object with the header keys and the provided line parsed', () => {
const headerLine = { content: [{ text: 'foo' }] };
const parsedHeaderLine = parseHeaderLine(headerLine, 2);
expect(parsedHeaderLine).toEqual({
isClosed: true,
isHeader: true,
line: {
...headerLine,
lineNumber: 2,
},
lines: [],
});
});
});
describe('parseLine', () => {
it('returns a new object with the lineNumber key added to the provided line object', () => {
const line = { content: [{ text: 'foo' }] };
const parsed = parseLine(line, 1);
expect(parsed.content).toEqual(line.content);
expect(parsed.lineNumber).toEqual(1);
});
});
describe('logLinesParser', () => {
let result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment