2016-07-21 22:16:45 +00:00
|
|
|
"use strict";
|
|
|
|
require("typings-test");
|
2016-09-22 10:00:33 +00:00
|
|
|
const events = require("events");
|
2016-09-29 20:05:20 +00:00
|
|
|
const lodash = require("lodash");
|
2016-09-21 11:44:11 +00:00
|
|
|
const should = require("should");
|
2016-09-22 10:00:33 +00:00
|
|
|
const lik = require("../dist/index");
|
2016-09-21 11:44:11 +00:00
|
|
|
describe('lik', function () {
|
|
|
|
describe('Stringmap', function () {
|
2016-07-21 22:16:45 +00:00
|
|
|
let testStringmap;
|
2016-09-21 11:44:11 +00:00
|
|
|
let testString1 = 'testString1';
|
|
|
|
let testString2 = 'testString2';
|
|
|
|
let testString3 = 'testString3';
|
2016-09-22 10:00:33 +00:00
|
|
|
let testString4 = 'testString4';
|
|
|
|
let testString5 = 'testString5';
|
|
|
|
let testString6 = 'testString6';
|
2016-09-29 20:05:20 +00:00
|
|
|
it('new lik.Objectmap() -> should create an instance of Stringmap', function () {
|
2016-07-21 22:16:45 +00:00
|
|
|
testStringmap = new lik.Stringmap();
|
2016-09-21 11:44:11 +00:00
|
|
|
should(testStringmap).be.instanceof(lik.Stringmap);
|
2016-07-21 22:16:45 +00:00
|
|
|
});
|
2016-09-29 20:05:20 +00:00
|
|
|
it('lik.Stringmap.checkString -> should return false for an string not in Stringmap', function () {
|
2016-09-21 11:44:11 +00:00
|
|
|
should(testStringmap.checkString(testString1)).be.false();
|
2016-07-21 22:16:45 +00:00
|
|
|
});
|
2016-09-29 20:05:20 +00:00
|
|
|
it('lik.Stringmap.addString -> should add an string to Stringmap', function () {
|
2016-07-21 22:16:45 +00:00
|
|
|
testStringmap.addString(testString1);
|
|
|
|
testStringmap.addString(testString2);
|
|
|
|
testStringmap.addString(testString3);
|
2016-09-21 11:44:11 +00:00
|
|
|
should(testStringmap.checkString(testString1)).be.true();
|
|
|
|
should(testStringmap.checkString(testString2)).be.true();
|
|
|
|
should(testStringmap.checkString(testString3)).be.true();
|
|
|
|
should(testStringmap.checkMinimatch('*String1')).be.true();
|
|
|
|
should(testStringmap.checkMinimatch('*String2')).be.true();
|
|
|
|
should(testStringmap.checkMinimatch('*String4')).be.false();
|
2016-07-21 22:16:45 +00:00
|
|
|
});
|
2016-09-29 20:05:20 +00:00
|
|
|
it('lik.Stringmap.addStringArray -> should add an array of strings', function () {
|
2016-09-22 10:00:33 +00:00
|
|
|
testStringmap.addStringArray([testString4, testString5, testString6]);
|
|
|
|
should(testStringmap.checkMinimatch('*String4')).be.true();
|
|
|
|
});
|
2016-09-29 20:05:20 +00:00
|
|
|
it('lik.Stringmap.removeString -> should remove a string from Stringmap', function () {
|
2016-07-21 22:16:45 +00:00
|
|
|
testStringmap.removeString(testString2);
|
2016-09-21 11:44:11 +00:00
|
|
|
should(testStringmap.checkString(testString2)).be.false();
|
2016-07-21 22:16:45 +00:00
|
|
|
});
|
2016-09-29 20:05:20 +00:00
|
|
|
it('lik.Stringmap.getStringArray() -> should return a copy of stringArray', function () {
|
2016-09-21 11:44:11 +00:00
|
|
|
let clonedArray = testStringmap.getStringArray();
|
|
|
|
should(clonedArray[0] === 'testString1').be.true();
|
|
|
|
should(clonedArray[0] === testString1).be.true();
|
2016-07-23 02:39:42 +00:00
|
|
|
});
|
2016-09-29 20:05:20 +00:00
|
|
|
it('lik.Stringmap.checkIsEmpty() -> should register a function to trigger when empty', function () {
|
2016-09-21 11:44:11 +00:00
|
|
|
testStringmap.registerUntilTrue(() => { return testStringmap.checkIsEmpty(); }, () => { console.log('Stringmap now is empty'); });
|
|
|
|
});
|
2016-09-29 20:05:20 +00:00
|
|
|
it('lik.Stringmap.empty() -> should remove wipe and then notify', function () {
|
2016-07-23 02:39:42 +00:00
|
|
|
testStringmap.wipe();
|
|
|
|
});
|
2016-07-21 22:16:45 +00:00
|
|
|
});
|
2016-09-21 11:44:11 +00:00
|
|
|
describe('Objectmap', function () {
|
2016-07-30 22:54:46 +00:00
|
|
|
let testObjectmap;
|
|
|
|
let testObject1 = {
|
2016-09-21 11:44:11 +00:00
|
|
|
propOne: 'hello',
|
|
|
|
propTwo: 'hello2'
|
2016-07-30 22:54:46 +00:00
|
|
|
};
|
|
|
|
let testObject2 = {
|
2016-09-21 11:44:11 +00:00
|
|
|
propOne: 'hello',
|
|
|
|
propTwo: 'hello2'
|
2016-07-30 22:54:46 +00:00
|
|
|
};
|
2016-09-29 20:05:20 +00:00
|
|
|
it('new lik.Objectmap() -> should correctly instantiate an Objectmap', function () {
|
2016-07-30 22:54:46 +00:00
|
|
|
testObjectmap = new lik.Objectmap();
|
2016-09-21 11:44:11 +00:00
|
|
|
should(testObjectmap).be.instanceof(lik.Objectmap);
|
2016-07-30 22:54:46 +00:00
|
|
|
});
|
2016-09-29 20:05:20 +00:00
|
|
|
it('lik.Objectmap.add() -> should correctly add an object to Objectmap', function () {
|
2016-07-30 22:54:46 +00:00
|
|
|
testObjectmap.add(testObject1);
|
2016-09-21 11:44:11 +00:00
|
|
|
should(testObjectmap.checkForObject(testObject1)).be.true;
|
|
|
|
should(testObjectmap.checkForObject(testObject2)).be.false;
|
2016-07-30 22:54:46 +00:00
|
|
|
});
|
2016-09-29 20:05:20 +00:00
|
|
|
it('lik.Objectmap.remove() -> should correctly remove an object to Objectmap', function () {
|
2016-07-30 22:54:46 +00:00
|
|
|
testObjectmap.add(testObject2);
|
|
|
|
testObjectmap.remove(testObject1);
|
2016-09-21 11:44:11 +00:00
|
|
|
should(testObjectmap.checkForObject(testObject1)).be.false;
|
|
|
|
should(testObjectmap.checkForObject(testObject2)).be.true;
|
2016-07-30 22:54:46 +00:00
|
|
|
});
|
2016-09-29 20:05:20 +00:00
|
|
|
it('Objectmap.forEach -> should correctly run a function forEach map object', function () {
|
2016-07-31 12:36:28 +00:00
|
|
|
testObjectmap.forEach(itemArg => {
|
2016-09-21 11:44:11 +00:00
|
|
|
should(itemArg).have.ownProperty('propOne');
|
2016-07-31 12:36:28 +00:00
|
|
|
});
|
|
|
|
});
|
2016-09-29 20:05:20 +00:00
|
|
|
it('lik.Objectmap.find() -> should correctly find an object', function () {
|
2016-09-21 11:44:11 +00:00
|
|
|
let myObject = { propOne: 'helloThere', propTwo: 'helloAnyway' };
|
2016-08-08 14:00:14 +00:00
|
|
|
testObjectmap.add(myObject);
|
2016-09-21 11:44:11 +00:00
|
|
|
let referenceObject = testObjectmap.find((itemArg) => { return (itemArg.propOne === 'helloThere'); });
|
|
|
|
should(myObject === referenceObject).be.true();
|
2016-08-08 14:00:14 +00:00
|
|
|
});
|
2016-09-29 20:05:20 +00:00
|
|
|
it('lik.Objectmap.getArray() -> should return a cloned array', function () {
|
|
|
|
let myObject = { propOne: 'test1', propTwo: 'wow, how awesome' };
|
|
|
|
testObjectmap.add(myObject);
|
|
|
|
let clonedArray = testObjectmap.getArray();
|
|
|
|
should(lodash.isEqual(clonedArray[clonedArray.length - 1], myObject)).be.true();
|
|
|
|
});
|
2016-07-30 22:54:46 +00:00
|
|
|
});
|
2016-09-22 10:00:33 +00:00
|
|
|
describe('Observablemap', function () {
|
|
|
|
let testObservablemap;
|
|
|
|
let testObservable1;
|
|
|
|
let testObservable2;
|
|
|
|
let testObservable3;
|
|
|
|
let testEmitter;
|
|
|
|
it('should create an instance', function () {
|
|
|
|
testObservablemap = new lik.Observablemap();
|
|
|
|
should(testObservablemap).be.instanceof(lik.Observablemap);
|
|
|
|
});
|
|
|
|
it('should accept a new emitter', function (done) {
|
|
|
|
testEmitter = new events.EventEmitter();
|
|
|
|
testObservable1 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event1');
|
|
|
|
testObservable1.subscribe(x => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
testObservable2 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event1');
|
|
|
|
testObservable3 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event2');
|
|
|
|
should(testObservable1 === testObservable2).be.true();
|
|
|
|
should(testObservable1 === testObservable3).be.false();
|
|
|
|
testEmitter.emit('event1');
|
|
|
|
});
|
|
|
|
});
|
2016-07-21 22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