class-o-mat
Version:
ALPHA VERSION ONLY: class-o-mats will help to create getter-setter functionality with validations that can be attached to a container class for easier coding. Some basic validations are included. class-o-mats also has the ability to store params as bloc
196 lines (157 loc) • 5.45 kB
JavaScript
import Bunyan from 'bunyan';
const log = Bunyan.createLogger({name: "NestedUsageTest"});
import 'mocha';
import { expect } from 'chai';
import { CLASS_O_MAT, NONE } from '../src/constants';
import ClassOMat from '../src/class-o-mat';
describe(`testing of onSet functions`,
()=>{
class TestClass {
TYPE = 'TEST';
}
var classOMat;
var testClass;
it(`create a basic classOMat created class`,
()=>{
classOMat = new ClassOMat();
classOMat.BaseClass(TestClass)
.$();
testClass = new (classOMat.$())();
expect(classOMat.TYPE).to.equal(CLASS_O_MAT);
expect(testClass.TYPE).to.equal('TEST');
}
);
it(`should be able to add a basic getterSetter field to
the classOMat and attach an onSet event to it.`,
()=>{
let _key = false;
let _value = NONE;
const onSetCallback =(self, key, value)=>{
_key = key;
_value = value;
}
classOMat.field('program').onSet(onSetCallback);
testClass = new (classOMat.$())();
testClass.program('CONSUL');
expect(testClass.TYPE).to.equal('TEST');
expect(_key).to.equal('program');
expect(_value).to.equal('CONSUL');
}
);
it(`should be able to add a basic getterSetter field to
the classOMat and attach an onGet event to it.`,
()=>{
let _key = false;
let _value = NONE;
const onGetCallback =(self, key, value)=>{
_key = key;
_value = value;
}
classOMat.field('program').onSet(onGetCallback);
testClass = new (classOMat.$())();
testClass.program('CONSUL');
expect(testClass.TYPE).to.equal('TEST');
expect(_key).to.equal('program');
expect(_value).to.equal('CONSUL');
}
);
it(`should be able to add multiple callbacks to a basic
getterSetter field using multiple onSet commands`,
()=>{
let _key = false;
let _value = NONE;
let _anotherKey = false;
let _anotherValue = NONE;
const onSetCallback =(self, key, value)=>{
_key = key;
_value = value;
}
const anotherOnSetCallback =(self, key, value)=>{
_anotherKey = key;
_anotherValue = value;
}
classOMat.field('program')
.onSet(onSetCallback)
.onSet(anotherOnSetCallback);
testClass = new (classOMat.$())();
testClass.program('CONSUL');
expect(_key).to.equal('program');
expect(_value).to.equal('CONSUL');
expect(_anotherKey).to.equal('program');
expect(_anotherValue).to.equal('CONSUL');
}
);
it(`should be able to add multiple callbacks to a basic
getterSetter field using a single onSet command`,
()=>{
let _key = false;
let _value = NONE;
let _anotherKey = false;
let _anotherValue = NONE;
const onSetCallback =(self, key, value)=>{
_key = key;
_value = value;
}
const anotherOnSetCallback =(self, key, value)=>{
_anotherKey = key;
_anotherValue = value;
}
classOMat.field('program')
.onSet(onSetCallback, anotherOnSetCallback)
testClass = new (classOMat.$())();
testClass.program('CONSUL');
expect(_key).to.equal('program');
expect(_value).to.equal('CONSUL');
expect(_anotherKey).to.equal('program');
expect(_anotherValue).to.equal('CONSUL');
}
);
it(`create another basic classOMat created class`,
()=>{
classOMat = new ClassOMat();
classOMat.BaseClass(TestClass)
.$();
testClass = new (classOMat.$())();
expect(classOMat.TYPE).to.equal(CLASS_O_MAT);
expect(testClass.TYPE).to.equal('TEST');
}
);
it(`should be able to add a basic getterSetter field to
the classOMat and attach an onSet to it by way of
creating a default class-level event.`,
()=>{
let _key = false;
let _value = NONE;
const onSetCallback =(self, key, value)=>{
_key = key;
_value = value;
}
classOMat.onSet(onSetCallback)
.field('program');
testClass = new (classOMat.$())();
testClass.program('CONSUL');
expect(testClass.TYPE).to.equal('TEST');
expect(_key).to.equal('program');
expect(_value).to.equal('CONSUL');
}
);
it(`should be able to add a basic getterSetter field to
the classOMat and attach an onGet event to it by way of
creating a default class-level event.`,
()=>{
let _key = false;
let _value = NONE;
const onGetCallback =(self, key, value)=>{
_key = key;
_value = value;
}
classOMat.onSet(onGetCallback).field('program');
testClass = new (classOMat.$())();
testClass.program('CONSUL');
expect(testClass.TYPE).to.equal('TEST');
expect(_key).to.equal('program');
expect(_value).to.equal('CONSUL');
}
);
}
);