const issue = {
comments: [
{
- createdAt: '2017-04-11T10:38:09+0200',
+ createdAt: '2017-04-11T10:38:090200',
htmlText: 'comment!',
key: 'AVtcKbZkQmGLa7yW8J71',
login: 'admin',
authorAvatar: 'c1244e6857f7be3dc4549d9e9d51c631',
authorLogin: 'admin',
authorName: 'Admin Admin',
- createdAt: '2017-04-11T10:38:09+0200',
+ createdAt: '2017-04-11T10:38:090200',
htmlText: 'comment!',
key: 'AVtcKbZkQmGLa7yW8J71',
login: undefined,
}
]);
});
+
+it('orders secondary locations', () => {
+ const issue = {
+ flows: [
+ { locations: [{ textRange: { startLine: 68, startOffset: 5, endLine: 68, endOffset: 7 } }] },
+ { locations: [{ textRange: { startLine: 43, startOffset: 8, endLine: 43, endOffset: 12 } }] },
+ { locations: [{ textRange: { startLine: 43, startOffset: 6, endLine: 43, endOffset: 8 } }] },
+ { locations: [{ textRange: { startLine: 70, startOffset: 12, endLine: 70, endOffset: 16 } }] }
+ ]
+ } as any;
+ expect(parseIssueFromResponse(issue).secondaryLocations).toEqual([
+ { textRange: { startLine: 43, startOffset: 6, endLine: 43, endOffset: 8 } },
+ { textRange: { startLine: 43, startOffset: 8, endLine: 43, endOffset: 12 } },
+ { textRange: { startLine: 68, startOffset: 5, endLine: 68, endOffset: 7 } },
+ { textRange: { startLine: 70, startOffset: 12, endLine: 70, endOffset: 16 } }
+ ]);
+});
function splitFlows(
issue: RawIssue
-): { secondaryLocations: Array<FlowLocation>; flows: Array<Array<FlowLocation>> } {
+): { secondaryLocations: FlowLocation[]; flows: FlowLocation[][] } {
const parsedFlows = (issue.flows || [])
.filter(flow => flow.locations != null)
.map(flow => flow.locations!.filter(location => location.textRange != null));
const onlySecondaryLocations = parsedFlows.every(flow => flow.length === 1);
return onlySecondaryLocations
- ? { secondaryLocations: flatten(parsedFlows), flows: [] }
+ ? { secondaryLocations: orderLocations(flatten(parsedFlows)), flows: [] }
: { secondaryLocations: [], flows: parsedFlows.map(reverseLocations) };
}
+function orderLocations(locations: FlowLocation[]) {
+ return sortBy(
+ locations,
+ location => location.textRange && location.textRange.startLine,
+ location => location.textRange && location.textRange.startOffset
+ );
+}
+
export function parseIssueFromResponse(
issue: RawIssue,
components?: Component[],