Skip to content

Commit

Permalink
fix: fix bug:GomlNode#enabled not works correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
moajo committed Feb 13, 2017
1 parent c545f79 commit 30ac3d9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/Components/GrimoireComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ class GrimoireComponent extends Component {
this.node.resolveAttributesValue();
this.getAttributeRaw("id").watch((attr) => {
this.node.element.id = attr ? attr : "";
}, true);
}, true, true);
this.getAttributeRaw("class").watch((attr) => {
this.node.element.className = Array.isArray(attr) ? attr.join(" ") : "";
}, true);
}, true, true);
this.getAttributeRaw("enabled").watch(attr => {
this.node["_enabled"] = attr;
const p = this.node.parent;
this.node.notifyActivenessUpdate(p ? p.isActive && this.node.enabled : this.node.enabled);
});
}, false, true);
this.node["_enabled"] = this.getAttribute("enabled");
this.node["_isActive"] = this.node.parent ? this.node.parent.isActive && this.enabled : this.enabled;
this.node["_isActive"] = this.node.parent ? this.node.parent.isActive && this.node.enabled : this.node.enabled;
}
}

Expand Down
64 changes: 62 additions & 2 deletions test/Node/GomlNode2Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,82 @@ test('attribute watch should work correctly2', (t) => {
t.truthy(spy.getCall(0).args[0] === "idid");
});

test('enabled should work correctly', (t) => {
const testNode3 = rootNode.children[0];
const testNode2 = testNode3.children[0];
t.truthy(rootNode.enabled);
t.truthy(rootNode.isActive);
t.truthy(!testNode3.enabled);
t.truthy(!testNode3.isActive);
t.truthy(testNode2.enabled);
t.truthy(!testNode2.isActive);
testNode3.enabled = true;
t.truthy(testNode3.enabled);
t.truthy(testNode3.isActive);
t.truthy(testNode2.enabled);
t.truthy(testNode2.isActive);
testNode2.enabled = false;
t.truthy(!testNode2.enabled);
t.truthy(!testNode2.isActive);
rootNode.enabled = false;
t.truthy(!rootNode.enabled);
t.truthy(!rootNode.isActive);
t.truthy(testNode3.enabled);
t.truthy(!testNode3.isActive);
t.truthy(!testNode2.enabled);
t.truthy(!testNode2.isActive);
});

test('Broadcast message should call correct order', (t) => {
rootNode.broadcastMessage("onTest");
sinon.assert.callOrder(testComponent3Spy, testComponent2Spy, testComponentOptionalSpy, testComponent1Spy);
});

test('Broadcast message with range should work correctly', (t) => {
const testNode3 = rootNode.children[0];
testNode3.enabled = true;
resetSpies();
testNode3.enabled = true;
rootNode.broadcastMessage(1, "onTest");
sinon.assert.called(testComponent3Spy);
sinon.assert.notCalled(testComponent2Spy);
sinon.assert.notCalled(testComponentOptionalSpy);
sinon.assert.notCalled(testComponent1Spy);
});

test('Broadcast message with enabled should work correctly', (t) => {
const testNode3 = rootNode.children[0];
const testNode2 = testNode3.children[0];

resetSpies();
sinon.assert.notCalled(testComponent3Spy);
sinon.assert.notCalled(testComponent2Spy);
sinon.assert.notCalled(testComponentOptionalSpy);
sinon.assert.notCalled(testComponent1Spy);

resetSpies();
rootNode.broadcastMessage("onTest");
sinon.assert.notCalled(testComponent3Spy);
sinon.assert.notCalled(testComponent2Spy);
sinon.assert.notCalled(testComponentOptionalSpy);
sinon.assert.notCalled(testComponent1Spy);

resetSpies();
testNode3.enabled = true;
testNode2.enabled = false;
rootNode.broadcastMessage("onTest");
sinon.assert.called(testComponent3Spy);
sinon.assert.notCalled(testComponent2Spy);
sinon.assert.notCalled(testComponentOptionalSpy);
sinon.assert.called(testComponent1Spy);

resetSpies();
testNode2.enabled = true;
rootNode.broadcastMessage("onTest");
sinon.assert.called(testComponent3Spy);
sinon.assert.called(testComponent2Spy);
sinon.assert.called(testComponentOptionalSpy);
sinon.assert.called(testComponent1Spy);
});

test('SendMessage should call correct order', (t) => {
const testNode2 = rootNode.children[0].children[0];
testNode2.sendMessage("onTest");
Expand Down

0 comments on commit 30ac3d9

Please sign in to comment.