176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich<script type="text/javascript" src="/build/yui/yui.js"></script>
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich logInclude:{"TestRunner":true},
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich useConsole: true,
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich allowRollup: false,
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min'
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich }).use("console", "test", "dump", "calendar", "node-event-simulate", function(Y) {
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich // Set up the page
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich btnRun = Y.one("#btnRun"),
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich myConsole = new Y.Console().render();
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich btnRun.set("disabled", false);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.on("click", function(){
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich var BasicCalendar = new Y.Test.Case({
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich name: "Basic Calendar Tests",
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich setUp : function () {
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich var firstcontainer = "<div id='firstcontainer'></div>";
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich var secondcontainer = "<div id='secondcontainer'></div>";
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.one('#container').appendChild(Y.Node.create(firstcontainer));
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.one('#container').appendChild(Y.Node.create(secondcontainer));
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich tearDown : function () {
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.one('#firstcontainer').remove();
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.one('#secondcontainer').remove();
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich testBasicCalendar : function() {
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich contentBox: "#firstcontainer",
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich date: new Date(2011,11,5)
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich //calendar is visible
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(this.firstcalendar.get('visible'), true);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich //calendar date is normalized correctly
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich var calendarDate = this.firstcalendar.get("date");
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(2011, calendarDate.getFullYear());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(11, calendarDate.getMonth());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(1, calendarDate.getDate());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich // Test that the first and last days of the month render correctly
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich // Test that showPreviousMonth and showNextMonth are false by default
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(false, this.firstcalendar.get("showPrevMonth"));
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(false, this.firstcalendar.get("showNextMonth"));
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich testPrevAndNextMonth : function () {
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich contentBox: "#firstcontainer",
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich date: new Date(2011,11,5),
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich showPrevMonth: true,
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich showNextMonth: true
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich // Test that showPreviousMonth and showNextMonth are true
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(true, this.firstcalendar.get("showPrevMonth"));
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(true, this.firstcalendar.get("showNextMonth"));
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich // Test that previous and next months are showing
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual("27", Y.one("#firstcontainer").one(".calendar_col2.yui3-calendar-prevmonth-day").getContent());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual("28", Y.one("#firstcontainer").one(".calendar_col3.yui3-calendar-prevmonth-day").getContent());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual("29", Y.one("#firstcontainer").one(".calendar_col4.yui3-calendar-prevmonth-day").getContent());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual("30", Y.one("#firstcontainer").one(".calendar_col5.yui3-calendar-prevmonth-day").getContent());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual("1", Y.one("#firstcontainer").one(".calendar_col2.yui3-calendar-nextmonth-day").getContent());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual("2", Y.one("#firstcontainer").one(".calendar_col3.yui3-calendar-nextmonth-day").getContent());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual("3", Y.one("#firstcontainer").one(".calendar_col4.yui3-calendar-nextmonth-day").getContent());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual("4", Y.one("#firstcontainer").one(".calendar_col5.yui3-calendar-nextmonth-day").getContent());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual("5", Y.one("#firstcontainer").one(".calendar_col6.yui3-calendar-nextmonth-day").getContent());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual("6", Y.one("#firstcontainer").one(".calendar_col7.yui3-calendar-nextmonth-day").getContent());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual("7", Y.one("#firstcontainer").one(".calendar_col8.yui3-calendar-nextmonth-day").getContent());
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich testTwoCalendars : function () {
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich contentBox: "#firstcontainer",
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich date: new Date(2011,11,5),
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich showPrevMonth: true,
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich showNextMonth: true
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich contentBox: "#secondcontainer",
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich date: new Date(2011,11,5),
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich showPrevMonth: true,
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich showNextMonth: true
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich this.secondcalendar = new Y.Calendar(cfg2);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areNotEqual(this.firstcalendar.get("id"), this.secondcalendar.get("id"));
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areNotEqual(this.firstcalendar._calendarId, this.secondcalendar._calendarId);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich testCalendarClick : function() {
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich contentBox: "#firstcontainer",
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich date: new Date(2011,11,5)
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich // Click on a specific calendar cell;
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich var calendarid = this.firstcalendar._calendarId;
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.one("#" + calendarid + "_pane_0_6_15").simulate("click");
ecb0e3c0ca1489bc78b763cdfb6163c8c1043e2eAllen Rabinovich var currentDate = this.firstcalendar.get("selectedDates")[0];
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(currentDate.getFullYear(), 2011);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(currentDate.getMonth(), 11);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(currentDate.getDate(), 15);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich // Click on a different calendar cell
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.one("#" + calendarid + "_pane_0_8_31").simulate("click");
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich currentDate = this.firstcalendar.get("selectedDates")[0];
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(currentDate.getFullYear(), 2011);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(currentDate.getMonth(), 11);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(currentDate.getDate(), 31);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich // Click to advance the month
ecb0e3c0ca1489bc78b763cdfb6163c8c1043e2eAllen Rabinovich Y.one(".yui3-calendarnav-nextmonth").simulate("click");
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich // Click on a date in the new month
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.one("#" + calendarid + "_pane_0_8_17").simulate("click");
ecb0e3c0ca1489bc78b763cdfb6163c8c1043e2eAllen Rabinovich currentDate = this.firstcalendar.get("selectedDates")[0];
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(currentDate.getFullYear(), 2012);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(currentDate.getMonth(), 0);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(currentDate.getDate(), 17);
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich testCustomHeader : function() {
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich contentBox: "#firstcontainer",
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich date: new Date(2011,11,5)
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich this.firstcalendar.set("headerRenderer", function (curDate) {
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich output = ydate.format(curDate, {
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich format: "%m %Y"
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich return output;
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich var currentHeaderString = this.firstcalendar.get("contentBox").one(".yui3-calendar-header-label").get("text");
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich Y.Assert.areEqual("12 2011", currentHeaderString);
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich // Click to advance the month
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich Y.one(".yui3-calendarnav-nextmonth").simulate("click");
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich currentHeaderString = this.firstcalendar.get("contentBox").one(".yui3-calendar-header-label").get("text");
76438e9b6959cc0bd7e35fb9cf5a11c87a37f744Allen Rabinovich Y.Assert.areEqual("01 2012", currentHeaderString);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich testMultiplePanes : function () {
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich contentBox: "#firstcontainer",
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich date: new Date(2011,11,5),
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich selectionMode: "multiple"
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich // Set the content template to a two-pane template
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.CalendarBase.CONTENT_TEMPLATE = Y.CalendarBase.TWO_PANE_TEMPLATE;
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich // Click on a date
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich var calendarid = this.firstcalendar._calendarId;
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.one("#" + calendarid + "_pane_0_6_29").simulate("click");
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich // Shift-click another date
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.one("#" + calendarid + "_pane_1_7_2").simulate("click", {shiftKey: true});
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich var date0 = this.firstcalendar.get("selectedDates")[0];
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich var date1 = this.firstcalendar.get("selectedDates")[1];
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich var date2 = this.firstcalendar.get("selectedDates")[2];
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich var date3 = this.firstcalendar.get("selectedDates")[3];
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich var date4 = this.firstcalendar.get("selectedDates")[4];
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(date0.getFullYear(), 2011);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(date1.getFullYear(), 2011);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(date2.getFullYear(), 2011);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(date3.getFullYear(), 2012);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Assert.areEqual(date4.getFullYear(), 2012);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich var suite = new Y.Test.Suite({name:"Basic Calendar Test Suite"});
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich suite.add(BasicCalendar);
176bb1f5c1bead550f24ffc878201352795c73adAllen Rabinovich Y.Test.Runner.setName("Calendar Test Runner");