Skip to content

Calendar: improve date getter/setter, add ARIA tests, clean up #1802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions tests/unit/calendar/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
} );

} );
86 changes: 0 additions & 86 deletions tests/unit/calendar/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
});
*/

} );
9 changes: 4 additions & 5 deletions tests/unit/date/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 ) {
Expand Down
15 changes: 13 additions & 2 deletions tests/unit/datepicker/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
17 changes: 7 additions & 10 deletions ui/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

Expand Down Expand Up @@ -156,7 +150,6 @@ $.extend( $.ui.date.prototype, {
this.eachDay( day );
}

// TODO use adjust("D", 1)?
printDate.setDate( printDate.getDate() + 1 );
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 3 additions & 4 deletions ui/widgets/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down