| 
									
										
										
										
											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-02-25 09:00:20 +08:00
										 |  |  | 	let DependenciesBlockVariableInstance, dependencyMock, sandbox; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-08 07:09:06 +08:00
										 |  |  | 	beforeEach(() => { | 
					
						
							| 
									
										
										
										
											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", () => | 
					
						
							| 
									
										
										
										
											2018-03-08 07:09:06 +08:00
										 |  |  | 			expect(DependenciesBlockVariableInstance.hasDependencies()).toBe(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(); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			expect(dependencyMock.disconnect.calledOnce).toBe(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; | 
					
						
							| 
									
										
										
										
											2018-03-08 07:09:06 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											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", () => | 
					
						
							| 
									
										
										
										
											2018-03-08 07:09:06 +08:00
										 |  |  | 			expect(hash.update.calledWith("dependencies-name")).toBe(true)); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 17:24:14 +08:00
										 |  |  | 		it("should update hash dependencies with expression", () => | 
					
						
							| 
									
										
										
										
											2018-03-08 07:09:06 +08:00
										 |  |  | 			expect(hash.update.calledWith("expression")).toBe(true)); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 17:24:14 +08:00
										 |  |  | 		it("should update hash inside dependencies", () => | 
					
						
							| 
									
										
										
										
											2018-03-08 07:09:06 +08:00
										 |  |  | 			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-02-25 09:00:20 +08:00
										 |  |  | 		let dependencyTemplates, applyMock; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-08 07:09:06 +08:00
										 |  |  | 		beforeEach(() => (applyMock = sandbox.spy())); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-26 10:23:03 +08:00
										 |  |  | 		it("applies 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 18:46:17 +08:00
										 |  |  | 				dependencyTemplates, | 
					
						
							|  |  |  | 				{}, | 
					
						
							|  |  |  | 				{} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			expect(applyMock.calledOnce).toBe(true); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-26 10:23:03 +08:00
										 |  |  | 		it("applies information inside dependency templates", () => { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:36:43 +08:00
										 |  |  | 			dependencyTemplates = { | 
					
						
							|  |  |  | 				get: function() { | 
					
						
							|  |  |  | 					return false; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			expect(() => { | 
					
						
							| 
									
										
										
										
											2017-02-03 21:37:56 +08:00
										 |  |  | 				DependenciesBlockVariableInstance.expressionSource( | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +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
										 |  |  | 	}); | 
					
						
							|  |  |  | }); |