diff --git a/tests/unit/calendar/core.js b/tests/unit/calendar/core.js index e165ec68151..e6dfab0929c 100644 --- a/tests/unit/calendar/core.js +++ b/tests/unit/calendar/core.js @@ -400,4 +400,45 @@ QUnit.test( "mouse", function( assert ) { step1(); } ); +QUnit.test( "ARIA", function( assert ) { + assert.expect( 15 ); + + var id = this.element.attr( "id" ), + headerId = id + "-title", + monthLabelId = id + "-month-label", + table = this.element.find( "table" ); + + assert.equal( this.element.attr( "role" ), "region", "Role attribute" ); + assert.equal( this.element.attr( "aria-labelledby" ), headerId, + "ARIA label attribute" ); + + assert.equal( this.element.find( "#" + headerId ).attr( "role" ), "header", + "Header role attribute" ); + assert.equal( this.element.find( "#" + monthLabelId ).attr( "role" ), "alert", + "Header month label role attribute" ); + + assert.equal( table.attr( "role" ), "grid", "Table role attribute" ); + assert.equal( table.attr( "aria-readonly" ), "true", + "Table ARIA readonly attribute" ); + assert.equal( table.attr( "aria-labelledby" ), monthLabelId, + "Table ARIA labelledby attribute" ); + assert.equal( table.attr( "tabindex" ), 0, "Table tabindex attribute" ); + + assert.equal( table.children( "thead" ).attr( "role" ), "presentation", + "Table head role attribute" ); + assert.equal( table.find( "thead tr" ).attr( "role" ), "row", + "Table head row role attribute" ); + assert.equal( table.find( "thead th" ).first().attr( "role" ), "columnheader", + "Table head cell role attribute" ); + + assert.equal( table.children( "tbody" ).attr( "role" ), "presentation", + "Table body role attribute" ); + assert.equal( table.find( "tbody tr" ).attr( "role" ), "row", + "Table body row role attribute" ); + assert.equal( table.find( "tbody td" ).first().attr( "role" ), "gridcell", + "Table body cell role attribute" ); + assert.equal( table.find( "tbody td" ).first().attr( "aria-describedby" ), + monthLabelId, "Table body cell ARIA describedby attribute" ); +} ); + } ); diff --git a/tests/unit/calendar/options.js b/tests/unit/calendar/options.js index abfbaf01651..03803a39acf 100644 --- a/tests/unit/calendar/options.js +++ b/tests/unit/calendar/options.js @@ -332,90 +332,4 @@ QUnit.test( "value", function( assert ) { assert.equal( this.element.calendar( "option", "value" ), null, "Value after invalid parameter" ); } ); -/* -// TODO: Move this to $.date, Globalize or calendar widget -test( "daylightSaving", function() { - expect( 25 ); - var inp = testHelper.init( "#inp" ), - dp = $( "#ui-datepicker-div" ); - ok(true, "Daylight saving - " + new Date()); - // Australia, Sydney - AM change, southern hemisphere - inp.val( "04/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(6) a", dp).simulate( "click" ); - equal(inp.val(), "04/05/2008", "Daylight saving - Australia 04/05/2008" ); - inp.val( "04/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(7) a", dp).simulate( "click" ); - equal(inp.val(), "04/06/2008", "Daylight saving - Australia 04/06/2008" ); - inp.val( "04/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(8) a", dp).simulate( "click" ); - equal(inp.val(), "04/07/2008", "Daylight saving - Australia 04/07/2008" ); - inp.val( "10/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(6) a", dp).simulate( "click" ); - equal(inp.val(), "10/04/2008", "Daylight saving - Australia 10/04/2008" ); - inp.val( "10/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(7) a", dp).simulate( "click" ); - equal(inp.val(), "10/05/2008", "Daylight saving - Australia 10/05/2008" ); - inp.val( "10/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(8) a", dp).simulate( "click" ); - equal(inp.val(), "10/06/2008", "Daylight saving - Australia 10/06/2008" ); - // Brasil, Brasilia - midnight change, southern hemisphere - inp.val( "02/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(20) a", dp).simulate( "click" ); - equal(inp.val(), "02/16/2008", "Daylight saving - Brasil 02/16/2008" ); - inp.val( "02/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(21) a", dp).simulate( "click" ); - equal(inp.val(), "02/17/2008", "Daylight saving - Brasil 02/17/2008" ); - inp.val( "02/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(22) a", dp).simulate( "click" ); - equal(inp.val(), "02/18/2008", "Daylight saving - Brasil 02/18/2008" ); - inp.val( "10/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(13) a", dp).simulate( "click" ); - equal(inp.val(), "10/11/2008", "Daylight saving - Brasil 10/11/2008" ); - inp.val( "10/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(14) a", dp).simulate( "click" ); - equal(inp.val(), "10/12/2008", "Daylight saving - Brasil 10/12/2008" ); - inp.val( "10/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(15) a", dp).simulate( "click" ); - equal(inp.val(), "10/13/2008", "Daylight saving - Brasil 10/13/2008" ); - // Lebanon, Beirut - midnight change, northern hemisphere - inp.val( "03/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(34) a", dp).simulate( "click" ); - equal(inp.val(), "03/29/2008", "Daylight saving - Lebanon 03/29/2008" ); - inp.val( "03/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(35) a", dp).simulate( "click" ); - equal(inp.val(), "03/30/2008", "Daylight saving - Lebanon 03/30/2008" ); - inp.val( "03/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(36) a", dp).simulate( "click" ); - equal(inp.val(), "03/31/2008", "Daylight saving - Lebanon 03/31/2008" ); - inp.val( "10/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(27) a", dp).simulate( "click" ); - equal(inp.val(), "10/25/2008", "Daylight saving - Lebanon 10/25/2008" ); - inp.val( "10/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(28) a", dp).simulate( "click" ); - equal(inp.val(), "10/26/2008", "Daylight saving - Lebanon 10/26/2008" ); - inp.val( "10/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(29) a", dp).simulate( "click" ); - equal(inp.val(), "10/27/2008", "Daylight saving - Lebanon 10/27/2008" ); - // US, Eastern - AM change, northern hemisphere - inp.val( "03/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(13) a", dp).simulate( "click" ); - equal(inp.val(), "03/08/2008", "Daylight saving - US 03/08/2008" ); - inp.val( "03/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(14) a", dp).simulate( "click" ); - equal(inp.val(), "03/09/2008", "Daylight saving - US 03/09/2008" ); - inp.val( "03/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(15) a", dp).simulate( "click" ); - equal(inp.val(), "03/10/2008", "Daylight saving - US 03/10/2008" ); - inp.val( "11/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(6) a", dp).simulate( "click" ); - equal(inp.val(), "11/01/2008", "Daylight saving - US 11/01/2008" ); - inp.val( "11/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(7) a", dp).simulate( "click" ); - equal(inp.val(), "11/02/2008", "Daylight saving - US 11/02/2008" ); - inp.val( "11/01/2008" ).calendar( "show" ); - $( ".ui-calendar-calendar td:eq(8) a", dp).simulate( "click" ); - equal(inp.val(), "11/03/2008", "Daylight saving - US 11/03/2008" ); - }); - */ - } ); diff --git a/tests/unit/date/core.js b/tests/unit/date/core.js index fc4dcd97539..e52ab183cbb 100644 --- a/tests/unit/date/core.js +++ b/tests/unit/date/core.js @@ -15,14 +15,15 @@ QUnit.test( "Instantiation", function( assert ) { assert.ok( $.ui.date( null, attributes ) instanceof $.ui.date, "instantiation without new" ); } ); -QUnit.test( "Check Sets and Gets", 4, function( assert ) { +QUnit.test( "Check Sets and Gets", 6, function( assert ) { var date = $.ui.date( null, attributes ); - assert.equal( date.setDay( 15 ).day(), 15, "Set day and retrieve" ); assert.equal( date.setFullDate( 2012, 9, 15 ).year(), 2012, "Set full date and retrieve year" ); assert.equal( date.month(), 9, "Set full date and retrieve month" ); assert.equal( date.day(), 15, "Set full date and retrieve day" ); - // TODO Add setTime test + assert.equal( date.setTimestamp( 1490912843735 ).year(), 2017, "Set timestamp and retrieve year" ); + assert.equal( date.month(), 2, "Set timestamp and retrieve month" ); + assert.equal( date.day(), 31, "Set timestamp and retrieve day" ); } ); QUnit.test( "Date Adjustments - Normal Use Cases", 10, function( assert ) { @@ -119,8 +120,6 @@ QUnit.test( "Clone", 2, function( assert ) { } ); QUnit.test( "Days", 1, function( assert ) { - - // TODO Needs work var date = $.ui.date( null, attributes ); date.eachDay = function( day ) { if ( day.lead && day.date > 20 ) { diff --git a/tests/unit/datepicker/core.js b/tests/unit/datepicker/core.js index 2aa89aa3655..e26c6c94d55 100644 --- a/tests/unit/datepicker/core.js +++ b/tests/unit/datepicker/core.js @@ -123,9 +123,20 @@ QUnit.test( "Keyboard handling: input", function( assert ) { "Picker updated as user types into input" ); } ); -// TODO: implement QUnit.test( "ARIA", function( assert ) { - assert.expect( 0 ); + assert.expect( 4 ); + + var widget = this.element.datepicker( "widget" ), + id = widget.attr( "id" ); + + assert.equal( this.element.attr( "aria-haspopup" ), "true", + "Input aria-haspopup attribute" ); + assert.equal( this.element.attr( "aria-owns" ), id, "ARIA owns attribute" ); + + assert.equal( widget.attr( "aria-hidden" ), "true", + "Widget ARIA hidden attribute" ); + assert.equal( widget.attr( "aria-expanded" ), "false", + "Widget ARIA expanded attribute" ); } ); QUnit.test( "mouse", function( assert ) { diff --git a/ui/date.js b/ui/date.js index aea91c413ea..d1a2153c8b9 100644 --- a/ui/date.js +++ b/ui/date.js @@ -48,19 +48,13 @@ $.extend( $.ui.date.prototype, { this.firstDay = this.attributes.firstDay; }, - // TODO: Same as the underlying Date object's terminology, but still misleading. - // TODO: We can use .setTime() instead of new Date and rename to setTimestamp. - setTime: function( time ) { - this.dateObject = new Date( time ); + setTimestamp: function( time ) { + this.dateObject.setTime( time ); return this; }, setDay: function( day ) { - var date = this.dateObject; - - // FIXME: Why not to use .setDate? - this.dateObject = new Date( date.getFullYear(), date.getMonth(), day, date.getHours(), - date.getMinutes(), date.getSeconds() ); + this.dateObject.setDate( day ); return this; }, @@ -156,7 +150,6 @@ $.extend( $.ui.date.prototype, { this.eachDay( day ); } - // TODO use adjust("D", 1)? printDate.setDate( printDate.getDate() + 1 ); } } @@ -190,6 +183,10 @@ $.extend( $.ui.date.prototype, { return format( this.dateObject ) === format( other ); }, + timestamp: function() { + return this.dateObject.getTime(); + }, + date: function() { return this.dateObject; } diff --git a/ui/widgets/calendar.js b/ui/widgets/calendar.js index 4bac6c32662..df919cb998d 100644 --- a/ui/widgets/calendar.js +++ b/ui/widgets/calendar.js @@ -196,7 +196,7 @@ return $.widget( "ui.calendar", { ( this.date.month() > this.viewDate.month() ? 1 : -1 ) ); } else { - this.viewDate.setTime( this.date.date().getTime() ); + this.viewDate.setTimestamp( this.date.timestamp() ); } this.refresh(); @@ -582,7 +582,6 @@ return $.widget( "ui.calendar", { this.labels = this.options.labels; // Determine which day grid cell to focus after refresh - // TODO: Prevent disabled cells from being focused if ( this.options.numberOfMonths === 1 ) { this.element.find( ".ui-calendar-title" ).replaceWith( this._buildTitle() ); this.element.find( ".ui-calendar-calendar" ).replaceWith( this._buildGrid() ); @@ -727,7 +726,7 @@ return $.widget( "ui.calendar", { this.viewDate.setAttributes( this._calendarDateOptions ); } if ( create || refresh ) { - this.viewDate.setTime( this.date.date().getTime() ); + this.viewDate.setTimestamp( this.date.timestamp() ); } if ( create ) { this.element.empty(); @@ -743,7 +742,7 @@ return $.widget( "ui.calendar", { _setOption: function( key, value ) { if ( key === "value" ) { if ( this._isValid( value ) ) { - this.date.setTime( value.getTime() ); + this.date.setTimestamp( value.getTime() ); } else { value = null; }