Parcourir la source

Add session to the console panel and update console panel tests

Steven Silvester il y a 8 ans
Parent
commit
01fa43d773
2 fichiers modifiés avec 30 ajouts et 17 suppressions
  1. 6 1
      packages/console/src/panel.ts
  2. 24 16
      test/src/console/panel.spec.ts

+ 6 - 1
packages/console/src/panel.ts

@@ -73,7 +73,7 @@ class ConsolePanel extends Panel {
       path = `${basePath || ''}/console-${count}-${uuid()}`;
     }
 
-    let session = new ClientSession({
+    let session = this.session = new ClientSession({
       manager: manager.sessions,
       path,
       name: name || `Console ${count}`,
@@ -111,6 +111,11 @@ class ConsolePanel extends Panel {
    */
   readonly console: CodeConsole;
 
+  /**
+   * The session used by the panel.
+   */
+  readonly session: IClientSession;
+
   /**
    * Dispose of the resources held by the widget.
    */

+ 24 - 16
test/src/console/panel.spec.ts

@@ -4,7 +4,7 @@
 import expect = require('expect.js');
 
 import {
-  Session, utils
+  ServiceManager
 } from '@jupyterlab/services';
 
 import {
@@ -46,23 +46,22 @@ const contentFactory = createConsolePanelFactory();
 describe('console/panel', () => {
 
   let panel: TestPanel;
-  let session: Session.ISession;
-
-  beforeEach(done => {
-    Session.startNew({ path: utils.uuid() }).then(newSession => {
-      session = newSession;
-      panel = new TestPanel({ contentFactory, rendermime, session,
-                              mimeTypeService });
-      done();
+  let manager = new ServiceManager();
+
+  before(() => {
+    return manager.ready;
+  });
+
+  beforeEach(() => {
+    panel = new TestPanel({
+      manager, contentFactory, rendermime, mimeTypeService
     });
   });
 
-  afterEach(done => {
-    session.shutdown().then(() => {
-      session.dispose();
+  afterEach(() => {
+    return panel.session.shutdown().then(() => {
       panel.dispose();
-      done();
-    }).catch(done);
+    });
   });
 
   describe('ConsolePanel', () => {
@@ -84,6 +83,15 @@ describe('console/panel', () => {
 
     });
 
+    describe('#session', () => {
+
+      it('should be a client session object', () => {
+        expect(panel.session.path).to.be.ok();
+      });
+
+    });
+
+
     describe('#dispose()', () => {
 
       it('should dispose of the resources held by the panel', () => {
@@ -151,12 +159,12 @@ describe('console/panel', () => {
 
       describe('#createConsole()', () => {
 
-        it('should create a notebook widget', () => {
+        it('should create a console widget', () => {
           let options = {
             contentFactory: contentFactory.consoleContentFactory,
             rendermime,
             mimeTypeService,
-            session
+            session: panel.session
           };
           expect(contentFactory.createConsole(options)).to.be.a(CodeConsole);
         });