11import { expect } from "chai" ;
22import { mix } from "mixwith" ;
33
4- import { ApplicationContextMixin , MaterialContextMixin } from "../src/context/mixins" ;
5- import { InMemoryEntity } from "../src/entity" ;
4+ import {
5+ ApplicationContextMixin ,
6+ ContextProvider ,
7+ createAndPatchRegistry ,
8+ MaterialContextMixin ,
9+ } from "../src/context" ;
610
711class MockMaterial {
812 static createDefault ( ) {
@@ -28,7 +32,7 @@ class SpecificMockApplication {
2832 }
2933}
3034
31- class ProviderEntity extends mix ( InMemoryEntity ) . with (
35+ class ProviderEntity extends mix ( ContextProvider ) . with (
3236 MaterialContextMixin ,
3337 ApplicationContextMixin ,
3438) {
@@ -43,6 +47,10 @@ class DerivedProviderEntity extends ProviderEntity {
4347 static Application = SpecificMockApplication ;
4448}
4549
50+ class ApplicationContextProvider extends mix ( ContextProvider ) . with ( ApplicationContextMixin ) {
51+ static Application = SpecificMockApplication ;
52+ }
53+
4654describe ( "Material & Application ContextMixin" , ( ) => {
4755 const config = { } ;
4856
@@ -58,3 +66,26 @@ describe("Material & Application ContextMixin", () => {
5866 expect ( provider . application ) . to . be . equal ( "defaultSpecificMockApplication" ) ;
5967 } ) ;
6068} ) ;
69+
70+ describe ( "ContextProviderRegistryContainer" , ( ) => {
71+ const classConfigObj = {
72+ DataManager : {
73+ providerCls : ProviderEntity ,
74+ config : { name : "example1" , domain : "important" } ,
75+ } ,
76+ ApplicationDataManager : {
77+ providerCls : ApplicationContextProvider ,
78+ config : { name : "example2" , domain : "important" } ,
79+ } ,
80+ } ;
81+
82+ it ( "can be created and patched" , ( ) => {
83+ const registry = createAndPatchRegistry ( classConfigObj , { Material : SpecificMockMaterial } ) ;
84+ const _dataProvider = registry . findProviderInstanceByName ( "DataManager" ) ;
85+ const dataProvider = new _dataProvider . constructor ( _dataProvider . config ) ;
86+ const _appProvider = registry . findProviderInstanceByName ( "ApplicationDataManager" ) ;
87+ const appProvider = new _appProvider . constructor ( _appProvider . config ) ;
88+ expect ( dataProvider . material ) . to . be . equal ( "defaultSpecificMockMaterial" ) ;
89+ expect ( appProvider . application ) . to . be . equal ( "defaultSpecificMockApplication" ) ;
90+ } ) ;
91+ } ) ;
0 commit comments