2015-06-20 18:52:44 +00:00
|
|
|
/*global describe:false, it:false */
|
|
|
|
|
|
|
|
"use client";
|
|
|
|
|
2015-07-01 08:28:16 +00:00
|
|
|
|
2015-06-20 18:52:44 +00:00
|
|
|
require(["lib/architect/architect", "lib/chai/chai"], function (architect, chai) {
|
|
|
|
var expect = chai.expect;
|
|
|
|
|
|
|
|
expect.setupArchitectTest([
|
|
|
|
"plugins/c9.core/ext",
|
|
|
|
"plugins/c9.core/util",
|
|
|
|
// Mock plugins
|
|
|
|
{
|
|
|
|
consumes: [],
|
|
|
|
provides: ["c9"],
|
|
|
|
setup: expect.html.mocked
|
|
|
|
},
|
|
|
|
{
|
|
|
|
consumes: ["util"],
|
|
|
|
provides: [],
|
|
|
|
setup: main
|
|
|
|
}
|
|
|
|
], architect);
|
|
|
|
|
|
|
|
function main(options, imports, register) {
|
|
|
|
var util = imports.util;
|
|
|
|
|
|
|
|
describe('getContentType, getFileIcon', function() {
|
|
|
|
it('should retrieve the content type based on a filename', function() {
|
|
|
|
expect(util.getContentType("test.js")).to.equal("application/javascript");
|
|
|
|
expect(util.getContentType("test.html")).to.equal("text/html");
|
|
|
|
});
|
|
|
|
it('should retrieve the icon class name based on a filename', function() {
|
|
|
|
expect(util.getFileIcon("test.js")).to.equal("page_white_code");
|
|
|
|
expect(util.getFileIcon("test.html")).to.equal("html");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-07-01 08:28:16 +00:00
|
|
|
describe('normalizePath', function() {
|
|
|
|
var normalizePath = util.normalizePath;
|
|
|
|
it('should handle home in workspaceDir', function() {
|
|
|
|
util.$initPaths("/home/ubuntu", "/");
|
|
|
|
expect(normalizePath("/home/ubuntu")).to.equal("/home/ubuntu/");
|
|
|
|
expect(normalizePath("/home/ubuntu/x")).to.equal("/home/ubuntu/x");
|
|
|
|
expect(normalizePath("/home/ubuntu/x/y")).to.equal("/home/ubuntu/x/y");
|
|
|
|
expect(normalizePath("/home/ubuntu/xy")).to.equal("/home/ubuntu/xy");
|
|
|
|
expect(normalizePath("/")).to.equal("/");
|
|
|
|
expect(normalizePath("~/z")).to.equal("/home/ubuntu/z");
|
|
|
|
});
|
|
|
|
it('should handle workspaceDir in home', function() {
|
|
|
|
util.$initPaths("/home/ubuntu", "/home/ubuntu/x");
|
|
|
|
expect(normalizePath("/home/ubuntu")).to.equal("~/");
|
|
|
|
expect(normalizePath("/home/ubuntu/x")).to.equal("/");
|
|
|
|
expect(normalizePath("/home/ubuntu/x/y")).to.equal("/y");
|
|
|
|
expect(normalizePath("/home/ubuntu/xy")).to.equal("~/xy");
|
|
|
|
expect(normalizePath("/")).to.equal("/");
|
|
|
|
expect(normalizePath("~/z")).to.equal("~/z");
|
|
|
|
});
|
|
|
|
it('should handle home == workspaceDir', function() {
|
|
|
|
util.$initPaths("/home/ubuntu", "/home/ubuntu");
|
|
|
|
expect(normalizePath("/home/ubuntu")).to.equal("/");
|
|
|
|
expect(normalizePath("/home/ubuntu/x")).to.equal("/x");
|
|
|
|
expect(normalizePath("/home/ubuntu/x/y")).to.equal("/x/y");
|
|
|
|
expect(normalizePath("/home/ubuntu/xy")).to.equal("/xy");
|
|
|
|
expect(normalizePath("/")).to.equal("/");
|
|
|
|
expect(normalizePath("~/z")).to.equal("/z");
|
|
|
|
});
|
|
|
|
it('should handle relative paths', function() {
|
|
|
|
util.$initPaths("/home/ubuntu", "/");
|
|
|
|
expect(normalizePath("/home/ubuntu/x/y/.//../z")).to.equal("/home/ubuntu/x/z");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-06-20 18:52:44 +00:00
|
|
|
onload && onload();
|
|
|
|
}
|
|
|
|
});
|