import { expect } from "chai" ; import "./setup" ; import ServerSling from "../store/ServerSling" ; import Cache from "../store/Cache" ; import { JavaSling } from "../references" ; import { EditDialogData , SlingResourceOptions } from "../store/Sling" ; import { ResourceComponent } from "../component/ResourceComponent" ; describe ( "ServerSling" , ( ) => { it ( "should include resource" , ( ) => { let html = "<div></div>" ; let cache = new Cache ( ) ; let javaSling = { includeResource : function ( path , resourceType ) : string { return html ; } } ; let sling = new ServerSling ( cache , ( javaSling as JavaSling ) ) ; let actualHtml = sling . includeResource ( "/test" , "/component/test" ) ; expect ( actualHtml ) . to . equal ( html ) ; expect ( cache . getIncluded ( "/test" ) ) . to . equal ( html ) ; } ) ; it ( "should subscribe to resource" , ( ) => { let resource = { text : "hi" } ; let path = "/test" ; let actualResource ; let actualPath ; let cache = new Cache ( ) ; let javaSling = { getResource : function ( _path , depth ? ) : string { if ( _path === path && depth === 3 ) { return JSON . stringify ( resource ) ; } else { return null ; } } } ; let sling = new ServerSling ( cache , ( javaSling as JavaSling ) ) ; let component = ( ( { changedResource : function ( _path , _resource ) : void { actualResource = _resource ; actualPath = _path ; } } as any ) as ResourceComponent < any , any , any > ) ; sling . subscribe ( component , path , { depth : 3 } ) ; expect ( actualPath ) . to . equal ( path ) ; expect ( actualResource ) . to . deep . equal ( resource ) ; } ) ; it ( "should include dialog" , ( ) => { let dialog = { element : "el" } ; let cache = new Cache ( ) ; let javaSling = { renderDialogScript : function ( path , resourceType ) : string { return JSON . stringify ( dialog ) ; } } ; let sling = new ServerSling ( cache , ( javaSling as JavaSling ) ) ; let actualDialog = sling . renderDialogScript ( "/test" , "/component/test" ) ; expect ( actualDialog ) . to . deep . equal ( dialog ) ; expect ( cache . getScript ( "/test" ) ) . to . deep . equal ( dialog ) ; } ) ; it ( "should include null dialog" , ( ) => { let cache = new Cache ( ) ; let javaSling = { renderDialogScript : function ( path , resourceType ) : string { return null ; } } ; let sling = new ServerSling ( cache , ( javaSling as JavaSling ) ) ; let actualDialog = sling . renderDialogScript ( "/test" , "/component/test" ) ; expect ( actualDialog ) . to . be . null ; } ) ; it ( "should get path" , ( ) => { let path = "/test" ; let javaSling = { getPagePath : function ( ) : string { return path ; } } ; let sling = new ServerSling ( null , ( javaSling as JavaSling ) ) ; let actualPath = sling . getRequestPath ( ) ; expect ( actualPath ) . to . equal ( path ) ; } ) ; } ) ;