|
@@ -4,7 +4,7 @@
|
|
import expect = require('expect.js');
|
|
import expect = require('expect.js');
|
|
|
|
|
|
import {
|
|
import {
|
|
- StateDB
|
|
|
|
|
|
+ StateDB, uuid
|
|
} from '@jupyterlab/coreutils';
|
|
} from '@jupyterlab/coreutils';
|
|
|
|
|
|
import {
|
|
import {
|
|
@@ -23,6 +23,10 @@ import {
|
|
FileBrowserModel
|
|
FileBrowserModel
|
|
} from '@jupyterlab/filebrowser';
|
|
} from '@jupyterlab/filebrowser';
|
|
|
|
|
|
|
|
+import {
|
|
|
|
+ acceptDialog, dismissDialog
|
|
|
|
+} from '../utils';
|
|
|
|
+
|
|
|
|
|
|
describe('filebrowser/model', () => {
|
|
describe('filebrowser/model', () => {
|
|
|
|
|
|
@@ -291,47 +295,51 @@ describe('filebrowser/model', () => {
|
|
describe('#upload()', () => {
|
|
describe('#upload()', () => {
|
|
|
|
|
|
it('should upload a file object', (done) => {
|
|
it('should upload a file object', (done) => {
|
|
- let file = new File(['<p>Hello world!</p>'], 'hello.html',
|
|
|
|
|
|
+ let fname = uuid() + '.html';
|
|
|
|
+ let file = new File(['<p>Hello world!</p>'], fname,
|
|
{ type: 'text/html' });
|
|
{ type: 'text/html' });
|
|
model.upload(file).then(contents => {
|
|
model.upload(file).then(contents => {
|
|
- expect(contents.name).to.be('hello.html');
|
|
|
|
|
|
+ expect(contents.name).to.be(fname);
|
|
done();
|
|
done();
|
|
}).catch(done);
|
|
}).catch(done);
|
|
});
|
|
});
|
|
|
|
|
|
- it('should allow overwrite', (done) => {
|
|
|
|
- let file = new File(['<p>Hello world!</p>'], 'hello2.html',
|
|
|
|
|
|
+ it('should overwrite', () => {
|
|
|
|
+ let fname = uuid() + '.html';
|
|
|
|
+ let file = new File(['<p>Hello world!</p>'], fname,
|
|
{ type: 'text/html' });
|
|
{ type: 'text/html' });
|
|
- model.upload(file).then(contents => {
|
|
|
|
- expect(contents.name).to.be('hello2.html');
|
|
|
|
- return model.upload(file, true);
|
|
|
|
|
|
+ return model.upload(file).then(contents => {
|
|
|
|
+ expect(contents.name).to.be(fname);
|
|
|
|
+ acceptDialog();
|
|
|
|
+ return model.upload(file);
|
|
}).then(contents => {
|
|
}).then(contents => {
|
|
- expect(contents.name).to.be('hello2.html');
|
|
|
|
- done();
|
|
|
|
- }).catch(done);
|
|
|
|
|
|
+ expect(contents.name).to.be(fname);
|
|
|
|
+ });
|
|
});
|
|
});
|
|
|
|
|
|
- it('should fail without an overwrite if the file exists', (done) => {
|
|
|
|
- let file = new File(['<p>Hello world!</p>'], 'hello2.html',
|
|
|
|
|
|
+ it('should not overwrite', () => {
|
|
|
|
+ let fname = uuid() + '.html';
|
|
|
|
+ let file = new File(['<p>Hello world!</p>'], fname,
|
|
{ type: 'text/html' });
|
|
{ type: 'text/html' });
|
|
- model.upload(file).then(contents => {
|
|
|
|
- expect(contents.name).to.be('hello2.html');
|
|
|
|
|
|
+ return model.upload(file).then(contents => {
|
|
|
|
+ expect(contents.name).to.be(fname);
|
|
|
|
+ dismissDialog();
|
|
return model.upload(file);
|
|
return model.upload(file);
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
- expect(err.message).to.be(`"${file.name}" already exists`);
|
|
|
|
- done();
|
|
|
|
|
|
+ expect(err).to.be('File not uploaded');
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
it('should emit the fileChanged signal', (done) => {
|
|
it('should emit the fileChanged signal', (done) => {
|
|
|
|
+ let fname = uuid() + '.html';
|
|
model.fileChanged.connect((sender, args) => {
|
|
model.fileChanged.connect((sender, args) => {
|
|
expect(sender).to.be(model);
|
|
expect(sender).to.be(model);
|
|
expect(args.type).to.be('save');
|
|
expect(args.type).to.be('save');
|
|
expect(args.oldValue).to.be(null);
|
|
expect(args.oldValue).to.be(null);
|
|
- expect(args.newValue.path).to.be('hello3.html');
|
|
|
|
|
|
+ expect(args.newValue.path).to.be(fname);
|
|
done();
|
|
done();
|
|
});
|
|
});
|
|
- let file = new File(['<p>Hello world!</p>'], 'hello3.html',
|
|
|
|
|
|
+ let file = new File(['<p>Hello world!</p>'], fname,
|
|
{ type: 'text/html' });
|
|
{ type: 'text/html' });
|
|
model.upload(file).catch(done);
|
|
model.upload(file).catch(done);
|
|
});
|
|
});
|