2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test( "ajax get 200", assert => {
|
|
|
|
App.Config.set('api_path', '/api/v1')
|
2020-09-11 14:45:49 +00:00
|
|
|
var done = assert.async(1)
|
2013-07-10 06:46:59 +00:00
|
|
|
|
2020-09-11 14:45:49 +00:00
|
|
|
new Promise( (resolve, reject) => {
|
2020-05-28 07:48:43 +00:00
|
|
|
App.Ajax.request({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/assets/tests/ajax-test.json',
|
2020-09-11 14:45:49 +00:00
|
|
|
success: resolve,
|
|
|
|
error: reject
|
2013-07-10 06:46:59 +00:00
|
|
|
});
|
2020-09-11 14:45:49 +00:00
|
|
|
}).then( function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok( true, "File found!")
|
|
|
|
assert.equal(data.success, true, "content parsable and assert.ok!")
|
|
|
|
assert.equal(data.success2, undefined, "content parsable and assert.ok!")
|
2020-09-11 14:45:49 +00:00
|
|
|
}, function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok( false, "Failed!")
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
.finally(done)
|
|
|
|
});
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test( "ajax - queue - ajax get 200 1/2", assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
var done = assert.async(1)
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
2020-05-28 07:48:43 +00:00
|
|
|
App.Ajax.request({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/tests/wait/2',
|
|
|
|
queue: true,
|
2020-09-11 14:45:49 +00:00
|
|
|
success: resolve,
|
|
|
|
error: reject
|
2013-07-10 06:46:59 +00:00
|
|
|
});
|
2020-09-11 14:45:49 +00:00
|
|
|
}).then( function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok( !window.testAjax, 'ajax - queue - check queue')
|
2020-09-11 14:45:49 +00:00
|
|
|
window.testAjax = true;
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.equal(data.success, true, "ajax - queue - content parsable and assert.ok!")
|
|
|
|
assert.equal(data.success2, undefined, "ajax - queue - content parsable and assert.ok!")
|
2020-09-11 14:45:49 +00:00
|
|
|
}, function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok( false, "Failed!")
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
.finally(done)
|
|
|
|
});
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test( "ajax - queue - ajax get 200 2/2", assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
var done = assert.async(1)
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
2020-05-28 07:48:43 +00:00
|
|
|
App.Ajax.request({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/tests/wait/1',
|
|
|
|
queue: true,
|
2020-09-11 14:45:49 +00:00
|
|
|
success: resolve,
|
|
|
|
error: reject
|
2013-07-10 06:46:59 +00:00
|
|
|
});
|
2020-09-11 14:45:49 +00:00
|
|
|
}).then( function(data) {
|
|
|
|
|
|
|
|
// check queue
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok( window.testAjax, 'ajax - queue - check queue')
|
2020-09-11 14:45:49 +00:00
|
|
|
window.testAjax = undefined;
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.equal(data.success, true, "content parsable and assert.ok!")
|
|
|
|
assert.equal(data.success2, undefined, "content parsable and assert.ok!")
|
2020-09-11 14:45:49 +00:00
|
|
|
}, function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok( false, "Failed!")
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
.finally(done)
|
|
|
|
});
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test( "ajax - parallel - ajax get 200", assert => {
|
|
|
|
var done = assert.async(2)
|
2013-07-10 06:46:59 +00:00
|
|
|
|
2020-09-11 14:45:49 +00:00
|
|
|
new Promise( (resolve, reject) => {
|
2020-05-28 07:48:43 +00:00
|
|
|
App.Ajax.request({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/tests/wait/3',
|
2020-09-11 14:45:49 +00:00
|
|
|
success: resolve,
|
|
|
|
error: reject
|
2013-07-10 06:46:59 +00:00
|
|
|
});
|
2016-11-29 20:54:49 +00:00
|
|
|
|
2020-09-11 14:45:49 +00:00
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Ajax.request({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/tests/wait/1',
|
|
|
|
success: resolve,
|
|
|
|
error: reject
|
|
|
|
});
|
|
|
|
}).then( function(data) {
|
|
|
|
|
|
|
|
// check queue
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok( !window.testAjaxQ, 'ajax - parallel - check queue')
|
2020-09-11 14:45:49 +00:00
|
|
|
window.testAjaxQ = true;
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.equal(data.success, true, "content parsable and assert.ok!")
|
|
|
|
assert.equal(data.success2, undefined, "content parsable and assert.ok!")
|
2020-09-11 14:45:49 +00:00
|
|
|
}, function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok( false, "Failed!")
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
.finally(done)
|
|
|
|
}).then( function(data) {
|
|
|
|
|
|
|
|
// check queue
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok( window.testAjaxQ, 'ajax - parallel - check queue')
|
2020-09-11 14:45:49 +00:00
|
|
|
window.testAjaxQ = undefined;
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.equal(data.success, true, "ajax - parallel - content parsable and assert.ok!")
|
|
|
|
assert.equal(data.success2, undefined, "ajax - parallel - content parsable and assert.ok!")
|
|
|
|
done()
|
2020-09-11 14:45:49 +00:00
|
|
|
}, function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok( false, "Failed!")
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('delay - test', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
var done = assert.async(1)
|
|
|
|
|
|
|
|
window.testDelay1 = false
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Delay.set(resolve, 1000, 'delay-test1', 'level');
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Delay.set(resolve, 2000, 'delay-test1', 'level');
|
|
|
|
}).then( function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(!window.testDelay1, 'delay - 1/2')
|
2020-09-11 14:45:49 +00:00
|
|
|
window.testDelay1 = 1;
|
|
|
|
})
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Delay.set(resolve, 3000, 'delay-test1-verify', 'level');
|
|
|
|
}).then( function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(window.testDelay1, 'delay - 2/2')
|
2020-09-11 14:45:49 +00:00
|
|
|
window.testDelay1 = false;
|
|
|
|
})
|
|
|
|
.finally(done)
|
|
|
|
}).then( function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(false, 'delay - 1/2 - FAILED - should not be executed, will be reset by next set()')
|
2020-09-11 14:45:49 +00:00
|
|
|
window.testDelay1 = true;
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('delay - test 2', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
var done = assert.async(1)
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Delay.set(resolve, 2000);
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Delay.set(resolve, 1000);
|
|
|
|
}).then( function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(!window.testDelay2, 'delay - test 2 - 1/3')
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Delay.set(resolve, 3000);
|
|
|
|
}).then( function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(window.testDelay2, 'delay - test 2 - 3/3')
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
.finally(done)
|
|
|
|
}).then( function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(!window.testDelay2, 'delay - test 2 - 2/3')
|
2020-09-11 14:45:49 +00:00
|
|
|
window.testDelay2 = 1;
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('delay - test 3', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
var done = assert.async(1)
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Delay.set(resolve, 1000, 'delay3');
|
2020-05-28 07:48:43 +00:00
|
|
|
App.Delay.clear('delay3')
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(true, 'delay - test 3 - 1/1')
|
2020-09-11 14:45:49 +00:00
|
|
|
done()
|
|
|
|
}).then( function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(false, 'delay - test 3 - 1/1 - FAILED')
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('delay - test 4', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
var done = assert.async(1)
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Delay.set(resolve, 1000, undefined, 'Page');
|
2020-05-28 07:48:43 +00:00
|
|
|
App.Delay.clearLevel('Page')
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(true, 'delay - test 4 - 1/1')
|
2020-09-11 14:45:49 +00:00
|
|
|
done()
|
|
|
|
}).then( function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(false, 'delay - test 4 - 1/1 - FAILED')
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('interval - test 1', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
var done = assert.async(1)
|
|
|
|
|
|
|
|
window.testInterval1 = 1
|
|
|
|
App.Interval.set(function() {
|
|
|
|
window.testInterval1 += 1;
|
|
|
|
},
|
|
|
|
100,
|
|
|
|
'interval-test1'
|
|
|
|
);
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Delay.set(resolve, 1000);
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Delay.set(resolve, 2000);
|
|
|
|
}).then( function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.equal(window.testInterval1, window.testInterval1Backup, 'interval - did not change after clear interval')
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
.finally(done)
|
|
|
|
}).then( function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.notEqual(window.testInterval1, 1, 'interval - interval moved up')
|
2020-09-11 14:45:49 +00:00
|
|
|
App.Interval.clear('interval-test1')
|
|
|
|
window.testInterval1Backup = window.testInterval1;
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('interval - test 2', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
var done = assert.async(1)
|
|
|
|
|
|
|
|
window.testInterval1 = 1
|
|
|
|
App.Interval.set(function() {
|
|
|
|
window.testInterval1 += 1;
|
|
|
|
},
|
|
|
|
100,
|
|
|
|
undefined,
|
|
|
|
'someLevel'
|
|
|
|
);
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Delay.set(resolve, 1000);
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Delay.set(resolve, 2000);
|
|
|
|
}).then( function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.equal(window.testInterval1, window.testInterval1Backup, 'interval - did not change after clear interval')
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
.finally(done)
|
|
|
|
}).then( function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.notEqual(window.testInterval1, 1, 'interval - interval moved up')
|
2020-09-11 14:45:49 +00:00
|
|
|
App.Interval.clearLevel('someLevel')
|
|
|
|
window.testInterval1Backup = window.testInterval1;
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// events
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('events simple', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
|
|
|
|
// single bind
|
|
|
|
App.Event.bind('test1', function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(true, 'event received - single bind')
|
|
|
|
assert.equal(data.success, true, 'event received - data assert.ok - single bind')
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
|
|
|
App.Event.bind('test2', function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(false, 'should not be triggered - single bind')
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
|
|
|
App.Event.trigger('test1', { success: true })
|
|
|
|
|
|
|
|
App.Event.unbind('test1')
|
|
|
|
App.Event.bind('test1', function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(false, 'should not be triggered - single bind')
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
|
|
|
App.Event.unbind('test1')
|
|
|
|
App.Event.trigger('test1', { success: true })
|
|
|
|
|
|
|
|
// multi bind
|
|
|
|
App.Event.bind('test1-1 test1-2', function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(true, 'event received - multi bind')
|
|
|
|
assert.equal(data.success, true, 'event received - data assert.ok - multi bind')
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
|
|
|
App.Event.bind('test1-3', function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(false, 'should not be triggered - multi bind')
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
|
|
|
App.Event.trigger('test1-2', { success: true })
|
|
|
|
|
|
|
|
App.Event.unbind('test1-1')
|
|
|
|
App.Event.bind('test1-1', function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(false, 'should not be triggered - multi bind')
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
|
|
|
App.Event.trigger('test1-2', { success: true })
|
|
|
|
});
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('events level', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
|
|
|
|
// bind with level
|
|
|
|
App.Event.bind('test3', function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(false, 'should not be triggered!')
|
2020-09-11 14:45:49 +00:00
|
|
|
}, 'test-level')
|
|
|
|
|
|
|
|
// unbind with level
|
|
|
|
App.Event.unbindLevel( 'test-level')
|
|
|
|
|
|
|
|
// bind with level
|
|
|
|
App.Event.bind('test3', function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(true, 'event received')
|
|
|
|
assert.equal(data.success, true, 'event received - data assert.ok - level bind')
|
2020-09-11 14:45:49 +00:00
|
|
|
}, 'test-level')
|
|
|
|
App.Event.trigger('test3', { success: true})
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// session store
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('session store', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
|
|
|
|
var tests = [
|
|
|
|
'some 123äöüßadajsdaiosjdiaoidj',
|
|
|
|
{ key: 123 },
|
|
|
|
{ key1: { key1: [1,2,3,4] }, key2: [1,2,'äöüß'] },
|
|
|
|
];
|
|
|
|
|
|
|
|
// write/get
|
|
|
|
App.SessionStorage.clear()
|
|
|
|
_.each(tests, function(test) {
|
|
|
|
App.SessionStorage.set('test1', test)
|
|
|
|
var item = App.SessionStorage.get('test1')
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(test, item, 'write/get - compare stored and actual data')
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// undefined/get
|
|
|
|
App.SessionStorage.clear()
|
|
|
|
_.each(tests, function(test) {
|
|
|
|
var item = App.SessionStorage.get('test1')
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(undefined, item, 'undefined/get - compare not existing data and actual data')
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// write/get/delete
|
|
|
|
var tests = [
|
|
|
|
{ key: 'test1', value: 'some 123äöüßadajsdaiosjdiaoidj' },
|
|
|
|
{ key: 123, value: { a: 123, b: 'sdaad' } },
|
|
|
|
{ key: '123äöüß', value: { key1: [1,2,3,4] }, key2: [1,2,'äöüß'] },
|
|
|
|
];
|
|
|
|
|
|
|
|
App.SessionStorage.clear()
|
|
|
|
_.each(tests, function(test) {
|
|
|
|
App.SessionStorage.set(test.key, test.value)
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each(tests, function(test) {
|
|
|
|
var item = App.SessionStorage.get(test.key)
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(test.value, item, 'write/get/delete - compare stored and actual data')
|
2020-09-11 14:45:49 +00:00
|
|
|
App.SessionStorage.delete( test.key)
|
|
|
|
item = App.SessionStorage.get(test.key)
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(undefined, item, 'write/get/delete - compare deleted data')
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// config
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('config', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
|
|
|
|
// simple
|
|
|
|
var tests = [
|
|
|
|
{ key: 'test1', value: 'some 123äöüßadajsdaiosjdiaoidj' },
|
|
|
|
{ key: 123, value: { a: 123, b: 'sdaad' } },
|
|
|
|
{ key: '123äöüß', value: { key1: [1,2,3,4] }, key2: [1,2,'äöüß'] },
|
|
|
|
];
|
|
|
|
|
|
|
|
_.each(tests, function(test) {
|
|
|
|
App.Config.set(test.key, test.value )
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each(tests, function(test) {
|
|
|
|
var item = App.Config.get(test.key )
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(item, test.value, 'set/get tests')
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// group
|
|
|
|
var test_groups = [
|
|
|
|
{ key: 'test2', value: [ 'some 123äöüßadajsdaiosjdiaoidj' ] },
|
|
|
|
{ key: 1234, value: { a: 123, b: 'sdaad' } },
|
|
|
|
{ key: '123äöüß', value: { key1: [1,2,3,4,5,6] }, key2: [1,2,'äöüß'] },
|
|
|
|
];
|
|
|
|
var group = {};
|
|
|
|
_.each(test_groups, function(test) {
|
|
|
|
App.Config.set(test.key, test.value, 'group1')
|
|
|
|
group[test.key] = test.value
|
|
|
|
});
|
|
|
|
|
|
|
|
// verify whole group
|
|
|
|
var item = App.Config.get('group1')
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(item, group, 'group - verify group hash')
|
2020-09-11 14:45:49 +00:00
|
|
|
|
|
|
|
// verify each setting
|
|
|
|
_.each(test_groups, function(test) {
|
|
|
|
var item = App.Config.get(test.key, 'group1')
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(item, test.value, 'group set/get tests')
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// clone
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('clone', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
|
|
|
|
// simple
|
|
|
|
var tests = [
|
|
|
|
{
|
|
|
|
key1: 123,
|
|
|
|
key2: 1234
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key1: 123,
|
|
|
|
key2: '1234'
|
|
|
|
},
|
|
|
|
[1,2,4,5,6],
|
|
|
|
'some string äöü',
|
|
|
|
{
|
|
|
|
key1: 123,
|
|
|
|
key2: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key1: 123,
|
|
|
|
key2: undefined,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key1: 123,
|
|
|
|
key2: undefined,
|
|
|
|
key3: {
|
|
|
|
keya: 'some',
|
|
|
|
keyb: undefined,
|
2020-05-28 07:48:43 +00:00
|
|
|
},
|
2020-09-11 14:45:49 +00:00
|
|
|
key4: ['a', 'b', null, false, true, undefined],
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
key1: 123,
|
|
|
|
key2: undefined,
|
|
|
|
key3: {
|
|
|
|
keya: 'some',
|
|
|
|
keyb: undefined,
|
2020-05-28 07:48:43 +00:00
|
|
|
},
|
2020-09-11 14:45:49 +00:00
|
|
|
key4: ['a', 'b', {
|
|
|
|
a: 123,
|
|
|
|
b: [1,5,7,8,1213,1231321]
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
_.each(tests, function(test) {
|
|
|
|
var item = clone( test )
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(item, test, 'clone')
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// complex test
|
|
|
|
var source = [
|
|
|
|
{ name: 'some name' },
|
|
|
|
{ name: 'some name2' },
|
|
|
|
{ fn: function() { return 'test' } },
|
|
|
|
]
|
|
|
|
var reference = [
|
|
|
|
{ name: 'some name' },
|
|
|
|
{ name: 'some name2' },
|
|
|
|
{ fn: undefined },
|
|
|
|
]
|
|
|
|
var result = clone( source )
|
|
|
|
|
|
|
|
// modify source later, should not have any result
|
|
|
|
source[0].name = 'some new name'
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(result, reference, 'clone')
|
2020-09-11 14:45:49 +00:00
|
|
|
|
|
|
|
// full test
|
|
|
|
var source = [
|
|
|
|
{ name: 'some name' },
|
|
|
|
{ name: 'some name2' },
|
|
|
|
{ fn: function a() { return 'test' } },
|
|
|
|
]
|
|
|
|
var reference = [
|
|
|
|
{ name: 'some name' },
|
|
|
|
{ name: 'some name2' },
|
|
|
|
{ fn: function a() { return 'test' } },
|
|
|
|
]
|
|
|
|
var result = clone( source, true )
|
|
|
|
|
|
|
|
// modify source later, should not have any result
|
|
|
|
source[0].name = 'some new name'
|
|
|
|
source[2].fn = 'some new name'
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(result[0], reference[0], 'clone full')
|
|
|
|
assert.deepEqual(result[1], reference[1], 'clone full')
|
2020-09-11 14:45:49 +00:00
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.equal(typeof reference[2].fn, 'function')
|
|
|
|
assert.equal(typeof result[2].fn, 'function')
|
2020-09-11 14:45:49 +00:00
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.equal(reference[2].fn(), 'test')
|
|
|
|
assert.equal(result[2].fn(), 'test')
|
2020-09-11 14:45:49 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// diff
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('difference', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
|
|
|
|
// simple
|
|
|
|
var object1 = {
|
|
|
|
key1: 123,
|
|
|
|
key2: 1234
|
|
|
|
}
|
|
|
|
var object2 = {
|
|
|
|
key1: 123,
|
|
|
|
key2: 1235
|
|
|
|
}
|
|
|
|
var result = {
|
|
|
|
key2: 1235
|
|
|
|
}
|
|
|
|
var item = difference(object1, object2)
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(item, result)
|
2020-05-28 07:48:43 +00:00
|
|
|
|
2020-09-11 14:45:49 +00:00
|
|
|
object1 = {
|
|
|
|
key1: 123,
|
|
|
|
key2: 123
|
|
|
|
}
|
|
|
|
object2 = {
|
|
|
|
key1: 123,
|
|
|
|
key2: 123
|
|
|
|
}
|
|
|
|
result = {}
|
|
|
|
item = difference(object1, object2)
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(item, result)
|
2020-05-28 07:48:43 +00:00
|
|
|
|
2020-09-11 14:45:49 +00:00
|
|
|
object1 = {
|
|
|
|
key1: 123,
|
|
|
|
key2: [1,3,5]
|
|
|
|
}
|
|
|
|
object2 = {
|
|
|
|
key1: 123,
|
|
|
|
key2: 123
|
|
|
|
}
|
|
|
|
result = {
|
|
|
|
key2: 123
|
|
|
|
}
|
|
|
|
item = difference(object1, object2)
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(item, result)
|
2016-11-29 20:54:49 +00:00
|
|
|
|
2020-09-11 14:45:49 +00:00
|
|
|
object1 = {
|
|
|
|
key1: 123,
|
|
|
|
key2: [1,3,5]
|
|
|
|
}
|
|
|
|
object2 = {
|
|
|
|
key1: 123,
|
|
|
|
}
|
|
|
|
result = {}
|
|
|
|
item = difference(object1, object2)
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(item, result)
|
2016-11-29 20:54:49 +00:00
|
|
|
|
2020-09-11 14:45:49 +00:00
|
|
|
object1 = {
|
|
|
|
key1: 123,
|
|
|
|
}
|
|
|
|
object2 = {
|
|
|
|
key1: 123,
|
|
|
|
key2: 124
|
|
|
|
}
|
|
|
|
result = {}
|
|
|
|
item = difference(object1, object2)
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(item, result)
|
2020-05-28 07:48:43 +00:00
|
|
|
|
2020-09-11 14:45:49 +00:00
|
|
|
object1 = {
|
|
|
|
customer_id: 1,
|
|
|
|
organization_id: 2,
|
|
|
|
}
|
|
|
|
object2 = {
|
|
|
|
customer_id: 1,
|
|
|
|
organization_id: null,
|
|
|
|
}
|
|
|
|
result = {
|
|
|
|
organization_id: null,
|
|
|
|
}
|
|
|
|
item = difference(object1, object2)
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(item, result)
|
2016-11-29 20:54:49 +00:00
|
|
|
|
2020-09-11 14:45:49 +00:00
|
|
|
object1 = {
|
|
|
|
customer_id: 1,
|
|
|
|
organization_id: null,
|
|
|
|
}
|
|
|
|
object2 = {
|
|
|
|
customer_id: 1,
|
|
|
|
organization_id: 2,
|
|
|
|
}
|
|
|
|
result = {
|
|
|
|
organization_id: 2,
|
|
|
|
}
|
|
|
|
item = difference(object1, object2)
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.deepEqual(item, result)
|
2016-11-29 20:54:49 +00:00
|
|
|
|
2020-09-11 14:45:49 +00:00
|
|
|
});
|
2016-11-29 20:54:49 +00:00
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('auth - not existing user', assert => {
|
2020-09-11 14:45:49 +00:00
|
|
|
var done = assert.async(1)
|
2016-11-29 20:54:49 +00:00
|
|
|
|
2020-09-11 14:45:49 +00:00
|
|
|
new Promise( (resolve, reject) => {
|
2020-05-28 07:48:43 +00:00
|
|
|
App.Auth.login({
|
|
|
|
data: {
|
|
|
|
username: 'not_existing',
|
|
|
|
password: 'not_existing',
|
2015-01-28 22:12:16 +00:00
|
|
|
},
|
2020-09-11 14:45:49 +00:00
|
|
|
success: resolve,
|
|
|
|
error: reject
|
|
|
|
});
|
|
|
|
}).then( function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(false, 'ok')
|
2020-09-11 14:45:49 +00:00
|
|
|
}, function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(true, 'ok')
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
.finally(done)
|
|
|
|
})
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test('auth - existing user', assert => {
|
|
|
|
App.Config.set('api_path', '/api/v1')
|
2020-09-11 14:45:49 +00:00
|
|
|
var done = assert.async(1)
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Auth.login({
|
|
|
|
data: {
|
2021-08-17 12:10:02 +00:00
|
|
|
username: 'admin@example.com',
|
2020-09-11 14:45:49 +00:00
|
|
|
password: 'test',
|
2015-01-28 22:12:16 +00:00
|
|
|
},
|
2020-09-11 14:45:49 +00:00
|
|
|
success: resolve,
|
|
|
|
error: reject
|
2020-05-28 07:48:43 +00:00
|
|
|
});
|
2020-09-11 14:45:49 +00:00
|
|
|
}).then( function(data) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(true, 'authenticated')
|
2020-09-11 14:45:49 +00:00
|
|
|
var user = App.Session.get('login')
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.equal('admin@example.com', user, 'session login')
|
2020-09-11 14:45:49 +00:00
|
|
|
}, function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(false, 'failed')
|
2020-09-11 14:45:49 +00:00
|
|
|
})
|
|
|
|
.finally(done)
|
|
|
|
})
|