aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tensorboard/components/tf_tensorboard/test/tensorboardTests.ts
blob: 33e11e3094d99546274b68ec35e5135172044e20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the 'License');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an 'AS IS' BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import * as backend_router from '../../tf-backend/router';
import {TABS} from '../../tf-globals/globals';

describe('tf-tensorboard tests', () => {
  window.HTMLImports.whenReady(() => {
    let tensorboard: any;
    beforeEach(function() {
      tensorboard = fixture('tensorboardFixture');
      tensorboard.demoDir = 'data';
      tensorboard.autoReloadEnabled = false;
    });

    it('specified tabs are correct', function(done) {
      setTimeout(function() {
        let tabs = tensorboard.$.tabs.getElementsByTagName('paper-tab');
        let tabMode = Array.prototype.map.call(tabs, (x) => x.dataMode);
        chai.assert.deepEqual(tabMode, TABS, 'mode is correct');
        let tabText =
            Array.prototype.map.call(tabs, (x) => x.innerText.toLowerCase());
        chai.assert.deepEqual(tabText, TABS, 'text is correct');
        done();
      });
    });

    it('respects router manually provided', function() {
      const router = backend_router.router('data', true);
      tensorboard.router = router;
      tensorboard.demoDir = null;
      chai.assert.equal(tensorboard._backend.router, router);
    });

    it('renders injected content', function() {
      let injected = tensorboard.querySelector('#inject-me');
      chai.assert.isNotNull(injected);
    });

    describe('reloading the selected dashboard', function() {
      TABS.forEach((name, tabIndex) => {
        // These tabs do not support reload mode.
        if (name === 'graphs' || name === 'projections') {
          return;
        }
        it(`${name}: calling reload reloads dashboard`, function(done) {
          tensorboard.$.tabs.set('selected', tabIndex);
          setTimeout(function() {
            let called = false;
            tensorboard.selectedDashboard().reload = function() {
              called = true;
            };
            tensorboard.reload();
            chai.assert.isFalse(
                tensorboard.$$('#reload-button').disabled,
                'reload button not disabled');
            chai.assert.isTrue(called, `reload was called`);
            done();
          });
        });
      });
    });

    it('reload is disabled for graph dashboard', function(done) {
      const idx = TABS.indexOf('graphs');
      chai.assert.notEqual(idx, -1, 'graphs was found');
      tensorboard.$.tabs.set('selected', idx);
      setTimeout(
          function() {  // async so that the queued tab change will happen
            let called = false;
            tensorboard.selectedDashboard().reload = function() {
              called = true;
            };
            tensorboard.reload();
            chai.assert.isTrue(
                tensorboard.$$('#reload-button').disabled,
                'reload button disabled');
            chai.assert.isFalse(called, `reload was not called`);
            done();
          });
    });

    describe('top right global icons', function() {
      it('Clicking the reload button will call reload', function() {
        let called = false;
        tensorboard.reload = function() { called = true; };
        tensorboard.$$('#reload-button').click();
        chai.assert.isTrue(called);
      });

      it('settings pane is hidden', function() {
        chai.assert.equal(tensorboard.$.settings.style['display'], 'none');
      });

      it('settings icon button opens the settings pane', function(done) {
        tensorboard.$$('#settings-button').click();
        // This test is a little hacky since we depend on polymer's
        // async behavior, which is difficult to predict.

        // keep checking until the panel is visible. error with a timeout if it
        // is broken.
        function verify() {
          if (tensorboard.$.settings.style['display'] !== 'none') {
            done();
          } else {
            setTimeout(verify, 3);  // wait and see if it becomes true
          }
        }
        verify();
      });

      it('Autoreload checkbox toggle works', function() {
        let checkbox = tensorboard.$$('#auto-reload-checkbox');
        chai.assert.equal(checkbox.checked, tensorboard.autoReloadEnabled);
        let oldValue = checkbox.checked;
        checkbox.click();
        chai.assert.notEqual(oldValue, checkbox.checked);
        chai.assert.equal(checkbox.checked, tensorboard.autoReloadEnabled);
      });

      it('Autoreload checkbox contains correct interval info', function() {
        let checkbox = tensorboard.$$('#auto-reload-checkbox');
        let timeInSeconds = tensorboard.autoReloadIntervalSecs + 's';
        chai.assert.include(checkbox.innerText, timeInSeconds);
      });
    });
  });
});