From b1b001ad66c3aabe44ba155bdc9c4e150c51dad1 Mon Sep 17 00:00:00 2001 From: Oleksandr Miroshnichenko Date: Wed, 20 Dec 2017 18:11:32 +0200 Subject: [PATCH] magento/magento2#12342: JSTestDriver removal - Added calendar.test.js and removed JsTestDriver equivalent. --- .../testsuite/mage/calendar/calendar-qunit.js | 77 -------- .../testsuite/mage/calendar/calendar-test.js | 102 ----------- .../testsuite/mage/calendar/calendar.html | 31 ---- .../mage/calendar/date-range-test.js | 63 ------- .../jasmine/tests/lib/mage/calendar.test.js | 173 ++++++++++++++++++ 5 files changed, 173 insertions(+), 273 deletions(-) delete mode 100644 dev/tests/js/JsTestDriver/testsuite/mage/calendar/calendar-qunit.js delete mode 100644 dev/tests/js/JsTestDriver/testsuite/mage/calendar/calendar-test.js delete mode 100644 dev/tests/js/JsTestDriver/testsuite/mage/calendar/calendar.html delete mode 100644 dev/tests/js/JsTestDriver/testsuite/mage/calendar/date-range-test.js create mode 100644 dev/tests/js/jasmine/tests/lib/mage/calendar.test.js diff --git a/dev/tests/js/JsTestDriver/testsuite/mage/calendar/calendar-qunit.js b/dev/tests/js/JsTestDriver/testsuite/mage/calendar/calendar-qunit.js deleted file mode 100644 index 60dffe84db0fc..0000000000000 --- a/dev/tests/js/JsTestDriver/testsuite/mage/calendar/calendar-qunit.js +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -test( "initialization", function() { - var calendar = $('#calendar').calendar(); - ok( calendar.is(':mage-calendar'), "this test is fine" ); - calendar.calendar('destroy'); -}); -test( "global configuration merge", function() { - $.extend(true, $, { - calendarConfig: { - showOn: 'button', - showAnim: '', - buttonImageOnly: true, - showButtonPanel: true, - showWeek: true, - timeFormat: '', - showTime: false, - showHour: false, - showMinute: false - } - }); - var calendar = $('#calendar').calendar(); - equal('button', calendar.calendar('option', 'showOn')); - equal('', calendar.calendar('option', 'showAnim')); - ok(calendar.calendar('option', 'buttonImageOnly')); - ok(calendar.calendar('option', 'showButtonPanel')); - ok(calendar.calendar('option', 'showWeek')); - equal('', calendar.calendar('option', 'timeFormat')); - equal(false, calendar.calendar('option', 'showTime')); - equal(false, calendar.calendar('option', 'showHour')); - equal(false, calendar.calendar('option', 'showMinute')); - calendar.calendar('destroy'); - delete $.calendarConfig; -}); -test( "specifying AM/PM in timeformat option changes AMPM option to true", function(){ - var calendar = $('#calendar').calendar({timeFormat: 'hh:mm tt', ampm: false}); - ok(calendar.calendar('option', 'ampm')); - calendar.calendar('destroy'); -}); -test( "omitting AM/PM in timeformat option changes AMPM option to false", function(){ - var calendar = $('#calendar').calendar({timeFormat: 'hh:mm'}); - notEqual(true, calendar.calendar('option', 'ampm')); - calendar.calendar('destroy'); -}); -test( "with server timezone offset", function(){ - var serverTimezoneSeconds = 1346122095, - calendar = $('#calendar').calendar({serverTimezoneSeconds: serverTimezoneSeconds}), - currentDate = new Date(); - currentDate.setTime((serverTimezoneSeconds + currentDate.getTimezoneOffset() * 60) * 1000); - ok(currentDate.toString() === calendar.calendar('getTimezoneDate').toString()); - calendar.calendar('destroy'); -}); -test( "without sever timezone offset", function() { - var calendar = $('#calendar').calendar(), - currentDate = new Date(); - ok(currentDate.toString() === calendar.calendar('getTimezoneDate').toString()); - calendar.calendar('destroy'); -}); -test( "dateTime format conversions", function() { - var calendar = $('#calendar').calendar({dateFormat: 'M/d/yy', timeFormat: 'h:mm a'}); - equal('mm/d/yy', calendar.calendar('option', 'dateFormat')); - equal('h:mm tt', calendar.calendar('option', 'timeFormat')); - calendar.calendar('destroy'); - calendar.calendar({dateFormat: 'MMMM/EEEE/yyyy', timeFormat: 'HH:mm'}); - equal('MM/DD/yy', calendar.calendar('option', 'dateFormat')); - equal('hh:mm', calendar.calendar('option', 'timeFormat')); - calendar.calendar('destroy'); -}); -test( "destroy", function() { - var calendar = $('#calendar').calendar(), - calendarExist = calendar.is(':mage-calendar'); - calendar.calendar('destroy'); - equal(true, calendarExist != calendar.is(':mage-calendar')); -}); diff --git a/dev/tests/js/JsTestDriver/testsuite/mage/calendar/calendar-test.js b/dev/tests/js/JsTestDriver/testsuite/mage/calendar/calendar-test.js deleted file mode 100644 index 7748106b303c3..0000000000000 --- a/dev/tests/js/JsTestDriver/testsuite/mage/calendar/calendar-test.js +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -CalendarTest = TestCase('CalendarTest'); -CalendarTest.prototype.testInit = function() { - /*:DOC += */ - var calendar = jQuery('#calendar').calendar(); - assertEquals(true, calendar.is(':mage-calendar')); - calendar.calendar('destroy'); -}; -CalendarTest.prototype.testGlobalConfigurationMerge = function() { - /*:DOC += */ - $.extend(true, $, { - calendarConfig: { - showOn: 'button', - showAnim: '', - buttonImageOnly: true, - showButtonPanel: true, - showWeek: true, - timeFormat: '', - showTime: false, - showHour: false, - showMinute: false - } - }); - var calendar = $('#calendar').calendar(); - assertEquals('button', calendar.calendar('option', 'showOn')); - assertEquals('', calendar.calendar('option', 'showAnim')); - assertEquals(true, calendar.calendar('option', 'buttonImageOnly')); - assertEquals(true, calendar.calendar('option', 'showButtonPanel')); - assertEquals(true, calendar.calendar('option', 'showWeek')); - assertEquals('', calendar.calendar('option', 'timeFormat')); - assertEquals(false, calendar.calendar('option', 'showTime')); - assertEquals(false, calendar.calendar('option', 'showHour')); - assertEquals(false, calendar.calendar('option', 'showMinute')); - calendar.calendar('destroy'); - delete $.calendarConfig; -}; -CalendarTest.prototype.testEnableAMPM = function() { - /*:DOC += */ - var calendar = $('#calendar').calendar({timeFormat: 'hh:mm tt', ampm: false}); - assertEquals(true, calendar.calendar('option', 'ampm')); - calendar.calendar('destroy'); -}; -CalendarTest.prototype.testDisableAMPM = function() { - /*:DOC += */ - var calendar = $('#calendar').calendar({timeFormat: 'hh:mm'}); - assertTrue(!calendar.calendar('option', 'ampm')); - calendar.calendar('destroy'); -}; -CalendarTest.prototype.testWithServerTimezoneOffset = function() { - /*:DOC += */ - var serverTimezoneSeconds = 1346122095, - calendar = $('#calendar').calendar({serverTimezoneSeconds: serverTimezoneSeconds}), - currentDate = new Date(); - currentDate.setTime((serverTimezoneSeconds + currentDate.getTimezoneOffset() * 60) * 1000); - assertEquals(true, currentDate.toString() === calendar.calendar('getTimezoneDate').toString()); - calendar.calendar('destroy'); -}; -CalendarTest.prototype.testWithServerTimezoneShift = function() { - /*:DOC += */ - var serverTimezoneOffset = 43200, - calendar = $('#calendar').calendar({serverTimezoneOffset: serverTimezoneOffset}), - currentDate = new Date(); - - setTimeout(function () { - currentDate.setTime(currentDate.getTime() + (serverTimezoneOffset + currentDate.getTimezoneOffset() * 60) * 1000); - assertEquals(true, currentDate.toString() === calendar.calendar('getTimezoneDate').toString()); - calendar.calendar('destroy'); - }, 61000); -}; -CalendarTest.prototype.testWithoutServerTimezoneOffset = function() { - /*:DOC += */ - var calendar = $('#calendar').calendar(), - currentDate = new Date(); - assertEquals(true, currentDate.toString() === calendar.calendar('getTimezoneDate').toString()); - calendar.calendar('destroy'); -}; -CalendarTest.prototype.testInitDateTimePicker = function() { - /*:DOC += */ - var calendar = $('#calendar').calendar(); - assertEquals(true, calendar.hasClass('_has-datepicker')); - calendar.calendar('destroy'); -}; -CalendarTest.prototype.testDateTimeMapping = function() { - /*:DOC += */ - var calendar = $('#calendar').calendar({dateFormat: 'M/d/yy', timeFormat: 'h:mm a'}); - assertEquals('mm/d/yy', calendar.calendar('option', 'dateFormat')); - assertEquals('h:mm TT', calendar.calendar('option', 'timeFormat')); - calendar.calendar('destroy'); - calendar.calendar({dateFormat: 'MMMM/EEEE/yyyy'}); - assertEquals('MM/DD/yy', calendar.calendar('option', 'dateFormat')); - calendar.calendar('destroy'); -}; -CalendarTest.prototype.testDestroy = function() { - /*:DOC += */ - var calendar = $('#calendar').calendar(), - calendarExist = calendar.is(':mage-calendar'); - calendar.calendar('destroy'); - assertEquals(true, calendarExist != calendar.is(':mage-calendar')); -}; diff --git a/dev/tests/js/JsTestDriver/testsuite/mage/calendar/calendar.html b/dev/tests/js/JsTestDriver/testsuite/mage/calendar/calendar.html deleted file mode 100644 index b474dc2d5ce95..0000000000000 --- a/dev/tests/js/JsTestDriver/testsuite/mage/calendar/calendar.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - Calendar Widget: QUnit Tests - - - - - - - - - - - -
-
- -
- - diff --git a/dev/tests/js/JsTestDriver/testsuite/mage/calendar/date-range-test.js b/dev/tests/js/JsTestDriver/testsuite/mage/calendar/date-range-test.js deleted file mode 100644 index 61211c067ad12..0000000000000 --- a/dev/tests/js/JsTestDriver/testsuite/mage/calendar/date-range-test.js +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ -DaterangeTest = TestCase('DaterangeTest'); -DaterangeTest.prototype.testInit = function() { - /*:DOC += -
- */ - var dateRange = jQuery('#date-range').dateRange(); - assertEquals(true, dateRange.is(':mage-dateRange')); - dateRange.dateRange('destroy'); -}; -DaterangeTest.prototype.testInitDateRangeDatepickers = function() { - /*:DOC += -
- - -
- */ - var options = { - from: { - id: "from" - }, - to: { - id: "to" - } - }, - dateRange = $('#date-range').dateRange(options), - from = $('#'+options.from.id), - to = $('#'+options.to.id); - - assertEquals(true, from.hasClass('_has-datepicker')); - assertEquals(true, to.hasClass('_has-datepicker')); - dateRange.dateRange('destroy'); -}; -DaterangeTest.prototype.testDestroy = function() { - /*:DOC += -
- - -
- */ - var options = { - from: { - id: "from" - }, - to: { - id: "to" - } - }, - dateRange = $('#date-range').dateRange(options), - from = $('#'+options.from.id), - to = $('#'+options.to.id), - dateRangeExist = dateRange.is(':mage-dateRange'), - fromExist = from.hasClass('_has-datepicker'), - toExist = to.hasClass('_has-datepicker'); - - dateRange.dateRange('destroy'); - assertEquals(true, dateRangeExist != dateRange.is(':mage-dateRange')); - assertEquals(true, fromExist != from.hasClass('_has-datepicker')); - assertEquals(true, toExist != to.hasClass('_has-datepicker')); -}; diff --git a/dev/tests/js/jasmine/tests/lib/mage/calendar.test.js b/dev/tests/js/jasmine/tests/lib/mage/calendar.test.js new file mode 100644 index 0000000000000..b2c6aed2c9fba --- /dev/null +++ b/dev/tests/js/jasmine/tests/lib/mage/calendar.test.js @@ -0,0 +1,173 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +/* eslint-disable max-nested-callbacks */ +define([ + 'jquery', + 'jquery/ui', + 'mage/calendar' +], function ($) { + 'use strict'; + + describe('mage/calendar', function () { + describe('Check calendar', function () { + var calendarSelector = '#calendar'; + + beforeEach(function () { + var $calendar = $(''); + + $('body').append($calendar); + }); + + afterEach(function () { + $(calendarSelector).remove(); + $(calendarSelector).calendar('destroy'); + }); + + it('Check that calendar inited', function () { + var $calendar = $(calendarSelector).calendar(); + + expect($calendar.is(':mage-calendar')).toBe(true); + }); + + it('Check configuration merge', function () { + var $calendar; + + $.extend(true, $, { + calendarConfig: { + showOn: 'button', + showAnim: '', + buttonImageOnly: true, + showButtonPanel: true, + showWeek: true, + timeFormat: '', + showTime: false, + showHour: false, + showMinute: false + } + }); + + $calendar = $(calendarSelector).calendar(); + + expect($calendar.calendar('option', 'showOn')).toBe('button'); + expect($calendar.calendar('option', 'showAnim')).toBe(''); + expect($calendar.calendar('option', 'buttonImageOnly')).toBe(true); + expect($calendar.calendar('option', 'showButtonPanel')).toBe(true); + expect($calendar.calendar('option', 'showWeek')).toBe(true); + expect($calendar.calendar('option', 'timeFormat')).toBe(''); + expect($calendar.calendar('option', 'showTime')).toBe(false); + expect($calendar.calendar('option', 'showHour')).toBe(false); + expect($calendar.calendar('option', 'showMinute')).toBe(false); + + delete $.calendarConfig; + }); + + it('Specifying AM/PM in timeformat option changes AMPM option to true', function () { + var $calendar = $(calendarSelector).calendar({ + timeFormat: 'hh:mm tt', + ampm: false + }); + + expect($calendar.calendar('option', 'ampm')).toBe(true); + }); + + it('Omitting AM/PM in timeformat option changes AMPM option to false', function () { + var $calendar = $(calendarSelector).calendar({ + timeFormat: 'hh:mm' + }); + + expect($calendar.calendar('option', 'ampm')).toBe(null); + }); + + it('With server timezone offset', function () { + var serverTimezoneSeconds = 1346122095, + $calendar = $(calendarSelector).calendar({ + serverTimezoneSeconds: serverTimezoneSeconds + }), + currentDate = new Date(); + + currentDate.setTime((serverTimezoneSeconds + currentDate.getTimezoneOffset() * 60) * 1000); + + expect($calendar.calendar('getTimezoneDate').toString()).toBe(currentDate.toString()); + }); + + it('Without sever timezone offset', function () { + var $calendar = $(calendarSelector).calendar(), + currentDate = new Date(); + + expect($calendar.calendar('getTimezoneDate').toString()).toBe(currentDate.toString()); + }); + + it('Check destroy', function () { + var $calendar = $(calendarSelector).calendar(); + + expect($calendar.is(':mage-calendar')).toBe(true); + $calendar.calendar('destroy'); + expect($calendar.is(':mage-calendar')).toBe(false); + }); + }); + describe('Check dateRange', function () { + var dateRangeSelector = '#date-range'; + + beforeEach(function () { + var $dateRange = $('
' + + '' + + '' + + '
'); + + $('body').append($dateRange); + }); + + afterEach(function () { + $(dateRangeSelector).remove(); + $(dateRangeSelector).dateRange('destroy'); + }); + + it('Check that dateRange inited', function () { + var $dateRange = $(dateRangeSelector).dateRange(); + + expect($dateRange.is(':mage-dateRange')).toBe(true); + }); + + it('Check that dateRange inited with additional options', function () { + var $from = $('#from'), + $to = $('#to'); + + $(dateRangeSelector).dateRange({ + from: { + id: 'from' + }, + to: { + id: 'to' + } + }); + + expect($from.hasClass('_has-datepicker')).toBe(true); + expect($to.hasClass('_has-datepicker')).toBe(true); + }); + + it('Check destroy', function () { + var $dateRange = $(dateRangeSelector).dateRange({ + from: { + id: 'from' + }, + to: { + id: 'to' + } + }), + $from = $('#from'), + $to = $('#to'); + + expect($dateRange.is(':mage-dateRange')).toBe(true); + expect($from.hasClass('_has-datepicker')).toBe(true); + expect($to.hasClass('_has-datepicker')).toBe(true); + $dateRange.dateRange('destroy'); + expect($dateRange.is(':mage-dateRange')).toBe(false); + expect($from.hasClass('_has-datepicker')).toBe(false); + expect($to.hasClass('_has-datepicker')).toBe(false); + }); + }); + }); +});