diff options
author | Pascal Mugnier <pascal.mugnier@sonarsource.com> | 2018-03-08 08:01:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-08 08:01:17 +0100 |
commit | 89562bc1246dd24f82e624ed6a319e5f42169980 (patch) | |
tree | 785172b6f95591a37a430085a1a040fb08c0f6d5 /server/sonar-web/src/main | |
parent | 8b35325a410dd5b38ac2ee79ea1d1441d34e6de2 (diff) | |
download | sonarqube-89562bc1246dd24f82e624ed6a319e5f42169980.tar.gz sonarqube-89562bc1246dd24f82e624ed6a319e5f42169980.zip |
SONAR-10397 Fix inconsistent list of files in "Code" tab with +100 files (#3129)
Diffstat (limited to 'server/sonar-web/src/main')
-rw-r--r-- | server/sonar-web/src/main/js/apps/code/bucket.ts | 4 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/code/components/__tests__/buckets-test.tsx | 64 |
2 files changed, 68 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/apps/code/bucket.ts b/server/sonar-web/src/main/js/apps/code/bucket.ts index 8fc8bce8e65..dd172ca8eef 100644 --- a/server/sonar-web/src/main/js/apps/code/bucket.ts +++ b/server/sonar-web/src/main/js/apps/code/bucket.ts @@ -43,6 +43,10 @@ export function addComponentChildren( total: number, page: number ): void { + const previous = getComponentChildren(componentKey); + if (previous) { + children = [...previous.children, ...children]; + } childrenBucket[componentKey] = { children, total, page }; } diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/buckets-test.tsx b/server/sonar-web/src/main/js/apps/code/components/__tests__/buckets-test.tsx new file mode 100644 index 00000000000..9ccf00c799d --- /dev/null +++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/buckets-test.tsx @@ -0,0 +1,64 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import { Component } from '../../types'; +import { + addComponent, + getComponent, + addComponentChildren, + getComponentChildren +} from '../../bucket'; + +const component: Component = { key: 'frodo', name: 'frodo', qualifier: 'frodo' }; + +const componentKey: string = 'foo'; +const childrenA: Component[] = [ + { key: 'foo', name: 'foo', qualifier: 'foo' }, + { key: 'bar', name: 'bar', qualifier: 'bar' } +]; +const childrenB: Component[] = [ + { key: 'bart', name: 'bart', qualifier: 'bart' }, + { key: 'simpson', name: 'simpson', qualifier: 'simpson' } +]; + +it('should have empty bucket at start', () => { + expect(getComponent(component.key)).toBeUndefined(); +}); + +it('should be able to store components in a bucket', () => { + addComponent(component); + expect(getComponent(component.key)).toEqual(component); +}); + +it('should have empty children bucket at start', () => { + expect(getComponentChildren(componentKey)).toBeUndefined(); +}); + +it('should be able to store children components in a bucket', () => { + addComponentChildren(componentKey, childrenA, childrenA.length, 1); + expect(getComponentChildren(componentKey).children).toEqual(childrenA); +}); + +it('should append new children components at the end of the bucket', () => { + addComponentChildren(componentKey, childrenB, 4, 2); + const finalBucket = getComponentChildren(componentKey); + expect(finalBucket.children).toEqual([...childrenA, ...childrenB]); + expect(finalBucket.total).toBe(4); + expect(finalBucket.page).toBe(2); +}); |