Skip to content

Commit

Permalink
Merge ef4efdf into 8ea8fa7
Browse files Browse the repository at this point in the history
  • Loading branch information
aarranz committed Mar 22, 2020
2 parents 8ea8fa7 + ef4efdf commit a28699d
Show file tree
Hide file tree
Showing 19 changed files with 464 additions and 145 deletions.
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
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
109 changes: 89 additions & 20 deletions src/js_tests/wirecloud/ui/SharingWindowMenuSpec.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 All @@ -22,15 +22,15 @@
/* globals StyledElements, Wirecloud */


(function () {
(function (utils) {

"use strict";

describe("Wirecloud.ui.SharingWindowMenu", () => {

beforeAll(() => {
// TODO
Wirecloud.ui.UserTypeahead = jasmine.createSpy("UserTypeahead").and.callFake(function () {
Wirecloud.ui.UserGroupTypeahead = jasmine.createSpy("UserGroupTypeahead").and.callFake(function () {
this.bind = jasmine.createSpy("bind");
this.addEventListener = jasmine.createSpy("addEventListener");
});
Expand Down Expand Up @@ -60,6 +60,7 @@
it("load sharing configuration from workspaces (public)", () => {
let workspace = {
model: {
groups: [],
users: [
{
username: "currentuser",
Expand Down Expand Up @@ -89,12 +90,18 @@
let dialog = new Wirecloud.ui.SharingWindowMenu(workspace);

expect(dialog.visibilityOptions.getValue()).toBe("public");
expect(Object.keys(dialog.sharingUsers).length).toBe(3);
expect(dialog.sharelist.length).toBe(3);
});

it("load sharing configuration from workspaces (public-auth)", () => {
let workspace = {
model: {
groups: [
{
name: "group",
accesslevel: "read"
}
],
users: [
{
username: "currentuser",
Expand All @@ -117,7 +124,7 @@
let dialog = new Wirecloud.ui.SharingWindowMenu(workspace);

expect(dialog.visibilityOptions.getValue()).toBe("public-auth");
expect(Object.keys(dialog.sharingUsers).length).toBe(2);
expect(dialog.sharelist.length).toBe(3);
});

});
Expand All @@ -129,9 +136,16 @@
beforeEach(() => {
let workspace = {
model: {
groups: [
{
name: "currentgroup",
accesslevel: "owner"
}
],
users: [
{
username: "currentuser",
fullname: "Current User",
organization: false,
accesslevel: "owner"
}
Expand All @@ -148,37 +162,63 @@
it("should add new users", () => {
callEventListener(dialog.inputSearchTypeahead, "select", {
context: {
username: "otheruser",
organization: false,
name: "otheruser",
type: "user",
accesslevel: "read"
}
});
expect(Object.keys(dialog.sharingUsers).length).toBe(2);
expect(dialog.sharelist.length).toBe(3);
});

it("should add new organizations", () => {
callEventListener(dialog.inputSearchTypeahead, "select", {
context: {
username: "org",
organization: true,
name: "org",
type: "organization",
accesslevel: "read"
}
});
expect(dialog.sharelist.length).toBe(3);
});

it("should add new groups", () => {
callEventListener(dialog.inputSearchTypeahead, "select", {
context: {
name: "onegroup",
type: "group",
accesslevel: "read"
}
});
expect(Object.keys(dialog.sharingUsers).length).toBe(2);
expect(dialog.sharelist.length).toBe(3);
});

it("should ignore already present users", () => {
let initialSharingUsers = dialog.sharingUsers;
let initialShareList = utils.clone(dialog.sharelist);

callEventListener(dialog.inputSearchTypeahead, "select", {
context: {
name: "currentuser",
fullname: "Updated fullname",
type: "user",
accesslevel: "read"
}
});

expect(dialog.sharelist).toEqual(initialShareList);
});

it("should ignore already present groups", () => {
let initialShareList = utils.clone(dialog.sharelist);

callEventListener(dialog.inputSearchTypeahead, "select", {
context: {
username: "currentuser",
organization: true,
name: "currentgroup",
type: "group",
accesslevel: "read"
}
});

expect(dialog.sharingUsers).toEqual(initialSharingUsers);
expect(dialog.sharelist).toEqual(initialShareList);
});

it("should be possible to remove added users", () => {
Expand All @@ -190,16 +230,37 @@

callEventListener(dialog.inputSearchTypeahead, "select", {
context: {
username: "otheruser",
organization: false,
name: "otheruser",
type: "user",
accesslevel: "read"
}
});
expect(dialog.sharelist.length).toBe(3);

callEventListener(button, "click");

expect(dialog.sharelist.length).toBe(2);
});

it("should be possible to remove added groups", () => {
var button;
spyOn(StyledElements, "Button").and.callFake(function () {
button = this;
this.addEventListener = jasmine.createSpy("addEventListener");
});

callEventListener(dialog.inputSearchTypeahead, "select", {
context: {
name: "otheruser",
type: "group",
accesslevel: "read"
}
});
expect(Object.keys(dialog.sharingUsers).length).toBe(2);
expect(dialog.sharelist.length).toBe(3);

callEventListener(button, "click");

expect(Object.keys(dialog.sharingUsers).length).toBe(1);
expect(dialog.sharelist.length).toBe(2);
});

});
Expand All @@ -211,9 +272,16 @@
beforeEach(() => {
workspace = {
model: {
groups: [
{
name: "group",
accesslevel: "read"
}
],
users: [
{
username: "currentuser",
type: "user",
organization: false,
accesslevel: "owner"
}
Expand All @@ -237,6 +305,7 @@
expect(dialog.btnCancel.enabled).toBe(false);

setTimeout(() => {
expect(workspace.model.preferences.set).toHaveBeenCalled();
expect(dialog._closeListener).toHaveBeenCalledWith();
done();
});
Expand Down Expand Up @@ -272,4 +341,4 @@
});
};

})();
})(StyledElements.Utils);
4 changes: 2 additions & 2 deletions src/js_tests/wirecloud/ui/WorkspaceTabViewSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2019 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 @@ -484,7 +484,7 @@
});

it("should handle changes to the baselayout preference", () => {
callEventListener(model.preferences, "pre-commit", {"baselayout": 5});
callEventListener(model.preferences, "post-commit", {"baselayout": 5});

expect(tab.dragboard._updateBaseLayout).toHaveBeenCalledWith();
});
Expand Down

0 comments on commit a28699d

Please sign in to comment.