Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to share dashboards with groups #478

Merged
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
- id: flake8
- repo: local
hooks:
- id: eslint
name: eslint
entry: eslint -c src/.eslintrc
language: node
'types': [javascript]
files: 'src/wirecloud/(commons|platform)/static/js/.*'
21 changes: 19 additions & 2 deletions src/js_tests/styledelements/PopupMenuBaseSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Future Internet Consulting and Development Solutions S.L.
* Copyright (c) 2019-2020 Future Internet Consulting and Development Solutions S.L.
*
* This file is part of Wirecloud Platform.
*
Expand Down Expand Up @@ -46,7 +46,7 @@

});

describe("append()", () => {
describe("append(child)", () => {

var menu;

Expand Down Expand Up @@ -110,6 +110,23 @@
expect(menu.lastEnabledItem).toBe(item);
});

it("should work when adding a disabled item while oneActiveAtLeast option is used", () => {
var listener = jasmine.createSpy("listener");
menu = new se.PopupMenuBase({oneActiveAtLeast: true});
var ref_element = new se.Button();
menu.show(ref_element);
menu.addEventListener("itemOver", listener);
var item = new se.MenuItem("Entry");
item.enabled = false;

expect(menu.append(item)).toBe(menu);

expect(listener).not.toHaveBeenCalled();
expect(menu.activeItem).toBe(null);
expect(menu.firstEnabledItem).toBe(null);
expect(menu.lastEnabledItem).toBe(null);
});

it("should add dynamic generated items", () => {
var listener = jasmine.createSpy("listener");
menu = new se.PopupMenuBase({oneActiveAtLeast: true});
Expand Down
45 changes: 43 additions & 2 deletions src/js_tests/styledelements/UtilsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/* globals StyledElements */


(function () {
(function (utils) {

"use strict";

Expand Down Expand Up @@ -429,6 +429,47 @@

});

describe("removeFromArray(arr, element)", () => {

it("should remove basic primitives from an array", () => {
let arr = [1, 2, 3];

utils.removeFromArray(arr, 2);

expect(arr).toEqual([1, 3]);
});

it("should remove only first element", () => {
let arr = [1, 2, 3, 2];

utils.removeFromArray(arr, 2);

expect(arr).toEqual([1, 3, 2]);
});

it("should work if element is not found", () => {
let arr = [1, 2, 3];

utils.removeFromArray(arr, 4);

expect(arr).toEqual([1, 2, 3]);
});

});

describe("setupdate(setA, setB)", () => {

it("should add all elements from setB into setA", () => {
let setA = new Set([1, 2, 3]);
let setB = new Set([5, 6, 7]);

expect(utils.setupdate(setA, setB)).toBe(setA);

expect(setA).toEqual(new Set([1, 2, 3, 5, 6, 7]));
});

});

describe("timeoutPromise(promise, ms, fallback)", () => {

beforeEach(() => {
Expand Down Expand Up @@ -631,4 +672,4 @@

});

})();
})(StyledElements.Utils);
58 changes: 49 additions & 9 deletions src/js_tests/wirecloud/PreferencesSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 Future Internet Consulting and Development Solutions S.L.
* Copyright (c) 2018-2020 Future Internet Consulting and Development Solutions S.L.
*
* This file is part of Wirecloud Platform.
*
Expand Down Expand Up @@ -197,10 +197,9 @@
() => {
expect(listener1).not.toHaveBeenCalled();
expect(listener2).not.toHaveBeenCalled();
done();
},
fail
);
).finally(done);
});

it("should update preferences on the server", (done) => {
Expand Down Expand Up @@ -234,12 +233,53 @@

t.then(
() => {
expect(listener1).toHaveBeenCalledWith(preferences, {"onepref": 20});
expect(listener2).toHaveBeenCalledWith(preferences, {"onepref": {"value": "20"}, "anotherpref": {"inherit": true}});
done();
expect(listener1).toHaveBeenCalledWith(preferences, {"onepref": {"value": "20"}, "anotherpref": {"inherit": true}});
expect(listener2).toHaveBeenCalledWith(preferences, {"onepref": 20});
},
fail
);
).finally(done);
});

describe("should handle errors from server", () => {
const test = function test(statuscode) {
it("(" + statuscode + ")", (done) => {
spyOn(Wirecloud.io, "makeRequest").and.callFake(function (url, options) {
return new Wirecloud.Task("Sending request", (resolve) => {resolve({status: statuscode});});
});
let listener1 = jasmine.createSpy("listener1");
preferences.addEventListener("pre-commit", listener1);
let listener2 = jasmine.createSpy("listener2");
preferences.addEventListener("post-commit", listener2);
preferences.preferences.onepref.value = 5;
preferences.preferences.onepref.getEffectiveValue.and.returnValues(5, 20);
Wirecloud.ui.InputInterfaceFactory.stringify.and.returnValue("20");

let t = preferences.set({
"onepref": {
"value": 20
}
});

t.then(
fail,
() => {
expect(listener1).toHaveBeenCalled();
expect(listener2).not.toHaveBeenCalled();
}
).finally(done);
});
};

// Error codes that are used by the API
test(401);
test(403);
test(422);
test(500);

// Other error codes
test(200);
test(404);
test(409);
});

});
Expand Down Expand Up @@ -313,8 +353,8 @@

preferences._handleParentChanges("notused", {"onepref": 25, "mypref": "newtext"});

expect(listener1).toHaveBeenCalledWith(preferences, {"mypref": "newtext"});
expect(listener2).not.toHaveBeenCalled();
expect(listener1).not.toHaveBeenCalled();
expect(listener2).toHaveBeenCalledWith(preferences, {"mypref": "newtext"});
});

});
Expand Down
Loading