Преглед изворни кода

wip update terminal and tests

Steven Silvester пре 8 година
родитељ
комит
9d95288325
2 измењених фајлова са 52 додато и 37 уклоњено
  1. 12 3
      src/terminal/index.ts
  2. 40 34
      test/src/terminal/terminal.spec.ts

+ 12 - 3
src/terminal/index.ts

@@ -63,9 +63,9 @@ class TerminalWidget extends Widget {
     this.node.appendChild(this._sheet);
 
     // Initialize settings.
-    this.fontSize = options.fontSize || 14;
-    this.background = options.background || 'black';
-    this.color = options.color || 'white';
+    this._fontSize = options.fontSize || 14;
+    this._background = options.background || 'black';
+    this._color = options.color || 'white';
     this.id = `jp-TerminalWidget-${Private.id++}`;
     this.title.label = 'Terminal';
   }
@@ -102,6 +102,9 @@ class TerminalWidget extends Widget {
    * Set the font size of the terminal in pixels.
    */
   set fontSize(size: number) {
+    if (this._fontSize === size) {
+      return;
+    }
     this._fontSize = size;
     this._needsSnap = true;
     this.update();
@@ -118,6 +121,9 @@ class TerminalWidget extends Widget {
    * Set the background color of the terminal.
    */
   set background(value: string) {
+    if (this._background === value) {
+      return;
+    }
     this._background = value;
     this._needsStyle = true;
     this.update();
@@ -134,6 +140,9 @@ class TerminalWidget extends Widget {
    * Set the text color of the terminal.
    */
   set color(value: string) {
+    if (this._color === value) {
+      return;
+    }
     this._color = value;
     this._needsStyle = true;
     this.update();

+ 40 - 34
test/src/terminal/terminal.spec.ts

@@ -8,7 +8,7 @@ import {
 } from '@jupyterlab/services';
 
 import {
-  Message
+  Message, sendMessage
 } from 'phosphor/lib/core/messaging';
 
 import {
@@ -113,9 +113,13 @@ describe('terminal/index', () => {
         expect(widget.fontSize).to.be(14);
       });
 
-      it('should be settable', () => {
+      it('should trigger an update request', (done) => {
         widget.fontSize = 13;
         expect(widget.fontSize).to.be(13);
+        requestAnimationFrame(() => {
+          expect(widget.methods).to.contain('onUpdateRequest');
+          done();
+        });
       });
 
     });
@@ -126,9 +130,13 @@ describe('terminal/index', () => {
         expect(widget.background).to.be('black');
       });
 
-      it('should be settable', () => {
+      it('should trigger an update request', (done) => {
         widget.background = 'white';
         expect(widget.background).to.be('white');
+        requestAnimationFrame(() => {
+          expect(widget.methods).to.contain('onUpdateRequest');
+          done();
+        });
       });
 
     });
@@ -139,23 +147,15 @@ describe('terminal/index', () => {
         expect(widget.color).to.be('white');
       });
 
-      it('should be settable', () => {
+      it('should trigger an update request', (done) => {
         widget.color = 'black';
         expect(widget.color).to.be('black');
-      });
-
-      it('should post an update request', (done) => {
-        widget.session = session;
-        Widget.attach(widget, document.body);
         requestAnimationFrame(() => {
-          widget.methods = [];
-          widget.color = 'black';
-          requestAnimationFrame(() => {
-            expect(widget.methods).to.contain('onUpdateRequest');
-            done();
-          });
+          expect(widget.methods).to.contain('onUpdateRequest');
+          done();
         });
       });
+
     });
 
     describe('#dispose()', () => {
@@ -181,7 +181,7 @@ describe('terminal/index', () => {
 
     describe('#onAfterAttach()', () => {
 
-      it('should post an update request if visible', (done) => {
+      it('should post an update request', (done) => {
         widget.session = session;
         Widget.attach(widget, document.body);
         requestAnimationFrame(() => {
@@ -190,16 +190,6 @@ describe('terminal/index', () => {
         });
       });
 
-      it('should not post an update request if not visible', (done) => {
-        widget.session = session;
-        widget.hide();
-        Widget.attach(widget, document.body);
-        requestAnimationFrame(() => {
-          expect(widget.methods).to.not.contain('onUpdateRequest');
-          done();
-        });
-      });
-
     });
 
     describe('#onAfterShow()', () => {
@@ -208,10 +198,13 @@ describe('terminal/index', () => {
         widget.session = session;
         widget.hide();
         Widget.attach(widget, document.body);
-        widget.show();
         requestAnimationFrame(() => {
-          expect(widget.methods).to.contain('onUpdateRequest');
-          done();
+          widget.methods = [];
+          widget.show();
+          requestAnimationFrame(() => {
+            expect(widget.methods).to.contain('onUpdateRequest');
+            done();
+          });
         });
       });
 
@@ -220,15 +213,23 @@ describe('terminal/index', () => {
     describe('#onCloseRequest', () => {
 
       it('should dispose of the terminal after closing', () => {
-
+        widget.close();
+        expect(widget.methods).to.contain('onCloseRequest');
+        expect(widget.isDisposed).to.be(true);
       });
 
     });
 
     describe('#onResize()', () => {
 
-      it('should resize the terminal', () => {
-
+      it('should trigger an update request', (done) => {
+        let msg = ResizeMessage.UnknownSize;
+        sendMessage(widget, msg);
+        expect(widget.methods).to.contain('onResize');
+        requestAnimationFrame(() => {
+          expect(widget.methods).to.contain('onUpdateRequest');
+          done();
+        });
       });
 
     });
@@ -244,7 +245,8 @@ describe('terminal/index', () => {
     describe('#onFitRequest', () => {
 
       it('should send a resize request', () => {
-
+        sendMessage(widget, WidgetMessage.FitRequest);
+        expect(widget.methods).to.contain('onResize');
       });
 
     });
@@ -252,7 +254,11 @@ describe('terminal/index', () => {
     describe('#onActivateRequest', () => {
 
       it('should focus the terminal element', () => {
-
+        Widget.attach(widget, document.body);
+        expect(widget.node.contains(document.activeElement)).to.be(false);
+        sendMessage(widget, WidgetMessage.ActivateRequest);
+        expect(widget.methods).to.contain('onActivateRequest');
+        expect(widget.node.contains(document.activeElement)).to.be(true);
       });
 
     });