From 935e51949c09597911dcf6bc12f0e10a9abd1809 Mon Sep 17 00:00:00 2001 From: Lachlan Sylvester Date: Tue, 20 Sep 2022 18:03:55 +1000 Subject: [PATCH] upgrade to QUnit 2 for ujs tests --- actionview/test/ujs/public/test/call-ajax.js | 12 +- .../ujs/public/test/call-remote-callbacks.js | 131 +- .../test/ujs/public/test/call-remote.js | 184 +- .../test/ujs/public/test/csrf-refresh.js | 7 +- actionview/test/ujs/public/test/csrf-token.js | 12 +- .../test/ujs/public/test/data-confirm.js | 208 +- .../test/ujs/public/test/data-disable-with.js | 271 +- .../test/ujs/public/test/data-disable.js | 225 +- .../test/ujs/public/test/data-method.js | 50 +- .../test/ujs/public/test/data-remote.js | 333 +- actionview/test/ujs/public/test/override.js | 34 +- actionview/test/ujs/public/test/settings.js | 32 +- actionview/test/ujs/public/vendor/qunit.css | 378 +- actionview/test/ujs/public/vendor/qunit.js | 10010 ++++++++++++---- ci/test_run.rb | 5 +- 15 files changed, 8938 insertions(+), 2954 deletions(-) diff --git a/actionview/test/ujs/public/test/call-ajax.js b/actionview/test/ujs/public/test/call-ajax.js index 4d0bfb0806..12cd970036 100644 --- a/actionview/test/ujs/public/test/call-ajax.js +++ b/actionview/test/ujs/public/test/call-ajax.js @@ -1,26 +1,28 @@ (function() { -module('call-ajax', { - setup: function() { +QUnit.module('call-ajax', { + beforeEach: function() { $('#qunit-fixture') .append($('', { href: '#' })) } }) -asyncTest('call ajax without "ajax:beforeSend"', 1, function() { +QUnit.test('call ajax without "ajax:beforeSend"', function(assert) { + const done = assert.async() + var link = $('#qunit-fixture a') link.bindNative('click', function() { Rails.ajax({ type: 'get', url: '/', success: function() { - ok(true, 'calling request in ajax:success') + assert.ok(true, 'calling request in ajax:success') + done() } }) }) link.triggerNative('click') - setTimeout(function() { start() }, 50) }) })() diff --git a/actionview/test/ujs/public/test/call-remote-callbacks.js b/actionview/test/ujs/public/test/call-remote-callbacks.js index 9c0c8cfb4b..8fb3a8b3a6 100644 --- a/actionview/test/ujs/public/test/call-remote-callbacks.js +++ b/actionview/test/ujs/public/test/call-remote-callbacks.js @@ -1,12 +1,12 @@ (function() { -module('call-remote-callbacks', { - setup: function() { +QUnit.module('call-remote-callbacks', { + beforeEach: function() { $('#qunit-fixture').append($('
', { action: '/echo', method: 'get', 'data-remote': 'true' })) }, - teardown: function() { + afterEach: function() { $(document).undelegate('form[data-remote]', 'ajax:beforeSend') $(document).undelegate('form[data-remote]', 'ajax:before') $(document).undelegate('form[data-remote]', 'ajax:send') @@ -17,15 +17,15 @@ module('call-remote-callbacks', { }) function submit(fn) { - var form = $('form') + var form = $('#qunit-fixture form') if (fn) fn(form) form.triggerNative('submit') - - setTimeout(function() { start() }, 13) } -asyncTest('modifying form fields with "ajax:before" sends modified data in request', 3, function() { +QUnit.test('modifying form fields with "ajax:before" sends modified data in request', function(assert) { + const done = assert.async() + $('form[data-remote]') .append($('')) .append($('')) @@ -40,14 +40,15 @@ asyncTest('modifying form fields with "ajax:before" sends modified data in reque submit(function(form) { form.bindNative('ajax:success', function(e, data, status, xhr) { - equal(data.params.user_name, 'steve', 'modified field value should have been submitted') - equal(data.params.other_user_name, 'jonathan', 'added field value should have been submitted') - equal(data.params.removed_user_name, undefined, 'removed field value should be undefined') + assert.equal(data.params.user_name, 'steve', 'modified field value should have been submitted') + assert.equal(data.params.other_user_name, 'jonathan', 'added field value should have been submitted') + assert.equal(data.params.removed_user_name, undefined, 'removed field value should be undefined') + done() }) }) }) -asyncTest('modifying data("type") with "ajax:before" requests new dataType in request', 1, function() { +QUnit.test('modifying data("type") with "ajax:before" requests new dataType in request', function(assert) { $('form[data-remote]').data('type', 'html') .bindNative('ajax:before', function() { this.setAttribute('data-type', 'xml') @@ -55,12 +56,12 @@ asyncTest('modifying data("type") with "ajax:before" requests new dataType in re submit(function(form) { form.bindNative('ajax:beforeSend', function(e, xhr, settings) { - equal(settings.dataType, 'xml', 'modified dataType should have been requested') + assert.equal(settings.dataType, 'xml', 'modified dataType should have been requested') }) }) }) -asyncTest('setting data("with-credentials",true) with "ajax:before" uses new setting in request', 1, function() { +QUnit.test('setting data("with-credentials",true) with "ajax:before" uses new setting in request', function(assert) { $('form[data-remote]').data('with-credentials', false) .bindNative('ajax:before', function() { this.setAttribute('data-with-credentials', true) @@ -68,34 +69,38 @@ asyncTest('setting data("with-credentials",true) with "ajax:before" uses new set submit(function(form) { form.bindNative('ajax:beforeSend', function(e, xhr, settings) { - equal(settings.withCredentials, true, 'setting modified in ajax:before should have forced withCredentials request') + assert.equal(settings.withCredentials, true, 'setting modified in ajax:before should have forced withCredentials request') }) }) }) -asyncTest('stopping the "ajax:beforeSend" event aborts the request', 1, function() { +QUnit.test('stopping the "ajax:beforeSend" event aborts the request', function(assert) { + const done = assert.async() + submit(function(form) { form.bindNative('ajax:beforeSend', function(e) { - ok(true, 'aborting request in ajax:beforeSend') + assert.ok(true, 'aborting request in ajax:beforeSend') e.preventDefault() }) form.unbind('ajax:send').bindNative('ajax:send', function() { - ok(false, 'ajax:send should not run') + assert.ok(false, 'ajax:send should not run') }) form.bindNative('ajax:error', function(e, response, status, xhr) { - ok(false, 'ajax:error should not run') + assert.ok(false, 'ajax:error should not run') }) form.bindNative('ajax:complete', function() { - ok(false, 'ajax:complete should not run') + assert.ok(false, 'ajax:complete should not run') }) }) + + setTimeout(function() { done() }, 13) }) function skipIt() { // This test cannot work due to the security feature in browsers which makes the value // attribute of file input fields readonly, so it cannot be set with default value. // This is what the test would look like though if browsers let us automate this test. - asyncTest('non-blank file form input field should abort remote request, but submit normally', 5, function() { + QUnit.test('non-blank file form input field should abort remote request, but submit normally', function(assert) { var form = $('form[data-remote]') .append($('')) .bindNative('ajax:beforeSend', function() { @@ -118,7 +123,7 @@ function skipIt() { }, 13) }) - asyncTest('file form input field should not abort remote request if file form input does not have a name attribute', 5, function() { + QUnit.test('file form input field should not abort remote request if file form input does not have a name attribute', function(assert) { var form = $('form[data-remote]') .append($('')) .bindNative('ajax:beforeSend', function() { @@ -139,7 +144,7 @@ function skipIt() { }, 13) }) - asyncTest('blank file input field should abort request entirely if handler bound to "ajax:aborted:file" event that returns false', 1, function() { + QUnit.test('blank file input field should abort request entirely if handler bound to "ajax:aborted:file" event that returns false', function(assert) { var form = $('form[data-remote]') .append($('')) .bindNative('ajax:beforeSend', function() { @@ -161,79 +166,103 @@ function skipIt() { }) } -asyncTest('"ajax:beforeSend" can be observed and stopped with event delegation', 1, function() { +QUnit.test('"ajax:beforeSend" can be observed and stopped with event delegation', function(assert) { + const done = assert.async() + $(document).delegate('form[data-remote]', 'ajax:beforeSend', function(e) { - ok(true, 'ajax:beforeSend observed with event delegation') + assert.ok(true, 'ajax:beforeSend observed with event delegation') e.preventDefault() }) submit(function(form) { form.unbind('ajax:send').bindNative('ajax:send', function() { - ok(false, 'ajax:send should not run') + assert.ok(false, 'ajax:send should not run') }) form.bindNative('ajax:complete', function() { - ok(false, 'ajax:complete should not run') + assert.ok(false, 'ajax:complete should not run') }) }) + + setTimeout(function() { done() }, 13) }) -asyncTest('"ajax:beforeSend", "ajax:send", "ajax:success" and "ajax:complete" are triggered', 8, function() { +QUnit.test('"ajax:beforeSend", "ajax:send", "ajax:success" and "ajax:complete" are triggered', function(assert) { + const done = assert.async(4) + submit(function(form) { form.bindNative('ajax:beforeSend', function(e, xhr, settings) { - ok(xhr.setRequestHeader, 'first argument to "ajax:beforeSend" should be an XHR object') - equal(settings.url, '/echo', 'second argument to "ajax:beforeSend" should be a settings object') + assert.ok(xhr.setRequestHeader, 'first argument to "ajax:beforeSend" should be an XHR object') + assert.equal(settings.url, '/echo', 'second argument to "ajax:beforeSend" should be a settings object') + done() }) form.bindNative('ajax:send', function(e, xhr) { - ok(xhr.abort, 'first argument to "ajax:send" should be an XHR object') + assert.ok(xhr.abort, 'first argument to "ajax:send" should be an XHR object') + done() }) form.bindNative('ajax:success', function(e, data, status, xhr) { - ok(data.REQUEST_METHOD, 'first argument to ajax:success should be a data object') - equal(status, 'OK', 'second argument to ajax:success should be a status string') - ok(xhr.getResponseHeader, 'third argument to "ajax:success" should be an XHR object') + assert.ok(data.REQUEST_METHOD, 'first argument to ajax:success should be a data object') + assert.equal(status, 'OK', 'second argument to ajax:success should be a status string') + assert.ok(xhr.getResponseHeader, 'third argument to "ajax:success" should be an XHR object') + done() }) form.bindNative('ajax:complete', function(e, xhr, status) { - ok(xhr.getResponseHeader, 'first argument to "ajax:complete" should be an XHR object') - equal(status, 'OK', 'second argument to ajax:complete should be a status string') + assert.ok(xhr.getResponseHeader, 'first argument to "ajax:complete" should be an XHR object') + assert.equal(status, 'OK', 'second argument to ajax:complete should be a status string') + done() }) }) }) -asyncTest('"ajax:beforeSend", "ajax:send", "ajax:error" and "ajax:complete" are triggered on error', 8, function() { +QUnit.test('"ajax:beforeSend", "ajax:send", "ajax:error" and "ajax:complete" are triggered on error', function(assert) { + const done = assert.async(4) + submit(function(form) { form.attr('action', '/error') - form.bindNative('ajax:beforeSend', function(arg) { ok(true, 'ajax:beforeSend') }) - form.bindNative('ajax:send', function(arg) { ok(true, 'ajax:send') }) + form.bindNative('ajax:beforeSend', function(arg) { + assert.ok(true, 'ajax:beforeSend') + done() + }) + form.bindNative('ajax:send', function(arg) { + assert.ok(true, 'ajax:send') + done() + }) form.bindNative('ajax:error', function(e, response, status, xhr) { - equal(response, '', 'first argument to ajax:error should be an HTTP status response') - equal(status, 'Forbidden', 'second argument to ajax:error should be a status string') - ok(xhr.getResponseHeader, 'third argument to "ajax:error" should be an XHR object') + assert.equal(response, '', 'first argument to ajax:error should be an HTTP status response') + assert.equal(status, 'Forbidden', 'second argument to ajax:error should be a status string') + assert.ok(xhr.getResponseHeader, 'third argument to "ajax:error" should be an XHR object') // Opera returns "0" for HTTP code - equal(xhr.status, window.opera ? 0 : 403, 'status code should be 403') + assert.equal(xhr.status, window.opera ? 0 : 403, 'status code should be 403') + done() }) form.bindNative('ajax:complete', function(e, xhr, status) { - ok(xhr.getResponseHeader, 'first argument to "ajax:complete" should be an XHR object') - equal(status, 'Forbidden', 'second argument to ajax:complete should be a status string') + assert.ok(xhr.getResponseHeader, 'first argument to "ajax:complete" should be an XHR object') + assert.equal(status, 'Forbidden', 'second argument to ajax:complete should be a status string') + done() }) }) }) -asyncTest('binding to ajax callbacks via .delegate() triggers handlers properly', 4, function() { +QUnit.test('binding to ajax callbacks via .delegate() triggers handlers properly', function(assert) { + const done = assert.async(4) + $(document) .delegate('form[data-remote]', 'ajax:beforeSend', function() { - ok(true, 'ajax:beforeSend handler is triggered') + assert.ok(true, 'ajax:beforeSend handler is triggered') + done() }) .delegate('form[data-remote]', 'ajax:send', function() { - ok(true, 'ajax:send handler is triggered') + assert.ok(true, 'ajax:send handler is triggered') + done() }) .delegate('form[data-remote]', 'ajax:success', function() { - ok(true, 'ajax:success handler is triggered') + assert.ok(true, 'ajax:success handler is triggered') + done() }) .delegate('form[data-remote]', 'ajax:complete', function() { - ok(true, 'ajax:complete handler is triggered') + assert.ok(true, 'ajax:complete handler is triggered') + done() }) $('form[data-remote]').triggerNative('submit') - - setTimeout(function() { start() }, 13) }) })() diff --git a/actionview/test/ujs/public/test/call-remote.js b/actionview/test/ujs/public/test/call-remote.js index aabbb80442..9e7f30a944 100644 --- a/actionview/test/ujs/public/test/call-remote.js +++ b/actionview/test/ujs/public/test/call-remote.js @@ -7,109 +7,149 @@ function buildForm(attrs) { .find('form').append($('')) } -module('call-remote') +QUnit.module('call-remote') function submit(fn) { - $('form') + $('#qunit-fixture form') .bindNative('ajax:success', fn) - .bindNative('ajax:complete', function() { start() }) .triggerNative('submit') } -asyncTest('form method is read from "method" and not from "data-method"', 1, function() { +QUnit.test('form method is read from "method" and not from "data-method"', function(assert) { + const done = assert.async() + buildForm({ method: 'post', 'data-method': 'get' }) submit(function(e, data, status, xhr) { - App.assertPostRequest(data) + assert.postRequest(data) + done() }) }) -asyncTest('form method is not read from "data-method" attribute in case of missing "method"', 1, function() { +QUnit.test('form method is not read from "data-method" attribute in case of missing "method"', function(assert) { + const done = assert.async() + buildForm({ 'data-method': 'put' }) submit(function(e, data, status, xhr) { - App.assertGetRequest(data) + assert.getRequest(data) + done() }) }) -asyncTest('form method is read from submit button "formmethod" if submit is triggered by that button', 1, function() { +QUnit.test('form method is read from submit button "formmethod" if submit is triggered by that button', function(assert) { + const done = assert.async() + var submitButton = $('') buildForm({ method: 'post' }) $('#qunit-fixture').find('form').append(submitButton) .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertGetRequest(data) + assert.getRequest(data) }) - .bindNative('ajax:complete', function() { start() }) + .bindNative('ajax:complete', function() { done() }) submitButton.triggerNative('click') }) -asyncTest('form default method is GET', 1, function() { +QUnit.test('form default method is GET', function(assert) { + const done = assert.async() + buildForm() submit(function(e, data, status, xhr) { - App.assertGetRequest(data) + assert.getRequest(data) + done() }) }) -asyncTest('form URL is picked up from "action"', 1, function() { +QUnit.test('form URL is picked up from "action"', function(assert) { + const done = assert.async() + buildForm({ method: 'post' }) submit(function(e, data, status, xhr) { - App.assertRequestPath(data, '/echo') + assert.requestPath(data, '/echo') + done() }) }) -asyncTest('form URL is read from "action" not "href"', 1, function() { +QUnit.test('form URL is read from "action" not "href"', function(assert) { + const done = assert.async() + buildForm({ method: 'post', href: '/echo2' }) submit(function(e, data, status, xhr) { - App.assertRequestPath(data, '/echo') + assert.requestPath(data, '/echo') + done() }) }) -asyncTest('form URL is read from submit button "formaction" if submit is triggered by that button', 1, function() { +QUnit.test('form URL is read from submit button "formaction" if submit is triggered by that button', function(assert) { + const done = assert.async() + var submitButton = $('') buildForm({ method: 'post', href: '/echo2' }) $('#qunit-fixture').find('form').append(submitButton) .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertRequestPath(data, '/echo') + assert.requestPath(data, '/echo') }) - .bindNative('ajax:complete', function() { start() }) + .bindNative('ajax:complete', function() { done() }) submitButton.triggerNative('click') }) -asyncTest('prefer JS, but accept any format', 1, function() { +QUnit.test('prefer JS, but accept any format', function(assert) { + const done = assert.async() + buildForm({ method: 'post' }) submit(function(e, data, status, xhr) { var accept = data.HTTP_ACCEPT - ok(accept.match(/text\/javascript.+\*\/\*/), 'Accept: ' + accept) + assert.ok(accept.match(/text\/javascript.+\*\/\*/), 'Accept: ' + accept) + done() }) }) -asyncTest('JS code should be executed', 1, function() { +QUnit.test('JS code should be executed', function(assert) { + const done = assert.async() + buildForm({ method: 'post', 'data-type': 'script' }) - $('form').append('') - $('form').append('') + window.callback = function() { + assert.ok(true, 'remote code should be run') + window.callback = null + done() + } + + $('form').append('') + $('form').append('') submit() }) -asyncTest('ecmascript code should be executed', 1, function() { +QUnit.test('ecmascript code should be executed', function(assert) { + const done = assert.async() + + window.callback = function() { + assert.ok(true, 'remote code should be run') + window.callback = null + + done() + } + buildForm({ method: 'post', 'data-type': 'script' }) $('form').append('') - $('form').append('') + $('form').append('') submit() }) -asyncTest('execution of JS code does not modify current DOM', 1, function() { +QUnit.test('execution of JS code does not modify current DOM', function(assert) { + const done = assert.async() + var docLength, newDocLength function getDocLength() { return document.documentElement.outerHTML.length @@ -124,87 +164,112 @@ asyncTest('execution of JS code does not modify current DOM', 1, function() { submit(function() { newDocLength = getDocLength() - ok(docLength === newDocLength, 'executed JS should not present in the document') + assert.ok(docLength === newDocLength, 'executed JS should not present in the document') + done() }) }) -asyncTest('HTML document should be parsed', 1, function() { +QUnit.test('HTML document should be parsed', function(assert) { + const done = assert.async() + buildForm({ method: 'post', 'data-type': 'html' }) $('form').append('') $('form').append('') submit(function(e, data, status, xhr) { - ok(data instanceof HTMLDocument, 'returned data should be an HTML document') + assert.ok(data instanceof HTMLDocument, 'returned data should be an HTML document') + done() }) }) -asyncTest('XML document should be parsed', 1, function() { +QUnit.test('XML document should be parsed', function(assert) { + const done = assert.async() + buildForm({ method: 'post', 'data-type': 'html' }) $('form').append('') $('form').append('') submit(function(e, data, status, xhr) { - ok(data instanceof Document, 'returned data should be an XML document') + assert.ok(data instanceof Document, 'returned data should be an XML document') + done() }) }) -asyncTest('accept application/json if "data-type" is json', 1, function() { +QUnit.test('accept application/json if "data-type" is json', function(assert) { + const done = assert.async() + buildForm({ method: 'post', 'data-type': 'json' }) submit(function(e, data, status, xhr) { - equal(data.HTTP_ACCEPT, 'application/json, text/javascript, */*; q=0.01') + assert.equal(data.HTTP_ACCEPT, 'application/json, text/javascript, */*; q=0.01') + done() }) }) -asyncTest('allow empty "data-remote" attribute', 1, function() { +QUnit.test('allow empty "data-remote" attribute', function(assert) { + const done = assert.async() + var form = $('#qunit-fixture').append($('')).find('form') submit(function() { - ok(true, 'form with empty "data-remote" attribute is also allowed') + assert.ok(true, 'form with empty "data-remote" attribute is also allowed') + done() }) }) -asyncTest('query string in form action should be stripped in a GET request in normal submit', 1, function() { +QUnit.test('query string in form action should be stripped in a GET request in normal submit', function(assert) { + const done = assert.async() + buildForm({ action: '/echo?param1=abc', 'data-remote': 'false' }) $(document).one('iframe:loaded', function(e, data) { - equal(data.params.param1, undefined, '"param1" should not be passed to server') - start() + assert.equal(data.params.param1, undefined, '"param1" should not be passed to server') + done() }) $('#qunit-fixture form').triggerNative('submit') }) -asyncTest('query string in form action should be stripped in a GET request in ajax submit', 1, function() { +QUnit.test('query string in form action should be stripped in a GET request in ajax submit', function(assert) { + const done = assert.async() + buildForm({ action: '/echo?param1=abc' }) submit(function(e, data, status, xhr) { - equal(data.params.param1, undefined, '"param1" should not be passed to server') + assert.equal(data.params.param1, undefined, '"param1" should not be passed to server') + done() }) }) -asyncTest('query string in form action should not be stripped in a POST request in normal submit', 1, function() { +QUnit.test('query string in form action should not be stripped in a POST request in normal submit', function(assert) { + const done = assert.async() + buildForm({ action: '/echo?param1=abc', method: 'post', 'data-remote': 'false' }) $(document).one('iframe:loaded', function(e, data) { - equal(data.params.param1, 'abc', '"param1" should be passed to server') - start() + assert.equal(data.params.param1, 'abc', '"param1" should be passed to server') + done() }) $('#qunit-fixture form').triggerNative('submit') }) -asyncTest('query string in form action should not be stripped in a POST request in ajax submit', 1, function() { +QUnit.test('query string in form action should not be stripped in a POST request in ajax submit', function(assert) { + const done = assert.async() + buildForm({ action: '/echo?param1=abc', method: 'post' }) submit(function(e, data, status, xhr) { - equal(data.params.param1, 'abc', '"param1" should be passed to server') + assert.equal(data.params.param1, 'abc', '"param1" should be passed to server') + done() }) }) -asyncTest('allow empty form "action"', 1, function() { +QUnit.test('allow empty form "action"', function(assert) { + const done = assert.async() + var currentLocation, ajaxLocation buildForm({ action: '' }) @@ -225,7 +290,7 @@ asyncTest('allow empty form "action"', 1, function() { // HACK: can no longer use settings.data below to see what was appended to URL, as of // jQuery 1.6.3 (see https://bugs.jquery.com/ticket/10202 and https://github.com/jquery/jquery/pull/544) ajaxLocation = settings.url.replace('user_name=john', '').replace(/&$/, '').replace(/\?$/, '') - equal(ajaxLocation.match(/^(.*)/)[1], currentLocation, 'URL should be current page by default') + assert.equal(ajaxLocation.match(/^(.*)/)[1], currentLocation, 'URL should be current page by default') // Prevent the request from actually getting sent to the current page and // causing an error. @@ -233,19 +298,23 @@ asyncTest('allow empty form "action"', 1, function() { }) .triggerNative('submit') - setTimeout(function() { start() }, 13) + setTimeout(function() { done() }, 13) }) -asyncTest('sends CSRF token in custom header', 1, function() { +QUnit.test('sends CSRF token in custom header', function(assert) { + const done = assert.async() + buildForm({ method: 'post' }) $('#qunit-fixture').append('') submit(function(e, data, status, xhr) { - equal(data.HTTP_X_CSRF_TOKEN, 'cf50faa3fe97702ca1ae', 'X-CSRF-Token header should be sent') + assert.equal(data.HTTP_X_CSRF_TOKEN, 'cf50faa3fe97702ca1ae', 'X-CSRF-Token header should be sent') + done() }) }) -asyncTest('intelligently guesses crossDomain behavior when target URL has a different protocol and/or hostname', 1, function() { +QUnit.test('intelligently guesses crossDomain behavior when target URL has a different protocol and/or hostname', function(assert) { + const done = assert.async() // Don't set data-cross-domain here, just set action to be a different domain than localhost buildForm({ action: 'http://www.alfajango.com' }) @@ -254,17 +323,18 @@ asyncTest('intelligently guesses crossDomain behavior when target URL has a diff $('#qunit-fixture').find('form') .bindNative('ajax:beforeSend', function(evt, req, settings) { - equal(settings.crossDomain, true, 'crossDomain should be set to true') + assert.equal(settings.crossDomain, true, 'crossDomain should be set to true') // prevent request from actually getting sent off-domain evt.preventDefault() }) .triggerNative('submit') - setTimeout(function() { start() }, 13) + setTimeout(function() { done() }, 13) }) -asyncTest('intelligently guesses crossDomain behavior when target URL consists of only a path', 1, function() { +QUnit.test('intelligently guesses crossDomain behavior when target URL consists of only a path', function(assert) { + const done = assert.async() // Don't set data-cross-domain here, just set action to be a different domain than localhost buildForm({ action: '/just/a/path' }) @@ -273,14 +343,14 @@ asyncTest('intelligently guesses crossDomain behavior when target URL consists o $('#qunit-fixture').find('form') .bindNative('ajax:beforeSend', function(evt, req, settings) { - equal(settings.crossDomain, false, 'crossDomain should be set to false') + assert.equal(settings.crossDomain, false, 'crossDomain should be set to false') // prevent request from actually getting sent off-domain evt.preventDefault() }) .triggerNative('submit') - setTimeout(function() { start() }, 13) + setTimeout(function() { done() }, 13) }) })() diff --git a/actionview/test/ujs/public/test/csrf-refresh.js b/actionview/test/ujs/public/test/csrf-refresh.js index e302042542..09f52ef822 100644 --- a/actionview/test/ujs/public/test/csrf-refresh.js +++ b/actionview/test/ujs/public/test/csrf-refresh.js @@ -1,8 +1,8 @@ (function() { -module('csrf-refresh', {}) +QUnit.module('csrf-refresh', {}) -asyncTest('refresh all csrf tokens', 1, function() { +QUnit.test('refresh all csrf tokens', function(assert) { var correctToken = 'cf50faa3fe97702ca1ae' var form = $('') @@ -17,8 +17,7 @@ asyncTest('refresh all csrf tokens', 1, function() { $.rails.refreshCSRFTokens() currentToken = $('#qunit-fixture #authenticity_token').val() - start() - equal(currentToken, correctToken) + assert.equal(currentToken, correctToken) }) })() diff --git a/actionview/test/ujs/public/test/csrf-token.js b/actionview/test/ujs/public/test/csrf-token.js index 388b40e057..ce6985a388 100644 --- a/actionview/test/ujs/public/test/csrf-token.js +++ b/actionview/test/ujs/public/test/csrf-token.js @@ -1,27 +1,25 @@ (function() { -module('csrf-token', {}) +QUnit.module('csrf-token', {}) -asyncTest('find csrf token', 1, function() { +QUnit.test('find csrf token', function(assert) { var correctToken = 'cf50faa3fe97702ca1ae' $('#qunit-fixture').append('') currentToken = $.rails.csrfToken() - start() - equal(currentToken, correctToken) + assert.equal(currentToken, correctToken) }) -asyncTest('find csrf param', 1, function() { +QUnit.test('find csrf param', function(assert) { var correctParam = 'authenticity_token' $('#qunit-fixture').append('') currentParam = $.rails.csrfParam() - start() - equal(currentParam, correctParam) + assert.equal(currentParam, correctParam) }) })() diff --git a/actionview/test/ujs/public/test/data-confirm.js b/actionview/test/ujs/public/test/data-confirm.js index 1bd57b69ad..0fb2ac64f7 100644 --- a/actionview/test/ujs/public/test/data-confirm.js +++ b/actionview/test/ujs/public/test/data-confirm.js @@ -1,5 +1,5 @@ -module('data-confirm', { - setup: function() { +QUnit.module('data-confirm', { + beforeEach: function() { $('#qunit-fixture').append($('', { href: '/echo', 'data-remote': 'true', @@ -35,224 +35,246 @@ module('data-confirm', { this.windowConfirm = window.confirm }, - teardown: function() { + afterEach: function() { window.confirm = this.windowConfirm } }) -asyncTest('clicking on a link with data-confirm attribute. Confirm yes.', 6, function() { +QUnit.test('clicking on a link with data-confirm attribute. Confirm yes.', function(assert) { + const done = assert.async() + var message // auto-confirm: window.confirm = function(msg) { message = msg; return true } $('a[data-confirm]') .bindNative('confirm:complete', function(e, data) { - App.assertCallbackInvoked('confirm:complete') - ok(data == true, 'confirm:complete passes in confirm answer (true)') + assert.callbackInvoked('confirm:complete') + assert.ok(data == true, 'confirm:complete passes in confirm answer (true)') }) .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertCallbackInvoked('ajax:success') - App.assertRequestPath(data, '/echo') - App.assertGetRequest(data) + assert.callbackInvoked('ajax:success') + assert.requestPath(data, '/echo') + assert.getRequest(data) - equal(message, 'Are you absolutely sure?') - start() + assert.equal(message, 'Are you absolutely sure?') + done() }) .triggerNative('click') }) -asyncTest('clicking on a button with data-confirm attribute. Confirm yes.', 6, function() { +QUnit.test('clicking on a button with data-confirm attribute. Confirm yes.', function(assert) { + const done = assert.async() + var message // auto-confirm: window.confirm = function(msg) { message = msg; return true } $('button[data-confirm]') .bindNative('confirm:complete', function(e, data) { - App.assertCallbackInvoked('confirm:complete') - ok(data == true, 'confirm:complete passes in confirm answer (true)') + assert.callbackInvoked('confirm:complete') + assert.ok(data == true, 'confirm:complete passes in confirm answer (true)') }) .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertCallbackInvoked('ajax:success') - App.assertRequestPath(data, '/echo') - App.assertGetRequest(data) + assert.callbackInvoked('ajax:success') + assert.requestPath(data, '/echo') + assert.getRequest(data) - equal(message, 'Are you absolutely sure?') - start() + assert.equal(message, 'Are you absolutely sure?') + done() }) .triggerNative('click') }) -asyncTest('clicking on a link with data-confirm attribute. Confirm No.', 3, function() { +QUnit.test('clicking on a link with data-confirm attribute. Confirm No.', function(assert) { + const done = assert.async() + var message // auto-decline: window.confirm = function(msg) { message = msg; return false } $('a[data-confirm]') .bindNative('confirm:complete', function(e, data) { - App.assertCallbackInvoked('confirm:complete') - ok(data == false, 'confirm:complete passes in confirm answer (false)') + assert.callbackInvoked('confirm:complete') + assert.ok(data == false, 'confirm:complete passes in confirm answer (false)') }) .bindNative('ajax:beforeSend', function(e, data, status, xhr) { - App.assertCallbackNotInvoked('ajax:beforeSend') + assert.callbackNotInvoked('ajax:beforeSend') }) .triggerNative('click') setTimeout(function() { - equal(message, 'Are you absolutely sure?') - start() + assert.equal(message, 'Are you absolutely sure?') + done() }, 50) }) -asyncTest('clicking on a button with data-confirm attribute. Confirm No.', 3, function() { +QUnit.test('clicking on a button with data-confirm attribute. Confirm No.', function(assert) { + const done = assert.async() + var message // auto-decline: window.confirm = function(msg) { message = msg; return false } $('button[data-confirm]') .bindNative('confirm:complete', function(e, data) { - App.assertCallbackInvoked('confirm:complete') - ok(data == false, 'confirm:complete passes in confirm answer (false)') + assert.callbackInvoked('confirm:complete') + assert.ok(data == false, 'confirm:complete passes in confirm answer (false)') }) .bindNative('ajax:beforeSend', function(e, data, status, xhr) { - App.assertCallbackNotInvoked('ajax:beforeSend') + assert.callbackNotInvoked('ajax:beforeSend') }) .triggerNative('click') setTimeout(function() { - equal(message, 'Are you absolutely sure?') - start() + assert.equal(message, 'Are you absolutely sure?') + done() }, 50) }) -asyncTest('clicking on a button with data-confirm attribute. Confirm error.', 3, function() { +QUnit.test('clicking on a button with data-confirm attribute. Confirm error.', function(assert) { + const done = assert.async() + var message // auto-decline: window.confirm = function(msg) { message = msg; throw 'some random error' } $('button[data-confirm]') .bindNative('confirm:complete', function(e, data) { - App.assertCallbackInvoked('confirm:complete') - ok(data == false, 'confirm:complete passes in confirm answer (false)') + assert.callbackInvoked('confirm:complete') + assert.ok(data == false, 'confirm:complete passes in confirm answer (false)') }) .bindNative('ajax:beforeSend', function(e, data, status, xhr) { - App.assertCallbackNotInvoked('ajax:beforeSend') + assert.callbackNotInvoked('ajax:beforeSend') }) .triggerNative('click') setTimeout(function() { - equal(message, 'Are you absolutely sure?') - start() + assert.equal(message, 'Are you absolutely sure?') + done() }, 50) }) -asyncTest('clicking on a submit button with form and data-confirm attributes. Confirm No.', 3, function() { +QUnit.test('clicking on a submit button with form and data-confirm attributes. Confirm No.', function(assert) { + const done = assert.async() + var message // auto-decline: window.confirm = function(msg) { message = msg; return false } - $('input[type=submit][form]') + $('#qunit-fixture input[type=submit][form]') .bindNative('confirm:complete', function(e, data) { - App.assertCallbackInvoked('confirm:complete') - ok(data == false, 'confirm:complete passes in confirm answer (false)') + assert.callbackInvoked('confirm:complete') + assert.ok(data == false, 'confirm:complete passes in confirm answer (false)') }) .bindNative('ajax:beforeSend', function(e, data, status, xhr) { - App.assertCallbackNotInvoked('ajax:beforeSend') + assert.callbackNotInvoked('ajax:beforeSend') }) .triggerNative('click') setTimeout(function() { - equal(message, 'Are you absolutely sure?') - start() + assert.equal(message, 'Are you absolutely sure?') + done() }, 50) }) -asyncTest('binding to confirm event of a link and returning false', 1, function() { +QUnit.test('binding to confirm event of a link and returning false', function(assert) { + const done = assert.async() + // redefine confirm function so we can make sure it's not called window.confirm = function(msg) { - ok(false, 'confirm dialog should not be called') + assert.ok(false, 'confirm dialog should not be called') } $('a[data-confirm]') .bindNative('confirm', function(e) { - App.assertCallbackInvoked('confirm') + assert.callbackInvoked('confirm') e.preventDefault() }) .bindNative('confirm:complete', function() { - App.assertCallbackNotInvoked('confirm:complete') + assert.callbackNotInvoked('confirm:complete') }) .triggerNative('click') setTimeout(function() { - start() + done() }, 50) }) -asyncTest('binding to confirm event of a button and returning false', 1, function() { +QUnit.test('binding to confirm event of a button and returning false', function(assert) { + const done = assert.async() + // redefine confirm function so we can make sure it's not called window.confirm = function(msg) { - ok(false, 'confirm dialog should not be called') + assert.ok(false, 'confirm dialog should not be called') } $('button[data-confirm]') .bindNative('confirm', function(e) { - App.assertCallbackInvoked('confirm') + assert.callbackInvoked('confirm') e.preventDefault() }) .bindNative('confirm:complete', function() { - App.assertCallbackNotInvoked('confirm:complete') + assert.callbackNotInvoked('confirm:complete') }) .triggerNative('click') setTimeout(function() { - start() + done() }, 50) }) -asyncTest('binding to confirm:complete event of a link and returning false', 2, function() { +QUnit.test('binding to confirm:complete event of a link and returning false', function(assert) { + const done = assert.async() + // auto-confirm: window.confirm = function(msg) { - ok(true, 'confirm dialog should be called') + assert.ok(true, 'confirm dialog should be called') return true } $('a[data-confirm]') .bindNative('confirm:complete', function(e) { - App.assertCallbackInvoked('confirm:complete') + assert.callbackInvoked('confirm:complete') e.preventDefault() }) .bindNative('ajax:beforeSend', function() { - App.assertCallbackNotInvoked('ajax:beforeSend') + assert.callbackNotInvoked('ajax:beforeSend') }) .triggerNative('click') setTimeout(function() { - start() + done() }, 50) }) -asyncTest('binding to confirm:complete event of a button and returning false', 2, function() { +QUnit.test('binding to confirm:complete event of a button and returning false', function(assert) { + const done = assert.async() + // auto-confirm: window.confirm = function(msg) { - ok(true, 'confirm dialog should be called') + assert.ok(true, 'confirm dialog should be called') return true } $('button[data-confirm]') .bindNative('confirm:complete', function(e) { - App.assertCallbackInvoked('confirm:complete') + assert.callbackInvoked('confirm:complete') e.preventDefault() }) .bindNative('ajax:beforeSend', function() { - App.assertCallbackNotInvoked('ajax:beforeSend') + assert.callbackNotInvoked('ajax:beforeSend') }) .triggerNative('click') setTimeout(function() { - start() + done() }, 50) }) -asyncTest('a button inside a form only confirms once', 1, function() { +QUnit.test('a button inside a form only confirms once', function(assert) { + const done = assert.async() + var confirmations = 0 window.confirm = function(msg) { confirmations++ @@ -265,13 +287,15 @@ asyncTest('a button inside a form only confirms once', 1, function() { text: 'Click me' }))) - $('form > button[data-confirm]').triggerNative('click') + $('#qunit-fixture form > button[data-confirm]').triggerNative('click') - ok(confirmations === 1, 'confirmation counter should be 1, but it was ' + confirmations) - start() + assert.ok(confirmations === 1, 'confirmation counter should be 1, but it was ' + confirmations) + done() }) -asyncTest('clicking on the children of a link should also trigger a confirm', 6, function() { +QUnit.test('clicking on the children of a link should also trigger a confirm', function(assert) { + const done = assert.async() + var message // auto-confirm: window.confirm = function(msg) { message = msg; return true } @@ -279,22 +303,24 @@ asyncTest('clicking on the children of a link should also trigger a confirm', 6, $('a[data-confirm]') .html('Click me') .bindNative('confirm:complete', function(e, data) { - App.assertCallbackInvoked('confirm:complete') - ok(data == true, 'confirm:complete passes in confirm answer (true)') + assert.callbackInvoked('confirm:complete') + assert.ok(data == true, 'confirm:complete passes in confirm answer (true)') }) .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertCallbackInvoked('ajax:success') - App.assertRequestPath(data, '/echo') - App.assertGetRequest(data) + assert.callbackInvoked('ajax:success') + assert.requestPath(data, '/echo') + assert.getRequest(data) - equal(message, 'Are you absolutely sure?') - start() + assert.equal(message, 'Are you absolutely sure?') + done() }) .find('strong') .triggerNative('click') }) -asyncTest('clicking on the children of a disabled button should not trigger a confirm.', 1, function() { +QUnit.test('clicking on the children of a disabled button should not trigger a confirm.', function(assert) { + const done = assert.async() + var message // auto-decline: window.confirm = function(msg) { message = msg; return false } @@ -302,41 +328,43 @@ asyncTest('clicking on the children of a disabled button should not trigger a co $('button[data-confirm][disabled]') .html('Click me') .bindNative('confirm', function() { - App.assertCallbackNotInvoked('confirm') + assert.callbackNotInvoked('confirm') }) .find('strong') .bindNative('click', function() { - App.assertCallbackInvoked('click') + assert.callbackInvoked('click') }) .triggerNative('click') setTimeout(function() { - start() + done() }, 50) }) -asyncTest('clicking on a link with data-confirm attribute with custom confirm handler. Confirm yes.', 7, function() { +QUnit.test('clicking on a link with data-confirm attribute with custom confirm handler. Confirm yes.', function(assert) { + const done = assert.async() + var message, element // redefine confirm function so we can make sure it's not called window.confirm = function(msg) { - ok(false, 'confirm dialog should not be called') + assert.ok(false, 'confirm dialog should not be called') } // custom auto-confirm: Rails.confirm = function(msg, elem) { message = msg; element = elem; return true } $('a[data-confirm]') .bindNative('confirm:complete', function(e, data) { - App.assertCallbackInvoked('confirm:complete') - ok(data == true, 'confirm:complete passes in confirm answer (true)') + assert.callbackInvoked('confirm:complete') + assert.ok(data == true, 'confirm:complete passes in confirm answer (true)') }) .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertCallbackInvoked('ajax:success') - App.assertRequestPath(data, '/echo') - App.assertGetRequest(data) + assert.callbackInvoked('ajax:success') + assert.requestPath(data, '/echo') + assert.getRequest(data) - equal(message, 'Are you absolutely sure?') - equal(element, $('a[data-confirm]').get(0)) - start() + assert.equal(message, 'Are you absolutely sure?') + assert.equal(element, $('a[data-confirm]').get(0)) + done() }) .triggerNative('click') }) diff --git a/actionview/test/ujs/public/test/data-disable-with.js b/actionview/test/ujs/public/test/data-disable-with.js index 10b8870171..a8601a1eed 100644 --- a/actionview/test/ujs/public/test/data-disable-with.js +++ b/actionview/test/ujs/public/test/data-disable-with.js @@ -1,5 +1,5 @@ -module('data-disable-with', { - setup: function() { +QUnit.module('data-disable-with', { + beforeEach: function() { $('#qunit-fixture').append($('', { action: '/echo', 'data-remote': 'true', @@ -38,106 +38,116 @@ module('data-disable-with', { 'data-disable-with': 'clicking...' })) }, - teardown: function() { + afterEach: function() { $(document).unbind('iframe:loaded') } }) -asyncTest('form input field with "data-disable-with" attribute', 7, function() { +QUnit.test('form input field with "data-disable-with" attribute', function(assert) { + const done = assert.async() + var form = $('form[data-remote]'), input = form.find('input[type=text]') - App.checkEnabledState(input, 'john') + assert.enabledState(input, 'john') form.bindNative('ajax:success', function(e, data) { setTimeout(function() { - App.checkEnabledState(input, 'john') - equal(data.params.user_name, 'john') - start() + assert.enabledState(input, 'john') + assert.equal(data.params.user_name, 'john') + done() }, 13) }) form.triggerNative('submit') - App.checkDisabledState(input, 'processing ...') + assert.disabledState(input, 'processing ...') }) -asyncTest('blank form input field with "data-disable-with" attribute', 7, function() { +QUnit.test('blank form input field with "data-disable-with" attribute', function(assert) { + const done = assert.async() + var form = $('form[data-remote]'), input = form.find('input[type=text]') input.val('') - App.checkEnabledState(input, '') + assert.enabledState(input, '') form.bindNative('ajax:success', function(e, data) { setTimeout(function() { - App.checkEnabledState(input, '') - equal(data.params.user_name, '') - start() + assert.enabledState(input, '') + assert.equal(data.params.user_name, '') + done() }, 13) }) form.triggerNative('submit') - App.checkDisabledState(input, 'processing ...') + assert.disabledState(input, 'processing ...') }) -asyncTest('form button with "data-disable-with" attribute', 6, function() { +QUnit.test('form button with "data-disable-with" attribute', function(assert) { + const done = assert.async() + var form = $('form[data-remote]'), button = $('') form.append(button) - App.checkEnabledState(button, 'Submit') + assert.enabledState(button, 'Submit') form.bindNative('ajax:success', function(e, data) { setTimeout(function() { - App.checkEnabledState(button, 'Submit') - start() + assert.enabledState(button, 'Submit') + done() }, 13) }) form.triggerNative('submit') - App.checkDisabledState(button, 'submitting ...') + assert.disabledState(button, 'submitting ...') }) -asyncTest('a[data-remote][data-disable-with] within a form disables and re-enables', 6, function() { - var form = $('form:not([data-remote])'), +QUnit.test('a[data-remote][data-disable-with] within a form disables and re-enables', function(assert) { + const done = assert.async() + + var form = $('#qunit-fixture form:not([data-remote])'), link = $('Click me') form.append(link) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link .bindNative('ajax:beforeSend', function() { - App.checkDisabledState(link, 'clicking...') + assert.disabledState(link, 'clicking...') }) .bindNative('ajax:complete', function() { setTimeout( function() { - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.remove() - start() + done() }, 15) }) .triggerNative('click') }) -asyncTest('form input[type=submit][data-disable-with] disables', 6, function() { - var form = $('form:not([data-remote])'), input = form.find('input[type=submit]') +QUnit.test('form input[type=submit][data-disable-with] disables', function(assert) { + const done = assert.async() - App.checkEnabledState(input, 'Submit') + var form = $('#qunit-fixture form:not([data-remote])'), input = form.find('input[type=submit]') + + assert.enabledState(input, 'Submit') $(document).bind('iframe:loaded', function(e, data) { setTimeout(function() { - App.checkDisabledState(input, 'submitting ...') - start() + assert.disabledState(input, 'submitting ...') + done() }, 30) }) form.triggerNative('submit') setTimeout(function() { - App.checkDisabledState(input, 'submitting ...') + assert.disabledState(input, 'submitting ...') }, 30) }) -test('form input[type=submit][data-disable-with] re-enables when `pageshow` event is triggered', function() { - var form = $('form:not([data-remote])'), input = form.find('input[type=submit]') +QUnit.test('form input[type=submit][data-disable-with] re-enables when `pageshow` event is triggered', function(assert) { + var form = $('#qunit-fixture form:not([data-remote])'), input = form.find('input[type=submit]') - App.checkEnabledState(input, 'Submit') + assert.enabledState(input, 'Submit') // Emulate the disabled state without submitting the form at all, what is the // state after going back on firefox after submitting a form. @@ -145,14 +155,16 @@ test('form input[type=submit][data-disable-with] re-enables when `pageshow` even // See https://github.com/rails/jquery-ujs/issues/357 $.rails.disableElement(form[0]) - App.checkDisabledState(input, 'submitting ...') + assert.disabledState(input, 'submitting ...') $(window).triggerNative('pageshow') - App.checkEnabledState(input, 'Submit') + assert.enabledState(input, 'Submit') }) -asyncTest('form[data-remote] input[type=submit][data-disable-with] is replaced in ajax callback', 2, function() { +QUnit.test('form[data-remote] input[type=submit][data-disable-with] is replaced in ajax callback', function(assert) { + const done = assert.async() + var form = $('#qunit-fixture form:not([data-remote])').attr('data-remote', 'true'), origFormContents = form.html() @@ -161,13 +173,15 @@ asyncTest('form[data-remote] input[type=submit][data-disable-with] is replaced i setTimeout(function() { var input = form.find('input[type=submit]') - App.checkEnabledState(input, 'Submit') - start() + assert.enabledState(input, 'Submit') + done() }, 30) }).triggerNative('submit') }) -asyncTest('form[data-remote] input[data-disable-with] is replaced with disabled field in ajax callback', 2, function() { +QUnit.test('form[data-remote] input[data-disable-with] is replaced with disabled field in ajax callback', function(assert) { + const done = assert.async() + var form = $('#qunit-fixture form:not([data-remote])').attr('data-remote', 'true'), input = form.find('input[type=submit]'), newDisabledInput = input.clone().attr('disabled', 'disabled') @@ -176,139 +190,151 @@ asyncTest('form[data-remote] input[data-disable-with] is replaced with disabled input.replaceWith(newDisabledInput) setTimeout(function() { - App.checkEnabledState(newDisabledInput, 'Submit') - start() + assert.enabledState(newDisabledInput, 'Submit') + done() }, 30) }).triggerNative('submit') }) -asyncTest('form input[type=submit][data-disable-with] using "form" attribute disables', 6, function() { +QUnit.test('form input[type=submit][data-disable-with] using "form" attribute disables', function(assert) { var form = $('#not_remote'), input = $('input[form=not_remote]') - App.checkEnabledState(input, 'Form Attr Submit') + assert.enabledState(input, 'Form Attr Submit') + const done = assert.async() $(document).bind('iframe:loaded', function(e, data) { setTimeout(function() { - App.checkDisabledState(input, 'form attr submitting') - start() + assert.disabledState(input, 'form attr submitting') + done() }, 30) }) form.triggerNative('submit') setTimeout(function() { - App.checkDisabledState(input, 'form attr submitting') + assert.disabledState(input, 'form attr submitting') }, 30) }) -asyncTest('form[data-remote] textarea[data-disable-with] attribute', 3, function() { +QUnit.test('form[data-remote] textarea[data-disable-with] attribute', function(assert) { + const done = assert.async() + var form = $('form[data-remote]'), textarea = $('').appendTo(form) form.bindNative('ajax:success', function(e, data) { setTimeout(function() { - equal(data.params.user_bio, 'born, lived, died.') - start() + assert.equal(data.params.user_bio, 'born, lived, died.') + done() }, 13) }) form.triggerNative('submit') - App.checkDisabledState(textarea, 'processing ...') + assert.disabledState(textarea, 'processing ...') }) -asyncTest('a[data-disable-with] disables', 4, function() { +QUnit.test('a[data-disable-with] disables', function(assert) { + const done = assert.async() + var link = $('a[data-disable-with]') - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click') - App.checkDisabledState(link, 'clicking...') - start() + assert.disabledState(link, 'clicking...') + done() }) -test('a[data-disable-with] re-enables when `pageshow` event is triggered', function() { +QUnit.test('a[data-disable-with] re-enables when `pageshow` event is triggered', function(assert) { var link = $('a[data-disable-with]') - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click') - App.checkDisabledState(link, 'clicking...') + assert.disabledState(link, 'clicking...') $(window).triggerNative('pageshow') - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') }) -asyncTest('a[data-remote][data-disable-with] disables and re-enables', 6, function() { - var link = $('a[data-disable-with]').attr('data-remote', true) +QUnit.test('a[data-remote][data-disable-with] disables and re-enables', function(assert) { + const done = assert.async() - App.checkEnabledState(link, 'Click me') + var link = $('a[data-disable-with]').attr('data-remote', true) + assert.enabledState(link, 'Click me') link .bindNative('ajax:beforeSend', function() { - App.checkDisabledState(link, 'clicking...') + assert.disabledState(link, 'clicking...') }) .bindNative('ajax:complete', function() { setTimeout( function() { - App.checkEnabledState(link, 'Click me') - start() + assert.enabledState(link, 'Click me') + done() }, 15) }) .triggerNative('click') }) -asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:before` event is cancelled', 6, function() { +QUnit.test('a[data-remote][data-disable-with] re-enables when `ajax:before` event is cancelled', function(assert) { + const done = assert.async() + var link = $('a[data-disable-with]').attr('data-remote', true) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link .bindNative('ajax:before', function(e) { - App.checkDisabledState(link, 'clicking...') + assert.disabledState(link, 'clicking...') e.preventDefault() }) .triggerNative('click') setTimeout(function() { - App.checkEnabledState(link, 'Click me') - start() + assert.enabledState(link, 'Click me') + done() }, 30) }) -asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:beforeSend` event is cancelled', 6, function() { +QUnit.test('a[data-remote][data-disable-with] re-enables when `ajax:beforeSend` event is cancelled', function(assert) { + const done = assert.async() + var link = $('a[data-disable-with]').attr('data-remote', true) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link .bindNative('ajax:beforeSend', function(e) { - App.checkDisabledState(link, 'clicking...') + assert.disabledState(link, 'clicking...') e.preventDefault() }) .triggerNative('click') setTimeout(function() { - App.checkEnabledState(link, 'Click me') - start() + assert.enabledState(link, 'Click me') + done() }, 30) }) -asyncTest('a[data-remote][data-disable-with] re-enables when `ajax:error` event is triggered', 6, function() { +QUnit.test('a[data-remote][data-disable-with] re-enables when `ajax:error` event is triggered', function(assert) { + const done = assert.async() + var link = $('a[data-disable-with]').attr('data-remote', true).attr('href', '/error') - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link .bindNative('ajax:beforeSend', function() { - App.checkDisabledState(link, 'clicking...') + assert.disabledState(link, 'clicking...') }) .triggerNative('click') setTimeout(function() { - App.checkEnabledState(link, 'Click me') - start() + assert.enabledState(link, 'Click me') + done() }, 30) }) -asyncTest('form[data-remote] input|button|textarea[data-disable-with] does not disable when `ajax:beforeSend` event is cancelled', 8, function() { +QUnit.test('form[data-remote] input|button|textarea[data-disable-with] does not disable when `ajax:beforeSend` event is cancelled', function(assert) { var form = $('form[data-remote]'), input = form.find('input:text'), button = $('').appendTo(form), @@ -322,113 +348,116 @@ asyncTest('form[data-remote] input|button|textarea[data-disable-with] does not d }) .triggerNative('submit') - App.checkEnabledState(input, 'john') - App.checkEnabledState(button, 'Submit') - App.checkEnabledState(textarea, 'born, lived, died.') - App.checkEnabledState(submit, 'Submit') - - start() + assert.enabledState(input, 'john') + assert.enabledState(button, 'Submit') + assert.enabledState(textarea, 'born, lived, died.') + assert.enabledState(submit, 'Submit') }) -asyncTest('ctrl-clicking on a link does not disable the link', 6, function() { +QUnit.test('ctrl-clicking on a link does not disable the link', function(assert) { var link = $('a[data-disable-with]') - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click', { metaKey: true }) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click', { metaKey: true }) - App.checkEnabledState(link, 'Click me') - start() + assert.enabledState(link, 'Click me') }) -asyncTest('right/mouse-wheel-clicking on a link does not disable the link', 10, function() { +QUnit.test('right/mouse-wheel-clicking on a link does not disable the link', function(assert) { var link = $('a[data-disable-with]') - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click', { button: 1 }) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click', { button: 1 }) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click', { button: 2 }) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click', { button: 2 }) - App.checkEnabledState(link, 'Click me') - start() + assert.enabledState(link, 'Click me') }) -asyncTest('button[data-remote][data-disable-with] disables and re-enables', 6, function() { +QUnit.test('button[data-remote][data-disable-with] disables and re-enables', function(assert) { + const done = assert.async() + var button = $('button[data-remote][data-disable-with]') - App.checkEnabledState(button, 'Click me') + assert.enabledState(button, 'Click me') button .bindNative('ajax:send', function() { - App.checkDisabledState(button, 'clicking...') + assert.disabledState(button, 'clicking...') }) .bindNative('ajax:complete', function() { setTimeout( function() { - App.checkEnabledState(button, 'Click me') - start() + assert.enabledState(button, 'Click me') + done() }, 15) }) .triggerNative('click') }) -asyncTest('button[data-remote][data-disable-with] re-enables when `ajax:before` event is cancelled', 6, function() { +QUnit.test('button[data-remote][data-disable-with] re-enables when `ajax:before` event is cancelled', function(assert) { + const done = assert.async() + var button = $('button[data-remote][data-disable-with]') - App.checkEnabledState(button, 'Click me') + assert.enabledState(button, 'Click me') button .bindNative('ajax:before', function(e) { - App.checkDisabledState(button, 'clicking...') + assert.disabledState(button, 'clicking...') e.preventDefault() }) .triggerNative('click') setTimeout(function() { - App.checkEnabledState(button, 'Click me') - start() + assert.enabledState(button, 'Click me') + done() }, 30) }) -asyncTest('button[data-remote][data-disable-with] re-enables when `ajax:beforeSend` event is cancelled', 6, function() { +QUnit.test('button[data-remote][data-disable-with] re-enables when `ajax:beforeSend` event is cancelled', function(assert) { + const done = assert.async() + var button = $('button[data-remote][data-disable-with]') - App.checkEnabledState(button, 'Click me') + assert.enabledState(button, 'Click me') button .bindNative('ajax:beforeSend', function(e) { - App.checkDisabledState(button, 'clicking...') + assert.disabledState(button, 'clicking...') e.preventDefault() }) .triggerNative('click') setTimeout(function() { - App.checkEnabledState(button, 'Click me') - start() + assert.enabledState(button, 'Click me') + done() }, 30) }) -asyncTest('button[data-remote][data-disable-with] re-enables when `ajax:error` event is triggered', 6, function() { +QUnit.test('button[data-remote][data-disable-with] re-enables when `ajax:error` event is triggered', function(assert) { + const done = assert.async() + var button = $('a[data-disable-with]').attr('data-remote', true).attr('href', '/error') - App.checkEnabledState(button, 'Click me') - + assert.enabledState(button, 'Click me') button .bindNative('ajax:send', function() { - App.checkDisabledState(button, 'clicking...') + assert.disabledState(button, 'clicking...') }) .triggerNative('click') setTimeout(function() { - App.checkEnabledState(button, 'Click me') - start() + assert.enabledState(button, 'Click me') + done() }, 30) }) diff --git a/actionview/test/ujs/public/test/data-disable.js b/actionview/test/ujs/public/test/data-disable.js index 9f84c4647e..feae3dc937 100644 --- a/actionview/test/ujs/public/test/data-disable.js +++ b/actionview/test/ujs/public/test/data-disable.js @@ -1,5 +1,5 @@ -module('data-disable', { - setup: function() { +QUnit.module('data-disable', { + beforeEach: function() { $('#qunit-fixture').append($('', { action: '/echo', 'data-remote': 'true', @@ -29,68 +29,76 @@ module('data-disable', { 'data-disable': 'true' })) }, - teardown: function() { + afterEach: function() { $(document).unbind('iframe:loaded') } }) -asyncTest('form input field with "data-disable" attribute', 7, function() { +QUnit.test('form input field with "data-disable" attribute', function(assert) { + const done = assert.async() + var form = $('form[data-remote]'), input = form.find('input[type=text]') - App.checkEnabledState(input, 'john') + assert.enabledState(input, 'john') form.bindNative('ajax:success', function(e, data) { setTimeout(function() { - App.checkEnabledState(input, 'john') - equal(data.params.user_name, 'john') - start() + assert.enabledState(input, 'john') + assert.equal(data.params.user_name, 'john') + done() }, 13) }) form.triggerNative('submit') - App.checkDisabledState(input, 'john') + assert.disabledState(input, 'john') }) -asyncTest('form button with "data-disable" attribute', 7, function() { +QUnit.test('form button with "data-disable" attribute', function(assert) { + const done = assert.async() + var form = $('form[data-remote]'), button = $('') form.append(button) - App.checkEnabledState(button, 'Submit') + assert.enabledState(button, 'Submit') form.bindNative('ajax:success', function(e, data) { setTimeout(function() { - App.checkEnabledState(button, 'Submit') - start() + assert.enabledState(button, 'Submit') + done() }, 13) }) form.triggerNative('submit') - App.checkDisabledState(button, 'Submit') - equal(button.data('ujs:enable-with'), undefined) + assert.disabledState(button, 'Submit') + assert.equal(button.data('ujs:enable-with'), undefined) }) -asyncTest('form input[type=submit][data-disable] disables', 6, function() { - var form = $('form:not([data-remote])'), input = form.find('input[type=submit]') +QUnit.test('form input[type=submit][data-disable] disables', function(assert) { + const done = assert.async() - App.checkEnabledState(input, 'Submit') + var form = $('#qunit-fixture form:not([data-remote])'), input = form.find('input[type=submit]') + + assert.enabledState(input, 'Submit') // WEEIRDD: attaching this handler makes the test work in IE7 $(document).bind('iframe:loading', function(e, f) {}) $(document).bind('iframe:loaded', function(e, data) { setTimeout(function() { - App.checkDisabledState(input, 'Submit') - start() + assert.disabledState(input, 'Submit') + done() }, 30) }) form.triggerNative('submit') setTimeout(function() { - App.checkDisabledState(input, 'Submit') + assert.disabledState(input, 'Submit') }, 30) }) -asyncTest('form[data-remote] input[type=submit][data-disable] is replaced in ajax callback', 2, function() { +QUnit.test('form[data-remote] input[type=submit][data-disable] is replaced in ajax callback', function(assert) { + const done = assert.async() + var form = $('#qunit-fixture form:not([data-remote])').attr('data-remote', 'true'), origFormContents = form.html() form.bindNative('ajax:success', function() { @@ -98,13 +106,15 @@ asyncTest('form[data-remote] input[type=submit][data-disable] is replaced in aja setTimeout(function() { var input = form.find('input[type=submit]') - App.checkEnabledState(input, 'Submit') - start() + assert.enabledState(input, 'Submit') + done() }, 30) }).triggerNative('submit') }) -asyncTest('form[data-remote] input[data-disable] is replaced with disabled field in ajax callback', 2, function() { +QUnit.test('form[data-remote] input[data-disable] is replaced with disabled field in ajax callback', function(assert) { + const done = assert.async() + var form = $('#qunit-fixture form:not([data-remote])').attr('data-remote', 'true'), input = form.find('input[type=submit]'), newDisabledInput = input.clone().attr('disabled', 'disabled') @@ -112,110 +122,119 @@ asyncTest('form[data-remote] input[data-disable] is replaced with disabled field input.replaceWith(newDisabledInput) setTimeout(function() { - App.checkEnabledState(newDisabledInput, 'Submit') - start() + assert.enabledState(newDisabledInput, 'Submit') + done() }, 30) }).triggerNative('submit') }) -asyncTest('form[data-remote] textarea[data-disable] attribute', 3, function() { +QUnit.test('form[data-remote] textarea[data-disable] attribute', function(assert) { + const done = assert.async() + var form = $('form[data-remote]'), textarea = $('').appendTo(form) form.bindNative('ajax:success', function(e, data) { setTimeout(function() { - equal(data.params.user_bio, 'born, lived, died.') - start() + assert.equal(data.params.user_bio, 'born, lived, died.') + done() }, 13) }) form.triggerNative('submit') - App.checkDisabledState(textarea, 'born, lived, died.') + assert.disabledState(textarea, 'born, lived, died.') }) -asyncTest('a[data-disable] disables', 5, function() { +QUnit.test('a[data-disable] disables', function(assert) { var link = $('a[data-disable]') - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click') - App.checkDisabledState(link, 'Click me') - equal(link.data('ujs:enable-with'), undefined) - start() + assert.disabledState(link, 'Click me') + assert.equal(link.data('ujs:enable-with'), undefined) }) -asyncTest('a[data-remote][data-disable] disables and re-enables', 6, function() { +QUnit.test('a[data-remote][data-disable] disables and re-enables', function(assert) { + const done = assert.async() + var link = $('a[data-disable]').attr('data-remote', true) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link .bindNative('ajax:send', function() { - App.checkDisabledState(link, 'Click me') + assert.disabledState(link, 'Click me') }) .bindNative('ajax:complete', function() { setTimeout( function() { - App.checkEnabledState(link, 'Click me') - start() + assert.enabledState(link, 'Click me') + done() }, 15) }) .triggerNative('click') }) -asyncTest('a[data-remote][data-disable] re-enables when `ajax:before` event is cancelled', 6, function() { +QUnit.test('a[data-remote][data-disable] re-enables when `ajax:before` event is cancelled', function(assert) { + const done = assert.async() + var link = $('a[data-disable]').attr('data-remote', true) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link .bindNative('ajax:before', function(e) { - App.checkDisabledState(link, 'Click me') + assert.disabledState(link, 'Click me') e.preventDefault() }) .triggerNative('click') setTimeout(function() { - App.checkEnabledState(link, 'Click me') - start() + assert.enabledState(link, 'Click me') + done() }, 30) }) -asyncTest('a[data-remote][data-disable] re-enables when `ajax:beforeSend` event is cancelled', 6, function() { +QUnit.test('a[data-remote][data-disable] re-enables when `ajax:beforeSend` event is cancelled', function(assert) { + const done = assert.async() + var link = $('a[data-disable]').attr('data-remote', true) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link .bindNative('ajax:beforeSend', function(e) { - App.checkDisabledState(link, 'Click me') + assert.disabledState(link, 'Click me') e.preventDefault() }) .triggerNative('click') setTimeout(function() { - App.checkEnabledState(link, 'Click me') - start() + assert.enabledState(link, 'Click me') + done() }, 30) }) -asyncTest('a[data-remote][data-disable] re-enables when `ajax:error` event is triggered', 6, function() { +QUnit.test('a[data-remote][data-disable] re-enables when `ajax:error` event is triggered', function(assert) { + const done = assert.async() + var link = $('a[data-disable]').attr('data-remote', true).attr('href', '/error') - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link .bindNative('ajax:send', function() { - App.checkDisabledState(link, 'Click me') + assert.disabledState(link, 'Click me') }) .triggerNative('click') setTimeout(function() { - App.checkEnabledState(link, 'Click me') - start() + assert.enabledState(link, 'Click me') + done() }, 30) }) -asyncTest('form[data-remote] input|button|textarea[data-disable] does not disable when `ajax:beforeSend` event is cancelled', 8, function() { +QUnit.test('form[data-remote] input|button|textarea[data-disable] does not disable when `ajax:beforeSend` event is cancelled', function(assert) { var form = $('form[data-remote]'), input = form.find('input:text'), button = $('').appendTo(form), @@ -229,130 +248,136 @@ asyncTest('form[data-remote] input|button|textarea[data-disable] does not disabl }) .triggerNative('submit') - App.checkEnabledState(input, 'john') - App.checkEnabledState(button, 'Submit') - App.checkEnabledState(textarea, 'born, lived, died.') - App.checkEnabledState(submit, 'Submit') - - start() + assert.enabledState(input, 'john') + assert.enabledState(button, 'Submit') + assert.enabledState(textarea, 'born, lived, died.') + assert.enabledState(submit, 'Submit') }) -asyncTest('ctrl-clicking on a link does not disables the link', 6, function() { +QUnit.test('ctrl-clicking on a link does not disables the link', function(assert) { var link = $('a[data-disable]') - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click', { metaKey: true }) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click', { ctrlKey: true }) - App.checkEnabledState(link, 'Click me') - start() + assert.enabledState(link, 'Click me') }) -asyncTest('right/mouse-wheel-clicking on a link does not disable the link', 10, function() { +QUnit.test('right/mouse-wheel-clicking on a link does not disable the link', function(assert) { var link = $('a[data-disable]') - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click', { button: 1 }) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click', { button: 1 }) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click', { button: 2 }) - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link.triggerNative('click', { button: 2 }) - App.checkEnabledState(link, 'Click me') - start() + assert.enabledState(link, 'Click me') }) -asyncTest('button[data-remote][data-disable] disables and re-enables', 6, function() { +QUnit.test('button[data-remote][data-disable] disables and re-enables', function(assert) { + const done = assert.async() + var button = $('button[data-remote][data-disable]') - App.checkEnabledState(button, 'Click me') + assert.enabledState(button, 'Click me') button .bindNative('ajax:send', function() { - App.checkDisabledState(button, 'Click me') + assert.disabledState(button, 'Click me') }) .bindNative('ajax:complete', function() { setTimeout( function() { - App.checkEnabledState(button, 'Click me') - start() + assert.enabledState(button, 'Click me') + done() }, 15) }) .triggerNative('click') }) -asyncTest('button[data-remote][data-disable] re-enables when `ajax:before` event is cancelled', 6, function() { +QUnit.test('button[data-remote][data-disable] re-enables when `ajax:before` event is cancelled', function(assert) { + const done = assert.async() + var button = $('button[data-remote][data-disable]') - App.checkEnabledState(button, 'Click me') + assert.enabledState(button, 'Click me') button .bindNative('ajax:before', function(e) { - App.checkDisabledState(button, 'Click me') + assert.disabledState(button, 'Click me') e.preventDefault() }) .triggerNative('click') setTimeout(function() { - App.checkEnabledState(button, 'Click me') - start() + assert.enabledState(button, 'Click me') + done() }, 30) }) -asyncTest('button[data-remote][data-disable] re-enables when `ajax:beforeSend` event is cancelled', 6, function() { +QUnit.test('button[data-remote][data-disable] re-enables when `ajax:beforeSend` event is cancelled', function(assert) { + const done = assert.async() + var button = $('button[data-remote][data-disable]') - App.checkEnabledState(button, 'Click me') + assert.enabledState(button, 'Click me') button .bindNative('ajax:beforeSend', function(e) { - App.checkDisabledState(button, 'Click me') + assert.disabledState(button, 'Click me') e.preventDefault() }) .triggerNative('click') setTimeout(function() { - App.checkEnabledState(button, 'Click me') - start() + assert.enabledState(button, 'Click me') + done() }, 30) }) -asyncTest('button[data-remote][data-disable] re-enables when `ajax:error` event is triggered', 6, function() { +QUnit.test('button[data-remote][data-disable] re-enables when `ajax:error` event is triggered', function(assert) { + const done = assert.async() + var button = $('a[data-disable]').attr('data-remote', true).attr('href', '/error') - App.checkEnabledState(button, 'Click me') + assert.enabledState(button, 'Click me') button .bindNative('ajax:send', function() { - App.checkDisabledState(button, 'Click me') + assert.disabledState(button, 'Click me') }) .triggerNative('click') setTimeout(function() { - App.checkEnabledState(button, 'Click me') - start() + assert.enabledState(button, 'Click me') + done() }, 30) }) -asyncTest('do not enable elements for XHR redirects', 6, function() { +QUnit.test('do not enable elements for XHR redirects', function(assert) { + const done = assert.async() + var link = $('a[data-disable]').attr('data-remote', true).attr('href', '/echo?with_xhr_redirect=true') - App.checkEnabledState(link, 'Click me') + assert.enabledState(link, 'Click me') link .bindNative('ajax:send', function() { - App.checkDisabledState(link, 'Click me') + assert.disabledState(link, 'Click me') }) .triggerNative('click') setTimeout(function() { - App.checkDisabledState(link, 'Click me') - start() + assert.disabledState(link, 'Click me') + done() }, 30) }) diff --git a/actionview/test/ujs/public/test/data-method.js b/actionview/test/ujs/public/test/data-method.js index 47d940c577..04764acf7c 100644 --- a/actionview/test/ujs/public/test/data-method.js +++ b/actionview/test/ujs/public/test/data-method.js @@ -1,12 +1,12 @@ (function() { -module('data-method', { - setup: function() { +QUnit.module('data-method', { + beforeEach: function() { $('#qunit-fixture').append($('', { href: '/echo', 'data-method': 'delete', text: 'destroy!' })) }, - teardown: function() { + afterEach: function() { $(document).unbind('iframe:loaded') } }) @@ -14,49 +14,59 @@ module('data-method', { function submit(fn, options) { $(document).bind('iframe:loaded', function(e, data) { fn(data) - start() }) $('#qunit-fixture').find('a') .triggerNative('click') } -asyncTest('link with "data-method" set to "delete"', 3, function() { +QUnit.test('link with "data-method" set to "delete"', function(assert) { + const done = assert.async() + submit(function(data) { - equal(data.REQUEST_METHOD, 'DELETE') - strictEqual(data.params.authenticity_token, undefined) - strictEqual(data.HTTP_X_CSRF_TOKEN, undefined) + assert.equal(data.REQUEST_METHOD, 'DELETE') + assert.strictEqual(data.params.authenticity_token, undefined) + assert.strictEqual(data.HTTP_X_CSRF_TOKEN, undefined) + done() }) }) -asyncTest('click on the child of link with "data-method"', 3, function() { +QUnit.test('click on the child of link with "data-method"', function(assert) { + const done = assert.async() + $(document).bind('iframe:loaded', function(e, data) { - equal(data.REQUEST_METHOD, 'DELETE') - strictEqual(data.params.authenticity_token, undefined) - strictEqual(data.HTTP_X_CSRF_TOKEN, undefined) - start() + assert.equal(data.REQUEST_METHOD, 'DELETE') + assert.strictEqual(data.params.authenticity_token, undefined) + assert.strictEqual(data.HTTP_X_CSRF_TOKEN, undefined) + done() }) $('#qunit-fixture a').html('destroy!').find('strong').triggerNative('click') }) -asyncTest('link with "data-method" and CSRF', 1, function() { +QUnit.test('link with "data-method" and CSRF', function(assert) { + const done = assert.async() + $('#qunit-fixture') .append('') .append('') submit(function(data) { - equal(data.params.authenticity_token, 'cf50faa3fe97702ca1ae') + assert.equal(data.params.authenticity_token, 'cf50faa3fe97702ca1ae') + done() }) }) -asyncTest('link "target" should be carried over to generated form', 1, function() { +QUnit.test('link "target" should be carried over to generated form', function(assert) { + const done = assert.async() + $('a[data-method]').attr('target', 'super-special-frame') submit(function(data) { - equal(data.params._target, 'super-special-frame') + assert.equal(data.params._target, 'super-special-frame') + done() }) }) -asyncTest('link with "data-method" and cross origin', 1, function() { +QUnit.test('link with "data-method" and cross origin', function(assert) { var data = {} $('#qunit-fixture') @@ -77,9 +87,7 @@ asyncTest('link with "data-method" and cross origin', 1, function() { link.triggerNative('click') - start() - - notEqual(data.authenticity_token, 'cf50faa3fe97702ca1ae') + assert.notEqual(data.authenticity_token, 'cf50faa3fe97702ca1ae') }) })() diff --git a/actionview/test/ujs/public/test/data-remote.js b/actionview/test/ujs/public/test/data-remote.js index 6ed0f27233..e1f33a8a7c 100644 --- a/actionview/test/ujs/public/test/data-remote.js +++ b/actionview/test/ujs/public/test/data-remote.js @@ -12,8 +12,8 @@ function buildSelect(attrs) { ) } -module('data-remote', { - setup: function() { +QUnit.module('data-remote', { + beforeEach: function() { $('#qunit-fixture') .append($('', { href: '/echo', @@ -44,9 +44,10 @@ module('data-remote', { } }) -asyncTest('ctrl-clicking on a link does not fire ajaxyness', 0, function() { +QUnit.test('ctrl-clicking on a link does not fire ajaxyness', function(assert) { + const done = assert.async() + assert.expect(0) var link = $('a[data-remote]') - // Ideally, we'd set up an iframe to intercept normal link clicks // and add a test to make sure the iframe:loaded event is triggered. // However, jquery doesn't actually cause a native `click` event and @@ -54,16 +55,21 @@ asyncTest('ctrl-clicking on a link does not fire ajaxyness', 0, function() { link .removeAttr('data-params') .bindNative('ajax:beforeSend', function() { - ok(false, 'ajax should not be triggered') + assert.ok(false, 'ajax should not be triggered') }) link.triggerNative('click', { metaKey: true }) link.triggerNative('click', { ctrlKey: true }) - setTimeout(function() { start() }, 13) + setTimeout(function() { + done() + }, 13) }) -asyncTest('right/mouse-wheel-clicking on a link does not fire ajaxyness', 0, function() { +QUnit.test('right/mouse-wheel-clicking on a link does not fire ajaxyness', function(assert) { + const done = assert.async() + assert.expect(0) + var link = $('a[data-remote]') // Ideally, we'd set up an iframe to intercept normal link clicks @@ -73,37 +79,43 @@ asyncTest('right/mouse-wheel-clicking on a link does not fire ajaxyness', 0, fun link .removeAttr('data-params') .bindNative('ajax:beforeSend', function() { - ok(false, 'ajax should not be triggered') + assert.ok(false, 'ajax should not be triggered') }) link.triggerNative('click', { button: 1 }) link.triggerNative('click', { button: 2 }) - setTimeout(function() { start() }, 13) + setTimeout(function() { + done() + }, 13) }) -asyncTest('clicking on a link via a non-mouse Event (such as from js) works', 1, function() { +QUnit.test('clicking on a link via a non-mouse Event (such as from js) works', function(assert) { var link = $('a[data-remote]') + const done = assert.async() + link .removeAttr('data-params') .bindNative('ajax:beforeSend', function() { - ok(true, 'ajax should be triggered') + assert.ok(true, 'ajax should be triggered') }) Rails.fire(link[0], 'click') - setTimeout(function() { start() }, 13) + setTimeout(function() { done() }, 13) }) -asyncTest('ctrl-clicking on a link still fires ajax for non-GET links and for links with "data-params"', 2, function() { +QUnit.test('ctrl-clicking on a link still fires ajax for non-GET links and for links with "data-params"', function(assert) { var link = $('a[data-remote]') + const done = assert.async() + link .removeAttr('data-params') .attr('data-method', 'POST') .bindNative('ajax:beforeSend', function() { - ok(true, 'ajax should be triggered') + assert.ok(true, 'ajax should be triggered') }) .triggerNative('click', { metaKey: true }) @@ -112,76 +124,89 @@ asyncTest('ctrl-clicking on a link still fires ajax for non-GET links and for li .attr('data-params', 'name=steve') .triggerNative('click', { metaKey: true }) - setTimeout(function() { start() }, 13) + setTimeout(function() { done() }, 13) }) -asyncTest('clicking on a link with data-remote attribute', 5, function() { +QUnit.test('clicking on a link with data-remote attribute', function(assert) { + const done = assert.async() + $('a[data-remote]') .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertCallbackInvoked('ajax:success') - App.assertRequestPath(data, '/echo') - equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value') - equal(data.params.data2, 'value2', 'ajax arguments should have key data2 with right value') - App.assertGetRequest(data) + assert.callbackInvoked('ajax:success') + assert.requestPath(data, '/echo') + assert.equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value') + assert.equal(data.params.data2, 'value2', 'ajax arguments should have key data2 with right value') + assert.getRequest(data) }) - .bindNative('ajax:complete', function() { start() }) + .bindNative('ajax:complete', function() { done() }) .triggerNative('click') }) -asyncTest('clicking on a link with both query string in href and data-params', 4, function() { +QUnit.test('clicking on a link with both query string in href and data-params', function(assert) { + const done = assert.async() + $('a[data-remote]') .attr('href', '/echo?data3=value3') .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertGetRequest(data) - equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value') - equal(data.params.data2, 'value2', 'ajax arguments should have key data2 with right value') - equal(data.params.data3, 'value3', 'query string in URL should be passed to server with right value') + assert.getRequest(data) + assert.equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value') + assert.equal(data.params.data2, 'value2', 'ajax arguments should have key data2 with right value') + assert.equal(data.params.data3, 'value3', 'query string in URL should be passed to server with right value') }) - .bindNative('ajax:complete', function() { start() }) + .bindNative('ajax:complete', function() { done() }) .triggerNative('click') }) -asyncTest('clicking on a link with both query string in href and data-params with POST method', 4, function() { +QUnit.test('clicking on a link with both query string in href and data-params with POST method', function(assert) { + const done = assert.async() + $('a[data-remote]') .attr('href', '/echo?data3=value3') .attr('data-method', 'post') .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertPostRequest(data) - equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value') - equal(data.params.data2, 'value2', 'ajax arguments should have key data2 with right value') - equal(data.params.data3, 'value3', 'query string in URL should be passed to server with right value') + assert.postRequest(data) + assert.equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value') + assert.equal(data.params.data2, 'value2', 'ajax arguments should have key data2 with right value') + assert.equal(data.params.data3, 'value3', 'query string in URL should be passed to server with right value') }) - .bindNative('ajax:complete', function() { start() }) + .bindNative('ajax:complete', function() { done() }) .triggerNative('click') }) -asyncTest('clicking on a link with disabled attribute', 0, function() { - $('a[disabled]') +QUnit.test('clicking on a link with disabled attribute', function(assert) { + const done = assert.async() + assert.expect(0) + + $('#qunit-fixture a[disabled]') .bindNative('ajax:before', function(e, data, status, xhr) { - App.assertCallbackNotInvoked('ajax:success') + assert.callbackNotInvoked('ajax:success') }) - .bindNative('ajax:complete', function() { start() }) .triggerNative('click') setTimeout(function() { - start() + done() }, 13) }) -asyncTest('clicking on a button with data-remote attribute', 5, function() { +QUnit.test('clicking on a button with data-remote attribute', function(assert) { + const done = assert.async() + $('button[data-remote]') .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertCallbackInvoked('ajax:success') - App.assertRequestPath(data, '/echo') - equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value') - equal(data.params.data2, 'value2', 'ajax arguments should have key data2 with right value') - App.assertGetRequest(data) + assert.callbackInvoked('ajax:success') + assert.requestPath(data, '/echo') + assert.equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value') + assert.equal(data.params.data2, 'value2', 'ajax arguments should have key data2 with right value') + assert.getRequest(data) }) - .bindNative('ajax:complete', function() { start() }) + .bindNative('ajax:complete', function() { done() }) .triggerNative('click') }) -asyncTest('right/mouse-wheel-clicking on a button with data-remote attribute does not fire ajaxyness', 0, function() { +QUnit.test('right/mouse-wheel-clicking on a button with data-remote attribute does not fire ajaxyness', function(assert) { + const done = assert.async() + assert.expect(0) + var button = $('button[data-remote]') // Ideally, we'd set up an iframe to intercept normal link clicks @@ -191,86 +216,98 @@ asyncTest('right/mouse-wheel-clicking on a button with data-remote attribute doe button .removeAttr('data-params') .bindNative('ajax:beforeSend', function() { - ok(false, 'ajax should not be triggered') + assert.ok(false, 'ajax should not be triggered') }) button.triggerNative('click', { button: 1 }) button.triggerNative('click', { button: 2 }) - setTimeout(function() { start() }, 13) + setTimeout(function() { + done() + }, 13) }) -asyncTest('changing a select option with data-remote attribute', 5, function() { +QUnit.test('changing a select option with data-remote attribute', function(assert) { + const done = assert.async() + buildSelect() $('select[data-remote]') .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertCallbackInvoked('ajax:success') - App.assertRequestPath(data, '/echo') - equal(data.params.user_data, 'optionValue2', 'ajax arguments should have key term with right value') - equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value') - App.assertGetRequest(data) + assert.callbackInvoked('ajax:success') + assert.requestPath(data, '/echo') + assert.equal(data.params.user_data, 'optionValue2', 'ajax arguments should have key term with right value') + assert.equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value') + assert.getRequest(data) }) - .bindNative('ajax:complete', function() { start() }) + .bindNative('ajax:complete', function() { done() }) .val('optionValue2') .triggerNative('change') }) -asyncTest('submitting form with data-remote attribute', 4, function() { +QUnit.test('submitting form with data-remote attribute', function(assert) { + const done = assert.async() + $('form[data-remote]') .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertCallbackInvoked('ajax:success') - App.assertRequestPath(data, '/echo') - equal(data.params.user_name, 'john', 'ajax arguments should have key user_name with right value') - App.assertPostRequest(data) + assert.callbackInvoked('ajax:success') + assert.requestPath(data, '/echo') + assert.equal(data.params.user_name, 'john', 'ajax arguments should have key user_name with right value') + assert.postRequest(data) }) - .bindNative('ajax:complete', function() { start() }) + .bindNative('ajax:complete', function() { done() }) .triggerNative('submit') }) -asyncTest('submitting form with data-remote attribute should include inputs in a fieldset only once', 3, function() { +QUnit.test('submitting form with data-remote attribute should include inputs in a fieldset only once', function(assert) { + const done = assert.async() + $('form[data-remote]') .append('
') .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertCallbackInvoked('ajax:success') - equal(data.params.items.length, 1, 'ajax arguments should only have the item once') - App.assertPostRequest(data) + assert.callbackInvoked('ajax:success') + assert.equal(data.params.items.length, 1, 'ajax arguments should only have the item once') + assert.postRequest(data) }) .bindNative('ajax:complete', function() { $('form[data-remote], fieldset').remove() - start() + done() }) .triggerNative('submit') }) -asyncTest('submitting form with data-remote attribute submits input with matching [form] attribute', 6, function() { +QUnit.test('submitting form with data-remote attribute submits input with matching [form] attribute', function(assert) { + const done = assert.async() + $('#qunit-fixture') .append($('')) .append($('')) $('form[data-remote]') .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertCallbackInvoked('ajax:success') - App.assertRequestPath(data, '/echo') - equal(data.params.user_name, 'john', 'ajax arguments should have key user_name with right value') - equal(data.params.user_data, 'value1', 'ajax arguments should have key user_data with right value') - equal(data.params.user_email, undefined, 'ajax arguments should not have disabled field') - App.assertPostRequest(data) + assert.callbackInvoked('ajax:success') + assert.requestPath(data, '/echo') + assert.equal(data.params.user_name, 'john', 'ajax arguments should have key user_name with right value') + assert.equal(data.params.user_data, 'value1', 'ajax arguments should have key user_data with right value') + assert.equal(data.params.user_email, undefined, 'ajax arguments should not have disabled field') + assert.postRequest(data) }) - .bindNative('ajax:complete', function() { start() }) + .bindNative('ajax:complete', function() { done() }) .triggerNative('submit') }) -asyncTest('submitting form with data-remote attribute by clicking button with matching [form] attribute', 5, function() { +QUnit.test('submitting form with data-remote attribute by clicking button with matching [form] attribute', function(assert) { + const done = assert.async() + $('form[data-remote]') .bindNative('ajax:success', function(e, data, status, xhr) { - App.assertCallbackInvoked('ajax:success') - App.assertRequestPath(data, '/echo') - equal(data.params.user_name, 'john', 'ajax arguments should have key user_name with right value') - equal(data.params.user_data, 'value2', 'ajax arguments should have key user_data with right value') - App.assertPostRequest(data) + assert.callbackInvoked('ajax:success') + assert.requestPath(data, '/echo') + assert.equal(data.params.user_name, 'john', 'ajax arguments should have key user_name with right value') + assert.equal(data.params.user_data, 'value2', 'ajax arguments should have key user_data with right value') + assert.postRequest(data) }) - .bindNative('ajax:complete', function() { start() }) + .bindNative('ajax:complete', function() { done() }) $('