import { expect } from "chai" ; import * as faker from "faker" ; import * as moq from "typemoq" ; import { RegisteredRuleset , Ruleset , RuleTypes } from "../presentation-common" ; describe ( "RegisteredRuleset" , ( ) => { let uniqueIdentifier ; const managerMock = moq . Mock . ofInstance ( function remove ( ruleset ) : void { ruleset ; } ) ; beforeEach ( ( ) => { managerMock . reset ( ) ; uniqueIdentifier = faker . random . uuid ( ) ; } ) ; describe ( "Ruleset implementation" , ( ) => { let ruleset ; let registered ; beforeEach ( ( ) => { ruleset = { id : faker . random . uuid ( ) , requiredSchemas : [ { name : faker . random . word ( ) } , ] , supplementationInfo : { supplementationPurpose : faker . random . words ( ) } , rules : [ { ruleType : RuleTypes . RootNodes , autoExpand : faker . random . boolean ( ) } ] , vars : [ { label : faker . random . words ( ) , vars : [ ] } ] } ; registered = new RegisteredRuleset ( ruleset , uniqueIdentifier , ( r ) => managerMock . object ( r ) ) ; } ) ; it ( "returns wrapper ruleset properties" , ( ) => { expect ( registered . uniqueIdentifier ) . to . eq ( uniqueIdentifier ) ; expect ( registered . id ) . to . deep . equal ( ruleset . id ) ; expect ( registered . supplementationInfo ) . to . deep . equal ( ruleset . supplementationInfo ) ; expect ( registered . rules ) . to . deep . equal ( ruleset . rules ) ; expect ( registered . vars ) . to . deep . equal ( ruleset . vars ) ; expect ( registered . toJSON ( ) ) . to . deep . equal ( ruleset ) ; } ) ; } ) ; describe ( "dispose" , ( ) => { it ( "unregisters ruleset from IRulesetManager" , ( ) => { const ruleset = { id : faker . random . uuid ( ) , rules : [ ] } ; const registered = new RegisteredRuleset ( ruleset , uniqueIdentifier , ( r ) => managerMock . object ( r ) ) ; registered . dispose ( ) ; managerMock . verify ( ( x ) => x ( registered ) , moq . Times . once ( ) ) ; } ) ; } ) ; } ) ;