1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #31493 -- Replaced var with const and let keywords in JavaScript.

The eslint configuration and the admin script compress.py have been
updated for ES6.

The unused fallback of globals.django in jquery.init.js was removed. It
is always included before jsi18n-mocks.test.js and it always sets the
global value.
This commit is contained in:
Jon Dufresne
2020-04-20 17:39:15 -07:00
committed by Carlton Gibson
parent 0dafadadb9
commit 5d37cc703b
30 changed files with 401 additions and 406 deletions

View File

@@ -4,8 +4,8 @@
QUnit.module('admin.inlines: tabular formsets', {
beforeEach: function() {
var $ = django.jQuery;
var that = this;
const $ = django.jQuery;
const that = this;
this.addText = 'Add another';
$('#qunit-fixture').append($('#tabular-formset').text());
@@ -25,14 +25,14 @@ QUnit.test('no forms', function(assert) {
});
QUnit.test('add form', function(assert) {
var addButton = this.table.find('.add-row a');
const addButton = this.table.find('.add-row a');
assert.equal(addButton.text(), this.addText);
addButton.click();
assert.ok(this.table.find('#first-1'));
});
QUnit.test('added form has remove button', function(assert) {
var addButton = this.table.find('.add-row a');
const addButton = this.table.find('.add-row a');
assert.equal(addButton.text(), this.addText);
addButton.click();
assert.equal(this.table.find('#first-1 .inline-deletelink').length, 1);
@@ -40,9 +40,9 @@ QUnit.test('added form has remove button', function(assert) {
QUnit.test('add/remove form events', function(assert) {
assert.expect(6);
var $ = django.jQuery;
var $document = $(document);
var addButton = this.table.find('.add-row a');
const $ = django.jQuery;
const $document = $(document);
const addButton = this.table.find('.add-row a');
$document.on('formset:added', function(event, $row, formsetName) {
assert.ok(true, 'event `formset:added` triggered');
assert.equal(true, $row.is('#first-1'));
@@ -50,8 +50,8 @@ QUnit.test('add/remove form events', function(assert) {
$document.off('formset:added');
});
addButton.click();
var deletedRow = $('#first-1');
var deleteLink = this.table.find('.inline-deletelink');
const deletedRow = $('#first-1');
const deleteLink = this.table.find('.inline-deletelink');
$document.on('formset:removed', function(event, $row, formsetName) {
assert.ok(true, 'event `formset:removed` triggered');
assert.equal(true, $row.is(deletedRow));
@@ -62,13 +62,13 @@ QUnit.test('add/remove form events', function(assert) {
});
QUnit.test('existing add button', function(assert) {
var $ = django.jQuery;
const $ = django.jQuery;
$('#qunit-fixture').empty(); // Clear the table added in beforeEach
$('#qunit-fixture').append($('#tabular-formset').text());
this.table = $('table.inline');
this.inlineRow = this.table.find('tr');
this.table.append('<i class="add-button"></i>');
var addButton = this.table.find('.add-button');
const addButton = this.table.find('.add-button');
this.inlineRow.tabularFormset('table.inline tr', {
prefix: 'first',
deleteText: 'Remove',
@@ -82,7 +82,7 @@ QUnit.test('existing add button', function(assert) {
QUnit.module('admin.inlines: tabular formsets with validation errors', {
beforeEach: function() {
var $ = django.jQuery;
const $ = django.jQuery;
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
this.table = $('table.inline');
@@ -94,7 +94,7 @@ QUnit.module('admin.inlines: tabular formsets with validation errors', {
});
QUnit.test('first form has delete checkbox and no button', function(assert) {
var tr = this.inlineRows.slice(0, 1);
const tr = this.inlineRows.slice(0, 1);
assert.ok(tr.hasClass('dynamic-second'));
assert.ok(tr.hasClass('has_original'));
assert.equal(tr.find('td.delete input').length, 1);
@@ -102,14 +102,14 @@ QUnit.test('first form has delete checkbox and no button', function(assert) {
});
QUnit.test('dynamic form has remove button', function(assert) {
var tr = this.inlineRows.slice(1, 2);
const tr = this.inlineRows.slice(1, 2);
assert.ok(tr.hasClass('dynamic-second'));
assert.notOk(tr.hasClass('has_original'));
assert.equal(tr.find('.inline-deletelink').length, 1);
});
QUnit.test('dynamic template has nothing', function(assert) {
var tr = this.inlineRows.slice(2, 3);
const tr = this.inlineRows.slice(2, 3);
assert.ok(tr.hasClass('empty-form'));
assert.notOk(tr.hasClass('dynamic-second'));
assert.notOk(tr.hasClass('has_original'));
@@ -117,19 +117,19 @@ QUnit.test('dynamic template has nothing', function(assert) {
});
QUnit.test('removing a form-row also removed related row with non-field errors', function(assert) {
var $ = django.jQuery;
const $ = django.jQuery;
assert.ok(this.table.find('.row-form-errors').length);
var tr = this.inlineRows.slice(1, 2);
var trWithErrors = tr.prev();
const tr = this.inlineRows.slice(1, 2);
const trWithErrors = tr.prev();
assert.ok(trWithErrors.hasClass('row-form-errors'));
var deleteLink = tr.find('a.inline-deletelink');
const deleteLink = tr.find('a.inline-deletelink');
deleteLink.trigger($.Event('click', {target: deleteLink}));
assert.notOk(this.table.find('.row-form-errors').length);
});
QUnit.module('admin.inlines: tabular formsets with max_num', {
beforeEach: function() {
var $ = django.jQuery;
const $ = django.jQuery;
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
this.table = $('table.inline');
this.maxNum = $('input.id_second-MAX_NUM_FORMS');
@@ -142,14 +142,14 @@ QUnit.module('admin.inlines: tabular formsets with max_num', {
});
QUnit.test('does not show the add button if already at max_num', function(assert) {
var addButton = this.table.find('tr.add_row > td > a');
const addButton = this.table.find('tr.add_row > td > a');
assert.notOk(addButton.is(':visible'));
});
QUnit.test('make addButton visible again', function(assert) {
var $ = django.jQuery;
var addButton = this.table.find('tr.add_row > td > a');
var removeButton = this.table.find('tr.form-row:first').find('a.inline-deletelink');
const $ = django.jQuery;
const addButton = this.table.find('tr.add_row > td > a');
const removeButton = this.table.find('tr.form-row:first').find('a.inline-deletelink');
removeButton.trigger($.Event( "click", { target: removeButton } ));
assert.notOk(addButton.is(':visible'));
});
@@ -157,7 +157,7 @@ QUnit.test('make addButton visible again', function(assert) {
QUnit.module('admin.inlines: tabular formsets with min_num', {
beforeEach: function() {
var $ = django.jQuery;
const $ = django.jQuery;
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
this.table = $('table.inline');
this.minNum = $('input#id_second-MIN_NUM_FORMS');
@@ -174,8 +174,8 @@ QUnit.test('does not show the remove buttons if already at min_num', function(as
});
QUnit.test('make removeButtons visible again', function(assert) {
var $ = django.jQuery;
var addButton = this.table.find('tr.add-row > td > a');
const $ = django.jQuery;
const addButton = this.table.find('tr.add-row > td > a');
addButton.trigger($.Event( "click", { target: addButton } ));
assert.equal(this.table.find('.inline-deletelink:visible').length, 2);
});