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 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-01-24 20:17:21 +08:00
|
|
|
const sandbox = sinon.sandbox.create();
|
|
|
|
|
const dependencyMock = {
|
|
|
|
|
constructor: {
|
|
|
|
|
name: "DependencyMock"
|
|
|
|
|
},
|
|
|
|
|
disconnect: sandbox.spy(),
|
|
|
|
|
updateHash: sandbox.spy()
|
|
|
|
|
};
|
|
|
|
|
const DependenciesBlockVariableInstance = new DependenciesBlockVariable("dependencies-name", "expression", [dependencyMock]);
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2018-01-24 20:17:21 +08:00
|
|
|
afterEach(() => {
|
|
|
|
|
sandbox.restore();
|
2017-01-06 01:36:43 +08:00
|
|
|
});
|
|
|
|
|
|
2018-01-24 20:17:21 +08:00
|
|
|
describe("hasDependencies", () => {
|
|
|
|
|
it("returns `true` if has dependencies", () => {
|
|
|
|
|
expect(DependenciesBlockVariableInstance.hasDependencies()).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2018-01-24 20:17:21 +08:00
|
|
|
describe("disconnect", () => {
|
2017-01-18 17:24:14 +08:00
|
|
|
it("trigger dependencies disconnection", () => {
|
2017-02-03 21:37:56 +08:00
|
|
|
DependenciesBlockVariableInstance.disconnect();
|
2018-01-24 20:17:21 +08:00
|
|
|
expect(dependencyMock.disconnect.calledOnce).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
describe("updateHash", () => {
|
2018-01-24 20:17:21 +08:00
|
|
|
const hash = {
|
|
|
|
|
update: sandbox.spy()
|
|
|
|
|
};
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2018-01-24 20:17:21 +08:00
|
|
|
DependenciesBlockVariableInstance.updateHash(hash);
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2018-01-24 20:17:21 +08:00
|
|
|
it("should update hash dependencies with name", () => {
|
|
|
|
|
expect(hash.update.calledWith("dependencies-name")).toBe(true);
|
|
|
|
|
});
|
2017-01-06 01:36:43 +08:00
|
|
|
|
2018-01-24 20:17:21 +08:00
|
|
|
it("should update hash dependencies with expression", () => {
|
|
|
|
|
expect(hash.update.calledWith("expression")).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should update hash inside dependencies", () => {
|
|
|
|
|
expect(dependencyMock.updateHash.calledOnce).toBe(true);
|
|
|
|
|
});
|
2017-01-06 01:36:43 +08:00
|
|
|
});
|
|
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
describe("expressionSource", () => {
|
2018-01-24 20:17:21 +08:00
|
|
|
const 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", () => {
|
2018-01-24 20:17:21 +08:00
|
|
|
const dependencyTemplates = {
|
|
|
|
|
get() {
|
2017-01-06 01:36:43 +08:00
|
|
|
return {
|
|
|
|
|
apply: applyMock
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-02-03 21:37:56 +08:00
|
|
|
DependenciesBlockVariableInstance.expressionSource(
|
2017-01-06 01:36:43 +08:00
|
|
|
dependencyTemplates, {}, {}
|
|
|
|
|
);
|
2018-01-24 20:17:21 +08:00
|
|
|
expect(applyMock.calledOnce).toBe(true);
|
2017-01-06 01:36:43 +08:00
|
|
|
});
|
|
|
|
|
|
2017-01-18 17:24:14 +08:00
|
|
|
it("aplies information inside dependency templates", () => {
|
2018-01-24 20:17:21 +08:00
|
|
|
const dependencyTemplates = {
|
|
|
|
|
get() {
|
2017-01-06 01:36:43 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-01-24 20:17:21 +08:00
|
|
|
expect(() => {
|
2017-02-03 21:37:56 +08:00
|
|
|
DependenciesBlockVariableInstance.expressionSource(
|
2017-01-06 01:36:43 +08:00
|
|
|
dependencyTemplates, {}, {}
|
2017-01-18 17:24:14 +08:00
|
|
|
);
|
2018-01-24 20:17:21 +08:00
|
|
|
}).toThrow("No template for dependency: DependencyMock");
|
2017-01-18 17:24:14 +08:00
|
|
|
});
|
2017-01-06 01:36:43 +08:00
|
|
|
});
|
|
|
|
|
});
|