2012-01-05 05:27:47 +04:00
|
|
|
define(function(require, exports, module) {
|
|
|
|
// Load dependent modules
|
2012-01-06 03:15:11 +04:00
|
|
|
var ProjectManager // Load from brackets.test
|
2012-01-11 06:08:41 +04:00
|
|
|
, PreferencesManager // Load from brackets.test
|
2012-01-05 05:27:47 +04:00
|
|
|
, SpecRunnerUtils = require("./SpecRunnerUtils.js")
|
|
|
|
;
|
2012-01-11 06:08:41 +04:00
|
|
|
|
2012-01-05 05:27:47 +04:00
|
|
|
describe("ProjectManager", function() {
|
|
|
|
|
2012-01-14 02:34:58 +04:00
|
|
|
var testPath = SpecRunnerUtils.getTestPath("/spec/ProjectManager-test-files");
|
2012-01-11 06:08:41 +04:00
|
|
|
|
2012-01-14 02:34:58 +04:00
|
|
|
beforeEach(function() {
|
|
|
|
SpecRunnerUtils.beforeTestWindow( this, function( testWindow ) {
|
|
|
|
// Load module instances from brackets.test
|
|
|
|
ProjectManager = testWindow.brackets.test.ProjectManager;
|
|
|
|
PreferencesManager = testWindow.brackets.test.PreferencesManager;
|
2012-01-05 05:27:47 +04:00
|
|
|
});
|
2011-12-21 05:04:07 +04:00
|
|
|
});
|
|
|
|
|
2012-01-11 06:08:41 +04:00
|
|
|
afterEach(function() {
|
2012-01-14 02:34:58 +04:00
|
|
|
SpecRunnerUtils.afterTestWindow();
|
2012-01-11 06:08:41 +04:00
|
|
|
});
|
|
|
|
|
2012-01-05 05:27:47 +04:00
|
|
|
describe("createNewItem", function() {
|
|
|
|
// TODO (jasonsj): test Commands.FILE_NEW
|
|
|
|
it("should create a new file with a given name", function() {
|
|
|
|
var didCreate = false, gotError = false;
|
2011-12-21 05:04:07 +04:00
|
|
|
|
2012-01-14 02:34:58 +04:00
|
|
|
SpecRunnerUtils.loadProject( testPath );
|
2011-12-21 05:04:07 +04:00
|
|
|
|
2012-01-05 05:27:47 +04:00
|
|
|
runs(function() {
|
|
|
|
// skip rename
|
2012-01-14 02:34:58 +04:00
|
|
|
ProjectManager.createNewItem(testPath, "Untitled.js", true)
|
2012-01-05 05:27:47 +04:00
|
|
|
.done(function() { didCreate = true; })
|
|
|
|
.fail(function() { gotError = true; });
|
2011-12-21 05:04:07 +04:00
|
|
|
});
|
2012-01-05 05:27:47 +04:00
|
|
|
waitsFor(function() { return didCreate && !gotError; }, "ProjectManager.createNewItem() timeout", 1000);
|
2011-12-21 21:52:20 +04:00
|
|
|
|
2012-01-05 05:27:47 +04:00
|
|
|
var error, stat, complete = false;
|
2012-01-14 02:34:58 +04:00
|
|
|
var filePath = testPath + "/Untitled.js";
|
2012-01-05 05:27:47 +04:00
|
|
|
runs(function() {
|
|
|
|
brackets.fs.stat(filePath, function(err, _stat) {
|
|
|
|
error = err;
|
|
|
|
stat = _stat;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
2011-12-21 21:52:20 +04:00
|
|
|
|
2012-01-05 05:27:47 +04:00
|
|
|
waitsFor(function() { return complete; }, 1000);
|
2011-12-21 21:52:20 +04:00
|
|
|
|
2012-01-05 05:27:47 +04:00
|
|
|
var unlinkError = brackets.fs.NO_ERROR;
|
|
|
|
runs(function() {
|
|
|
|
expect(error).toBeFalsy();
|
|
|
|
expect(stat.isFile()).toBe(true);
|
|
|
|
|
|
|
|
// delete the new file
|
|
|
|
complete = false;
|
|
|
|
brackets.fs.unlink(filePath, function(err) {
|
|
|
|
unlinkError = err;
|
|
|
|
complete = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
waitsFor(function() {
|
|
|
|
return complete && unlinkError == brackets.fs.NO_ERROR;
|
|
|
|
}
|
|
|
|
, "unlink() failed to cleanup Untitled.js, err=" + unlinkError
|
|
|
|
, 1000
|
|
|
|
);
|
2011-12-21 21:52:20 +04:00
|
|
|
});
|
|
|
|
|
2012-01-05 05:27:47 +04:00
|
|
|
it("should fail when a file already exists", function() {
|
|
|
|
var didCreate = false, gotError = false;
|
2011-12-21 21:52:20 +04:00
|
|
|
|
2012-01-14 02:34:58 +04:00
|
|
|
SpecRunnerUtils.loadProject( testPath );
|
2011-12-21 21:52:20 +04:00
|
|
|
|
2012-01-05 05:27:47 +04:00
|
|
|
runs(function() {
|
|
|
|
// skip rename
|
2012-01-14 02:34:58 +04:00
|
|
|
ProjectManager.createNewItem(testPath, "file.js", true)
|
2012-01-05 05:27:47 +04:00
|
|
|
.done(function() { didCreate = true; })
|
|
|
|
.fail(function() { gotError = true; });
|
|
|
|
});
|
|
|
|
waitsFor(function() { return !didCreate && gotError; }, "ProjectManager.createNewItem() timeout", 1000);
|
2011-12-21 21:52:20 +04:00
|
|
|
|
2012-01-05 05:27:47 +04:00
|
|
|
runs(function() {
|
|
|
|
expect(gotError).toBeTruthy();
|
|
|
|
expect(didCreate).toBeFalsy();
|
|
|
|
});
|
2011-12-21 21:52:20 +04:00
|
|
|
});
|
2011-12-21 23:03:09 +04:00
|
|
|
|
2012-01-05 05:27:47 +04:00
|
|
|
it("should fail when a file name matches a directory that already exists", function() {
|
|
|
|
var didCreate = false, gotError = false;
|
2011-12-21 23:03:09 +04:00
|
|
|
|
2012-01-14 02:34:58 +04:00
|
|
|
SpecRunnerUtils.loadProject( testPath );
|
2011-12-21 23:03:09 +04:00
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
// skip rename
|
2012-01-14 02:34:58 +04:00
|
|
|
ProjectManager.createNewItem(testPath, "directory", true)
|
2011-12-21 23:03:09 +04:00
|
|
|
.done(function() { didCreate = true; })
|
|
|
|
.fail(function() { gotError = true; });
|
|
|
|
});
|
|
|
|
waitsFor(function() { return !didCreate && gotError; }, "ProjectManager.createNewItem() timeout", 1000);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(gotError).toBeTruthy();
|
|
|
|
expect(didCreate).toBeFalsy();
|
|
|
|
});
|
2012-01-05 05:27:47 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should fail when file name contains special characters", function() {
|
|
|
|
var chars = "/?*:;{}<>\\";
|
|
|
|
var i = 0;
|
|
|
|
var len = chars.length;
|
|
|
|
var charAt, didCreate, gotError;
|
|
|
|
|
2012-01-14 02:34:58 +04:00
|
|
|
SpecRunnerUtils.loadProject( testPath );
|
2012-01-05 05:27:47 +04:00
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
didCreate = false;
|
|
|
|
gotError = false;
|
|
|
|
charAt = chars.charAt(i);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
// skip rename
|
2012-01-14 02:34:58 +04:00
|
|
|
ProjectManager.createNewItem(testPath, "file" + charAt + ".js", true)
|
2012-01-05 05:27:47 +04:00
|
|
|
.done(function() { didCreate = true; })
|
|
|
|
.fail(function() { gotError = true; });
|
|
|
|
});
|
|
|
|
waitsFor(function() { return !didCreate && gotError; }, "ProjectManager.createNewItem() timeout", 1000);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
expect(gotError).toBeTruthy();
|
|
|
|
expect(didCreate).toBeFalsy();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2011-12-21 23:03:09 +04:00
|
|
|
});
|
2012-01-05 05:27:47 +04:00
|
|
|
|
2011-12-21 05:04:07 +04:00
|
|
|
});
|
2011-12-22 01:45:21 +04:00
|
|
|
});
|