import * as enzyme from "enzyme" ; import * as Adapter from 'enzyme-adapter-react-16' ; import { ClientAemContext } from "../AemContext" ; import RootComponent from "../component/RootComponent" ; import RootComponentRegistry from "../RootComponentRegistry" ; import ComponentRegistry from "../ComponentRegistry" ; import { Container } from "../di/Container" ; import ComponentManager from "../ComponentManager" ; import { Cq } from "../references" ; import * as React from "react" ; import Cache from "../store/Cache" ; import MockSling from "./MockSling" ; enzyme . configure ( { adapter : new Adapter ( ) } ) ; export default class AemTest { private registry : RootComponentRegistry = new RootComponentRegistry ( ) ; public currentAemContext : ClientAemContext ; public init ( ) { this . registry . init ( ) ; let container = new Container ( ( { } as Cq ) ) ; let cache = new Cache ( ) ; container . register ( "cache" , cache ) ; container . register ( "sling" , new MockSling ( cache ) ) ; let componentManager = new ComponentManager ( this . registry , container , ( { } as Document ) ) ; this . currentAemContext = { registry : this . registry , componentManager : componentManager , container : container } ; } public addRegistry ( registry ) { this . registry . add ( registry ) ; } public addResource ( path , resource , depth ? ) { let cache = this . currentAemContext . container . get ( "cache" ) ; cache . put ( path , resource , depth ) ; } public render ( resource , path ? ) { this . addResource ( path || "/" , resource ) ; let component = this . registry . getComponent ( resource . resourceType ) ; if ( ! component ) { throw new Error ( "cannot find component for " + resource . resourceType ) ; } return enzyme . render ( < RootComponent comp = { component } path = { path || "/" } wcmmode = "disabled" aemContext = { this . currentAemContext } / > ) ; } }