paper-date-picker.html 1.81 KB
<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
  <script src="../bower_components/web-component-tester/browser.js"></script>
  <!-- import the element to test -->
  <link rel="import" href="../paper-date-picker.html">
</head>

<body>

  <test-fixture id="max-date-fixture">
    <template>
      <paper-date-picker
        id="picker"
        date="January 1, 2016"
        max-date="February 28, 2016">
      </paper-date-picker>
    </template>
  </test-fixture>

  <script>

    describe('paper-date-picker', function() {
      var element;

      context('with a max-date', function() {

        beforeEach(function() {
          element = fixture('max-date-fixture');
        });

        it('should not swipe after the max bound', function(done) {

          // Check initialization
          expect(element.date).to.be.not.null;
          expect(element.maxDate).to.be.not.null;

          // Try to swipe after the max bound
          var calendar = element.$$('paper-calendar');
          calendar._swipeNextMonth();
          calendar._swipeNextMonth();
          calendar._swipeNextMonth();
          calendar._swipeNextMonth();

          // Check after all animation that the calendar has been transformed
          // once
          setTimeout(function() {
            // When the max bound is reached, the div `months` contains only two
            // months. So we check that the current position is equal to the
            // half of the width, else it means the calendar has undergone too
            // much transformations
            expect(calendar._currentPos).to.equal(
              -(calendar.$.months.clientWidth / 2)
            );
            done();
          }, 500);
        });

      });

    });

  </script>
</body>

</html>