Maintenance: Unpredictable JS parsing and App boot up time causes race condition for JS Core interval (timing) tests.

This commit is contained in:
Thorsten Eckel 2020-05-28 09:48:43 +02:00
parent a7ee192c9d
commit f14607e265
2 changed files with 787 additions and 780 deletions

View file

@ -1,7 +1,8 @@
window.onload = function() {
// ajax
App.Ajax.request({
callback = function() {
// ajax
App.Ajax.request({
type: 'GET',
url: '/assets/tests/ajax-test.json',
success: function (data) {
@ -16,10 +17,10 @@ App.Ajax.request({
ok( false, "Failed!")
});
}
});
});
// ajax queueing
App.Ajax.request({
// ajax queueing
App.Ajax.request({
type: 'GET',
url: '/tests/wait/2',
queue: true,
@ -38,8 +39,8 @@ App.Ajax.request({
ok( false, "Failed!")
});
}
});
App.Ajax.request({
});
App.Ajax.request({
type: 'GET',
url: '/tests/wait/1',
queue: true,
@ -58,10 +59,10 @@ App.Ajax.request({
ok( false, "Failed!")
});
}
});
});
// ajax parallel
App.Ajax.request({
// ajax parallel
App.Ajax.request({
type: 'GET',
url: '/tests/wait/3',
success: function (data) {
@ -79,8 +80,8 @@ App.Ajax.request({
ok( false, "Failed!")
});
}
});
App.Ajax.request({
});
App.Ajax.request({
type: 'GET',
url: '/tests/wait/1',
success: function (data) {
@ -98,11 +99,11 @@ App.Ajax.request({
ok( false, "Failed!")
});
}
});
});
// delay
window.testDelay1 = false
App.Delay.set(function() {
// delay
window.testDelay1 = false
App.Delay.set(function() {
test('delay - test 1 - 1/3 - should not be executed, will be reset by next set()', function() {
// check
@ -113,8 +114,8 @@ App.Delay.set(function() {
1000,
'delay-test1',
'level'
);
App.Delay.set(function() {
);
App.Delay.set(function() {
test('delay - test 1 - 2/3', function() {
// check
@ -125,8 +126,8 @@ App.Delay.set(function() {
2000,
'delay-test1',
'level'
);
App.Delay.set(function() {
);
App.Delay.set(function() {
test('delay - test 1 - 2/3', function() {
// check
@ -137,9 +138,9 @@ App.Delay.set(function() {
3000,
'delay-test1-verify',
'level'
);
);
App.Delay.set(function() {
App.Delay.set(function() {
test('delay - test 2 - 1/3', function() {
// check
@ -148,8 +149,8 @@ App.Delay.set(function() {
});
},
2000
);
App.Delay.set(function() {
);
App.Delay.set(function() {
test('delay - test 2 - 2/3', function() {
// check
@ -157,8 +158,8 @@ App.Delay.set(function() {
});
},
1000
);
App.Delay.set(function() {
);
App.Delay.set(function() {
test('delay - test 2 - 3/3', function() {
// check
@ -166,10 +167,10 @@ App.Delay.set(function() {
});
},
3000
);
);
window.testDelay3 = 1;
App.Delay.set(function() {
window.testDelay3 = 1;
App.Delay.set(function() {
test('delay - test 3 - 1/1', function() {
// check
@ -178,10 +179,10 @@ App.Delay.set(function() {
},
1000,
'delay3'
);
App.Delay.clear('delay3')
);
App.Delay.clear('delay3')
App.Delay.set(function() {
App.Delay.set(function() {
test('delay - test 4 - 1/1', function() {
// check
@ -191,19 +192,19 @@ App.Delay.set(function() {
1000,
undefined,
'Page'
);
App.Delay.clearLevel('Page')
);
App.Delay.clearLevel('Page')
// interval 1
window.testInterval1 = 1
App.Interval.set(function() {
// interval 1
window.testInterval1 = 1
App.Interval.set(function() {
window.testInterval1 += 1;
},
2000,
'interval-test1'
);
App.Delay.set(function() {
);
App.Delay.set(function() {
test('interval - test 1 - 1/2', function() {
// check
@ -212,8 +213,8 @@ App.Delay.set(function() {
});
},
5200
);
App.Delay.set(function() {
);
App.Delay.set(function() {
test('interval - test 1 - 2/2', function() {
// check
@ -221,19 +222,19 @@ App.Delay.set(function() {
});
},
6500
);
);
// interval 2
window.testInterval2 = 1
App.Interval.set(function() {
// interval 2
window.testInterval2 = 1
App.Interval.set(function() {
window.testInterval2 += 1;
},
2000,
undefined,
'someLevel'
);
App.Delay.set(function() {
);
App.Delay.set(function() {
test('interval - test 2 - 1/2', function() {
// check
@ -242,8 +243,8 @@ App.Delay.set(function() {
});
},
5200
);
App.Delay.set(function() {
);
App.Delay.set(function() {
test('interval - test 2 - 2/2', function() {
// check
@ -251,180 +252,11 @@ App.Delay.set(function() {
});
},
6900
);
);
// i18n
test('i18n', function() {
// de
App.i18n.set('de-de')
var translated = App.i18n.translateContent('yes')
equal(translated, 'ja', 'de-de - yes / ja translated correctly')
translated = App.i18n.translatePlain('yes')
equal(translated, 'ja', 'de-de - yes / ja translated correctly')
translated = App.i18n.translateInline('yes')
equal(translated, 'ja', 'de-de - yes / ja translated correctly')
translated = App.i18n.translateContent('%s ago', 123);
equal(translated, 'vor 123', 'de-de - %s')
translated = App.i18n.translateContent('%s ago', '<b>quote</b>')
equal(translated, 'vor &lt;b&gt;quote&lt;/b&gt;', 'de-de - %s - quote')
translated = App.i18n.translateContent('%s %s test', 123, 'xxx |B|')
equal(translated, '123 xxx |B| test', 'de-de - %s %s')
translated = App.i18n.translateContent('|%s| %s test', 123, 'xxx')
equal(translated, '<b>123</b> xxx test', 'de-de - *%s* %s')
translated = App.i18n.translateContent('||%s|| %s test', 123, 'xxx')
equal(translated, '<i>123</i> xxx test', 'de-de - *%s* %s')
translated = App.i18n.translateContent('_%s_ %s test', 123, 'xxx')
equal(translated, '<u>123</u> xxx test', 'de-de - _%s_ %s')
translated = App.i18n.translateContent('§%s§ %s test', 123, 'xxx')
equal(translated, '<kbd>123</kbd> xxx test', 'de-de - §%s§ %s')
translated = App.i18n.translateContent('//%s// %s test', 123, 'xxx')
equal(translated, '<del>123</del> xxx test', 'de-de - //%s// %s')
translated = App.i18n.translateContent('\'%s\' %s test', 123, 'xxx')
equal(translated, '&#39;123&#39; xxx test', 'de-de - \'%s\' %s')
translated = App.i18n.translateContent('<test&now>//*äöüß')
equal(translated, '&lt;test&amp;now&gt;//*äöüß', 'de - <test&now>//*äöüß')
translated = App.i18n.translateContent('some link [to what ever](http://lalala)')
equal(translated, 'some link <a href="http://lalala" target="_blank">to what ever</a>', 'de-de - link')
translated = App.i18n.translateContent('some link [to what ever](%s)', 'http://lalala')
equal(translated, 'some link <a href="http://lalala" target="_blank">to what ever</a>', 'de-de - link')
translated = App.i18n.translateContent('Enables user authentication via %s. Register your app first at [%s](%s).', 'XXX', 'YYY', 'http://lalala')
equal(translated, 'Aktivieren der Benutzeranmeldung über XXX. Registriere Deine Anwendung zuerst über <a href="http://lalala" target="_blank">YYY</a>.', 'en-us - link')
var time_local = new Date();
var offset = time_local.getTimezoneOffset();
var timestamp = App.i18n.translateTimestamp('2012-11-06T21:07:24Z', offset);
equal(timestamp, '06.11.2012 21:07', 'de-de - timestamp translated correctly')
timestamp = App.i18n.translateTimestamp('', offset);
equal(timestamp, '', 'de-de - timestamp translated correctly')
timestamp = App.i18n.translateTimestamp(null, offset);
equal(timestamp, null, 'de-de - timestamp translated correctly')
timestamp = App.i18n.translateTimestamp(undefined, offset);
equal(timestamp, undefined, 'de-de - timestamp translated correctly')
var date = App.i18n.translateDate('2012-11-06', 0)
equal(date, '06.11.2012', 'de-de - date translated correctly')
date = App.i18n.translateDate('', 0)
equal(date, '', 'de-de - date translated correctly')
date = App.i18n.translateDate(null, 0)
equal(date, null, 'de-de - date translated correctly')
date = App.i18n.translateDate(undefined, 0)
equal(date, undefined, 'de-de - date translated correctly')
// en
App.i18n.set('en-us')
translated = App.i18n.translateContent('yes')
equal(translated, 'yes', 'en-us - yes translated correctly')
translated = App.i18n.translatePlain('yes')
equal(translated, 'yes', 'en-us - yes translated correctly')
translated = App.i18n.translateInline('yes')
equal(translated, 'yes', 'en-us - yes translated correctly')
translated = App.i18n.translateContent('%s ago', 123);
equal(translated, '123 ago', 'en-us - %s')
translated = App.i18n.translateContent('%s ago', '<b>quote</b>')
equal(translated, '&lt;b&gt;quote&lt;/b&gt; ago', 'en-us - %s - qupte')
translated = App.i18n.translateContent('%s %s test', 123, 'xxx')
equal(translated, '123 xxx test', 'en-us - %s %s')
translated = App.i18n.translateContent('|%s| %s test', 123, 'xxx |B|')
equal(translated, '<b>123</b> xxx |B| test', 'en-us - *%s* %s')
translated = App.i18n.translateContent('||%s|| %s test', 123, 'xxx')
equal(translated, '<i>123</i> xxx test', 'en-us - *%s* %s')
translated = App.i18n.translateContent('_%s_ %s test', 123, 'xxx')
equal(translated, '<u>123</u> xxx test', 'en-us - _%s_ %s')
translated = App.i18n.translateContent('§%s§ %s test', 123, 'xxx')
equal(translated, '<kbd>123</kbd> xxx test', 'en-us - §%s§ %s')
translated = App.i18n.translateContent('Here you can search for tickets, customers and organizations. Use the wildcard §*§ to find everything. E. g. §smi*§ or §rosent*l§. You also can use ||double quotes|| for searching phrases §"some phrase"§.')
equal(translated, 'Here you can search for tickets, customers and organizations. Use the wildcard <kbd>*</kbd> to find everything. E. g. <kbd>smi*</kbd> or <kbd>rosent*l</kbd>. You also can use <i>double quotes</i> for searching phrases <kbd>&quot;some phrase&quot;</kbd>.', 'en-us - §§ §§ §§ || §§')
translated = App.i18n.translateContent('//%s// %s test', 123, 'xxx')
equal(translated, '<del>123</del> xxx test', 'en-us - //%s// %s')
translated = App.i18n.translateContent('\'%s\' %s test', 123, 'xxx')
equal(translated, '&#39;123&#39; xxx test', 'en-us - \'%s\' %s')
translated = App.i18n.translateContent('<test&now>')
equal(translated, '&lt;test&amp;now&gt;', 'en-us - <test&now>')
translated = App.i18n.translateContent('some link [to what ever](http://lalala)')
equal(translated, 'some link <a href="http://lalala" target="_blank">to what ever</a>', 'en-us - link')
translated = App.i18n.translateContent('some link [to what ever](%s)', 'http://lalala')
equal(translated, 'some link <a href="http://lalala" target="_blank">to what ever</a>', 'en-us - link')
translated = App.i18n.translateContent('Enables user authentication via %s. Register your app first at [%s](%s).', 'XXX', 'YYY', 'http://lalala')
equal(translated, 'Enables user authentication via XXX. Register your app first at <a href="http://lalala" target="_blank">YYY</a>.', 'en-us - link')
timestamp = App.i18n.translateTimestamp('2012-11-06T21:07:24Z', offset)
equal(timestamp, '11/06/2012 21:07', 'en - timestamp translated correctly')
timestamp = App.i18n.translateTimestamp('', offset);
equal(timestamp, '', 'en - timestamp translated correctly')
timestamp = App.i18n.translateTimestamp(null, offset);
equal(timestamp, null, 'en - timestamp translated correctly')
timestamp = App.i18n.translateTimestamp(undefined, offset);
equal(timestamp, undefined, 'en - timestamp translated correctly')
date = App.i18n.translateDate('2012-11-06', 0)
equal(date, '11/06/2012', 'en - date translated correctly')
date = App.i18n.translateDate('', 0)
equal(date, '', 'en - date translated correctly')
date = App.i18n.translateDate(null, 0)
equal(date, null, 'en - date translated correctly')
date = App.i18n.translateDate(undefined, 0)
equal(date, undefined, 'en - date translated correctly')
// locale alias test
// de
App.i18n.set('de')
var translated = App.i18n.translateContent('yes')
equal(translated, 'ja', 'de - yes / ja translated correctly')
// locale detection test
// de-ch
App.i18n.set('de-ch')
var translated = App.i18n.translateContent('yes')
equal(translated, 'ja', 'de - yes / ja translated correctly')
});
// events
test('events simple', function() {
// events
test('events simple', function() {
// single bind
App.Event.bind('test1', function(data) {
@ -458,9 +290,9 @@ test('events simple', function() {
ok(false, 'should not be triggered - multi bind')
});
App.Event.trigger('test1-2', { success: true })
});
});
test('events level', function() {
test('events level', function() {
// bind with level
App.Event.bind('test3', function(data) {
@ -477,10 +309,10 @@ test('events level', function() {
}, 'test-level')
App.Event.trigger('test3', { success: true})
});
});
// session store
test('session store', function() {
// session store
test('session store', function() {
var tests = [
'some 123äöüßadajsdaiosjdiaoidj',
@ -523,10 +355,10 @@ test('session store', function() {
deepEqual(undefined, item, 'write/get/delete - compare deleted data')
});
});
});
// config
test('config', function() {
// config
test('config', function() {
// simple
var tests = [
@ -565,11 +397,11 @@ test('config', function() {
var item = App.Config.get(test.key, 'group1')
deepEqual(item, test.value, 'group set/get tests')
});
});
});
// clone
test('clone', function() {
// clone
test('clone', function() {
// simple
var tests = [
@ -667,10 +499,10 @@ test('clone', function() {
equal(reference[2].fn(), 'test')
equal(result[2].fn(), 'test')
});
});
// diff
test('difference', function() {
// diff
test('difference', function() {
// simple
var object1 = {
@ -763,10 +595,10 @@ test('difference', function() {
item = difference(object1, object2)
deepEqual(item, result)
});
});
// auth
App.Auth.login({
// auth
App.Auth.login({
data: {
username: 'not_existing',
password: 'not_existing',
@ -782,9 +614,9 @@ App.Auth.login({
authWithSession()
})
}
});
});
var authWithSession = function() {
var authWithSession = function() {
App.Auth.login({
data: {
username: 'master@example.com',
@ -803,6 +635,12 @@ var authWithSession = function() {
})
}
});
}
}
}
// run tests after the app has been initialized to avoid race condition
// between interval (timing) checks that may delayed by JS parsing
// and App initialization
App.Event.bind("app:ready", callback)
}

View file

@ -55,4 +55,173 @@ test('i18n .detectBrowserLocale', function() {
equal(App.i18n.detectBrowserLocale(), 'lt')
reset()
// i18n
test('i18n', function() {
// de
App.i18n.set('de-de')
var translated = App.i18n.translateContent('yes')
equal(translated, 'ja', 'de-de - yes / ja translated correctly')
translated = App.i18n.translatePlain('yes')
equal(translated, 'ja', 'de-de - yes / ja translated correctly')
translated = App.i18n.translateInline('yes')
equal(translated, 'ja', 'de-de - yes / ja translated correctly')
translated = App.i18n.translateContent('%s ago', 123);
equal(translated, 'vor 123', 'de-de - %s')
translated = App.i18n.translateContent('%s ago', '<b>quote</b>')
equal(translated, 'vor &lt;b&gt;quote&lt;/b&gt;', 'de-de - %s - quote')
translated = App.i18n.translateContent('%s %s test', 123, 'xxx |B|')
equal(translated, '123 xxx |B| test', 'de-de - %s %s')
translated = App.i18n.translateContent('|%s| %s test', 123, 'xxx')
equal(translated, '<b>123</b> xxx test', 'de-de - *%s* %s')
translated = App.i18n.translateContent('||%s|| %s test', 123, 'xxx')
equal(translated, '<i>123</i> xxx test', 'de-de - *%s* %s')
translated = App.i18n.translateContent('_%s_ %s test', 123, 'xxx')
equal(translated, '<u>123</u> xxx test', 'de-de - _%s_ %s')
translated = App.i18n.translateContent('§%s§ %s test', 123, 'xxx')
equal(translated, '<kbd>123</kbd> xxx test', 'de-de - §%s§ %s')
translated = App.i18n.translateContent('//%s// %s test', 123, 'xxx')
equal(translated, '<del>123</del> xxx test', 'de-de - //%s// %s')
translated = App.i18n.translateContent('\'%s\' %s test', 123, 'xxx')
equal(translated, '&#39;123&#39; xxx test', 'de-de - \'%s\' %s')
translated = App.i18n.translateContent('<test&now>//*äöüß')
equal(translated, '&lt;test&amp;now&gt;//*äöüß', 'de - <test&now>//*äöüß')
translated = App.i18n.translateContent('some link [to what ever](http://lalala)')
equal(translated, 'some link <a href="http://lalala" target="_blank">to what ever</a>', 'de-de - link')
translated = App.i18n.translateContent('some link [to what ever](%s)', 'http://lalala')
equal(translated, 'some link <a href="http://lalala" target="_blank">to what ever</a>', 'de-de - link')
translated = App.i18n.translateContent('Enables user authentication via %s. Register your app first at [%s](%s).', 'XXX', 'YYY', 'http://lalala')
equal(translated, 'Aktivieren der Benutzeranmeldung über XXX. Registriere Deine Anwendung zuerst über <a href="http://lalala" target="_blank">YYY</a>.', 'en-us - link')
var time_local = new Date();
var offset = time_local.getTimezoneOffset();
var timestamp = App.i18n.translateTimestamp('2012-11-06T21:07:24Z', offset);
equal(timestamp, '06.11.2012 21:07', 'de-de - timestamp translated correctly')
timestamp = App.i18n.translateTimestamp('', offset);
equal(timestamp, '', 'de-de - timestamp translated correctly')
timestamp = App.i18n.translateTimestamp(null, offset);
equal(timestamp, null, 'de-de - timestamp translated correctly')
timestamp = App.i18n.translateTimestamp(undefined, offset);
equal(timestamp, undefined, 'de-de - timestamp translated correctly')
var date = App.i18n.translateDate('2012-11-06', 0)
equal(date, '06.11.2012', 'de-de - date translated correctly')
date = App.i18n.translateDate('', 0)
equal(date, '', 'de-de - date translated correctly')
date = App.i18n.translateDate(null, 0)
equal(date, null, 'de-de - date translated correctly')
date = App.i18n.translateDate(undefined, 0)
equal(date, undefined, 'de-de - date translated correctly')
// en
App.i18n.set('en-us')
translated = App.i18n.translateContent('yes')
equal(translated, 'yes', 'en-us - yes translated correctly')
translated = App.i18n.translatePlain('yes')
equal(translated, 'yes', 'en-us - yes translated correctly')
translated = App.i18n.translateInline('yes')
equal(translated, 'yes', 'en-us - yes translated correctly')
translated = App.i18n.translateContent('%s ago', 123);
equal(translated, '123 ago', 'en-us - %s')
translated = App.i18n.translateContent('%s ago', '<b>quote</b>')
equal(translated, '&lt;b&gt;quote&lt;/b&gt; ago', 'en-us - %s - qupte')
translated = App.i18n.translateContent('%s %s test', 123, 'xxx')
equal(translated, '123 xxx test', 'en-us - %s %s')
translated = App.i18n.translateContent('|%s| %s test', 123, 'xxx |B|')
equal(translated, '<b>123</b> xxx |B| test', 'en-us - *%s* %s')
translated = App.i18n.translateContent('||%s|| %s test', 123, 'xxx')
equal(translated, '<i>123</i> xxx test', 'en-us - *%s* %s')
translated = App.i18n.translateContent('_%s_ %s test', 123, 'xxx')
equal(translated, '<u>123</u> xxx test', 'en-us - _%s_ %s')
translated = App.i18n.translateContent('§%s§ %s test', 123, 'xxx')
equal(translated, '<kbd>123</kbd> xxx test', 'en-us - §%s§ %s')
translated = App.i18n.translateContent('Here you can search for tickets, customers and organizations. Use the wildcard §*§ to find everything. E. g. §smi*§ or §rosent*l§. You also can use ||double quotes|| for searching phrases §"some phrase"§.')
equal(translated, 'Here you can search for tickets, customers and organizations. Use the wildcard <kbd>*</kbd> to find everything. E. g. <kbd>smi*</kbd> or <kbd>rosent*l</kbd>. You also can use <i>double quotes</i> for searching phrases <kbd>&quot;some phrase&quot;</kbd>.', 'en-us - §§ §§ §§ || §§')
translated = App.i18n.translateContent('//%s// %s test', 123, 'xxx')
equal(translated, '<del>123</del> xxx test', 'en-us - //%s// %s')
translated = App.i18n.translateContent('\'%s\' %s test', 123, 'xxx')
equal(translated, '&#39;123&#39; xxx test', 'en-us - \'%s\' %s')
translated = App.i18n.translateContent('<test&now>')
equal(translated, '&lt;test&amp;now&gt;', 'en-us - <test&now>')
translated = App.i18n.translateContent('some link [to what ever](http://lalala)')
equal(translated, 'some link <a href="http://lalala" target="_blank">to what ever</a>', 'en-us - link')
translated = App.i18n.translateContent('some link [to what ever](%s)', 'http://lalala')
equal(translated, 'some link <a href="http://lalala" target="_blank">to what ever</a>', 'en-us - link')
translated = App.i18n.translateContent('Enables user authentication via %s. Register your app first at [%s](%s).', 'XXX', 'YYY', 'http://lalala')
equal(translated, 'Enables user authentication via XXX. Register your app first at <a href="http://lalala" target="_blank">YYY</a>.', 'en-us - link')
timestamp = App.i18n.translateTimestamp('2012-11-06T21:07:24Z', offset)
equal(timestamp, '11/06/2012 21:07', 'en - timestamp translated correctly')
timestamp = App.i18n.translateTimestamp('', offset);
equal(timestamp, '', 'en - timestamp translated correctly')
timestamp = App.i18n.translateTimestamp(null, offset);
equal(timestamp, null, 'en - timestamp translated correctly')
timestamp = App.i18n.translateTimestamp(undefined, offset);
equal(timestamp, undefined, 'en - timestamp translated correctly')
date = App.i18n.translateDate('2012-11-06', 0)
equal(date, '11/06/2012', 'en - date translated correctly')
date = App.i18n.translateDate('', 0)
equal(date, '', 'en - date translated correctly')
date = App.i18n.translateDate(null, 0)
equal(date, null, 'en - date translated correctly')
date = App.i18n.translateDate(undefined, 0)
equal(date, undefined, 'en - date translated correctly')
// locale alias test
// de
App.i18n.set('de')
var translated = App.i18n.translateContent('yes')
equal(translated, 'ja', 'de - yes / ja translated correctly')
// locale detection test
// de-ch
App.i18n.set('de-ch')
var translated = App.i18n.translateContent('yes')
equal(translated, 'ja', 'de - yes / ja translated correctly')
});
})