[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/bootstrap/js/eternicode-bootstrap-datepicker/tests/suites/ -> component.js (source)

   1  module('Component', {
   2      setup: function(){
   3          this.component = $('<div class="input-append date" id="datepicker">'+
   4                                  '<input size="16" type="text" value="12-02-2012" readonly>'+
   5                                  '<span class="add-on"><i class="icon-th"></i></span>'+
   6                              '</div>')
   7                          .appendTo('#qunit-fixture')
   8                          .datepicker({format: "dd-mm-yyyy"});
   9          this.input = this.component.find('input');
  10          this.addon = this.component.find('.add-on');
  11          this.dp = this.component.data('datepicker')
  12          this.picker = this.dp.picker;
  13      },
  14      teardown: function(){
  15          this.picker.remove();
  16      }
  17  });
  18  
  19  
  20  test('Component gets date/viewDate from input value', function(){
  21      datesEqual(this.dp.date, new Date(2012, 1, 12));
  22      datesEqual(this.dp.viewDate, new Date(2012, 1, 12));
  23  });
  24  
  25  test('Activation by component', function(){
  26      ok(!this.picker.is(':visible'));
  27      this.addon.click();
  28      ok(this.picker.is(':visible'));
  29  });
  30  
  31  test('simple keyboard nav test', function(){
  32      var target;
  33  
  34      equal(this.dp.viewMode, 0);
  35      target = this.picker.find('.datepicker-days thead th.switch');
  36      equal(target.text(), 'February 2012', 'Title is "February 2012"');
  37      datesEqual(this.dp.date, new Date(2012, 1, 12));
  38      datesEqual(this.dp.viewDate, new Date(2012, 1, 12));
  39  
  40      // Navigation: -1 day, left arrow key
  41      this.input.trigger({
  42          type: 'keydown',
  43          keyCode: 37
  44      });
  45      datesEqual(this.dp.viewDate, new Date(2012, 1, 11));
  46      datesEqual(this.dp.date, new Date(2012, 1, 11));
  47      // Month not changed
  48      target = this.picker.find('.datepicker-days thead th.switch');
  49      equal(target.text(), 'February 2012', 'Title is "February 2012"');
  50  
  51      // Navigation: +1 month, shift + right arrow key
  52      this.input.trigger({
  53          type: 'keydown',
  54          keyCode: 39,
  55          shiftKey: true
  56      });
  57      datesEqual(this.dp.viewDate, new Date(2012, 2, 11));
  58      datesEqual(this.dp.date, new Date(2012, 2, 11));
  59      target = this.picker.find('.datepicker-days thead th.switch');
  60      equal(target.text(), 'March 2012', 'Title is "March 2012"');
  61  
  62      // Navigation: -1 year, ctrl + left arrow key
  63      this.input.trigger({
  64          type: 'keydown',
  65          keyCode: 37,
  66          ctrlKey: true
  67      });
  68      datesEqual(this.dp.viewDate, new Date(2011, 2, 11));
  69      datesEqual(this.dp.date, new Date(2011, 2, 11));
  70      target = this.picker.find('.datepicker-days thead th.switch');
  71      equal(target.text(), 'March 2011', 'Title is "March 2011"');
  72  });
  73  
  74  test('setValue', function(){
  75      this.dp.date = new Date(2012, 2, 13)
  76      this.dp.setValue()
  77      datesEqual(this.dp.date, new Date(2012, 2, 13));
  78      equal(this.input.val(), '13-03-2012');
  79  });
  80  
  81  test('update', function(){
  82      this.input.val('13-03-2012');
  83      this.dp.update()
  84      datesEqual(this.dp.date, new Date(2012, 2, 13));
  85  });
  86  
  87  test('Navigating to/from decade view', function(){
  88      var target;
  89  
  90      this.addon.click();
  91      this.input.val('31-03-2012');
  92      this.dp.update();
  93  
  94      equal(this.dp.viewMode, 0);
  95      target = this.picker.find('.datepicker-days thead th.switch');
  96      ok(target.is(':visible'), 'View switcher is visible');
  97  
  98      target.click();
  99      ok(this.picker.find('.datepicker-months').is(':visible'), 'Month picker is visible');
 100      equal(this.dp.viewMode, 1);
 101      // Not modified when switching modes
 102      datesEqual(this.dp.viewDate, new Date(2012, 2, 31));
 103      datesEqual(this.dp.date, new Date(2012, 2, 31));
 104  
 105      target = this.picker.find('.datepicker-months thead th.switch');
 106      ok(target.is(':visible'), 'View switcher is visible');
 107  
 108      target.click();
 109      ok(this.picker.find('.datepicker-years').is(':visible'), 'Year picker is visible');
 110      equal(this.dp.viewMode, 2);
 111      // Not modified when switching modes
 112      datesEqual(this.dp.viewDate, new Date(2012, 2, 31));
 113      datesEqual(this.dp.date, new Date(2012, 2, 31));
 114  
 115      // Change years to test internal state changes
 116      target = this.picker.find('.datepicker-years tbody span:contains(2011)');
 117      target.click();
 118      equal(this.dp.viewMode, 1);
 119      // Only viewDate modified
 120      datesEqual(this.dp.viewDate, new Date(2011, 2, 31));
 121      datesEqual(this.dp.date, new Date(2012, 2, 31));
 122  
 123      target = this.picker.find('.datepicker-months tbody span:contains(Apr)');
 124      target.click();
 125      equal(this.dp.viewMode, 0);
 126      // Only viewDate modified
 127      datesEqual(this.dp.viewDate, new Date(2011, 3, 30));
 128      datesEqual(this.dp.date, new Date(2012, 2, 31));
 129  });
 130  
 131  test('Selecting date resets viewDate and date', function(){
 132      var target;
 133  
 134      this.addon.click();
 135      this.input.val('31-03-2012');
 136      this.dp.update();
 137  
 138      // Rendered correctly
 139      equal(this.dp.viewMode, 0);
 140      target = this.picker.find('.datepicker-days tbody td:first');
 141      equal(target.text(), '26'); // Should be Feb 26
 142  
 143      // Updated internally on click
 144      target.click();
 145      datesEqual(this.dp.viewDate, new Date(2012, 1, 26))
 146      datesEqual(this.dp.date, new Date(2012, 1, 26))
 147  
 148      // Re-rendered on click
 149      target = this.picker.find('.datepicker-days tbody td:first');
 150      equal(target.text(), '29'); // Should be Jan 29
 151  });


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1