Skip to content

Commit

Permalink
Merge 48bb022 into 8ea8fa7
Browse files Browse the repository at this point in the history
  • Loading branch information
aarranz committed Mar 21, 2020
2 parents 8ea8fa7 + 48bb022 commit 6bf3526
Show file tree
Hide file tree
Showing 36 changed files with 1,592 additions and 317 deletions.
2 changes: 2 additions & 0 deletions src/GruntFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ var WirecloudFiles = [
'wirecloud/platform/static/js/wirecloud/LogManager.js',
'wirecloud/commons/static/js/wirecloud/Task.js',
'wirecloud/commons/static/js/wirecloud/ui/Draggable.js',
'wirecloud/commons/static/js/wirecloud/ui/ResizeHandle.js',
'wirecloud/commons/static/js/wirecloud/ui/MACSearch.js',
'wirecloud/commons/static/js/wirecloud/ui/WindowMenu.js',
'wirecloud/commons/static/js/wirecloud/ui/AlertWindowMenu.js',
Expand All @@ -126,6 +127,7 @@ var WirecloudFiles = [
'wirecloud/platform/static/js/wirecloud/wiring/KeywordSuggestion.js',
'wirecloud/platform/static/js/wirecloud/wiring/Operator.js',
'wirecloud/platform/static/js/wirecloud/ui/WidgetViewDraggable.js',
'wirecloud/platform/static/js/wirecloud/ui/WidgetViewResizeHandle.js',
'wirecloud/platform/static/js/wirecloud/ui/WidgetView.js',
'wirecloud/platform/static/js/wirecloud/ui/WiringEditor.js',
'wirecloud/platform/static/js/wirecloud/ui/WiringEditor/Behaviour.js',
Expand Down
8 changes: 4 additions & 4 deletions src/js_tests/styledelements/PopupMenuBaseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
expect(menu.append(item)).toBe(menu);

expect(menu.activeItem).toBe(null);
expect(menu.firstEnabledItem).toBe(item.menuItem);
expect(menu.lastEnabledItem).toBe(item.menuItem);
expect(menu.firstEnabledItem).toBe(item.menuitem);
expect(menu.lastEnabledItem).toBe(item.menuitem);
});

it("should work on visible menus", () => {
Expand Down Expand Up @@ -129,7 +129,7 @@
expect(listener).toHaveBeenCalledWith(menu, item2);
expect(menu.activeItem).toBe(item2);
expect(menu.firstEnabledItem).toBe(item2);
expect(menu.lastEnabledItem).toBe(item4.menuItem);
expect(menu.lastEnabledItem).toBe(item4.menuitem);
});

});
Expand Down Expand Up @@ -821,7 +821,7 @@
.append(item).show(ref_element)
.moveFocusDown();

item.menuItem.dispatchEvent("click");
item.menuitem.dispatchEvent("click");
});

});
Expand Down
176 changes: 176 additions & 0 deletions src/js_tests/styledelements/SubMenuItemSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* Copyright (c) 2020 Future Internet Consulting and Development Solutions S.L.
*
* This file is part of Wirecloud Platform.
*
* Wirecloud Platform is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Wirecloud 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 Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Wirecloud Platform. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

/* globals StyledElements */


(function (se) {

"use strict";

describe("Styled SubMenuItem", () => {

let item;

afterEach(() => {
item = null;
});

describe("SubMenuItem(title[, options])", () => {

it("should work only by providing a title", () => {
let item = new se.SubMenuItem("item");
expect(item).not.toEqual(null);
});

});

describe("addEventListener(eventId, listener)", () => {

const test = function test(eventId, menuitem) {
it("should " + (menuitem ? "shortcut" : "handle") + " " + eventId + " events", () => {
item = new se.SubMenuItem("submenu");
let listener = jasmine.createSpy("listener");
spyOn(item.menuitem, "addEventListener");
spyOn(StyledElements.PopupMenuBase.prototype, "addEventListener").and.returnValue(item);

expect(item.addEventListener(eventId, listener)).toBe(item);

if (menuitem) {
expect(item.menuitem.addEventListener).toHaveBeenCalledWith(eventId, listener);
expect(StyledElements.PopupMenuBase.prototype.addEventListener).not.toHaveBeenCalled();
} else {
expect(item.menuitem.addEventListener).not.toHaveBeenCalled();
expect(StyledElements.PopupMenuBase.prototype.addEventListener).toHaveBeenCalledWith(eventId, listener);
}
});
};

test('mouseenter', true);
test('mouseleave', true);
test('click', true);
test('blur', true);
test('focus', true);

test('visibilityChange', false);
test('itemOver', false);
});

describe("addIconClass(iconClass)", () => {

it("should be a shortcut", () => {
item = new se.SubMenuItem("submenu");
spyOn(item.menuitem, "addIconClass");

expect(item.addIconClass("class")).toBe(item);

expect(item.menuitem.addIconClass).toHaveBeenCalledWith("class");
});

});

describe("disable()", () => {

it("should be a shortcut", () => {
item = new se.SubMenuItem("submenu");
spyOn(item.menuitem, "disable");

expect(item.disable()).toBe(item);

expect(item.menuitem.disable).toHaveBeenCalledWith();
});

});

describe("enable()", () => {

it("should be a shortcut", () => {
item = new se.SubMenuItem("submenu");
spyOn(item.menuitem, "enable");

expect(item.enable()).toBe(item);

expect(item.menuitem.enable).toHaveBeenCalledWith();
});

});

describe("setDisabled(disabled)", () => {

it("should be a shortcut", () => {
item = new se.SubMenuItem("submenu");
spyOn(item.menuitem, "setDisabled");

expect(item.setDisabled(true)).toBe(item);

expect(item.menuitem.setDisabled).toHaveBeenCalledWith(true);
});

});

describe("destroy()", () => {

it("should work", () => {
item = new se.SubMenuItem("submenu");

expect(item.destroy()).toBe(undefined);
});

});

describe("_menuItemCallback(menuitem)", () => {

it("should support menu parents", () => {
item = new se.SubMenuItem("submenu");
item.parentMenu = {
hide: jasmine.createSpy("hide"),
_context: "ab"
};
let child = {
run: jasmine.createSpy("run")
};

item._menuItemCallback(child);

expect(child.run).toHaveBeenCalledWith("ab");
});

it("should support submenu parents", () => {
item = new se.SubMenuItem("submenu");
item.parentMenu = new se.SubMenuItem("parent");
item.parentMenu.parentMenu = {
hide: jasmine.createSpy("hide"),
_context: "abc"
};
let child = {
run: jasmine.createSpy("run")
};

item._menuItemCallback(child);

expect(child.run).toHaveBeenCalledWith("abc");
});

});

});

})(StyledElements);
20 changes: 20 additions & 0 deletions src/js_tests/wirecloud/WidgetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@

describe("Wirecloud.Widget", function () {

beforeAll(() => {
spyOn(console, "log");
spyOn(console, "info");
});

// TODO
beforeEach(() => {
Wirecloud.PropertyCommiter = jasmine.createSpy("PropertyCommiter").and.returnValue({
Expand Down Expand Up @@ -1191,6 +1196,9 @@

it("should allow to modify all the position properties", () => {
const new_position = {
anchor: "bottom-left",
relx: false,
rely: true,
x: 1,
y: 2,
z: 3
Expand All @@ -1203,13 +1211,19 @@
it("should ignore extra properties", () => {
const new_position = {
extra: 123,
anchor: "bottom-left",
relx: true,
rely: false,
x: 1,
y: 2,
z: 3
};
expect(widget.setPosition(new_position)).toBe(widget);

expect(widget.position).toEqual({
anchor: "bottom-left",
relx: true,
rely: false,
x: 1,
y: 2,
z: 3
Expand Down Expand Up @@ -1239,6 +1253,8 @@

it("should allow to modify all the shape properties", () => {
const new_shape = {
relwidth: true,
relheight: true,
width: 2,
height: 3
};
Expand All @@ -1250,12 +1266,16 @@
it("should ignore extra properties", () => {
const new_shape = {
extra: 123,
relwidth: true,
relheight: true,
width: 2,
height: 3
};
expect(widget.setShape(new_shape)).toBe(widget);

expect(widget.shape).toEqual({
relwidth: true,
relheight: true,
width: 2,
height: 3
});
Expand Down
5 changes: 5 additions & 0 deletions src/js_tests/wirecloud/WiringSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@

describe("Wiring", function () {

beforeAll(() => {
spyOn(console, "log");
spyOn(console, "info");
});

beforeEach(function () {

spyOn(Wirecloud.wiring, "Operator").and.callFake(function (wiring, meta, data) {
Expand Down
8 changes: 4 additions & 4 deletions src/js_tests/wirecloud/ui/ColumnLayoutSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

expect(widget1.setShape).toHaveBeenCalledWith({width: 4});
expect(widget2.setShape).toHaveBeenCalledWith({width: 4});
expect(widget2.setPosition).toHaveBeenCalledWith(new Wirecloud.DragboardPosition(0, 1));
expect(widget2.setPosition).toHaveBeenCalledWith({relx: true, x: 0, rely: true, y: 1});
});

it("should move colliding widgets", () => {
Expand Down Expand Up @@ -217,8 +217,8 @@
let widget = createWidgetMock({id: "1", x: 0, y: 0, width: 3, height: 1});
layout.addWidget(widget);
layout.initializeMove(widget, draggable);
layout.moveTemporally(1, 0);
layout.moveTemporally(2, 0);
layout.moveTemporally(200, 0);
layout.moveTemporally(420, 0);
layout.acceptMove();

expect(widget.position).toEqual({x: 1, y: 0});
Expand All @@ -229,7 +229,7 @@
let widget = createWidgetMock({id: "1", x: 0, y: 0, width: 2, height: 1});
layout.addWidget(widget);
layout.initializeMove(widget, draggable);
layout.moveTemporally(10, 0);
layout.moveTemporally(1000, 0);
layout.acceptMove();

expect(widget.position).toEqual({x: 2, y: 0});
Expand Down
53 changes: 52 additions & 1 deletion src/js_tests/wirecloud/ui/DragboardLayoutSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@

});


describe("updatePosition(widget, element)", () => {

it("should update widget css", () => {
Expand All @@ -488,6 +487,58 @@

});

describe("updateShape(widget, element)", () => {

it("should update widget css", () => {
let layout = new ns.DragboardLayout({});
layout.getWidthInPixels = jasmine.createSpy("getWidthInPixels").and.returnValue(10);
layout.getHeightInPixels = jasmine.createSpy("getHeightInPixels").and.returnValue(20);
let widget = {
element: document.createElement('div'),
minimized: false,
shape: {width: 1, height: 3}
};

layout.updateShape(widget, widget.element);

expect(widget.element.style.width).toBe("10px");
expect(widget.element.style.height).toBe("20px");
});

it("should update widget css (minimized)", () => {
let layout = new ns.DragboardLayout({});
layout.getWidthInPixels = jasmine.createSpy("getWidthInPixels").and.returnValue(10);
layout.getHeightInPixels = jasmine.createSpy("getHeightInPixels").and.returnValue(20);
let widget = {
element: document.createElement('div'),
minimized: true,
shape: {width: 1, height: 3}
};

layout.updateShape(widget, widget.element);

expect(widget.element.style.width).toBe("10px");
expect(widget.element.style.height).toBe("");
});

it("should update widget css (null sizes)", () => {
let layout = new ns.DragboardLayout({});
layout.getWidthInPixels = jasmine.createSpy("getWidthInPixels").and.returnValue(null);
layout.getHeightInPixels = jasmine.createSpy("getHeightInPixels").and.returnValue(null);
let widget = {
element: document.createElement('div'),
minimized: false,
shape: {width: 1, height: 3}
};

layout.updateShape(widget, widget.element);

expect(widget.element.style.width).toBe("");
expect(widget.element.style.height).toBe("");
});

});

describe("provides basic implementations of", () => {
["_notifyResizeEvent", "initializeMove", "moveTemporally", "acceptMove", "cancelMove", "disableCursor"].forEach((method) => {
it("", () => {
Expand Down

0 comments on commit 6bf3526

Please sign in to comment.