spec: refactor wait_for_ajax
to work with out new ajax utils
`wait_for_ajax` is not used anymore, but it may be in the future.
This commit is contained in:
parent
f621bd63e5
commit
6d312e1716
2 changed files with 23 additions and 14 deletions
|
@ -26,14 +26,17 @@ export function delegate(eventNames, selector, callback) {
|
|||
}
|
||||
|
||||
export function getJSON(url, data, method = 'get') {
|
||||
incrementActiveRequestsCount();
|
||||
data = method !== 'get' ? JSON.stringify(data) : data;
|
||||
return $.ajax({
|
||||
method,
|
||||
url,
|
||||
data,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json'
|
||||
});
|
||||
return Promise.resolve(
|
||||
$.ajax({
|
||||
method,
|
||||
url,
|
||||
data,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json'
|
||||
})
|
||||
).finally(decrementActiveRequestsCount);
|
||||
}
|
||||
|
||||
export function scrollTo(container, scrollTo) {
|
||||
|
@ -62,3 +65,15 @@ function offset(element) {
|
|||
left: rect.left + document.body.scrollLeft
|
||||
};
|
||||
}
|
||||
|
||||
const DATA_ACTIVE_REQUESTS_COUNT = 'data-active-requests-count';
|
||||
|
||||
function incrementActiveRequestsCount() {
|
||||
const count = document.body.getAttribute(DATA_ACTIVE_REQUESTS_COUNT) || '0';
|
||||
document.body.setAttribute(DATA_ACTIVE_REQUESTS_COUNT, parseInt(count) + 1);
|
||||
}
|
||||
|
||||
function decrementActiveRequestsCount() {
|
||||
const count = document.body.getAttribute(DATA_ACTIVE_REQUESTS_COUNT) || '0';
|
||||
document.body.setAttribute(DATA_ACTIVE_REQUESTS_COUNT, parseInt(count) - 1);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
module WaitForAjax
|
||||
def wait_for_ajax
|
||||
Timeout.timeout(Capybara.default_max_wait_time) do
|
||||
loop until finished_all_ajax_requests?
|
||||
end
|
||||
end
|
||||
|
||||
def finished_all_ajax_requests?
|
||||
page.evaluate_script('jQuery.active').zero?
|
||||
expect(page).to have_selector('body[data-active-requests-count="0"]')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue