import { expect } from "chai" ; import "./setup" ; import * as React from "react" ; import { ResourceComponent } from "../component/ResourceComponent" ; import ComponentRegistry from "../ComponentRegistry" ; import { Mapping } from "../RootComponentRegistry" ; import { ComponentConfig } from "../component/WrapperFactory" ; describe ( "ComponentRegistry" , ( ) => { class TestView extends ResourceComponent < any , any , any > { public renderBody ( ) { return ( < span > { this . getResource ( ) . text } < /span>); } } it ( "should register component" , ( ) => { let registry = new ComponentRegistry ( "/components" ) ; registry . register ( TestView ) ; let mapping = registry . mappings [ 0 ] ; expect ( mapping . componentClass ) . to . equal ( TestView ) ; expect ( mapping . resourceType ) . to . equal ( "/components/test-view" ) ; expect ( mapping . vanillaClass ) . to . be . null ; } ) ; it ( "should register component with special mapping" , ( ) => { let registry = new ComponentRegistry ( ( name ) => { return "/x/" + name ; } ) ; registry . register ( TestView ) ; let mapping = registry . mappings [ 0 ] ; expect ( mapping . componentClass ) . to . equal ( TestView ) ; expect ( mapping . resourceType ) . to . equal ( "/x/TestView" ) ; expect ( mapping . vanillaClass ) . to . be . null ; } ) ; it ( "should register vanilla component" , ( ) => { let registry = new ComponentRegistry ( "/components/vanilla" ) ; let componentConfig = { component : TestView } ; registry . registerVanilla ( componentConfig ) ; let mapping = registry . mappings [ 0 ] ; expect ( mapping . componentClass ) . to . not . equal ( TestView ) ; expect ( mapping . resourceType ) . to . equal ( "/components/vanilla/test-view" ) ; expect ( mapping . vanillaClass ) . to . equal ( TestView ) ; } ) ; } ) ;