aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorPascal Mugnier <pascal.mugnier@sonarsource.com>2018-03-07 14:26:27 +0100
committerPascal Mugnier <pascal.mugnier@sonarsource.com>2018-03-07 14:26:27 +0100
commitd39405a06b3ec3af82ec70ff71170a578ffbe284 (patch)
treef3cff10b6b42236f7089b241c4c528231d7af718 /server
parentbfbc7ac7338abda5703fa1fcab9b8a06bf020cc1 (diff)
downloadsonarqube-d39405a06b3ec3af82ec70ff71170a578ffbe284.tar.gz
sonarqube-d39405a06b3ec3af82ec70ff71170a578ffbe284.zip
SONAR-10397 Test for buckets
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/src/main/js/apps/code/bucket.ts2
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/__tests__/buckets-test.tsx65
-rw-r--r--server/sonar-web/src/main/js/components/workspace/models/items.js5
-rw-r--r--server/sonar-web/src/main/js/helpers/storage.ts10
4 files changed, 79 insertions, 3 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 503b56e30e8..7431dc36efa 100644
--- a/server/sonar-web/src/main/js/apps/code/bucket.ts
+++ b/server/sonar-web/src/main/js/apps/code/bucket.ts
@@ -46,7 +46,7 @@ export function addComponentChildren(
): void {
const previous = getComponentChildren(componentKey);
if (previous) {
- children = concat(children, previous.children);
+ children = concat(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..49334c29a77
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/buckets-test.tsx
@@ -0,0 +1,65 @@
+/*
+ * 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 { concat } from 'lodash';
+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(concat(childrenA, childrenB));
+ expect(finalBucket.total).toBe(4);
+ expect(finalBucket.page).toBe(2);
+});
diff --git a/server/sonar-web/src/main/js/components/workspace/models/items.js b/server/sonar-web/src/main/js/components/workspace/models/items.js
index c191ca98a90..0b1c4c3adf1 100644
--- a/server/sonar-web/src/main/js/components/workspace/models/items.js
+++ b/server/sonar-web/src/main/js/components/workspace/models/items.js
@@ -19,6 +19,7 @@
*/
import Backbone from 'backbone';
import Item from './item';
+import { saveWorkspace, getWorkspace } from '../../../helpers/storage';
const STORAGE_KEY = 'sonarqube-workspace';
@@ -31,11 +32,11 @@ export default Backbone.Collection.extend({
save() {
const dump = JSON.stringify(this.toJSON());
- window.localStorage.setItem(STORAGE_KEY, dump);
+ saveWorkspace(dump);
},
load() {
- const dump = window.localStorage.getItem(STORAGE_KEY);
+ const dump = getWorkspace(STORAGE_KEY);
if (dump != null) {
try {
const parsed = JSON.parse(dump);
diff --git a/server/sonar-web/src/main/js/helpers/storage.ts b/server/sonar-web/src/main/js/helpers/storage.ts
index fc54899c8b4..37533dbdfaa 100644
--- a/server/sonar-web/src/main/js/helpers/storage.ts
+++ b/server/sonar-web/src/main/js/helpers/storage.ts
@@ -28,6 +28,8 @@ const PROJECTS_SORT = 'sonarqube.projects.sort';
const PROJECT_ACTIVITY_GRAPH = 'sonarqube.project_activity.graph';
const PROJECT_ACTIVITY_GRAPH_CUSTOM = 'sonarqube.project_activity.graph.custom';
+const WORKSPACE = 'sonarqube-workspace';
+
function save(key: string, value?: string): void {
try {
if (value) {
@@ -41,6 +43,14 @@ function save(key: string, value?: string): void {
}
}
+export function saveWorkspace(dump: string): void {
+ window.localStorage.setItem(WORKSPACE, dump);
+}
+
+export function getWorkspace(): string | null {
+ return window.localStorage.getItem(WORKSPACE);
+}
+
export function saveFavorite(): void {
save(PROJECTS_DEFAULT_FILTER, PROJECTS_FAVORITE);
}