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
77b559fd
Commit
77b559fd
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
c0a42580
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
34 deletions
+64
-34
app/assets/javascripts/jobs/store/utils.js
app/assets/javascripts/jobs/store/utils.js
+4
-6
spec/frontend/jobs/store/utils_spec.js
spec/frontend/jobs/store/utils_spec.js
+60
-28
No files found.
app/assets/javascripts/jobs/store/utils.js
View file @
77b559fd
...
...
@@ -58,12 +58,12 @@ export const logLinesParser = (lines = [], lineNumberStart) =>
/**
* 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.
* Returns a new
array
with the updated log without
* the repeated offset
*
* @param Array newLog
* @param Array oldParsed
* @returns
Object
* @returns
Array
*
*/
export
const
findOffsetAndRemove
=
(
newLog
,
oldParsed
)
=>
{
...
...
@@ -72,19 +72,17 @@ export const findOffsetAndRemove = (newLog, oldParsed) => {
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
;
};
...
...
spec/frontend/jobs/store/utils_spec.js
View file @
77b559fd
...
...
@@ -86,30 +86,56 @@ 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
existingLog
=
[
{
isHeader
:
true
,
isClosed
:
true
,
line
:
{
content
:
[{
text
:
'
bar
'
}],
offset
:
10
,
lineNumber
:
1
},
},
];
describe
(
'
and matches the offset
'
,
()
=>
{
it
(
'
returns an array with the item removed
'
,
()
=>
{
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
(
'
and does not match the offset
'
,
()
=>
{
it
(
'
returns the provided existing log
'
,
()
=>
{
const
newData
=
[{
offset
:
110
,
content
:
[{
text
:
'
foobar
'
}]
}];
const
result
=
findOffsetAndRemove
(
newData
,
existingLog
);
expect
(
result
).
toEqual
(
existingLog
);
});
});
});
describe
(
'
when last item is a regular line
'
,
()
=>
{
const
existingLog
=
[{
content
:
[{
text
:
'
bar
'
}],
offset
:
10
,
lineNumber
:
1
}];
describe
(
'
and matches the offset
'
,
()
=>
{
it
(
'
returns an
object with the item removed and the lastLine
'
,
()
=>
{
it
(
'
returns an
array with the item removed
'
,
()
=>
{
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 of
fset
'
,
()
=>
{
it
(
'
returns an object with the last nested line item removed and the lastLine
'
,
()
=>
{
describe
(
'
and does not match the fo
fset
'
,
()
=>
{
it
(
'
returns the provided old log
'
,
()
=>
{
const
newData
=
[{
offset
:
101
,
content
:
[{
text
:
'
foobar
'
}]
}];
const
result
=
findOffsetAndRemove
(
newData
,
existingLog
);
expect
(
result
).
toEqual
(
existingLog
);
});
});
});
describe
(
'
when last item is nested
'
,
()
=>
{
const
existingLog
=
[
{
isHeader
:
true
,
...
...
@@ -122,20 +148,26 @@ describe('Jobs Store Utils', () => {
},
},
];
describe
(
'
and matches the offset
'
,
()
=>
{
it
(
'
returns an array with the last nested line item removed
'
,
()
=>
{
const
newData
=
[{
offset
:
101
,
content
:
[{
text
:
'
foobar
'
}]
}];
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
}
}];
describe
(
'
and
does not match the offset
'
,
()
=>
{
it
(
'
returns the provided old log
'
,
()
=>
{
const
newData
=
[{
offset
:
120
,
content
:
[{
text
:
'
foobar
'
}]
}];
const
result
=
findOffsetAndRemove
(
newData
,
existingLog
);
expect
(
result
).
toEqual
(
existingLog
);
});
});
});
});
describe
(
'
updateIncrementalTrace
'
,
()
=>
{
describe
(
'
without repeated section
'
,
()
=>
{
...
...
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