2017-01-18 17:24:14 +08:00
|
|
|
"use strict";
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
const should = require("should");
|
|
|
|
|
const sinon = require("sinon");
|
2017-02-28 22:28:44 +08:00
|
|
|
const DependenciesBlockVariable = require("../lib/DependenciesBlockVariable");
|
2017-01-18 17:24:14 +08:00
|
|
|
|
2017-02-03 21:37:56 +08:00
|
|
|
describe("DependenciesBlockVariable", () => {
|
2018-02-25 09:00:20 +08:00
|
|
|
let DependenciesBlockVariableInstance, dependencyMock, sandbox;
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
before(() => {
|
2017-01-06 01:36:43 +08:00
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
|
dependencyMock = {
|
|
|
|
|
constructor: {
|
|
|
|
|
name: "DependencyMock"
|
|
|
|
|
},
|
|
|
|
|
disconnect: sandbox.spy(),
|
|
|
|
|
updateHash: sandbox.spy()
|
|
|
|
|
};
|
2017-02-03 21:37:56 +08:00
|
|
|
DependenciesBlockVariableInstance = new DependenciesBlockVariable(
|
2017-01-06 01:36:43 +08:00
|
|
|
"dependencies-name",
|
2018-02-25 09:00:20 +08:00
|
|
|
"expression",
|
|
|
|
|
[dependencyMock]
|
|
|
|
|
);
|
2017-01-06 01:36:43 +08:00
|
|
|
});
|
|
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
afterEach(() => sandbox.restore());
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
describe("hasDependencies", () =>
|
|
|
|
|
it("returns `true` if has dependencies", () =>
|
2017-02-03 21:37:56 +08:00
|
|
|
should(DependenciesBlockVariableInstance.hasDependencies()).be.true()));
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
describe("disconnect", () =>
|
|
|
|
|
it("trigger dependencies disconnection", () => {
|
2017-02-03 21:37:56 +08:00
|
|
|
DependenciesBlockVariableInstance.disconnect();
|
2017-01-06 01:36:43 +08:00
|
|
|
should(dependencyMock.disconnect.calledOnce).be.true();
|
2017-01-18 17:24:14 +08:00
|
|
|
}));
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
describe("updateHash", () => {
|
|
|
|
|
let hash;
|
|
|
|
|
before(() => {
|
2017-01-06 01:36:43 +08:00
|
|
|
hash = {
|
|
|
|
|
update: sandbox.spy()
|
|
|
|
|
};
|
2017-02-03 21:37:56 +08:00
|
|
|
DependenciesBlockVariableInstance.updateHash(hash);
|
2017-01-06 01:36:43 +08:00
|
|
|
});
|
|
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
it("should update hash dependencies with name", () =>
|
|
|
|
|
should(hash.update.calledWith("dependencies-name")).be.true());
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
it("should update hash dependencies with expression", () =>
|
|
|
|
|
should(hash.update.calledWith("expression")).be.true());
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
it("should update hash inside dependencies", () =>
|
|
|
|
|
should(dependencyMock.updateHash.calledOnce).be.true());
|
2017-01-06 01:36:43 +08:00
|
|
|
});
|
|
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
describe("expressionSource", () => {
|
2018-02-25 09:00:20 +08:00
|
|
|
let dependencyTemplates, applyMock;
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2018-02-25 09:00:20 +08:00
|
|
|
before(() => (applyMock = sandbox.spy()));
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
it("aplies information inside dependency templates", () => {
|
2017-01-06 01:36:43 +08:00
|
|
|
dependencyTemplates = {
|
|
|
|
|
get: function() {
|
|
|
|
|
return {
|
|
|
|
|
apply: applyMock
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-02-03 21:37:56 +08:00
|
|
|
DependenciesBlockVariableInstance.expressionSource(
|
2018-02-25 09:00:20 +08:00
|
|
|
dependencyTemplates,
|
|
|
|
|
{},
|
|
|
|
|
{}
|
2017-01-06 01:36:43 +08:00
|
|
|
);
|
|
|
|
|
should(applyMock.calledOnce).be.true();
|
|
|
|
|
});
|
|
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
it("aplies information inside dependency templates", () => {
|
2017-01-06 01:36:43 +08:00
|
|
|
dependencyTemplates = {
|
|
|
|
|
get: function() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-01-18 17:24:14 +08:00
|
|
|
should(() => {
|
2017-02-03 21:37:56 +08:00
|
|
|
DependenciesBlockVariableInstance.expressionSource(
|
2018-02-25 09:00:20 +08:00
|
|
|
dependencyTemplates,
|
|
|
|
|
{},
|
|
|
|
|
{}
|
2017-01-18 17:24:14 +08:00
|
|
|
);
|
2017-01-06 01:36:43 +08:00
|
|
|
}).throw("No template for dependency: DependencyMock");
|
2017-01-18 17:24:14 +08:00
|
|
|
});
|
2017-01-06 01:36:43 +08:00
|
|
|
});
|
|
|
|
|
});
|