From: Jeremy Davis Date: Fri, 1 Nov 2019 11:08:19 +0000 (+0900) Subject: SONAR-12599 Increase snippet expand step X-Git-Tag: 8.1.0.31237~103 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fbcd0ca6d13677c26d38572e05f1518aa1d54f4f;p=sonarqube.git SONAR-12599 Increase snippet expand step --- diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx index 0f5f5ecbaf3..a06177b9618 100644 --- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx @@ -49,7 +49,7 @@ it('should render correctly with secondary locations', () => { // 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 = { @@ -63,42 +63,45 @@ it('should render correctly with secondary locations', () => { 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 () => { @@ -137,7 +140,7 @@ it('should get the right branch when expanding', 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({ @@ -148,7 +151,7 @@ it('should get the right branch when expanding', async () => { 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', () => { diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/utils-test.ts b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/utils-test.ts index 1492af96501..d76fdcdb501 100644 --- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/utils-test.ts +++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/utils-test.ts @@ -97,7 +97,7 @@ describe('createSnippets', () => { }); 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', () => { @@ -119,8 +119,8 @@ describe('createSnippets', () => { }); 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', () => { @@ -145,48 +145,29 @@ describe('createSnippets', () => { }); 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 }); }); }); @@ -197,7 +178,7 @@ describe('expandSnippet', () => { 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', () => { @@ -206,21 +187,21 @@ describe('expandSnippet', () => { 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 }); }); }); diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/utils.ts b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/utils.ts index 1d2843da6ba..f46b71e77a8 100644 --- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/utils.ts +++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/utils.ts @@ -21,7 +21,7 @@ const LINES_ABOVE = 5; const LINES_BELOW = 5; export const MERGE_DISTANCE = 4; // Merge if snippets are four lines away (separated by 3 lines) or fewer export const LINES_BELOW_ISSUE = 9; -export const EXPAND_BY_LINES = 10; +export const EXPAND_BY_LINES = 50; function unknownComponent(key: string): T.SnippetsByComponent { return {