From 1eef1158084bf9ecda71914241ff83ddb06ab825 Mon Sep 17 00:00:00 2001 From: a <455919189@qq.com> Date: Mon, 16 May 2022 07:58:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'test/Django-2.1.15/js=5Ftests/admin'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js_tests/admin/DateTimeShortcuts.test.js | 32 ++++++ .../js_tests/admin/actions.test.js | 24 ++++ .../Django-2.1.15/js_tests/admin/core.test.js | 104 ++++++++++++++++++ .../js_tests/admin/inlines.test.js | 71 ++++++++++++ .../js_tests/admin/jsi18n-mocks.test.js | 90 +++++++++++++++ 5 files changed, 321 insertions(+) create mode 100644 test/Django-2.1.15/js_tests/admin/DateTimeShortcuts.test.js create mode 100644 test/Django-2.1.15/js_tests/admin/actions.test.js create mode 100644 test/Django-2.1.15/js_tests/admin/core.test.js create mode 100644 test/Django-2.1.15/js_tests/admin/inlines.test.js create mode 100644 test/Django-2.1.15/js_tests/admin/jsi18n-mocks.test.js diff --git a/test/Django-2.1.15/js_tests/admin/DateTimeShortcuts.test.js b/test/Django-2.1.15/js_tests/admin/DateTimeShortcuts.test.js new file mode 100644 index 0000000..4e53495 --- /dev/null +++ b/test/Django-2.1.15/js_tests/admin/DateTimeShortcuts.test.js @@ -0,0 +1,32 @@ +/* global QUnit, DateTimeShortcuts */ +/* eslint global-strict: 0, strict: 0 */ +'use strict'; + +QUnit.module('admin.DateTimeShortcuts'); + +QUnit.test('init', function(assert) { + var $ = django.jQuery; + + var dateField = $('
'); + $('#qunit-fixture').append(dateField); + + DateTimeShortcuts.init(); + + var shortcuts = $('.datetimeshortcuts'); + assert.equal(shortcuts.length, 1); + assert.equal(shortcuts.find('a:first').text(), 'Today'); + assert.equal(shortcuts.find('a:last .date-icon').length, 1); + + // To prevent incorrect timezone warnings on date/time widgets, timezoneOffset + // should be 0 when a timezone offset isn't set in the HTML body attribute. + assert.equal(DateTimeShortcuts.timezoneOffset, 0); +}); + +QUnit.test('custom time shortcuts', function(assert) { + var $ = django.jQuery; + var timeField = $(''); + $('#qunit-fixture').append(timeField); + DateTimeShortcuts.clockHours.time_test = [['3 a.m.', 3]]; + DateTimeShortcuts.init(); + assert.equal($('.clockbox').find('a').first().text(), '3 a.m.'); +}); diff --git a/test/Django-2.1.15/js_tests/admin/actions.test.js b/test/Django-2.1.15/js_tests/admin/actions.test.js new file mode 100644 index 0000000..3ff8709 --- /dev/null +++ b/test/Django-2.1.15/js_tests/admin/actions.test.js @@ -0,0 +1,24 @@ +/* global QUnit */ +/* eslint global-strict: 0, strict: 0 */ +'use strict'; + +QUnit.module('admin.actions', { + beforeEach: function() { + // Number of results shown on page + /* eslint-disable */ + window._actions_icnt = '100'; + /* eslint-enable */ + + var $ = django.jQuery; + $('#qunit-fixture').append($('#result-table').text()); + + $('tr input.action-select').actions(); + } +}); + +QUnit.test('check', function(assert) { + var $ = django.jQuery; + assert.notOk($('.action-select').is(':checked')); + $('#action-toggle').click(); + assert.ok($('.action-select').is(':checked')); +}); diff --git a/test/Django-2.1.15/js_tests/admin/core.test.js b/test/Django-2.1.15/js_tests/admin/core.test.js new file mode 100644 index 0000000..eaf882d --- /dev/null +++ b/test/Django-2.1.15/js_tests/admin/core.test.js @@ -0,0 +1,104 @@ +/* global QUnit */ +/* eslint global-strict: 0, strict: 0 */ +'use strict'; + +QUnit.module('admin.core'); + +QUnit.test('Date.getTwelveHours', function(assert) { + assert.equal(new Date(2011, 0, 1, 0, 0).getTwelveHours(), 12, '0:00'); + assert.equal(new Date(2011, 0, 1, 11, 0).getTwelveHours(), 11, '11:00'); + assert.equal(new Date(2011, 0, 1, 16, 0).getTwelveHours(), 4, '16:00'); +}); + +QUnit.test('Date.getTwoDigitMonth', function(assert) { + assert.equal(new Date(2011, 0, 1).getTwoDigitMonth(), '01', 'jan 1'); + assert.equal(new Date(2011, 9, 1).getTwoDigitMonth(), '10', 'oct 1'); +}); + +QUnit.test('Date.getTwoDigitDate', function(assert) { + assert.equal(new Date(2011, 0, 1).getTwoDigitDate(), '01', 'jan 1'); + assert.equal(new Date(2011, 0, 15).getTwoDigitDate(), '15', 'jan 15'); +}); + +QUnit.test('Date.getTwoDigitTwelveHour', function(assert) { + assert.equal(new Date(2011, 0, 1, 0, 0).getTwoDigitTwelveHour(), '12', '0:00'); + assert.equal(new Date(2011, 0, 1, 4, 0).getTwoDigitTwelveHour(), '04', '4:00'); + assert.equal(new Date(2011, 0, 1, 22, 0).getTwoDigitTwelveHour(), '10', '22:00'); +}); + +QUnit.test('Date.getTwoDigitHour', function(assert) { + assert.equal(new Date(2014, 6, 1, 9, 0).getTwoDigitHour(), '09', '9:00 am is 09'); + assert.equal(new Date(2014, 6, 1, 11, 0).getTwoDigitHour(), '11', '11:00 am is 11'); +}); + +QUnit.test('Date.getTwoDigitMinute', function(assert) { + assert.equal(new Date(2014, 6, 1, 0, 5).getTwoDigitMinute(), '05', '12:05 am is 05'); + assert.equal(new Date(2014, 6, 1, 0, 15).getTwoDigitMinute(), '15', '12:15 am is 15'); +}); + +QUnit.test('Date.getTwoDigitSecond', function(assert) { + assert.equal(new Date(2014, 6, 1, 0, 0, 2).getTwoDigitSecond(), '02', '12:00:02 am is 02'); + assert.equal(new Date(2014, 6, 1, 0, 0, 20).getTwoDigitSecond(), '20', '12:00:20 am is 20'); +}); + +QUnit.test('Date.getHourMinute', function(assert) { + assert.equal(new Date(2014, 6, 1, 11, 0).getHourMinute(), '11:00', '11:00 am is 11:00'); + assert.equal(new Date(2014, 6, 1, 13, 25).getHourMinute(), '13:25', '1:25 pm is 13:25'); +}); + +QUnit.test('Date.getHourMinuteSecond', function(assert) { + assert.equal(new Date(2014, 6, 1, 11, 0, 0).getHourMinuteSecond(), '11:00:00', '11:00 am is 11:00:00'); + assert.equal(new Date(2014, 6, 1, 17, 45, 30).getHourMinuteSecond(), '17:45:30', '5:45:30 pm is 17:45:30'); +}); + +QUnit.test('Date.strftime', function(assert) { + var date = new Date(2014, 6, 1, 11, 0, 5); + assert.equal(date.strftime('%Y-%m-%d %H:%M:%S'), '2014-07-01 11:00:05'); + assert.equal(date.strftime('%B %d, %Y'), 'July 01, 2014'); +}); + +QUnit.test('String.strptime', function(assert) { + // Use UTC functions for extracting dates since the calendar uses them as + // well. Month numbering starts with 0 (January). + var firstParsedDate = '1988-02-26'.strptime('%Y-%m-%d'); + assert.equal(firstParsedDate.getUTCDate(), 26); + assert.equal(firstParsedDate.getUTCMonth(), 1); + assert.equal(firstParsedDate.getUTCFullYear(), 1988); + + var secondParsedDate = '26/02/88'.strptime('%d/%m/%y'); + assert.equal(secondParsedDate.getUTCDate(), 26); + assert.equal(secondParsedDate.getUTCMonth(), 1); + assert.equal(secondParsedDate.getUTCFullYear(), 1988); + + var format = django.get_format('DATE_INPUT_FORMATS')[0]; + var thirdParsedDate = '1983-11-20'.strptime(format); + + assert.equal(thirdParsedDate.getUTCDate(), 20); + assert.equal(thirdParsedDate.getUTCMonth(), 10); + assert.equal(thirdParsedDate.getUTCFullYear(), 1983); + + // Extracting from a Date object with local time must give the correct + // result. Without proper conversion, timezones from GMT+0100 to GMT+1200 + // gives a date one day earlier than necessary, e.g. converting local time + // Feb 26, 1988 00:00:00 EEST is Feb 25, 21:00:00 UTC. + + // Checking timezones from GMT+0100 to GMT+1200 + var i, tz, date; + for (i = 1; i <= 12; i++) { + tz = i > 9 ? '' + i : '0' + i; + date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT+' + tz + '00')); + assert.notEqual(date.getUTCDate(), 26); + assert.equal(date.getUTCDate(), 25); + assert.equal(date.getUTCMonth(), 1); + assert.equal(date.getUTCFullYear(), 1988); + } + + // Checking timezones from GMT+0000 to GMT-1100 + for (i = 0; i <= 11; i++) { + tz = i > 9 ? '' + i : '0' + i; + date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT-' + tz + '00')); + assert.equal(date.getUTCDate(), 26); + assert.equal(date.getUTCMonth(), 1); + assert.equal(date.getUTCFullYear(), 1988); + } +}); diff --git a/test/Django-2.1.15/js_tests/admin/inlines.test.js b/test/Django-2.1.15/js_tests/admin/inlines.test.js new file mode 100644 index 0000000..433ea06 --- /dev/null +++ b/test/Django-2.1.15/js_tests/admin/inlines.test.js @@ -0,0 +1,71 @@ +/* global QUnit */ +/* eslint global-strict: 0, strict: 0 */ +'use strict'; + +QUnit.module('admin.inlines: tabular formsets', { + beforeEach: function() { + var $ = django.jQuery; + var that = this; + this.addText = 'Add another'; + + $('#qunit-fixture').append($('#tabular-formset').text()); + this.table = $('table.inline'); + this.inlineRow = this.table.find('tr'); + that.inlineRow.tabularFormset('table.inline tr', { + prefix: 'first', + addText: that.addText, + deleteText: 'Remove' + }); + } +}); + +QUnit.test('no forms', function(assert) { + assert.ok(this.inlineRow.hasClass('dynamic-first')); + assert.equal(this.table.find('.add-row a').text(), this.addText); +}); + +QUnit.test('add form', function(assert) { + var addButton = this.table.find('.add-row a'); + assert.equal(addButton.text(), this.addText); + addButton.click(); + assert.ok(this.table.find('#first-1').hasClass('row2')); +}); + +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'); + $document.on('formset:added', function(event, $row, formsetName) { + assert.ok(true, 'event `formset:added` triggered'); + assert.equal(true, $row.is($('.row2'))); + assert.equal(formsetName, 'first'); + }); + addButton.click(); + var deletedRow = $('.row2'); + var 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)); + assert.equal(formsetName, 'first'); + }); + deleteLink.click(); +}); + +QUnit.test('existing add button', function(assert) { + var $ = 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(''); + var addButton = this.table.find('.add-button'); + this.inlineRow.tabularFormset('table.inline tr', { + prefix: 'first', + deleteText: 'Remove', + addButton: addButton + }); + assert.equal(this.table.find('.add-row a').length, 0); + addButton.click(); + assert.ok(this.table.find('#first-1').hasClass('row2')); +}); diff --git a/test/Django-2.1.15/js_tests/admin/jsi18n-mocks.test.js b/test/Django-2.1.15/js_tests/admin/jsi18n-mocks.test.js new file mode 100644 index 0000000..f04b057 --- /dev/null +++ b/test/Django-2.1.15/js_tests/admin/jsi18n-mocks.test.js @@ -0,0 +1,90 @@ +(function(globals) { + 'use strict'; + var django = globals.django || (globals.django = {}); + + django.pluralidx = function(count) { return (count === 1) ? 0 : 1; }; + + /* gettext identity library */ + + django.gettext = function(msgid) { return msgid; }; + django.ngettext = function(singular, plural, count) { + return (count === 1) ? singular : plural; + }; + django.gettext_noop = function(msgid) { return msgid; }; + django.pgettext = function(context, msgid) { return msgid; }; + django.npgettext = function(context, singular, plural, count) { + return (count === 1) ? singular : plural; + }; + + django.interpolate = function(fmt, obj, named) { + if (named) { + return fmt.replace(/%\(\w+\)s/g, function(match) { + return String(obj[match.slice(2, -2)]); + }); + } else { + return fmt.replace(/%s/g, function(match) { + return String(obj.shift()); + }); + } + }; + + /* formatting library */ + + django.formats = { + "DATETIME_FORMAT": "N j, Y, P", + "DATETIME_INPUT_FORMATS": [ + "%Y-%m-%d %H:%M:%S", + "%Y-%m-%d %H:%M:%S.%f", + "%Y-%m-%d %H:%M", + "%Y-%m-%d", + "%m/%d/%Y %H:%M:%S", + "%m/%d/%Y %H:%M:%S.%f", + "%m/%d/%Y %H:%M", + "%m/%d/%Y", + "%m/%d/%y %H:%M:%S", + "%m/%d/%y %H:%M:%S.%f", + "%m/%d/%y %H:%M", + "%m/%d/%y" + ], + "DATE_FORMAT": "N j, Y", + "DATE_INPUT_FORMATS": [ + "%Y-%m-%d", + "%m/%d/%Y", + "%m/%d/%y" + ], + "DECIMAL_SEPARATOR": ".", + "FIRST_DAY_OF_WEEK": 0, + "MONTH_DAY_FORMAT": "F j", + "NUMBER_GROUPING": 3, + "SHORT_DATETIME_FORMAT": "m/d/Y P", + "SHORT_DATE_FORMAT": "m/d/Y", + "THOUSAND_SEPARATOR": ",", + "TIME_FORMAT": "P", + "TIME_INPUT_FORMATS": [ + "%H:%M:%S", + "%H:%M:%S.%f", + "%H:%M" + ], + "YEAR_MONTH_FORMAT": "F Y" + }; + + django.get_format = function(format_type) { + var value = django.formats[format_type]; + if (typeof value === 'undefined') { + return format_type; + } else { + return value; + } + }; + + /* add to global namespace */ + globals.pluralidx = django.pluralidx; + globals.gettext = django.gettext; + globals.ngettext = django.ngettext; + globals.gettext_noop = django.gettext_noop; + globals.pgettext = django.pgettext; + globals.npgettext = django.npgettext; + globals.interpolate = django.interpolate; + globals.get_format = django.get_format; + +}(this));