Skip to content

Commit

Permalink
Fix error when attempting to render layoutData without parent in flush
Browse files Browse the repository at this point in the history
This error only occured if a flush caused a layoutData to be rendered
when the widget has no parent. It worked fine outside a flush or when
only the sibling is missing.

This is the least invasive solution. I will come back to this code later
and refactor.

Fix #303

Change-Id: Ic2490b49b382c8c8ae42f19d6f6cd675b1e022a8
  • Loading branch information
tbuschto committed Feb 27, 2015
1 parent 9cb06ba commit 03fea36
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/js/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

var emptyParent = {
children: function() {
return null;
return [];
}
};

Expand Down
19 changes: 17 additions & 2 deletions test/js/Layout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,36 @@ describe("Layout:", function() {
expect(layoutData.top).toEqual([other, 42]);
});

it("throws if selector does not resolve", function() {
it("throws if selector does not resolve due to missing sibling", function() {
other.dispose();

expect(function() {
encode({left: 23, right: "#other", top: ["#other", 42]}, widget);
}).toThrow();
});

it("replaces unresolved selector with 0 if forced ", function() {
it("throws if selector does not resolve due to missing parent", function() {
widget = tabris.create("TestType");

expect(function() {
encode({left: 23, right: "#other", top: ["#other", 42]}, widget);
}).toThrow();
});

it("replaces selector not resolved due to missing sibling with 0", function() {
other.dispose();

expect(encode({left: 23, right: "#noone", top: ["#noone", 42]}, widget, true))
.toEqual({left: 23, right: [0, 0], top: [0, 42]});
});

it("replaces selector not resolved due to missing parent with 0", function() {
widget = tabris.create("TestType");

expect(encode({left: 23, right: "#noone", top: ["#noone", 42]}, widget, true))
.toEqual({left: 23, right: [0, 0], top: [0, 42]});
});

});

});
44 changes: 30 additions & 14 deletions test/js/Widgets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,25 +244,41 @@ describe("Widgets", function() {
expect(call.properties.layoutData).toEqual(expected);
});

it("SET layoutData again until selector resolves", function() {
it("SET layoutData again until selector resolves by adding sibling", function() {
other.dispose();

widget.set("layoutData", {right: "#other"});
var calls1 = nativeBridge.calls({op: "set"});
nativeBridge.resetCalls();
var calls2 = nativeBridge.calls({op: "set"});
nativeBridge.resetCalls();
var withoutSibling = nativeBridge.calls({op: "set"});
var retry = nativeBridge.calls({op: "set"});
other = tabris.create("TestType", {id: "other"}).appendTo(parent);
var calls3 = nativeBridge.calls({op: "set"});
var withSibling = nativeBridge.calls({op: "set"});
var noRetry = nativeBridge.calls({op: "set"});

expect(withoutSibling.length).toBe(1);
expect(retry.length).toBe(1);
expect(withSibling.length).toBe(2);
expect(noRetry.length).toBe(2);
expect(withoutSibling[0].properties.layoutData).toEqual({right: [0, 0]});
expect(withSibling[1].properties.layoutData).toEqual({right: [other.cid, 0]});
});

it("SET layoutData again until selector resolves by setting parent", function() {
widget = tabris.create("TestType");
nativeBridge.resetCalls();
var calls4 = nativeBridge.calls({op: "set"});

expect(calls1.length).toBe(1);
expect(calls2.length).toBe(0);
expect(calls3.length).toBe(1);
expect(calls4.length).toBe(0);
expect(calls1[0].properties.layoutData).toEqual({right: [0, 0]});
expect(calls3[0].properties.layoutData).toEqual({right: [other.cid, 0]});

widget.set("layoutData", {right: "#other"});
var withoutParent = nativeBridge.calls({op: "set"});
var retry = nativeBridge.calls({op: "set"});
widget.appendTo(parent);
var withParent = nativeBridge.calls({op: "set"});
var noRetry = nativeBridge.calls({op: "set"});

expect(withoutParent.length).toBe(1);
expect(retry.length).toBe(1);
expect(withParent.length).toBe(2);
expect(noRetry.length).toBe(2);
expect(withoutParent[0].properties.layoutData).toEqual({right: [0, 0]});
expect(withParent[1].properties.layoutData).toEqual({right: [other.cid, 0]});
});

});
Expand Down

0 comments on commit 03fea36

Please sign in to comment.