// issue with secondary locations but no flows
const issue = mockIssue(true, {
flows: [],
- textRange: { startLine: 5, endLine: 5, startOffset: 5, endOffset: 10 }
+ textRange: { startLine: 7, endLine: 7, startOffset: 5, endOffset: 10 }
});
const snippetGroup: T.SnippetGroup = {
textRange: { startLine: 54, endLine: 54, startOffset: 0, endOffset: 0 }
})
],
- ...mockSnippetsByComponent('a', [...range(3, 15), 32, 33, 34, 35, 36, 52, 53, 54, 55, 56])
+ ...mockSnippetsByComponent('a', [...range(2, 17), ...range(29, 39), ...range(49, 59)])
};
const wrapper = shallowRender({ issue, snippetGroup });
expect(wrapper.state('snippets')).toHaveLength(3);
- expect(wrapper.state('snippets')[0]).toEqual({ index: 0, start: 3, end: 14 });
- expect(wrapper.state('snippets')[1]).toEqual({ index: 1, start: 32, end: 36 });
- expect(wrapper.state('snippets')[2]).toEqual({ index: 2, start: 52, end: 56 });
+ expect(wrapper.state('snippets')[0]).toEqual({ index: 0, start: 2, end: 16 });
+ expect(wrapper.state('snippets')[1]).toEqual({ index: 1, start: 29, end: 39 });
+ expect(wrapper.state('snippets')[2]).toEqual({ index: 2, start: 49, end: 59 });
});
it('should expand block', async () => {
(getSources as jest.Mock).mockResolvedValueOnce(
- Object.values(mockSnippetsByComponent('a', [22, 23, 24, 25, 26, 27, 28, 29, 30, 31]).sources)
+ Object.values(mockSnippetsByComponent('a', range(6, 59)).sources)
);
+ const issue = mockIssue(true, {
+ textRange: { startLine: 64, endLine: 64, startOffset: 5, endOffset: 10 }
+ });
const snippetGroup: T.SnippetGroup = {
locations: [
mockFlowLocation({
component: 'a',
- textRange: { startLine: 34, endLine: 34, startOffset: 0, endOffset: 0 }
+ textRange: { startLine: 64, endLine: 64, startOffset: 0, endOffset: 0 }
}),
mockFlowLocation({
component: 'a',
- textRange: { startLine: 54, endLine: 54, startOffset: 0, endOffset: 0 }
+ textRange: { startLine: 87, endLine: 87, startOffset: 0, endOffset: 0 }
})
],
- ...mockSnippetsByComponent('a', [32, 33, 34, 35, 36, 52, 53, 54, 55, 56])
+ ...mockSnippetsByComponent('a', [...range(59, 73), ...range(82, 92)])
};
- const wrapper = shallowRender({ snippetGroup });
+ const wrapper = shallowRender({ issue, snippetGroup });
wrapper.instance().expandBlock(0, 'up');
await waitAndUpdate(wrapper);
- expect(getSources).toHaveBeenCalledWith({ from: 19, key: 'a', to: 31 });
+ expect(getSources).toHaveBeenCalledWith({ from: 6, key: 'a', to: 58 });
expect(wrapper.state('snippets')).toHaveLength(2);
- expect(wrapper.state('snippets')[0]).toEqual({ index: 0, start: 22, end: 36 });
- expect(Object.keys(wrapper.state('additionalLines'))).toHaveLength(10);
+ expect(wrapper.state('snippets')[0]).toEqual({ index: 0, start: 9, end: 73 });
+ expect(Object.keys(wrapper.state('additionalLines'))).toHaveLength(53);
});
it('should expand full component', async () => {
);
const snippetGroup: T.SnippetGroup = {
locations: [mockFlowLocation()],
- ...mockSnippetsByComponent('a', [1, 2, 3, 4])
+ ...mockSnippetsByComponent('a', [1, 2, 3, 4, 5, 6, 7])
};
const wrapper = shallowRender({
wrapper.instance().expandBlock(0, 'down');
await waitAndUpdate(wrapper);
- expect(getSources).toHaveBeenCalledWith({ branch: 'asdf', from: 5, key: 'a', to: 17 });
+ expect(getSources).toHaveBeenCalledWith({ branch: 'asdf', from: 8, key: 'a', to: 60 });
});
it('should handle correctly open/close issue', () => {
});
expect(results).toHaveLength(1);
- expect(results[0]).toEqual({ index: 0, start: 14, end: 28 });
+ expect(results[0]).toEqual({ index: 0, start: 11, end: 28 });
});
it('should merge snippets correctly, even when not in sequence', () => {
});
expect(results).toHaveLength(2);
- expect(results[0]).toEqual({ index: 0, start: 12, end: 23 });
- expect(results[1]).toEqual({ index: 1, start: 45, end: 49 });
+ expect(results[0]).toEqual({ index: 0, start: 9, end: 23 });
+ expect(results[1]).toEqual({ index: 1, start: 42, end: 52 });
});
it('should merge three snippets together', () => {
});
expect(results).toHaveLength(2);
- expect(results[0]).toEqual({ index: 0, start: 14, end: 25 });
- expect(results[1]).toEqual({ index: 1, start: 45, end: 49 });
+ expect(results[0]).toEqual({ index: 0, start: 11, end: 28 });
+ expect(results[1]).toEqual({ index: 1, start: 42, end: 52 });
});
it("should prepend the issue's main location if necessary", () => {
const locations = [
mockFlowLocation({
- textRange: { startLine: 47, startOffset: 2, endLine: 47, endOffset: 3 }
+ textRange: { startLine: 65, startOffset: 2, endLine: 65, endOffset: 3 }
}),
mockFlowLocation({
- textRange: { startLine: 22, startOffset: 2, endLine: 22, endOffset: 3 }
+ textRange: { startLine: 32, startOffset: 2, endLine: 32, endOffset: 3 }
})
];
const results = createSnippets({
locations,
issue: mockIssue(false, {
- textRange: { startLine: 5, endLine: 5, startOffset: 0, endOffset: 0 }
+ textRange: { startLine: 12, endLine: 12, startOffset: 0, endOffset: 0 }
}),
addIssueLocation: true
});
expect(results).toHaveLength(3);
- expect(results[0]).toEqual({ index: 0, start: 3, end: 14 });
- });
-
- it('should handle last component', () => {
- const locations = [
- mockFlowLocation({
- textRange: { startLine: 16, startOffset: 10, endLine: 16, endOffset: 14 }
- }),
- mockFlowLocation({
- textRange: { startLine: 19, startOffset: 2, endLine: 19, endOffset: 3 }
- })
- ];
- const results = createSnippets({
- locations,
- issue: mockIssue(false, locations[1]),
- addIssueLocation: false
- });
-
- expect(results).toHaveLength(1);
- expect(results[0]).toEqual({ index: 0, start: 14, end: 28 });
+ expect(results[0]).toEqual({ index: 0, start: 7, end: 21 });
});
});
const result = expandSnippet({ direction: 'up', snippetIndex: 0, snippets });
expect(result).toHaveLength(1);
- expect(result[0]).toEqual({ start: 4, end: 18, index: 0 });
+ expect(result[0]).toEqual({ start: 0, end: 18, index: 0 });
});
it('should add lines below', () => {
const result = expandSnippet({ direction: 'down', snippetIndex: 0, snippets });
expect(result).toHaveLength(1);
- expect(result[0]).toEqual({ start: 4, end: 18, index: 0 });
+ expect(result[0]).toEqual({ start: 4, end: 58, index: 0 });
});
it('should merge snippets if necessary', () => {
const snippets = [
- { index: 1, start: 4, end: 8 },
- { index: 2, start: 38, end: 42 },
- { index: 3, start: 17, end: 21 }
+ { index: 1, start: 4, end: 14 },
+ { index: 2, start: 72, end: 82 },
+ { index: 3, start: 37, end: 47 }
];
const result = expandSnippet({ direction: 'down', snippetIndex: 1, snippets });
expect(result).toHaveLength(3);
- expect(result[0]).toEqual({ index: 1, start: 4, end: 21 });
- expect(result[1]).toEqual({ index: 2, start: 38, end: 42 });
- expect(result[2]).toEqual({ index: 3, start: 17, end: 21, toDelete: true });
+ expect(result[0]).toEqual({ index: 1, start: 4, end: 64 });
+ expect(result[1]).toEqual({ index: 2, start: 72, end: 82 });
+ expect(result[2]).toEqual({ index: 3, start: 37, end: 47, toDelete: true });
});
});