<commit_before>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Calendar Date Select Test Cases</title>
  <script src="../prototype.js" type="text/javascript"></script>
  <script src="../unittest.js" type="text/javascript"></script>
  <!-- other JavaScript includes -->
  <script src="../../public/javascripts/calendar_date_select/calendar_date_select.js" type="text/javascript"></script>
  
  <link rel="stylesheet" href="../../public/stylesheets/calendar_date_select/red.css" type="text/css" />
  <link rel="stylesheet" href="../test.css" type="text/css" />
</head>
<body>

<!-- Log output -->
<div id="testlog"> </div>

<!-- here go any elements you do the testing on -->
<div id="cds_test_div">
  <input type="text" id="cds_test" />
</div>

<!-- Tests -->
<script type="text/javascript" language="javascript">
// <![CDATA[
  new Test.Unit.Runner({
    setup: function() { with(this){
      $("cds_test").value="";
      $("cds_test").disabled = false;
      $("cds_test").readOnly = false;

    }},
    testMixedTime_feedDateWithAndWithoutTime_shouldSetAccordingly: function() { with(this) {
      $A(["January 2, 2007 5:00 pm", "January 2, 2007 0:00 pm"]).each(function(d) {
        $("cds_test").value=d;
        cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
        assertEqual(true, cds.use_time);
        cds.close();
      })
      
      $("cds_test").value="January 2, 2007";
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
      assertEqual(false, cds.use_time);
      cds.close();      
    }},
    testTodayNowButton_mixedMode_shouldSetUseTimeAccordingly: function() { with(this){
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
      today_now = $$(".cds_buttons a[href=#]");
      today_now[0].onclick();
      assertEqual(false, cds.use_time, "when clicking today link");
      
      today_now[1].onclick();
      assertEqual(true, cds.use_time, "should have been true when clicking now link");
      cds.close();
    }},
    test_updateSelectedDate: function() { with(this){
      $("cds_test").value = "January 1, 2007"
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});

      cds.use_time=true;
      cds.updateSelectedDate({hour: ""})
      assertEqual(false, cds.use_time, "when setting hour to ''");
      
      cds.use_time=true;
      cds.updateSelectedDate({minute: ""})
      assertEqual(false, cds.use_time, "when setting minute to ''");
      
      cds.use_time=false;
      cds.updateSelectedDate({hour: 0})
      assertEqual(true, cds.use_time, "when setting hour to 0");
      
      cds.use_time=false;
      cds.updateSelectedDate({minute: 0})
      assertEqual(true, cds.use_time, "when setting minute to 0");
      
      cds.close();
    }},
    test_navYear: function() { with(this){
      $("cds_test").value = "January 1, 2007";
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
      cds.navYear(1870);
      assertEqual(2007, cds.selected_date.getFullYear());
      assertEqual(1870, cds.date.getFullYear());
      cds.close();
    }},
    test_navMonth: function() { with(this){
      $("cds_test").value = "January 1, 2007";
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
      cds.navMonth(5);
      assertEqual(0, cds.selected_date.getMonth());
      assertEqual(5, cds.date.getMonth())
      cds.close();
    }},
    test_disabledElement_cantUpdate: function() {with(this){
      $("cds_test").value = "May 10, 2007";
      $("cds_test").disabled = true;
      cds = new CalendarDateSelect($("cds_test"));
      
      runTest = function() {
        cds.updateSelectedDate({day: 1, month:0, year: 2007});
        assertEqual(10, cds.selected_date.getDate())
      }
      runTest();
      $("cds_test").disabled = false;
      $("cds_test").readOnly = true;
      runTest();
      
      $("cds_test").readOnly = false;
      cds.close();
    }},
    test_readOnlyElement_forcePopup_shouldUpdate: function() {with(this){
      $("cds_test").value = "May 10, 2007";
      $("cds_test").readOnly = true;
      cds = new CalendarDateSelect($("cds_test"), {popup: "force"});
      
      cds.updateSelectedDate({day: 1, month:0, year: 2007});
      assertEqual(1, cds.selected_date.getDate())
      
      $("cds_test").readOnly = false;
      cds.close();
    }},
    test_timePassed_notUsingTime_shouldIgnore: function() {with(this) {
      $("cds_test").value = "May 10, 2007 5:00 pm";
      cds = new CalendarDateSelect($("cds_test"), {time:false});
      assertEqual(false, cds.use_time, "When parsing time");
      cds.today(); // this will close the control
      assertEqual(false, cds.use_time, "When calling today");
      
      cds = new CalendarDateSelect($("cds_test"), {time:false});
      cds.updateSelectedDate({hours: 5, minutes:30}) // this will close the control
      assertEqual(false, cds.use_time, "When setting hour/minute");
    }},
    test_setUseTime_true_notUsingTime_shouldIgnore: function() {with(this) {
      $("cds_test").value = "May 10, 2007 5:00 pm";
      cds = new CalendarDateSelect($("cds_test"), {time:false});
      assertEqual(false, cds.use_time, "When parsing time");
      cds.setUseTime(true); // this will close the control
      assert(! cds.use_time, "After calling setUseTime(true)");
      cds.close();
    }},
    test_setMinute_notOnInterval_usesFloor: function() {with(this){
      $("cds_test").value = "May 10, 2007 5:25 pm";
      cds = new CalendarDateSelect($("cds_test"), {time:true});
      cds.updateSelectedDate({hour: 1, minute: 4});
      assertEqual(0, cds.selected_date.getMinutes());
      assertEqual(1, cds.selected_date.getHours());
      
      cds.close();
    }},
    // this checks for a safari 2 bug where safari parses "" as a date back in 1969
    test_parseDate_blankInput_interpretsAsNotSelected: function() {with(this){
      $("cds_test").value = " ";
      cds = new CalendarDateSelect($("cds_test"), {time:true});
      assertEqual(new Date().getFullYear(), cds.selected_date.getFullYear());
      assertEqual(new Date().getFullYear(), cds.date.getFullYear());
      assert(! cds.selection_made)
      cds.close();
    }},
    test_parseDate_timeTrue_noTimePassed_useTimeSetToTrueAnyway: function() {with(this){
      $("cds_test").value = "December 1, 2007 ";
      cds = new CalendarDateSelect($("cds_test"), {time:true});
      assert(cds.use_time)
      cds.close();
    }},
    test_passDivElement__shouldUseChildInputForTargetElement: function() {with(this){
      cds = new CalendarDateSelect($("cds_test_div"), {time:true});
      assertEqual("INPUT", cds.target_element.nodeName)
      cds.close();
    }},
    test__flexibleYearRange__datePassedWayBackWhen__shouldInitYearSelectAroundDate: function() {with(this){
      $("cds_test").value = "July 4, 1776";
      cds = new CalendarDateSelect($("cds_test_div"), {time:true});
      assert(cds.flexibleYearRange(), " should have had a flexibleYearRange");
      assert(cds.year_select.setValue(1776), "Should have allowed me to select 1776");
      cds.close();
    }},
    test__nonflexibleYearRange__dateRangeAtEnds__shouldntAllowNavigationPassedBoundary: function() {with(this){
      $("cds_test").value = "January 1, 2007";
      cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: [2007, 2007]});
      
      assert(! cds.navYear(2006), "should not allow year navigation outside of boundary");
      assert(! cds.navYear(2008), "should not allow year navigation outside of boundary");
      assert(! cds.navMonth(-1), "shouldnt allow me to go beyond boundary");
      assert(! cds.navMonth(13), "shouldnt allow me to go beyond boundary");
      assert(cds.navMonth(1), "should allow me to be in boundary");
      assert(cds.navYear(2007), "should allow me to be in boundary");
      cds.close();
    }},
    test__nonflexibleYearRange__shouldPopulateRange: function() {with(this){
      $("cds_test").value = "January 1, 2007";
      cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: [2007, 2007]});
      assert(cds.year_select.setValue(2007), "should allow me to select 2007");
      cds.close();
    }}
  });
// ]]>
</script>
</body><commit_msg>test case to chcek auto-repopulating of flexibleYearRanges<commit_after>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Calendar Date Select Test Cases</title>
  <script src="../prototype.js" type="text/javascript"></script>
  <script src="../unittest.js" type="text/javascript"></script>
  <!-- other JavaScript includes -->
  <script src="../../public/javascripts/calendar_date_select/calendar_date_select.js" type="text/javascript"></script>
  
  <link rel="stylesheet" href="../../public/stylesheets/calendar_date_select/red.css" type="text/css" />
  <link rel="stylesheet" href="../test.css" type="text/css" />
</head>
<body>

<!-- Log output -->
<div id="testlog"> </div>

<!-- here go any elements you do the testing on -->
<div id="cds_test_div">
  <input type="text" id="cds_test" />
</div>

<!-- Tests -->
<script type="text/javascript" language="javascript">
// <![CDATA[
  new Test.Unit.Runner({
    setup: function() { with(this){
      $("cds_test").value="";
      $("cds_test").disabled = false;
      $("cds_test").readOnly = false;

    }},
    testMixedTime_feedDateWithAndWithoutTime_shouldSetAccordingly: function() { with(this) {
      $A(["January 2, 2007 5:00 pm", "January 2, 2007 0:00 pm"]).each(function(d) {
        $("cds_test").value=d;
        cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
        assertEqual(true, cds.use_time);
        cds.close();
      })
      
      $("cds_test").value="January 2, 2007";
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
      assertEqual(false, cds.use_time);
      cds.close();      
    }},
    testTodayNowButton_mixedMode_shouldSetUseTimeAccordingly: function() { with(this){
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
      today_now = $$(".cds_buttons a[href=#]");
      today_now[0].onclick();
      assertEqual(false, cds.use_time, "when clicking today link");
      
      today_now[1].onclick();
      assertEqual(true, cds.use_time, "should have been true when clicking now link");
      cds.close();
    }},
    test_updateSelectedDate: function() { with(this){
      $("cds_test").value = "January 1, 2007"
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});

      cds.use_time=true;
      cds.updateSelectedDate({hour: ""})
      assertEqual(false, cds.use_time, "when setting hour to ''");
      
      cds.use_time=true;
      cds.updateSelectedDate({minute: ""})
      assertEqual(false, cds.use_time, "when setting minute to ''");
      
      cds.use_time=false;
      cds.updateSelectedDate({hour: 0})
      assertEqual(true, cds.use_time, "when setting hour to 0");
      
      cds.use_time=false;
      cds.updateSelectedDate({minute: 0})
      assertEqual(true, cds.use_time, "when setting minute to 0");
      
      cds.close();
    }},
    test_navYear: function() { with(this){
      $("cds_test").value = "January 1, 2007";
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
      cds.navYear(1870);
      assertEqual(2007, cds.selected_date.getFullYear());
      assertEqual(1870, cds.date.getFullYear());
      cds.close();
    }},
    test_navMonth: function() { with(this){
      $("cds_test").value = "January 1, 2007";
      cds = new CalendarDateSelect($("cds_test"), {time: "mixed"});
      cds.navMonth(5);
      assertEqual(0, cds.selected_date.getMonth());
      assertEqual(5, cds.date.getMonth())
      cds.close();
    }},
    test_disabledElement_cantUpdate: function() {with(this){
      $("cds_test").value = "May 10, 2007";
      $("cds_test").disabled = true;
      cds = new CalendarDateSelect($("cds_test"));
      
      runTest = function() {
        cds.updateSelectedDate({day: 1, month:0, year: 2007});
        assertEqual(10, cds.selected_date.getDate())
      }
      runTest();
      $("cds_test").disabled = false;
      $("cds_test").readOnly = true;
      runTest();
      
      $("cds_test").readOnly = false;
      cds.close();
    }},
    test_readOnlyElement_forcePopup_shouldUpdate: function() {with(this){
      $("cds_test").value = "May 10, 2007";
      $("cds_test").readOnly = true;
      cds = new CalendarDateSelect($("cds_test"), {popup: "force"});
      
      cds.updateSelectedDate({day: 1, month:0, year: 2007});
      assertEqual(1, cds.selected_date.getDate())
      
      $("cds_test").readOnly = false;
      cds.close();
    }},
    test_timePassed_notUsingTime_shouldIgnore: function() {with(this) {
      $("cds_test").value = "May 10, 2007 5:00 pm";
      cds = new CalendarDateSelect($("cds_test"), {time:false});
      assertEqual(false, cds.use_time, "When parsing time");
      cds.today(); // this will close the control
      assertEqual(false, cds.use_time, "When calling today");
      
      cds = new CalendarDateSelect($("cds_test"), {time:false});
      cds.updateSelectedDate({hours: 5, minutes:30}) // this will close the control
      assertEqual(false, cds.use_time, "When setting hour/minute");
    }},
    test_setUseTime_true_notUsingTime_shouldIgnore: function() {with(this) {
      $("cds_test").value = "May 10, 2007 5:00 pm";
      cds = new CalendarDateSelect($("cds_test"), {time:false});
      assertEqual(false, cds.use_time, "When parsing time");
      cds.setUseTime(true); // this will close the control
      assert(! cds.use_time, "After calling setUseTime(true)");
      cds.close();
    }},
    test_setMinute_notOnInterval_usesFloor: function() {with(this){
      $("cds_test").value = "May 10, 2007 5:25 pm";
      cds = new CalendarDateSelect($("cds_test"), {time:true});
      cds.updateSelectedDate({hour: 1, minute: 4});
      assertEqual(0, cds.selected_date.getMinutes());
      assertEqual(1, cds.selected_date.getHours());
      
      cds.close();
    }},
    // this checks for a safari 2 bug where safari parses "" as a date back in 1969
    test_parseDate_blankInput_interpretsAsNotSelected: function() {with(this){
      $("cds_test").value = " ";
      cds = new CalendarDateSelect($("cds_test"), {time:true});
      assertEqual(new Date().getFullYear(), cds.selected_date.getFullYear());
      assertEqual(new Date().getFullYear(), cds.date.getFullYear());
      assert(! cds.selection_made)
      cds.close();
    }},
    test_parseDate_timeTrue_noTimePassed_useTimeSetToTrueAnyway: function() {with(this){
      $("cds_test").value = "December 1, 2007 ";
      cds = new CalendarDateSelect($("cds_test"), {time:true});
      assert(cds.use_time)
      cds.close();
    }},
    test_passDivElement__shouldUseChildInputForTargetElement: function() {with(this){
      cds = new CalendarDateSelect($("cds_test_div"), {time:true});
      assertEqual("INPUT", cds.target_element.nodeName)
      cds.close();
    }},
    test__flexibleYearRange__datePassedWayBackWhen__shouldInitYearSelectAroundDate: function() {with(this){
      $("cds_test").value = "July 4, 1776";
      cds = new CalendarDateSelect($("cds_test_div"), {time:true});
      assert(cds.flexibleYearRange(), " should have had a flexibleYearRange");
      assert(cds.year_select.setValue(1776), "Should have allowed me to select 1776");
      cds.close();
    }},
    test__nonflexibleYearRange__dateRangeAtEnds__shouldntAllowNavigationPassedBoundary: function() {with(this){
      $("cds_test").value = "January 1, 2007";
      cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: [2007, 2007]});
      
      assert(! cds.navYear(2006), "should not allow year navigation outside of boundary");
      assert(! cds.navYear(2008), "should not allow year navigation outside of boundary");
      assert(! cds.navMonth(-1), "shouldnt allow me to go beyond boundary");
      assert(! cds.navMonth(13), "shouldnt allow me to go beyond boundary");
      assert(cds.navMonth(1), "should allow me to be in boundary");
      assert(cds.navYear(2007), "should allow me to be in boundary");
      cds.close();
    }},
    test__nonflexibleYearRange__shouldPopulateRange: function() {with(this){
      $("cds_test").value = "January 1, 2007";
      cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: [2007, 2007]});
      assert(cds.year_select.setValue(2007), "should allow me to select 2007");
      cds.close();
    }},
    test__flexibleYearRange__goToBoundary__shouldRefreshRange: function() {with(this){
      $("cds_test").value = "January 1, 2007";
      cds = new CalendarDateSelect($("cds_test_div"), {time:true, year_range: 10});
      cds.navYear(1997);
      assert(cds.year_select.setValue(1987), "should have refreshed with 1997 as the center");
      cds.navYear(2017);
      assert(cds.year_select.setValue(2027), "should have refreshed with 2027 as the center");
      cds.close();
    }}
  });
// ]]>
</script>
</body>
{'fraction_non_alphanumeric': 0.16846189483437574, 'fraction_numerical': 0.025191104933981932, 'mean_word_length': 3.5194975137398585, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2114330', 'n_tokens_mistral': 6150, 'n_tokens_neox': 5583, 'n_words': 1141}