mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-01-11 01:48:40 +00:00
Implement more tests
This commit is contained in:
parent
bf3ec231dd
commit
45017a4936
|
|
@ -31,13 +31,15 @@
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
available ()
|
||||
{
|
||||
try {
|
||||
return 'localStorage' in window && window.localStorage !== null;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
jsOMS.DataStorage.LocalStorage.available = function ()
|
||||
{
|
||||
try {
|
||||
return 'localStorage' in window && window.localStorage !== null;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}(window.jsOMS = window.jsOMS || {}));
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
for (let id in this.groups[group]) {
|
||||
for (let id in this.groups[group]) {
|
||||
if (!this.groups[group].hasOwnProperty(id) || !this.groups[group][id]) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -109,10 +109,8 @@
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
trigger (group, id, data)
|
||||
trigger (group, id = '', data = null)
|
||||
{
|
||||
id = typeof id !== 'undefined' ? id : 0;
|
||||
|
||||
if (!this.callbacks.hasOwnProperty(group)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -130,9 +128,11 @@
|
|||
} else if (this.callbacks[group].reset) {
|
||||
this.reset(group);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -148,8 +148,51 @@
|
|||
*/
|
||||
detach (group)
|
||||
{
|
||||
delete this.callbacks[group];
|
||||
delete this.groups[group];
|
||||
return this.detachCallback(group) | this.detachGroup(group);
|
||||
};
|
||||
|
||||
/**
|
||||
* Detach callback
|
||||
*
|
||||
* @param {string|int} group Group id
|
||||
*
|
||||
* @return {void}
|
||||
*
|
||||
* @method
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
detachCallback(group)
|
||||
{
|
||||
if (this.callbacks.hasOwnProperty(group)) {
|
||||
delete this.callbacks[group];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Detach group
|
||||
*
|
||||
* @param {string|int} group Group id
|
||||
*
|
||||
* @return {void}
|
||||
*
|
||||
* @method
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
detachGroup(group)
|
||||
{
|
||||
if (this.groups.hasOwnProperty(group)) {
|
||||
delete this.groups[group];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -188,7 +231,7 @@
|
|||
*/
|
||||
count ()
|
||||
{
|
||||
return this.callbacks.length;
|
||||
return Object.keys(this.callbacks).length;
|
||||
};
|
||||
}
|
||||
}(window.jsOMS = window.jsOMS || {}));
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ describe('AccountTypeTest', function ()
|
|||
expect(Object.keys(jsOMS.Account.AccountType).length).toBe(2);
|
||||
});
|
||||
|
||||
it('Testing amount of enums', function ()
|
||||
it('Testing values of enums', function ()
|
||||
{
|
||||
expect(jsOMS.Account.AccountType.USER).toBe(0);
|
||||
expect(jsOMS.Account.AccountType.GROUP).toBe(1);
|
||||
|
|
|
|||
|
|
@ -2,14 +2,6 @@ describe('OptionsTest', function ()
|
|||
{
|
||||
"use strict";
|
||||
|
||||
beforeEach(function ()
|
||||
{
|
||||
});
|
||||
|
||||
afterEach(function ()
|
||||
{
|
||||
});
|
||||
|
||||
describe('testDefault', function ()
|
||||
{
|
||||
it('Testing default functionality', function ()
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ describe('LocalStorageTest', function ()
|
|||
{
|
||||
"use strict";
|
||||
|
||||
beforeEach(function ()
|
||||
{
|
||||
});
|
||||
|
||||
afterEach(function ()
|
||||
describe('testDefault', function ()
|
||||
{
|
||||
it('Testing default functionality', function ()
|
||||
{
|
||||
expect(jsOMS.DataStorage.LocalStorage.available()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,11 +2,76 @@ describe('EventManagerTest', function ()
|
|||
{
|
||||
"use strict";
|
||||
|
||||
beforeEach(function ()
|
||||
describe('testDefault', function ()
|
||||
{
|
||||
it('Testing default functionality', function ()
|
||||
{
|
||||
let manager = new jsOMS.Event.EventManager();
|
||||
|
||||
expect(manager.hasOutstanding('invalid')).toBeFalsy(null);
|
||||
expect(manager.trigger('invalid')).toBeFalsy(null);
|
||||
expect(manager.count()).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function ()
|
||||
describe('testBase', function ()
|
||||
{
|
||||
it('Testing base functionality', function ()
|
||||
{
|
||||
let manager = new jsOMS.Event.EventManager();
|
||||
|
||||
expect(manager.attach('group', function() { return true; }, false, false)).toBeTruthy();
|
||||
expect(manager.attach('group', function() { return true; }, false, false)).toBeFalsy();
|
||||
expect(manager.count()).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('testReset', function ()
|
||||
{
|
||||
it('Testing reset functionality', function ()
|
||||
{
|
||||
let manager = new jsOMS.Event.EventManager();
|
||||
|
||||
expect(manager.attach('group', function() { return true; }, false, true)).toBeTruthy();
|
||||
manager.addGroup('group', 'id1');
|
||||
manager.addGroup('group', 'id2');
|
||||
|
||||
expect(manager.trigger('group', 'id1')).toBeFalsy();
|
||||
expect(manager.trigger('group', 'id2')).toBeTruthy();
|
||||
expect(manager.trigger('group', 'id2')).toBeFalsy();
|
||||
expect(manager.count()).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('testDetach', function ()
|
||||
{
|
||||
it('Testing detach functionality', function ()
|
||||
{
|
||||
let manager = new jsOMS.Event.EventManager();
|
||||
|
||||
expect(manager.attach('group', function() { return true; }, false, true)).toBeTruthy();
|
||||
manager.addGroup('group', 'id1');
|
||||
manager.addGroup('group', 'id2');
|
||||
|
||||
expect(manager.count()).toBe(1);
|
||||
expect(manager.detach('group')).toBeTruthy();
|
||||
expect(manager.count()).toBe(0);
|
||||
expect(manager.detach('group')).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('testRemove', function ()
|
||||
{
|
||||
it('Testing remove functionality', function ()
|
||||
{
|
||||
let manager = new jsOMS.Event.EventManager();
|
||||
|
||||
expect(manager.attach('group1', function() { return true; }, true, false)).toBeTruthy();
|
||||
expect(manager.attach('group2', function() { return true; }, true, false)).toBeTruthy();
|
||||
expect(manager.count()).toBe(2);
|
||||
|
||||
manager.trigger('group1');
|
||||
expect(manager.count()).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
<!-- include source files here... -->
|
||||
<script src="../Asset/AssetManager.js"></script>
|
||||
<script src="../Autoloader.js"></script>
|
||||
<script src="../Log/Logger.js"></script>
|
||||
|
||||
<script src="../Account/Account.js"></script>
|
||||
<script src="../Account/AccountManager.js"></script>
|
||||
|
|
@ -25,6 +26,10 @@
|
|||
|
||||
<script src="../Config/Options.js"></script>
|
||||
|
||||
<script src="../DataStorage/LocalStorage.js"></script>
|
||||
|
||||
<script src="../Event/EventManager.js"></script>
|
||||
|
||||
<script src="../Uri/Http.js"></script>
|
||||
<script src="../Uri/UriFactory.js"></script>
|
||||
|
||||
|
|
@ -37,6 +42,10 @@
|
|||
|
||||
<script src="Config/OptionsTest.js"></script>
|
||||
|
||||
<script src="DataStorage/LocalStorageTest.js"></script>
|
||||
|
||||
<script src="Event/EventManagerTest.js"></script>
|
||||
|
||||
<script src="Uri/HttpTest.js"></script>
|
||||
<script src="Uri/UriFactoryTest.js"></script>
|
||||
</head>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user