Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c0a42580
Commit
c0a42580
authored
Sep 24, 2019
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Creates findAndReplaceOffset funtion
Creates a function to find the last offset and remove it if repeated
parent
09020aea
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
0 deletions
+87
-0
app/assets/javascripts/jobs/store/utils.js
app/assets/javascripts/jobs/store/utils.js
+33
-0
spec/frontend/jobs/store/utils_spec.js
spec/frontend/jobs/store/utils_spec.js
+54
-0
No files found.
app/assets/javascripts/jobs/store/utils.js
View file @
c0a42580
...
...
@@ -55,6 +55,39 @@ export const logLinesParser = (lines = [], lineNumberStart) =>
return
acc
;
},
[]);
/**
* Finds the repeated offset, removes the old one
*
* Returns a new object with the updated log without
* the repeated offset and the last line number.
*
* @param Array newLog
* @param Array oldParsed
* @returns Object
*
*/
export
const
findOffsetAndRemove
=
(
newLog
,
oldParsed
)
=>
{
const
cloneOldLog
=
[...
oldParsed
];
const
lastIndex
=
cloneOldLog
.
length
-
1
;
const
last
=
cloneOldLog
[
lastIndex
];
const
firstNew
=
newLog
[
0
];
const
parsed
=
{};
if
(
last
.
offset
===
firstNew
.
offset
||
(
last
.
line
&&
last
.
line
.
offset
===
firstNew
.
offset
))
{
cloneOldLog
.
splice
(
lastIndex
);
parsed
.
lastLine
=
last
.
lineNumber
;
}
else
if
(
last
.
lines
&&
last
.
lines
.
length
)
{
const
lastNestedIndex
=
last
.
lines
.
length
-
1
;
const
lastNested
=
last
.
lines
[
lastNestedIndex
];
if
(
lastNested
.
offset
===
firstNew
.
offset
)
{
last
.
lines
.
splice
(
lastNestedIndex
);
parsed
.
lastLine
=
lastNested
.
lineNumber
;
}
}
return
cloneOldLog
;
};
/**
* When the trace is not complete, backend may send the last received line
* in the new response.
...
...
spec/frontend/jobs/store/utils_spec.js
View file @
c0a42580
...
...
@@ -3,6 +3,7 @@ import {
updateIncrementalTrace
,
parseHeaderLine
,
parseLine
,
findOffsetAndRemove
,
}
from
'
~/jobs/store/utils
'
;
import
{
utilsMockData
,
...
...
@@ -83,6 +84,59 @@ describe('Jobs Store Utils', () => {
});
});
describe
(
'
findOffsetAndRemove
'
,
()
=>
{
describe
(
'
when last item is header
'
,
()
=>
{
describe
(
'
when last item matches the offset
'
,
()
=>
{
it
(
'
returns an object with the item removed and the lastLine
'
,
()
=>
{
const
newData
=
[{
offset
:
10
,
content
:
[{
text
:
'
foobar
'
}]
}];
const
existingLog
=
[{
line
:
{
content
:
[{
text
:
'
bar
'
}],
offset
:
10
,
lineNumber
:
1
}
}];
const
result
=
findOffsetAndRemove
(
newData
,
existingLog
);
expect
(
result
).
toEqual
([]);
});
});
});
describe
(
'
when last item is a regular line
'
,
()
=>
{
describe
(
'
and matches the offset
'
,
()
=>
{
it
(
'
returns an object with the item removed and the lastLine
'
,
()
=>
{
const
newData
=
[{
offset
:
10
,
content
:
[{
text
:
'
foobar
'
}]
}];
const
existingLog
=
[{
content
:
[{
text
:
'
bar
'
}],
offset
:
10
,
lineNumber
:
1
}];
const
result
=
findOffsetAndRemove
(
newData
,
existingLog
);
expect
(
result
).
toEqual
([]);
});
});
});
describe
(
'
when last collaspible line item matches the offset
'
,
()
=>
{
it
(
'
returns an object with the last nested line item removed and the lastLine
'
,
()
=>
{
const
newData
=
[{
offset
:
101
,
content
:
[{
text
:
'
foobar
'
}]
}];
const
existingLog
=
[
{
isHeader
:
true
,
isClosed
:
true
,
lines
:
[{
offset
:
101
,
content
:
[{
text
:
'
foobar
'
}],
lineNumber
:
2
}],
line
:
{
offset
:
10
,
lineNumber
:
1
,
section_duration
:
'
10:00
'
,
},
},
];
const
result
=
findOffsetAndRemove
(
newData
,
existingLog
);
expect
(
result
[
0
].
lines
).
toEqual
([]);
});
});
describe
(
'
when it does not match the offset
'
,
()
=>
{
it
(
'
returns an object with the complete old log and the last line number
'
,
()
=>
{
const
newData
=
[{
offset
:
101
,
content
:
[{
text
:
'
foobar
'
}]
}];
const
existingLog
=
[{
line
:
{
content
:
[{
text
:
'
bar
'
}],
offset
:
10
,
lineNumber
:
1
}
}];
const
result
=
findOffsetAndRemove
(
newData
,
existingLog
);
expect
(
result
).
toEqual
(
existingLog
);
});
});
});
describe
(
'
updateIncrementalTrace
'
,
()
=>
{
describe
(
'
without repeated section
'
,
()
=>
{
it
(
'
concats and parses both arrays
'
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment