2021-10-14 14:35:12 +00:00
|
|
|
function check_ajax_field(field, value, count, callback, assert, waitTotal = 30000, wait = 0) {
|
2020-09-24 11:34:04 +00:00
|
|
|
$elementInput = $('[name="' + field + '"].js-shadow + .js-input')
|
|
|
|
if ($elementInput.val() != value) {
|
2022-02-02 09:51:08 +00:00
|
|
|
$elementInput.trigger('focus').val(value).trigger('input')
|
2020-09-24 11:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var $element = $('[name="' + field + '"]').closest('.searchableSelect').find('.js-optionsList')
|
|
|
|
var entries = $element.find('li:not(.is-hidden)').length
|
|
|
|
var match = entries == count
|
|
|
|
|
|
|
|
if (match || wait >= waitTotal) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.equal(entries, count, 'search result found for email address ' + value)
|
2020-09-24 11:34:04 +00:00
|
|
|
callback()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
wait += 100
|
|
|
|
if (wait % 3000 == 0) {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.ok(true, 'check_ajax_field for ' + field + ' waiting ' + wait)
|
2020-09-24 11:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2021-10-14 14:35:12 +00:00
|
|
|
check_ajax_field(field, value, count, callback, assert, waitTotal, wait)
|
2020-09-24 11:34:04 +00:00
|
|
|
}, 100)
|
|
|
|
}
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
QUnit.test( "autocompletion_ajax check", assert => {
|
2020-09-24 11:34:04 +00:00
|
|
|
var done = assert.async(1)
|
|
|
|
|
|
|
|
$('#forms').append('<hr><h1>autocompletion_ajax check</h1><form id="form1"></form>')
|
|
|
|
var el = $('#form1')
|
|
|
|
|
|
|
|
new App.ControllerForm({
|
|
|
|
el: el,
|
|
|
|
model: {
|
|
|
|
configure_attributes: [
|
|
|
|
{
|
|
|
|
name: 'autocompletion_ajax1',
|
|
|
|
display: 'AutocompletionAjax1',
|
|
|
|
tag: 'autocompletion_ajax',
|
|
|
|
relation: 'User'
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
autofocus: true
|
|
|
|
})
|
|
|
|
|
|
|
|
new Promise( (resolve, reject) => {
|
|
|
|
App.Auth.login({
|
|
|
|
data: {
|
2021-08-17 12:10:02 +00:00
|
|
|
username: 'admin@example.com',
|
2020-09-24 11:34:04 +00:00
|
|
|
password: 'test',
|
|
|
|
},
|
|
|
|
success: resolve,
|
|
|
|
error: resolve
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then( function() {
|
|
|
|
return new Promise( (resolve, reject) => {
|
2021-10-14 14:35:12 +00:00
|
|
|
assert.notEqual(App.Session.get(), undefined, 'User is logged in so the api requests will work')
|
2020-09-24 11:34:04 +00:00
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
check_ajax_field('autocompletion_ajax1', 'admin@example.com', 1, resolve, assert)
|
2020-09-24 11:34:04 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
.then( function() {
|
|
|
|
return new Promise( (resolve, reject) => {
|
2021-10-14 14:35:12 +00:00
|
|
|
check_ajax_field('autocompletion_ajax1', 'xxx@example.com', 0, resolve, assert)
|
2020-09-24 11:34:04 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
.finally(done)
|
|
|
|
})
|