Ver código fonte

Use mock contents from services

Steven Silvester 9 anos atrás
pai
commit
aceec1a87d

+ 1 - 1
package.json

@@ -8,7 +8,7 @@
     "ansi_up": "^1.3.0",
     "backbone": "^1.2.0",
     "codemirror": "^5.12.0",
-    "jupyter-js-services": "^0.9.0",
+    "jupyter-js-services": "^0.9.2",
     "jupyter-js-utils": "^0.4.0",
     "jupyter-js-widgets": "0.0.17",
     "marked": "^0.3.5",

+ 4 - 4
test/src/filehandler/creator.spec.ts

@@ -4,6 +4,10 @@
 
 import expect = require('expect.js');
 
+import {
+  MockContentsManager
+} from 'jupyter-js-services/lib/mockcontents';
+
 import {
   IContentsModel, IContentsManager, ContentsManager
 } from 'jupyter-js-services';
@@ -12,10 +16,6 @@ import {
   FileCreator, DirectoryCreator
 } from '../../../lib/filehandler/creator';
 
-import {
-  MockContentsManager
-} from '../mock';
-
 import {
   acceptDialog, dismissDialog, waitForDialog
 } from '../utils';

+ 4 - 4
test/src/filehandler/default.spec.ts

@@ -9,6 +9,10 @@ import {
   IAjaxSettings, ContentsManager
 } from 'jupyter-js-services';
 
+import {
+  MockContentsManager
+} from 'jupyter-js-services/lib/mockcontents';
+
 import {
   CodeMirrorWidget
 } from '../../../lib/codemirror/widget';
@@ -17,10 +21,6 @@ import {
   FileHandler
 } from '../../../lib/filehandler/default';
 
-import {
-  MockContentsManager
-} from '../mock';
-
 
 class MyFileHandler extends FileHandler {
 

+ 4 - 4
test/src/filehandler/filehandler.spec.ts

@@ -9,6 +9,10 @@ import {
   IAjaxSettings, ContentsManager
 } from 'jupyter-js-services';
 
+import {
+  MockContentsManager
+} from 'jupyter-js-services/lib/mockcontents';
+
 import {
   sendMessage
 } from 'phosphor-messaging';
@@ -21,10 +25,6 @@ import {
   AbstractFileHandler
 } from '../../../lib/filehandler/handler';
 
-import {
-  MockContentsManager
-} from '../mock';
-
 import {
   acceptDialog, dismissDialog
 } from '../utils';

+ 4 - 4
test/src/filehandler/registry.spec.ts

@@ -9,6 +9,10 @@ import {
   IAjaxSettings, ContentsManager
 } from 'jupyter-js-services';
 
+import {
+  MockContentsManager
+} from 'jupyter-js-services/lib/mockcontents';
+
 import {
   Widget
 } from 'phosphor-widget';
@@ -33,10 +37,6 @@ import {
   FileHandlerRegistry
 } from '../../../lib/filehandler/registry';
 
-import {
-  MockContentsManager
-} from '../mock';
-
 import {
   acceptDialog, dismissDialog
 } from '../utils';

+ 0 - 160
test/src/mock.ts

@@ -1,160 +0,0 @@
-// Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
-'use strict';
-
-import {
-  IContentsModel, IContentsManager, IContentsOpts, ICheckpointModel,
-  IAjaxSettings, ContentsManager
-} from 'jupyter-js-services';
-
-
-export
-class MockContentsManager implements IContentsManager {
-
-  methods: string[] = [];
-
-  DEFAULT_TEXT = 'the quick brown fox jumped over the lazy dog';
-
-  /**
-   * Create a file with default content.
-   */
-  createFile(path: string): void {
-    let model = {
-      name: path.split('/').pop(),
-      path: path,
-      type: 'file',
-      content: this.DEFAULT_TEXT
-    }
-    this._files[path] = model;
-  }
-
-  /**
-   * Get a path in the format it was saved or created in.
-   */
-  get(path: string, options?: IContentsOpts): Promise<IContentsModel> {
-    this.methods.push('get');
-    let model = this._files[path];
-    if (!model) {
-      return Promise.reject(new Error('Path not found'));
-    }
-    return Promise.resolve(this._copyModel(model));
-  }
-
-  newUntitled(path: string, options?: IContentsOpts): Promise<IContentsModel> {
-    this.methods.push('newUntitled');
-    options = options || {};
-    let ext = options.ext || '';
-    let name = options.name || `untitled${ext}`;
-    path = `${path}/${name}`;
-    let model = {
-      name,
-      path,
-      format: options.format || 'text',
-      type: options.type || 'file',
-      content: options.content || this.DEFAULT_TEXT
-    };
-    this._files[path] = model;
-    return Promise.resolve(this._copyModel(model));
-  }
-
-  delete(path: string): Promise<void> {
-    this.methods.push('delete');
-    delete this._files[path];
-    return Promise.resolve(void 0);
-  }
-
-  rename(path: string, newPath: string): Promise<IContentsModel> {
-    this.methods.push('rename');
-    let model = this._files[path];
-    if (!model) {
-      return Promise.reject(new Error('Path not found'));
-    }
-    model.name = newPath.split('/').pop();
-    model.path = newPath;
-    delete this._files[path];
-    this._files[newPath] = model;
-    return Promise.resolve(model);
-  }
-
-  save(path: string, model: IContentsModel): Promise<IContentsModel> {
-    this.methods.push('save');
-    this._files[path] = this._copyModel(model);
-    return Promise.resolve(model);
-  }
-
-  copy(path: string, toDir: string): Promise<IContentsModel> {
-    this.methods.push('copy');
-    let model = this._files[path];
-    if (!model) {
-      return Promise.reject(new Error('Path not found'));
-    }
-    let newModel = JSON.parse(JSON.stringify(model)) as IContentsModel;
-    newModel.path = `${toDir}/${model.name}`;
-    this._files[newModel.path] = newModel;
-    return Promise.resolve(newModel);
-  }
-
-  listContents(path: string): Promise<IContentsModel> {
-    this.methods.push('listContents');
-    let files: IContentsModel[] = [];
-    for (let key of Object.keys(this._files)) {
-      let model = this._files[key];
-      let dname = model.path.slice(0, model.name.length);
-      if (dname === path) {
-        files.push(model);
-      }
-    }
-    return Promise.resolve({
-      name: path.split('/').pop(),
-      path,
-      type: 'directory',
-      content: files
-    });
-  }
-
-  createCheckpoint(path: string): Promise<ICheckpointModel> {
-    this.methods.push('createCheckpoint');
-    let fileModel = this._files[path];
-    if (!fileModel) {
-      return Promise.reject(new Error('Path not found'));
-    }
-    let checkpoints: ICheckpointModel[] = this._checkpoints[path] || [];
-    let id = String(this._id++);
-    let date = new Date(Date.now());
-    let last_modified = date.toISOString();
-    let model: ICheckpointModel = { id, last_modified };
-    checkpoints.push(model);
-    this._checkpoints[path] = checkpoints;
-    this._fileSnaps[id] = this._copyModel(fileModel);
-    return Promise.resolve(model);
-  }
-
-  listCheckpoints(path: string): Promise<ICheckpointModel[]> {
-    this.methods.push('listCheckpoints');
-    let checkpoints: ICheckpointModel[] = this._checkpoints[path] || [];
-    return Promise.resolve(checkpoints);
-  }
-
-  restoreCheckpoint(path: string, checkpointID: string): Promise<void> {
-    this.methods.push('restoreCheckpoint');
-    this._files[path] = this._copyModel(this._fileSnaps[checkpointID]);
-    return Promise.resolve(void 0);
-  }
-
-  deleteCheckpoint(path: string, checkpointID: string): Promise<void> {
-    this.methods.push('deleteCheckpoint');
-    delete this._fileSnaps[checkpointID];
-    return Promise.resolve(void 0);
-  }
-
-  private _copyModel(model: IContentsModel): IContentsModel {
-    return JSON.parse(JSON.stringify(model)) as IContentsModel;
-  }
-
-  ajaxSettings: IAjaxSettings = {};
-
-  private _files: { [key: string]: IContentsModel } = Object.create(null);
-  private _checkpoints: { [key: string]: ICheckpointModel[] } = Object.create(null);
-  private _fileSnaps: { [key: string]: IContentsModel } = Object.create(null);
-  private _id = 0;
-}