disabled-state.html 2.84 KB
<!doctype html>
<!--
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
  <title>disabled-state</title>

  <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
  <script src="../../web-component-tester/browser.js"></script>
  <script src="../../test-fixture/test-fixture-mocha.js"></script>

  <link rel="import" href="../../polymer/polymer.html">
  <link rel="import" href="../../test-fixture/test-fixture.html">
  <link rel="import" href="test-elements.html">
</head>
<body>

  <test-fixture id="TrivialDisabledState">
    <template>
      <test-control></test-control>
    </template>
  </test-fixture>

  <test-fixture id="InitiallyDisabledState">
    <template>
      <test-control disabled></test-control>
    </template>
  </test-fixture>

  <script>
    suite('disabled-state', function() {
      var disableTarget;

      suite('a trivial disabled state', function() {
        setup(function() {
          disableTarget = fixture('TrivialDisabledState');
        });

        suite('when disabled is true', function() {
          test('receives a disabled attribute', function() {
            disableTarget.disabled = true;
            expect(disableTarget.hasAttribute('disabled')).to.be.eql(true);
          });

          test('receives an appropriate aria attribute', function() {
            disableTarget.disabled = true;
            expect(disableTarget.getAttribute('aria-disabled')).to.be.eql('true');
          });
        });

        suite('when disabled is false', function() {
          test('loses the disabled attribute', function() {
            disableTarget.disabled = true;
            expect(disableTarget.hasAttribute('disabled')).to.be.eql(true);
            disableTarget.disabled = false;
            expect(disableTarget.hasAttribute('disabled')).to.be.eql(false);
          });
        });
      });

      suite('a state with an initially disabled target', function() {
        setup(function() {
          disableTarget = fixture('InitiallyDisabledState');
        });

        test('preserves the disabled attribute on target', function() {
          expect(disableTarget.hasAttribute('disabled')).to.be.eql(true);
          expect(disableTarget.disabled).to.be.eql(true);
        });

        test('adds `aria-disabled` to the target', function() {
          expect(disableTarget.getAttribute('aria-disabled')).to.be.eql('true');
        });
      });
    });
  </script>

</body>
</html>