Example #1
0
 it('should delete the given checkpoint', async () => {
   await context.initialize(true);
   const model = await context.createCheckpoint();
   context.deleteCheckpoint(model.id);
   const models = await context.listCheckpoints();
   expect(models.length).to.equal(0);
 });
Example #2
0
      it("should emit 'failed' when the save operation fails out", async () => {
        context = new Context({
          manager,
          factory,
          path: 'src/readonly-temp.txt'
        });

        let called = 0;
        let checked;
        context.saveState.connect((sender, args) => {
          if (called > 0) {
            expect(sender).to.equal(context);
            checked = args;
          }

          called += 1;
        });

        try {
          await context.initialize(true);
        } catch (err) {
          expect(err.message).to.contain('Invalid response: 403 Forbidden');
        }

        expect(called).to.equal(2);
        expect(checked).to.equal('failed');

        await acceptDialog();
      });
Example #3
0
 it('should revert the contents of the file to the disk', async () => {
   await context.initialize(true);
   context.model.fromString('foo');
   await context.save();
   context.model.fromString('bar');
   await context.revert();
   expect(context.model.toString()).to.equal('foo');
 });
Example #4
0
 it('should just save if the file name does not change', async () => {
   const path = context.path;
   await context.initialize(true);
   const promise = context.saveAs();
   await acceptDialog();
   await promise;
   expect(context.path).to.equal(path);
 });
Example #5
0
 it('should add a sibling widget', () => {
   let called = false;
   let opener = (widget: Widget) => {
     called = true;
   };
   context = new Context({ manager, factory, path: uuid() + '.txt', opener });
   context.addSibling(new Widget());
   expect(called).to.be(true);
 });
Example #6
0
 beforeEach(() => {
   context = new Context({
     manager,
     factory,
     path: UUID.uuid4() + '.txt'
   });
   handler = new SaveHandler({ context });
   return context.initialize(true);
 });
Example #7
0
 it('should normalize CRLF line endings to LF', async () => {
   await context.initialize(true);
   await manager.contents.save(context.path, {
     type: factory.contentType,
     format: factory.fileFormat,
     content: 'foo\r\nbar'
   });
   await context.revert();
   expect(context.model.toString()).to.equal('foo\nbar');
 });
Example #8
0
 it('should restore the value to the last checkpoint value', async () => {
   context.model.fromString('bar');
   await context.initialize(true);
   const model = await context.createCheckpoint();
   context.model.fromString('foo');
   const id = model.id;
   await context.save();
   await context.restoreCheckpoint(id);
   await context.revert();
   expect(context.model.toString()).to.equal('bar');
 });
Example #9
0
 it('should save the contents of the file to disk', async () => {
   await context.initialize(true);
   context.model.fromString('foo');
   await context.save();
   let opts: Contents.IFetchOptions = {
     format: factory.fileFormat,
     type: factory.contentType,
     content: true
   };
   const model = await manager.contents.get(context.path, opts);
   expect(model.content).to.be('foo');
 });
Example #10
0
 it('should list the checkpoints for the file', async () => {
   await context.initialize(true);
   const model = await context.createCheckpoint();
   const id = model.id;
   const models = await context.listCheckpoints();
   let found = false;
   for (const model of models) {
     if (model.id === id) {
       found = true;
     }
   }
   expect(found).to.equal(true);
 });
Example #11
0
 it('should be set after poulation', (done) => {
   context.ready.then(() => {
     expect(context.contentsModel.name).to.be('foo');
     done();
   });
   context.save().catch(done);
 });
Example #12
0
 it('should create a checkpoint for the file', (done) => {
   context.createCheckpoint().then(model => {
     expect(model.id).to.be.ok();
     expect(model.last_modified).to.be.ok();
     done();
   }).catch(done);
 });
Example #13
0
      it('should overwrite the file on disk', async () => {
        const delegate = new PromiseDelegate();

        // Lower the duration multiplier.
        (handler as any)._multiplier = 1;
        context.model.fromString('foo');
        await context.initialize(true);

        // The server has a one second resolution for saves.
        setTimeout(async () => {
          await manager.contents.save(context.path, {
            type: factory.contentType,
            format: factory.fileFormat,
            content: 'bar'
          });
          handler.saveInterval = 1;
          handler.start();
          context.model.fromString('baz');
          context.fileChanged.connect(() => {
            expect(context.model.toString()).to.equal('baz');
            delegate.resolve(undefined);
          });
        }, 1500);

        // Extend the timeout to wait for the dialog because of the setTimeout.
        await acceptDialog(document.body, 3000);
        await delegate.promise;
      });
 it('should revert to the file on disk', (done) => {
   context.model.fromString('foo');
   context.save().then(() => {
     context.fileChanged.connect(() => {
       expect(context.model.toString()).to.be('bar');
       done();
     });
     setTimeout(() => {
       manager.contents.save(context.path, {
         type: factory.contentType,
         format: factory.fileFormat,
         content: 'bar'
       }).catch(done);
       handler.saveInterval = 1;
       handler.start();
       context.model.fromString('baz');
     }, 1500);  // The server has a one second resolution for saves.
   }).catch(done);
   waitForDialog().then(() => {
     let dialog = document.body.getElementsByClassName('jp-Dialog')[0];
     let buttons = dialog.getElementsByTagName('button');
     for (let i = 0; i < buttons.length; i++) {
       if (buttons[i].textContent === 'REVERT') {
         buttons[i].click();
       }
     }
   });
 });
Example #15
0
      it('should be set after population', async () => {
        const { path } = context;

        context.initialize(true);
        await context.ready;
        expect(context.contentsModel.path).to.be(path);
      });
Example #16
0
 it('should be set after poulation', (done) => {
   let path = context.path;
   context.ready.then(() => {
     expect(context.contentsModel.path).to.be(path);
     done();
   });
   context.initialize(true).catch(done);
 });
Example #17
0
 it('should be emitted when the context is disposed', (done) => {
   context.disposed.connect((sender, args) => {
     expect(sender).to.be(context);
     expect(args).to.be(void 0);
     done();
   });
   context.dispose();
 });
Example #18
0
 it('should initialize the model when the file is saved for the first time', async () => {
   const context = await createNotebookContext();
   context.model.fromJSON(DEFAULT_CONTENT);
   expect(context.model.cells.canUndo).to.be(true);
   await context.initialize(true);
   await context.ready;
   expect(context.model.cells.canUndo).to.be(false);
 });
Example #19
0
 it('should indicate whether the context is ready', (done) => {
   expect(context.isReady).to.be(false);
   context.ready.then(() => {
     expect(context.isReady).to.be(true);
     done();
   }).catch(done);
   context.initialize(true).catch(done);
 });
Example #20
0
 it('should change notebook to edit mode if we have a single empty code cell', async () => {
   const panel = NBTestUtils.createNotebookPanel(context);
   const model = panel.content.model;
   expect(model).to.equal(context.model);
   await context.initialize(true);
   await context.ready;
   expect(panel.content.mode).to.equal('edit');
 });
Example #21
0
 it('should be emitted when the file is saved', (done) => {
   context.fileChanged.connect((sender, args) => {
     expect(sender).to.be(context);
     expect(args.name).to.be('foo');
     done();
   });
   context.save();
 });
Example #22
0
 it('should should preserve CRLF line endings upon save', async () => {
   await context.initialize(true);
   await manager.contents.save(context.path, {
     type: factory.contentType,
     format: factory.fileFormat,
     content: 'foo\r\nbar'
   });
   await context.revert();
   await context.save();
   const opts: Contents.IFetchOptions = {
     format: factory.fileFormat,
     type: factory.contentType,
     content: true
   };
   const model = await manager.contents.get(context.path, opts);
   expect(model.content).to.equal('foo\r\nbar');
 });
Example #23
0
 it('should create a checkpoint for the file', () => {
   return context.initialize(true).then(() => {
     return context.createCheckpoint();
   }).then(model => {
     expect(model.id).to.be.ok();
     expect(model.last_modified).to.be.ok();
   });
 });
Example #24
0
 it('should resolve when the file is reverted for the first time', async () => {
   manager.contents.save(context.path, {
     type: factory.contentType,
     format: factory.fileFormat,
     content: 'foo'
   });
   await context.initialize(false);
   await context.ready;
 });
Example #25
0
 it('should resolve an absolute server url to a download url', (done) => {
   let contextPromise = context.getDownloadUrl('foo');
   let contentsPromise = manager.contents.getDownloadUrl('foo');
   Promise.all([contextPromise, contentsPromise])
   .then(values => {
     expect(values[0]).to.be(values[1]);
     done();
   }).catch(done);
 });
Example #26
0
 it('should just save if the file name does not change', () => {
   acceptDialog();
   let path = context.path;
   return context.initialize(true).then(() => {
     return context.saveAs();
   }).then(() => {
     expect(context.path).to.be(path);
   });
 });
Example #27
0
 it('should be emitted when the file is saved', (done) => {
   let path = context.path;
   context.fileChanged.connect((sender, args) => {
     expect(sender).to.be(context);
     expect(args.path).to.be(path);
     done();
   });
   context.initialize(true).catch(done);
 });
Example #28
0
 it('should resolve when the file is reverted for the first time', (done) => {
   manager.contents.save(context.path, {
     type: factory.contentType,
     format: factory.fileFormat,
     content: 'foo'
   });
   context.ready.then(done, done);
   context.revert().catch(done);
 });
Example #29
0
 it('should be emitted when the context is disposed', () => {
   let called = false;
   context.disposed.connect((sender, args) => {
     expect(sender).to.equal(context);
     expect(args).to.be.undefined;
     called = true;
   });
   context.dispose();
   expect(called).to.equal(true);
 });
Example #30
0
      it('should save the document to a different path chosen by the user', async () => {
        const initialize = context.initialize(true);
        const newPath = UUID.uuid4() + '.txt';

        const func = async () => {
          await initialize;
          await waitForDialog();
          const dialog = document.body.getElementsByClassName('jp-Dialog')[0];
          const input = dialog.getElementsByTagName('input')[0];

          input.value = newPath;
          await acceptDialog();
        };
        const promise = func();
        await initialize;
        await context.saveAs();
        expect(context.path).to.equal(newPath);
        await promise;
      });