import { expect } from "chai" ; import "./setup" ; import * as jsdom from "jsdom" ; import * as React from "react" ; import ComponentManager from "../ComponentManager" ; import Cache from "../store/Cache" ; import { ComponentTreeConfig } from "../ComponentManager" ; import { ResourceComponent } from "../component/ResourceComponent" ; import { Container } from "../di/Container" ; import { Cq } from "../references" ; import { SlingResourceOptions } from "../store/Sling" ; describe ( "ComponentManager" , ( ) => { it ( "should not install components when wcmmode is not disabled" , ( ) => { let cache = new Cache ( ) ; let data = { cache : cache , wcmmode : "edit" , path : "/test" , resourceType : "/components/test" } ; let doc = jsdom . jsdom ( "<html><div data-react-id='1'></div><textarea id='1'>" + JSON . stringify ( data ) + "</textarea></html>" ) ; let cm = new ComponentManager ( null , null , doc ) ; let element = doc . querySelector ( "div" ) ; cm . initReactComponent ( element ) ; } ) ; it ( "should instantiate react components" , ( ) => { class Test extends ResourceComponent < any , any , any > { public renderBody ( ) { return ( < span > test < /span>); } ; } let cache = new Cache ( ) ; let data = { cache : cache , wcmmode : "disabled" , path : "/test" , resourceType : "/components/test" } ; let cqx = { } ; let container = new Container ( ( cqx as Cq ) ) ; container . register ( "cache" , cache ) ; let sling = { subscribe : function ( listener , path , options ? ) { listener . changedResource ( path , { } ) ; } } ; container . register ( "sling" , sling ) ; let registry = { getComponent : function ( resourceType ) : any { return Test ; } } ; let doc = jsdom . jsdom ( "<html><div data-react data-react-id='1'></div><textarea id='1'>" + JSON . stringify ( data ) + "</textarea></html>" ) ; let cm = new ComponentManager ( registry , container , doc ) ; let element = doc . querySelector ( "div" ) ; cm . initReactComponent ( element ) ; let count = cm . initReactComponents ( ) ; expect ( count ) . to . equal ( 1 ) ; } ) ; } ) ;