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

wip notebook actions tests

Steven Silvester пре 8 година
родитељ
комит
e769202e0e

+ 17 - 1
src/notebook/notebook/actions.ts

@@ -44,6 +44,14 @@ export
 namespace NotebookActions {
   /**
    * Split the active cell into two cells.
+   *
+   * #### Notes
+   * The second cell will be activated.
+   * The leading whitespace in the second cell will be removed.
+   * If there is no content, two empty cells are created.
+   * It is a no-op if there is no model.
+   * Both cells will have the same type as the original cell.
+   * This action is undo-able.
    */
   export
   function splitCell(widget: Notebook): void {
@@ -72,7 +80,15 @@ namespace NotebookActions {
   }
 
   /**
-   * Merge selected cells.
+   * Merge the selected cells.
+   *
+   * #### Notes
+   * It will be a no-op if there is no model or only one cell is
+   * selected.
+   * Existing selections are removed.
+   * This action is undo-able.
+   * It will unrender a markdown cell.
+   * The final cell will have the same type as the active cell.
    */
   export
   function mergeCells(widget: Notebook): void {

+ 6 - 69
test/src/docmanager/mockcontext.ts

@@ -1,11 +1,8 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-import expect = require('expect.js');
-
 import {
-  IKernelId, IKernel, IKernelSpecIds, ISessionId, IContentsModel,
-  IKernelLanguageInfo
+  IKernelId, IKernel, IKernelSpecIds, ISessionId, IContentsModel
 } from 'jupyter-js-services';
 
 import {
@@ -28,60 +25,9 @@ import {
   IDocumentContext, IDocumentModel
 } from '../../../lib/docregistry';
 
-
-
-/**
- * The default kernel spec ids.
- */
-const KERNELSPECS: IKernelSpecIds = {
-  default: 'python',
-  kernelspecs: {
-    python: {
-      name: 'python',
-      spec: {
-        language: 'python',
-        argv: [],
-        display_name: 'Python',
-        env: {}
-      },
-      resources: {}
-    },
-    shell: {
-      name: 'shell',
-      spec: {
-        language: 'shell',
-        argv: [],
-        display_name: 'Shell',
-        env: {}
-      },
-      resources: {}
-    }
-  }
-};
-
-/**
- * The default language infos.
- */
-const LANGUAGE_INFOS: { [key: string]: IKernelLanguageInfo } = {
-  python: {
-    name: 'python',
-    version: '1',
-    mimetype: 'text/x-python',
-    file_extension: '.py',
-    pygments_lexer: 'python',
-    codemirror_mode: 'python',
-    nbconverter_exporter: ''
-  },
-  shell: {
-    name: 'shell',
-    version: '1',
-    mimetype: 'text/x-sh',
-    file_extension: '.sh',
-    pygments_lexer: 'shell',
-    codemirror_mode: 'shell',
-    nbconverter_exporter: ''
-  }
-};
+import {
+  KERNELSPECS, getKernelInfo
+} from '../utils';
 
 
 export
@@ -140,19 +86,12 @@ class MockContext<T extends IDocumentModel> implements IDocumentContext<T> {
     this._kernel = new MockKernel(options);
     if (options.name) {
       let name = options.name;
-      if (!LANGUAGE_INFOS[name]) {
+      if (!KERNELSPECS.kernelspecs[name]) {
         name = KERNELSPECS['default'];
       }
       let kernel = this._kernel as MockKernel;
       kernel.setKernelSpec(KERNELSPECS.kernelspecs[name].spec);
-      kernel.setKernelInfo({
-        protocol_version: '1',
-        implementation: 'foo',
-        implementation_version: '1',
-        language_info: LANGUAGE_INFOS[name],
-        banner: 'Hello',
-        help_links: {}
-      });
+      kernel.setKernelInfo(getKernelInfo(name));
     }
 
     this.kernelChanged.emit(this._kernel);
@@ -187,8 +126,6 @@ class MockContext<T extends IDocumentModel> implements IDocumentContext<T> {
 }
 
 
-
-
 /**
  * A namespace for private data.
  */

+ 8 - 3
test/src/index.ts

@@ -1,17 +1,22 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
-
 import './dialog/dialog.spec';
+
 import './docregistry/default.spec';
+
 import './renderers/renderers.spec';
-import './rendermime/rendermime.spec';
 import './renderers/latex.spec';
+
+import './rendermime/rendermime.spec';
+
 import './notebook/cells/editor.spec';
 import './notebook/cells/widget.spec';
 import './notebook/cells/model.spec';
-import './notebook/notebook/nbformat.spec';
+
+import './notebook/notebook/actions.spec';
 import './notebook/notebook/model.spec';
 import './notebook/notebook/modelfactory.spec';
+import './notebook/notebook/nbformat.spec';
 import './notebook/notebook/panel.spec';
 import './notebook/notebook/toolbar.spec';
 import './notebook/notebook/trust.spec';

+ 140 - 0
test/src/notebook/notebook/actions.spec.ts

@@ -0,0 +1,140 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+import expect = require('expect.js');
+
+import {
+  IKernel
+} from 'jupyter-js-services';
+
+import {
+  MockKernel
+} from 'jupyter-js-services/lib/mockkernel';
+
+import {
+  MimeData
+} from 'phosphor-dragdrop';
+
+import {
+ NotebookModel
+} from '../../../../lib/notebook/notebook/model';
+
+import {
+  NotebookActions
+} from '../../../../lib/notebook/notebook/actions';
+
+import {
+  Notebook
+} from '../../../../lib/notebook/notebook/widget';
+
+import {
+  defaultRenderMime
+} from '../../rendermime/rendermime.spec';
+
+import {
+  acceptDialog, dismissDialog, KERNELSPECS, getKernelInfo
+} from '../../utils';
+
+import {
+  DEFAULT_CONTENT
+} from '../utils';
+
+
+const clipboard = new MimeData();
+
+
+describe('notebook/notebook/actions', () => {
+
+  describe('NotebookActions', () => {
+
+    let widget: Notebook;
+    let kernel: IKernel;
+
+    beforeEach(() => {
+      widget = new Notebook({ rendermime: defaultRenderMime() });
+      let model = new NotebookModel();
+      model.fromJSON(DEFAULT_CONTENT);
+      widget.model = model;
+
+      kernel = new MockKernel({ name: 'python' });
+      (kernel as MockKernel).setKernelInfo(getKernelInfo('python'));
+      let spec = KERNELSPECS.kernelspecs['python'].spec;
+      (kernel as MockKernel).setKernelSpec(spec);
+    });
+
+    afterEach(() => {
+      widget.dispose();
+      kernel.dispose();
+    });
+
+    describe('#splitCell()', () => {
+
+      it('should split the active cell into two cells', () => {
+
+      });
+
+      it('should remove leading white space in the second cell', () => {
+
+      });
+
+      it('should remove existing selections', () => {
+
+      });
+
+      it('should activate the second cell', () => {
+
+      });
+
+      it('should preserve the types of each cell', () => {
+
+      });
+
+      it('should create two empty cells if there is no content', () => {
+
+      });
+
+      it('should be a no-op if there is no model', () => {
+
+      });
+
+      it('should be undo-able', () => {
+
+      });
+
+    });
+
+    describe('#mergeCells', () => {
+
+      it('should merged the selected cells', () => {
+
+      });
+
+      it('should be a no-op if there is no model', () => {
+
+      });
+
+      it('should be a no-op if only one cell is selected', () => {
+
+      });
+
+      it('should remove existing selections', () => {
+
+      });
+
+      it('should be undo-able', () => {
+
+      });
+
+      it('should unrender a markdown cell', () => {
+
+      });
+
+      it('should preserve the cell type of the active cell', () => {
+
+      });
+
+    });
+
+  });
+
+});

+ 72 - 0
test/src/utils.ts

@@ -1,11 +1,83 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import {
+  IKernelSpecIds, IKernelLanguageInfo, IKernelInfo
+} from 'jupyter-js-services';
+
 import {
   simulate
 } from 'simulate-event';
 
 
+/**
+ * The default kernel spec ids.
+ */
+export
+const KERNELSPECS: IKernelSpecIds = {
+  default: 'python',
+  kernelspecs: {
+    python: {
+      name: 'python',
+      spec: {
+        language: 'python',
+        argv: [],
+        display_name: 'Python',
+        env: {}
+      },
+      resources: {}
+    },
+    shell: {
+      name: 'shell',
+      spec: {
+        language: 'shell',
+        argv: [],
+        display_name: 'Shell',
+        env: {}
+      },
+      resources: {}
+    }
+  }
+};
+
+/**
+ * The default language infos.
+ */
+export
+function getKernelInfo(name: string): IKernelInfo {
+  return {
+    protocol_version: '1',
+    implementation: 'foo',
+    implementation_version: '1',
+    language_info: LANGUAGE_INFOS[name],
+    banner: 'Hello',
+    help_links: {}
+  };
+}
+
+
+const LANGUAGE_INFOS: { [key: string]: IKernelLanguageInfo } = {
+  python: {
+    name: 'python',
+    version: '1',
+    mimetype: 'text/x-python',
+    file_extension: '.py',
+    pygments_lexer: 'python',
+    codemirror_mode: 'python',
+    nbconverter_exporter: ''
+  },
+  shell: {
+    name: 'shell',
+    version: '1',
+    mimetype: 'text/x-sh',
+    file_extension: '.sh',
+    pygments_lexer: 'shell',
+    codemirror_mode: 'shell',
+    nbconverter_exporter: ''
+  }
+};
+
+
 /**
  * Wait for a dialog to be attached to an element.
  */