You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1165 lines
40 KiB
1165 lines
40 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
|
"http://www.w3.org/TR/html4/strict.dtd"> |
|
<html> |
|
<head> |
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|
<title>doh.robot DateTextBox Test</title> |
|
|
|
<style> |
|
@import "../../../../util/doh/robot/robot.css"; |
|
</style> |
|
|
|
<!-- required: dojo.js --> |
|
<script type="text/javascript" src="../../../../dojo/dojo.js"></script> |
|
|
|
<script type="text/javascript"> |
|
dojo.require("dijit.robotx"); |
|
dojo.require("dojo.date"); |
|
dojo.require("dijit.tests.helpers"); // functions to help test |
|
|
|
dojo.ready(function(){ |
|
doh.robot.initRobot('../test_DateTextBox.html'); |
|
|
|
// refs to DateTextBox widgets |
|
var american, german, localLong, pattern, handler; |
|
|
|
// log of calls to onChange handler, and watch(value) |
|
var changes = [], watches = []; |
|
|
|
// ctrl-page-down / page-up will go forward/barck a year, except on chrome where |
|
// it switches browser tabs. use alt instead |
|
var yearModifierKey = dojo.isChrome ? {alt: true} : {ctrl: true}; |
|
|
|
doh.register("setup", |
|
function setUp(){ |
|
// refs to DateTextBox widgets |
|
american = dijit.byId('american'); |
|
german = dijit.byId('german'); |
|
localLong = dijit.byId('localLong'); |
|
pattern = dijit.byId('pattern'); |
|
|
|
// setup onChange handler to monitor onChange calls on american textbox |
|
dojo.connect(american, 'onChange', function(val){ |
|
console.log('onchange w/value: ', val); |
|
changes.push(val); |
|
}); |
|
|
|
american.watch("value", function(attr, oldV, newV){ |
|
watches.push(newV); |
|
}); |
|
} |
|
); |
|
|
|
doh.register("keyboard: direct input", { |
|
name: "direct input", |
|
timeout: 6000, |
|
setUp: function(){ |
|
// clear the field |
|
changes = []; |
|
watches = []; |
|
american.focus(); |
|
}, |
|
runTest: function(){ |
|
var d = new doh.Deferred(), |
|
r1 = true, |
|
r2 = true, |
|
r3 = true, |
|
r4 = true, |
|
r5 = true, |
|
r6 = false, |
|
r7 = false, |
|
r8 = true; |
|
|
|
handler = dojo.connect(american, 'onChange', d.getTestCallback(function(){ |
|
doh.f(r1, "1 out of range"); |
|
doh.f(r2, "1/ out of range"); |
|
doh.f(r3, "1/3 out of range"); |
|
doh.f(r4, "1/3/ out of range"); |
|
doh.f(r5, "1/3/2 out of range"); |
|
doh.t(r6, "1/3/20 in range"); |
|
doh.t(r7, "1/3/200 in range"); |
|
doh.f(r8, "1/3/2005 out of range"); |
|
var value = american.get('value'); |
|
doh.is(0, dojo.date.compare(new Date(2005, 0, 3), value), 'actual value is ' + value); |
|
doh.is(1, changes.length, 'one onchange event'); // #9018 |
|
doh.is(2, watches.length, 'one watch(value) event from the onblur'); |
|
doh.is(0, dojo.date.compare(new Date(2005, 0, 3), changes[0]), |
|
'value reported by onchange: ' + changes[0] + |
|
', should be ' + new Date(2005, 0, 3)); |
|
doh.is(0, dojo.date.compare(new Date(2005, 0, 3), watches[1]), |
|
'value reported by watch(value): ' + watches[1] + |
|
', should be ' + new Date(2005, 0, 3)); |
|
})); |
|
|
|
american.set('value', null, false); |
|
|
|
doh.robot.typeKeys('1', 1000, 200); |
|
doh.robot.sequence(function(){ |
|
r1 = american._isDefinitelyOutOfRange(); |
|
}, 100); |
|
doh.robot.typeKeys('/', 100, 200); |
|
doh.robot.sequence(function(){ |
|
r2 = american._isDefinitelyOutOfRange(); |
|
}, 100); |
|
doh.robot.typeKeys('3', 100, 200); |
|
doh.robot.sequence(function(){ |
|
r3 = american._isDefinitelyOutOfRange(); |
|
}, 100); |
|
doh.robot.typeKeys('/', 100, 200); |
|
doh.robot.sequence(function(){ |
|
r4 = american._isDefinitelyOutOfRange(); |
|
}, 100); |
|
doh.robot.typeKeys('2', 100, 200); |
|
doh.robot.sequence(function(){ |
|
r5 = american._isDefinitelyOutOfRange(); |
|
}, 100); |
|
doh.robot.typeKeys('0', 100, 200); |
|
doh.robot.sequence(function(){ |
|
r6 = american._isDefinitelyOutOfRange(); |
|
}, 100); |
|
doh.robot.typeKeys('0', 100, 200); |
|
doh.robot.sequence(function(){ |
|
r7 = american._isDefinitelyOutOfRange(); |
|
}, 100); |
|
doh.robot.typeKeys('5', 100, 200); |
|
doh.robot.sequence(function(){ |
|
r8 = american._isDefinitelyOutOfRange(); |
|
}, 100); |
|
|
|
doh.robot.keyPress(dojo.keys.TAB, 500, {}); // focus german |
|
|
|
return d; |
|
}, |
|
tearDown: function(){ |
|
dojo.disconnect(handler); |
|
} |
|
}); |
|
|
|
doh.register("keyboard: drop down", [ |
|
{ |
|
name: "initial popup display", |
|
timeout: 6000, |
|
setUp: function(){ |
|
// set to may 10 |
|
changes = []; |
|
american.set('displayedValue', "", false); |
|
watches = []; // put after set() so we can ignore the watch() published by set() |
|
american.focus(); |
|
}, |
|
runTest: function(){ |
|
var d = new doh.Deferred(), |
|
calendar; |
|
|
|
handler = dojo.connect(american, 'openDropDown', function(){ |
|
dojo.disconnect(handler); |
|
calendar = dijit.byId("american_popup"); |
|
handler = dojo.connect(calendar, 'focus', function(){ |
|
// Use setTimeout() because focus on IE9+ is asynchronous. |
|
setTimeout(d.getTestCallback(function(){ |
|
// calendar exists and is shown |
|
doh.t(calendar && isVisible(calendar), "calendar is visible"); |
|
|
|
// calendar is on the right month |
|
doh.is("May", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "calendar starts on month selected in input box"); |
|
|
|
// and the right year |
|
var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode); |
|
doh.is(1, selectedYearButtons.length, "current year is shown"); |
|
doh.is("2005", innerText(selectedYearButtons[0]), "current year is 2005"); |
|
|
|
// and the currently selected date is right too |
|
var selectedDays = dojo.query(".dijitCalendarSelectedDate", calendar.domNode); |
|
doh.is(1, selectedDays.length, "one day selected"); |
|
doh.is("10", innerText(selectedDays[0]), "correct day is selected"); |
|
|
|
// focus moved to the calendar |
|
doh.is(10, innerText(dojo.global.dijit.focus.curNode), "focus on selected calendar cell"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 0); |
|
}); |
|
}); |
|
|
|
doh.robot.typeKeys("5/10/2005", 1000, 1800); |
|
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 700, {}); |
|
|
|
return d; |
|
}, |
|
tearDown: function(){ |
|
dojo.disconnect(handler); |
|
} |
|
}, |
|
|
|
{ |
|
name: "forward two days", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {}); |
|
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar, "calendar popup exists"); |
|
doh.t(isVisible(calendar), "calendar is visible"); |
|
|
|
// selected day not changed (because no ENTER/SPACE) |
|
var selectedDays = dojo.query(".dijitCalendarSelectedDate", calendar.domNode); |
|
doh.is(1, selectedDays.length, "one day selected"); |
|
doh.is(10, innerText(selectedDays[0]), "correct day is selected"); |
|
|
|
// focus still on the calendar, moved forward 2 days |
|
doh.is(12, innerText(dojo.global.dijit.focus.curNode), "focus"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "back a day", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar, "calendar popup exists"); |
|
doh.t(isVisible(calendar), "calendar is visible"); |
|
|
|
// focus still on the calendar, moved back 1 day |
|
doh.is(11, innerText(dojo.global.dijit.focus.curNode), "focus"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "forward four weeks", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 750, {}); |
|
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 750, {}); |
|
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 750, {}); |
|
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 750, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar, "calendar popup exists"); |
|
doh.t(isVisible(calendar), "calendar is visible"); |
|
|
|
// should have advanced to next month |
|
doh.is("June", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "month changed"); |
|
|
|
// and focused day changed |
|
doh.is(8, innerText(dojo.global.dijit.focus.curNode), "focus"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "back three weeks", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.robot.keyPress(dojo.keys.UP_ARROW, 750, {}); |
|
doh.robot.keyPress(dojo.keys.UP_ARROW, 750, {}); |
|
doh.robot.keyPress(dojo.keys.UP_ARROW, 750, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar, "calendar popup exists"); |
|
doh.t(isVisible(calendar), "calendar is visible"); |
|
|
|
// should have scrolled back to previous month |
|
doh.is("May", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "month changed"); |
|
|
|
// focused day still the same |
|
doh.is(18, innerText(dojo.global.dijit.focus.curNode), "focus"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "forward two months", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.robot.keyPress(dojo.keys.PAGE_DOWN, 750, {}); |
|
doh.robot.keyPress(dojo.keys.PAGE_DOWN, 750, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar, "calendar popup exists"); |
|
doh.t(isVisible(calendar), "calendar is visible"); |
|
|
|
// focused day still the same |
|
doh.is(18, innerText(dojo.global.dijit.focus.curNode), "focus"); |
|
|
|
// month changed |
|
doh.is("July", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "month changed"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "back a month", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.robot.keyPress(dojo.keys.PAGE_UP, 750, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar, "calendar popup exists"); |
|
doh.t(isVisible(calendar), "calendar is visible"); |
|
|
|
// focused day still the same |
|
doh.is(18, innerText(dojo.global.dijit.focus.curNode), "focus"); |
|
|
|
// month changed |
|
doh.is("June", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "month changed"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "forward two years", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.robot.keyPress(dojo.keys.PAGE_DOWN, 750, yearModifierKey); |
|
doh.robot.keyPress(dojo.keys.PAGE_DOWN, 750, yearModifierKey); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar, "calendar popup exists"); |
|
doh.t(isVisible(calendar), "calendar is visible"); |
|
|
|
// focused day still the same (focused even though disabled) |
|
doh.is(18, innerText(dojo.global.dijit.focus.curNode), "focus"); |
|
|
|
// same month |
|
doh.is("June", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "same month"); |
|
|
|
// year changed |
|
var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode); |
|
doh.is(1, selectedYearButtons.length, "current year is shown"); |
|
doh.is("2007", innerText(selectedYearButtons[0]), "year changed"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "back a year", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.robot.keyPress(dojo.keys.PAGE_UP, 750, yearModifierKey); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar, "calendar popup exists"); |
|
doh.t(isVisible(calendar), "calendar is visible"); |
|
|
|
// focused day still the same |
|
doh.is(18, innerText(dojo.global.dijit.focus.curNode), "focus"); |
|
|
|
// same month |
|
doh.is("June", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "same month"); |
|
|
|
// year changed |
|
var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode); |
|
doh.is(1, selectedYearButtons.length, "current year is shown"); |
|
doh.is("2006", innerText(selectedYearButtons[0]), "year changed"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "first day of month", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.robot.keyPress(dojo.keys.HOME, 500, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar, "calendar popup exists"); |
|
doh.t(isVisible(calendar), "calendar is visible"); |
|
|
|
// focused on first day of month |
|
doh.is(1, innerText(dojo.global.dijit.focus.curNode), "focus"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "last day of month", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.robot.keyPress(dojo.keys.END, 500, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar, "calendar popup exists"); |
|
doh.t(isVisible(calendar), "calendar is visible"); |
|
|
|
// focused on last day of month |
|
doh.is(30, innerText(dojo.global.dijit.focus.curNode), "focus"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "select a date", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
// select |
|
doh.robot.keyPress(dojo.keys.ENTER, 500, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
doh.is('6/30/2006', american.get('displayedValue'), 'displayed value of american'); |
|
|
|
var expectedVal = new Date(2006, 5, 30); // 6/30/2006 |
|
doh.is(0, dojo.date.compare(expectedVal, american.get('value')), 'wire value of american: ' + american.get('value')); |
|
|
|
doh.is(1, changes.length, "onchange event fired"); |
|
doh.is(1, watches.length, "watch(value) event fired"); |
|
doh.is(0, dojo.date.compare(expectedVal, changes[0]), 'onchange of american: ' + changes[0]); |
|
doh.is(0, dojo.date.compare(expectedVal, watches[0]), 'watch(value) of american: ' + watches[0]); |
|
|
|
// focus moved back to <input> |
|
doh.is("american", dojo.global.dijit.focus.curNode.id, "focus on <input>") |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "tab away", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
handler = dojo.connect(american, '_onFocus', d.getTestCallback(function(){ |
|
doh.is(1, changes.length, "no new onchange events"); // #9018 |
|
doh.is(1, watches.length, "no new watch(value) events yet"); |
|
})); |
|
|
|
doh.robot.keyPress(dojo.keys.TAB, 500, {}); |
|
doh.robot.keyPress(dojo.keys.TAB, 500, {shift:true}); |
|
|
|
return d; |
|
}, |
|
tearDown: function(){ |
|
dojo.disconnect(handler); |
|
} |
|
} |
|
]); |
|
|
|
// TODO: add key-repeat tests |
|
|
|
doh.register("mouse: drop down", [ |
|
{ |
|
name: "initial popup display", |
|
timeout: 6000, |
|
setUp: function(){ |
|
// clear the field |
|
changes = []; |
|
american.set('displayedValue', "", false); |
|
watches = []; // do it here to ignore watch() notification for above set() call |
|
}, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
handler = dojo.connect(american, 'openDropDown', d.getTestCallback(function(){ |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
// drop down automatically opened on click |
|
doh.t(calendar && isVisible(calendar), "calendar is visible"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
})); |
|
|
|
doh.robot.mouseMoveAt(american._buttonNode, 0, 1); |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
return d; |
|
}, |
|
tearDown: function(){ |
|
dojo.disconnect(handler); |
|
} |
|
}, |
|
|
|
{ |
|
name: "close and reopen", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
handler = dojo.connect(american, 'closeDropDown', function(){ |
|
dojo.disconnect(handler); |
|
|
|
handler = dojo.connect(american, 'openDropDown', d.getTestCallback(function(){ |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
// calendar exists and is shown |
|
doh.t(calendar && isVisible(calendar), "calendar is visible"); |
|
|
|
// calendar is on the right month |
|
doh.is("May", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "calendar starts on month selected in input box"); |
|
|
|
// and the right year |
|
var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode); |
|
doh.is(1, selectedYearButtons.length, "current year is shown"); |
|
doh.is("2005", innerText(selectedYearButtons[0]), "current year is 2005"); |
|
|
|
// and the currently selected date is right too |
|
var selectedDays = dojo.query(".dijitCalendarSelectedDate", calendar.domNode); |
|
doh.is(1, selectedDays.length, "one day selected"); |
|
doh.is("10", innerText(selectedDays[0]), "correct day is selected"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
})); |
|
|
|
// type a value |
|
doh.robot.typeKeys("5/10/2005", 500, 1800); |
|
// And open dropdown again (manually) |
|
doh.robot.mouseMoveAt(american._buttonNode, 500, 1); |
|
doh.robot.mouseClick({left:true}, 500); |
|
}); |
|
|
|
// Close drop down |
|
doh.robot.keyPress(dojo.keys.ESCAPE, 500, {}); |
|
|
|
return d; |
|
}, |
|
tearDown: function(){ |
|
dojo.disconnect(handler); |
|
} |
|
}, |
|
|
|
{ |
|
name: "advance a month", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"), |
|
nextMonthButtons = dojo.query(".dijitCalendarIncrease", calendar.domNode); |
|
|
|
doh.is(1, nextMonthButtons.length, "found next month button"); |
|
|
|
doh.robot.mouseMoveAt(nextMonthButtons[0], 100, 1); // delay to allow previous keyUp to occur |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar && isVisible(calendar), "calendar is visible"); |
|
|
|
// calendar moved to the next month |
|
doh.is("June", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "moved from may to june"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "advance a month with the menu dropdown", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.is(1, dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode).length, "found month label"); |
|
doh.t(calendar.monthWidget.dropDown, "month dropdown exists"); |
|
doh.f(isVisible(calendar.monthWidget.dropDown), "month dropdown is not visible"); |
|
|
|
doh.robot.mouseMoveAt(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0], 0, 1); |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
doh.robot.mouseMoveAt(function(){ |
|
return dojo.query("[month=6]", calendar.monthWidget.dropDown.domNode)[0]; |
|
}, 1000, 1); |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar && isVisible(calendar), "calendar is visible"); |
|
|
|
// calendar moved to the next month |
|
doh.is("July", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "moved from june to july"); |
|
var rows = dojo.query("TR.dijitCalendarWeekTemplate", calendar.domNode), |
|
firstRowDays = dojo.query("TD", rows[0]); |
|
doh.is(7, firstRowDays.length, "7 days in first row"); |
|
doh.t(dojo.hasClass(firstRowDays[0], "dijitCalendarPreviousMonth"), "previous month class applied"); |
|
doh.is("26", innerText(firstRowDays[0]), "first day is june 26"); |
|
doh.is("1", innerText(firstRowDays[5]), "sixth day is june 1"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "advance a year", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
var calendar = dijit.byId("american_popup"), |
|
nextYearButtons = dojo.query(".dijitCalendarNextYear", calendar.domNode); |
|
|
|
doh.is(1, nextYearButtons.length, "found next year button"); |
|
|
|
doh.robot.mouseMoveAt(nextYearButtons[0], 0, 1); |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar && isVisible(calendar), "calendar is visible"); |
|
|
|
// calendar moved to the next year |
|
var yearNodes = dojo.query(".dijitCalendarSelectedYear", calendar.domNode); |
|
doh.is(1, yearNodes.length, "found year node"); |
|
doh.is("2006", innerText(yearNodes[0]), "moved from 2005 to 2006"); |
|
|
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "check disabled dates", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
// Move forward another year, to see disabled days (this date text box is valid only to 2006) |
|
var calendar = dijit.byId("american_popup"), |
|
nextYearButtons = dojo.query(".dijitCalendarNextYear", calendar.domNode); |
|
|
|
doh.is(1, nextYearButtons.length, "found next year button"); |
|
|
|
doh.robot.mouseMoveAt(nextYearButtons[0], 0, 1); |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
dojo.query(".dijitCalendarDateTemplate", calendar.domNode).forEach(function(node){ |
|
doh.t(dojo.hasClass(node, 'dijitCalendarDisabledDate'), 'every day in 2007 is disabled'); |
|
}); |
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 500); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "check enabled dates", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
// Move back a year, dates should be enabled again |
|
var calendar = dijit.byId("american_popup"), |
|
previousYearButtons = dojo.query(".dijitCalendarPreviousYear", calendar.domNode); |
|
|
|
doh.is(1, previousYearButtons.length, "found previous year button"); |
|
|
|
doh.robot.mouseMoveAt(previousYearButtons[0], 0, 1); |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
dojo.query(".dijitCalendarDateTemplate", calendar.domNode).forEach(function(node){ |
|
doh.f(dojo.hasClass(node, 'dijitCalendarDisabledDate'), "every day in 2006 is enabled"); |
|
}); |
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 500); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "check calendar display", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var calendar = dijit.byId("american_popup"), |
|
rows = dojo.query("TR.dijitCalendarWeekTemplate", calendar.domNode); |
|
|
|
doh.is(6, rows.length, "six weeks shown"); |
|
var firstRowDays = dojo.query("TD", rows[0]); |
|
doh.is(7, firstRowDays.length, "7 days in first row"); |
|
doh.t(dojo.hasClass(firstRowDays[0], "dijitCalendarPreviousMonth"), "previous month class applied"); |
|
doh.is("25", innerText(firstRowDays[0]), "first day is june 25"); |
|
doh.is("1", innerText(firstRowDays[6]), "seventh day is july 1"); |
|
|
|
var lastRowDays = dojo.query("TD", rows[5]); |
|
doh.t(dojo.hasClass(lastRowDays[3], 'dijitCalendarNextMonth'), "last row is for next month"); |
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
} |
|
}, |
|
|
|
{ |
|
name: "hover a date", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
var calendar = dijit.byId("american_popup"), |
|
rows = dojo.query("TR.dijitCalendarWeekTemplate", calendar.domNode), |
|
thirdRowDays = dojo.query("TD", rows[2]), |
|
day = thirdRowDays[6]; |
|
|
|
// hover June 15 |
|
doh.is("15", innerText(day), "found july 15"); |
|
doh.robot.mouseMoveAt(day, 0, 1); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
doh.t(dojo.hasClass(day, 'dijitCalendarHoveredDate'), "hovered date has hover class"); |
|
doh.is(0, changes.length, "no onchange events yet"); |
|
doh.is(0, watches.length, "no watch(value) events yet"); |
|
}), 500); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "select a date", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
// select June 15 |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
doh.is('7/15/2006', american.get('displayedValue'), 'displayed value of american'); |
|
|
|
var expectedVal = new Date(2006, 6, 15); // 7/15/2006 |
|
doh.is(0, dojo.date.compare(expectedVal, american.get('value')), 'wire value of american: ' + american.get('value')); |
|
|
|
doh.is(1, changes.length, "onchange event fired"); |
|
doh.is(1, watches.length, "watch(value) event fired"); |
|
doh.is(0, dojo.date.compare(expectedVal, changes[0]), 'onchange of american: ' + changes[0]); |
|
doh.is(0, dojo.date.compare(expectedVal, watches[0]), 'watch(value) of american: ' + watches[0]); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "tab away", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
doh.robot.keyPress(dojo.keys.TAB, 500, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
doh.is(1, changes.length, "no new onchange events"); // #9018 |
|
doh.is(1, watches.length, "no new watch(value) events"); |
|
}), 1000); |
|
return d; |
|
} |
|
} |
|
]); |
|
|
|
// Tests that drop down displays correct year/month, and that correct cell is focused, |
|
// based on this.value and this.dropDownDefaultValue |
|
doh.register("focused popup value", [ |
|
{ |
|
name: "today", |
|
timeout: 6000, |
|
setUp: function(){ |
|
german.closeDropDown(true); // close drop down and focus widget |
|
german.set('value', null); |
|
german.set("dropDownDefaultValue", null); |
|
}, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
var today = new Date(); |
|
|
|
var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", german.dropDown.domNode); |
|
doh.is(today.getFullYear(), innerText(selectedYearButtons[0]), "current year is selected"); |
|
|
|
var selectedDates = dojo.query(".dijitCalendarSelectedDate", german.dropDown.domNode); |
|
doh.is(0, selectedDates.length, "no selected date"); |
|
}), 500); |
|
|
|
return d; |
|
} |
|
}, |
|
{ |
|
name: "dropDownDefaultValue", |
|
timeout: 6000, |
|
setUp: function(){ |
|
german.closeDropDown(true); |
|
german.set('value', null); |
|
german.set("dropDownDefaultValue", new Date(2000,11,21)); |
|
}, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", german.dropDown.domNode); |
|
doh.is("2000", innerText(selectedYearButtons[0]), "specified default year is selected"); |
|
|
|
var selectedDates = dojo.query(".dijitCalendarSelectedDate", german.dropDown.domNode); |
|
doh.is(0, selectedDates.length, "no selected date"); |
|
|
|
doh.is("21", innerText(dojo.global.dijit.focus.curNode), "but focused on the 21st"); |
|
}), 500); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
// Testing that value overrides dropDownDefaultValue |
|
{ |
|
name: "textbox value", |
|
timeout: 6000, |
|
setUp: function(){ |
|
german.closeDropDown(true); |
|
german.set("dropDownDefaultValue", new Date(2000,11,21)); |
|
german.set('value', new Date(2004,10,25)); |
|
}, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", german.dropDown.domNode); |
|
doh.is("2004", innerText(selectedYearButtons[0]), "textbox year is selected"); |
|
|
|
var selectedDates = dojo.query(".dijitCalendarSelectedDate", german.dropDown.domNode); |
|
doh.is(1, selectedDates.length, "one selected date"); |
|
doh.is("25", innerText(selectedDates[0]), "25th is selected"); |
|
|
|
doh.is("25", innerText(dojo.global.dijit.focus.curNode), "and also focused on the 25th"); |
|
}), 500); |
|
|
|
return d; |
|
} |
|
}, |
|
{ |
|
name: "close", |
|
timeout: 3000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
handler = dojo.connect(german, 'closeDropDown', d.getTestCallback(function(){})); |
|
// Close the drop down so it doesn't interfere with the next test by covering up the |
|
// <input> that we want to focus. |
|
doh.robot.keyPress(dojo.keys.ESCAPE, 500, {}); |
|
return d; |
|
}, |
|
tearDown: function(){ |
|
dojo.disconnect(handler); |
|
} |
|
} |
|
]); |
|
|
|
// Testing that canceling an edit doesn't select anything |
|
doh.register("cancel edit", { |
|
name: "no value", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
var wasBlank = !pattern.get("value"); |
|
|
|
handler = dojo.connect(pattern, 'openDropDown', function(){ |
|
dojo.disconnect(handler); |
|
var calendar = dijit.byId("pattern_popup"); |
|
var wasVisible = calendar && isVisible(calendar); |
|
|
|
handler = dojo.connect(pattern, 'closeDropDown', d.getTestCallback(function(){ |
|
doh.t(wasBlank, "initially blank"); |
|
doh.t(wasVisible, "calendar was visible"); |
|
var calendar = dijit.byId("pattern_popup"); |
|
doh.f(calendar && isVisible(calendar), "calendar popup destroyed or hidden"); |
|
doh.t(!pattern.get("value"), "no value set into DateTextBox") |
|
})); |
|
|
|
// close the drop down |
|
doh.robot.mouseMoveAt("pattern", 0, 1, pattern.domNode.offsetWidth + 20, pattern.domNode.offsetHeight/2); |
|
doh.robot.mouseClick({left:true}, 500); |
|
}); |
|
|
|
// open the drop down |
|
doh.robot.mouseMoveAt(pattern._buttonNode, 100, 1); // delay to allow previous keyUp to occur |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
return d; |
|
}, |
|
tearDown: function(){ |
|
dojo.disconnect(handler); |
|
} |
|
}); |
|
|
|
doh.register("month drop down edge case", [ |
|
{ |
|
name: "initial popup display", |
|
timeout: 6000, |
|
setUp: function(){ |
|
american.set('value', new Date(2006, 11, 31), false); |
|
}, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
handler = dojo.connect(american, 'openDropDown', d.getTestCallback(function(){ |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
// calendar exists and is shown |
|
doh.t(calendar && isVisible(calendar), "calendar is visible"); |
|
|
|
// calendar is on the right month |
|
doh.is("December", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "calendar starts on month selected in input box"); |
|
|
|
// and the right year |
|
var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode); |
|
doh.is(1, selectedYearButtons.length, "current year is shown"); |
|
doh.is("2006", innerText(selectedYearButtons[0]), "current year"); |
|
|
|
// and the currently focused date is the 31'st |
|
doh.is("31", innerText(dojo.query(".dijitCalendarSelectedDate", calendar.domNode)[0]), "correct day is selected"); |
|
})); |
|
|
|
doh.robot.mouseMoveAt(american._buttonNode, 100, 1); // delay to allow previous mouseUp to occur |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
return d; |
|
}, |
|
tearDown: function(){ |
|
dojo.disconnect(handler); |
|
} |
|
}, |
|
|
|
// Switching to February to test that movement works even though there is no Feb 31st. |
|
{ |
|
name: "switch to february", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.is(1, dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode).length, "found month label"); |
|
doh.t(calendar.monthWidget.dropDown, "month dropdown exists"); |
|
doh.f(isVisible(calendar.monthWidget.dropDown), "month dropdown is not visible"); |
|
|
|
doh.robot.mouseMoveAt(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0], 0, 1); |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
doh.robot.mouseMoveAt(function(){ |
|
return dojo.query("[month=1]", calendar.monthWidget.dropDown.domNode)[0]; |
|
}, 1000, 1); |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar, "calendar popup exists"); |
|
doh.t(isVisible(calendar), "calendar is visible"); |
|
|
|
// calendar moved to feb 2006 |
|
doh.is("February", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "moved from December to February"); |
|
var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode); |
|
doh.is(1, selectedYearButtons.length, "current year is shown"); |
|
doh.is("2006", innerText(selectedYearButtons[0]), "current year"); |
|
}), 500); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
// Switching to December to make sure that drop down isn't cut off |
|
{ |
|
name: "switch back to december", |
|
timeout: 6000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
var calendar = dijit.byId("american_popup"); |
|
|
|
doh.is(1, dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode).length, "found month label"); |
|
doh.t(calendar.monthWidget.dropDown, "month dropdown exists"); |
|
doh.f(isVisible(calendar.monthWidget.dropDown), "month dropdown is not visible"); |
|
|
|
doh.robot.mouseMoveAt(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0], 0, 1); |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
doh.robot.mouseMoveAt(function(){ |
|
return dojo.query("[month=11]", calendar.monthWidget.dropDown.domNode)[0]; |
|
}, 1000, 1); |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// calendar still exists and is shown |
|
doh.t(calendar, "calendar popup exists"); |
|
doh.t(isVisible(calendar), "calendar is visible"); |
|
|
|
// calendar moved to dec 2006 |
|
doh.is("December", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "moved from june to july"); |
|
var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode); |
|
doh.is(1, selectedYearButtons.length, "current year is shown"); |
|
doh.is("2006", innerText(selectedYearButtons[0]), "current year"); |
|
}), 1000); |
|
|
|
return d; |
|
} |
|
}, |
|
|
|
{ |
|
name: "cancel", |
|
timeout: 3000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
handler = dojo.connect(american, 'closeDropDown', d.getTestCallback(function(){ |
|
var calendar = dijit.byId("american_popup"); |
|
doh.f(calendar && isVisible(calendar), "calendar isn't visible"); |
|
})); |
|
doh.robot.keyPress(dojo.keys.ESCAPE, 500, {}); |
|
|
|
return d; |
|
}, |
|
tearDown: function(){ |
|
dojo.disconnect(handler); |
|
} |
|
} |
|
]); |
|
|
|
doh.register("clicking input", [ |
|
{ |
|
name: "click on input", |
|
timeout: 10000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
handler = dojo.connect(localLong.focusNode, 'onfocus', function(){ |
|
dojo.disconnect(handler); |
|
var calendar = dijit.byId("localLong_popup"); |
|
var wasVisible = calendar && isVisible(calendar); |
|
handler = dojo.connect(localLong, 'openDropDown', d.getTestCallback(function(){ |
|
doh.f(wasVisible, "calendar isn't visible"); |
|
calendar = dijit.byId("localLong_popup"); |
|
doh.t(calendar && isVisible(calendar), "calendar is visible"); |
|
})); |
|
doh.robot.mouseMoveAt(localLong._buttonNode, 0, 1); |
|
doh.robot.mouseClick({left:true}, 500); |
|
}); |
|
|
|
doh.robot.mouseMoveAt(localLong.focusNode, 100, 1); // delay to allow previous keyUp to occur |
|
doh.robot.mouseClick({left:true}, 500); |
|
|
|
return d; |
|
}, |
|
tearDown: function(){ |
|
dojo.disconnect(handler); |
|
localLong.closeDropDown(); |
|
} |
|
} |
|
]); |
|
|
|
doh.run(); |
|
}); |
|
</script> |
|
</head> |
|
</html>
|
|
|