2016-07-22 00:16:45 +02:00
|
|
|
"use strict";
|
|
|
|
require("typings-test");
|
2016-09-22 12:00:33 +02:00
|
|
|
const events = require("events");
|
2016-09-21 13:44:11 +02:00
|
|
|
const should = require("should");
|
2016-09-22 12:00:33 +02:00
|
|
|
const lik = require("../dist/index");
|
2016-09-21 13:44:11 +02:00
|
|
|
describe('lik', function () {
|
|
|
|
describe('Stringmap', function () {
|
2016-07-22 00:16:45 +02:00
|
|
|
let testStringmap;
|
2016-09-21 13:44:11 +02:00
|
|
|
let testString1 = 'testString1';
|
|
|
|
let testString2 = 'testString2';
|
|
|
|
let testString3 = 'testString3';
|
2016-09-22 12:00:33 +02:00
|
|
|
let testString4 = 'testString4';
|
|
|
|
let testString5 = 'testString5';
|
|
|
|
let testString6 = 'testString6';
|
2016-09-21 13:44:11 +02:00
|
|
|
it('should create an instance of Stringmap', function () {
|
2016-07-22 00:16:45 +02:00
|
|
|
testStringmap = new lik.Stringmap();
|
2016-09-21 13:44:11 +02:00
|
|
|
should(testStringmap).be.instanceof(lik.Stringmap);
|
2016-07-22 00:16:45 +02:00
|
|
|
});
|
2016-09-21 13:44:11 +02:00
|
|
|
it('should return false for an string not in Stringmap', function () {
|
|
|
|
should(testStringmap.checkString(testString1)).be.false();
|
2016-07-22 00:16:45 +02:00
|
|
|
});
|
2016-09-21 13:44:11 +02:00
|
|
|
it('should add an string to Stringmap', function () {
|
2016-07-22 00:16:45 +02:00
|
|
|
testStringmap.addString(testString1);
|
|
|
|
testStringmap.addString(testString2);
|
|
|
|
testStringmap.addString(testString3);
|
2016-09-21 13:44:11 +02: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-22 00:16:45 +02:00
|
|
|
});
|
2016-09-22 12:00:33 +02:00
|
|
|
it('should add an array of strings', function () {
|
|
|
|
testStringmap.addStringArray([testString4, testString5, testString6]);
|
|
|
|
should(testStringmap.checkMinimatch('*String4')).be.true();
|
|
|
|
});
|
2016-09-21 13:44:11 +02:00
|
|
|
it('should remove a string from Stringmap', function () {
|
2016-07-22 00:16:45 +02:00
|
|
|
testStringmap.removeString(testString2);
|
2016-09-21 13:44:11 +02:00
|
|
|
should(testStringmap.checkString(testString2)).be.false();
|
2016-07-22 00:16:45 +02:00
|
|
|
});
|
2016-09-21 13:44:11 +02:00
|
|
|
it('should return a copy of stringArray', function () {
|
|
|
|
let clonedArray = testStringmap.getStringArray();
|
|
|
|
should(clonedArray[0] === 'testString1').be.true();
|
|
|
|
should(clonedArray[0] === testString1).be.true();
|
2016-07-23 04:39:42 +02:00
|
|
|
});
|
2016-09-21 13:44:11 +02:00
|
|
|
it('should register a function to trigger when empty', function () {
|
|
|
|
testStringmap.registerUntilTrue(() => { return testStringmap.checkIsEmpty(); }, () => { console.log('Stringmap now is empty'); });
|
|
|
|
});
|
|
|
|
it('should remove wipe and then notify', function () {
|
2016-07-23 04:39:42 +02:00
|
|
|
testStringmap.wipe();
|
|
|
|
});
|
2016-07-22 00:16:45 +02:00
|
|
|
});
|
2016-09-21 13:44:11 +02:00
|
|
|
describe('Objectmap', function () {
|
2016-07-31 00:54:46 +02:00
|
|
|
let testObjectmap;
|
|
|
|
let testObject1 = {
|
2016-09-21 13:44:11 +02:00
|
|
|
propOne: 'hello',
|
|
|
|
propTwo: 'hello2'
|
2016-07-31 00:54:46 +02:00
|
|
|
};
|
|
|
|
let testObject2 = {
|
2016-09-21 13:44:11 +02:00
|
|
|
propOne: 'hello',
|
|
|
|
propTwo: 'hello2'
|
2016-07-31 00:54:46 +02:00
|
|
|
};
|
2016-09-21 13:44:11 +02:00
|
|
|
it('should correctly instantiate an Objectmap', function () {
|
2016-07-31 00:54:46 +02:00
|
|
|
testObjectmap = new lik.Objectmap();
|
2016-09-21 13:44:11 +02:00
|
|
|
should(testObjectmap).be.instanceof(lik.Objectmap);
|
2016-07-31 00:54:46 +02:00
|
|
|
});
|
2016-09-21 13:44:11 +02:00
|
|
|
it('should correctly add an object to Objectmap', function () {
|
2016-07-31 00:54:46 +02:00
|
|
|
testObjectmap.add(testObject1);
|
2016-09-21 13:44:11 +02:00
|
|
|
should(testObjectmap.checkForObject(testObject1)).be.true;
|
|
|
|
should(testObjectmap.checkForObject(testObject2)).be.false;
|
2016-07-31 00:54:46 +02:00
|
|
|
});
|
2016-09-21 13:44:11 +02:00
|
|
|
it('should correctly remove an object to Objectmap', function () {
|
2016-07-31 00:54:46 +02:00
|
|
|
testObjectmap.add(testObject2);
|
|
|
|
testObjectmap.remove(testObject1);
|
2016-09-21 13:44:11 +02:00
|
|
|
should(testObjectmap.checkForObject(testObject1)).be.false;
|
|
|
|
should(testObjectmap.checkForObject(testObject2)).be.true;
|
2016-07-31 00:54:46 +02:00
|
|
|
});
|
2016-09-21 13:44:11 +02:00
|
|
|
it('should correctly run a function forEach map object', function () {
|
2016-07-31 14:36:28 +02:00
|
|
|
testObjectmap.forEach(itemArg => {
|
2016-09-21 13:44:11 +02:00
|
|
|
should(itemArg).have.ownProperty('propOne');
|
2016-07-31 14:36:28 +02:00
|
|
|
});
|
|
|
|
});
|
2016-09-21 13:44:11 +02:00
|
|
|
it('should correctly find an object', function () {
|
|
|
|
let myObject = { propOne: 'helloThere', propTwo: 'helloAnyway' };
|
2016-08-08 16:00:14 +02:00
|
|
|
testObjectmap.add(myObject);
|
2016-09-21 13:44:11 +02:00
|
|
|
let referenceObject = testObjectmap.find((itemArg) => { return (itemArg.propOne === 'helloThere'); });
|
|
|
|
should(myObject === referenceObject).be.true();
|
2016-08-08 16:00:14 +02:00
|
|
|
});
|
2016-07-31 00:54:46 +02:00
|
|
|
});
|
2016-09-22 12:00:33 +02: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-22 00:16:45 +02:00
|
|
|
});
|
2016-09-22 12:00:33 +02:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMsaUNBQWdDO0FBRWhDLHFDQUFxQztBQUNyQyxRQUFRLENBQUMsS0FBSyxFQUFDO0lBQ1gsUUFBUSxDQUFDLFdBQVcsRUFBQztRQUNqQixJQUFJLGFBQTRCLENBQUE7UUFDaEMsSUFBSSxXQUFXLEdBQUcsYUFBYSxDQUFBO1FBQy9CLElBQUksV0FBVyxHQUFHLGFBQWEsQ0FBQTtRQUMvQixJQUFJLFdBQVcsR0FBRyxhQUFhLENBQUE7UUFDL0IsSUFBSSxXQUFXLEdBQUcsYUFBYSxDQUFBO1FBQy9CLElBQUksV0FBVyxHQU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