Exemple #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);
 });
Exemple #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();
      });
Exemple #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');
 });
Exemple #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);
 });
Exemple #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);
 });
 beforeEach(() => {
   context = new Context({
     manager,
     factory,
     path: UUID.uuid4() + '.txt'
   });
   handler = new SaveHandler({ context });
   return context.initialize(true);
 });
Exemple #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');
 });
Exemple #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');
 });
Exemple #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');
 });
Exemple #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);
 });