Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions app/components/file-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,34 @@ export default Ember.Component.extend({
text: fileName,
parent: parentPath,
icon: "glyphicon glyphicon-file light-gray",
path: path
path: path,
leaf: true
};
});

let paths = _.uniq(_.pluck(treeData, 'text'));
let parents = _.uniq(_.pluck(treeData, 'parent'));
parents.forEach(function(parent) {
if (!paths.contains(parent) && parent !== "#") {
let splitPath = parent.split("/");
let parentPath = splitPath.slice(0, -1).join("/");
let fileName = splitPath[splitPath.length - 1];
if (parentPath === "") {
parentPath = "#";
}
treeData.push({
id: "node" + seq++,
text: parent,
parent: "#",
icon: "glyphicon glyphicon-folder-open yellow"
text: fileName,
parent: parentPath,
icon: "glyphicon glyphicon-folder-open yellow",
path: parent
});
}
});

let idMap = {};
treeData.forEach(function(node) {
idMap[node.text] = node.id;
idMap[node.path] = node.id;
});

treeData.forEach(function(node) {
Expand All @@ -57,7 +65,7 @@ export default Ember.Component.extend({

actions: {
handleSelectTreeNode(node) {
if (node.original.path) {
if (node.original.leaf) {
this.attrs.openFile(node.original.path);
return;
}
Expand Down
13 changes: 8 additions & 5 deletions tests/integration/components/file-tree-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ moduleForComponent('file-tree', 'Integration | Component | file tree', {
filePath: "some/path.js"
});

this.file3 = Ember.Object.create({
filePath: "some/long/path.js"
});

this.gist = Ember.Object.create({
id: '74bae9a34142370ff5a3',
files: [this.file1, this.file2],
files: [this.file1, this.file2, this.file3],
history: [],
ownerLogin: 'Gaurav0',
isNew: false
Expand Down Expand Up @@ -48,10 +52,9 @@ test('it has 2 initial nodes', function(assert) {

assert.equal(this.$('.jstree-anchor').length, 2, "There are 2 initial nodes");

this.$('.jstree-anchor').eq(0).click();
this.$('.jstree-anchor').eq(1).click();
this.$('.jstree-ocl').click();

assert.equal(this.$('.jstree-anchor').length, 3, "There are 3 nodes once each is expanded");
assert.equal(this.$('.jstree-anchor').length, 4, "There are 4 nodes once you expand the folder");
});

test('it calls openFile when you click on a leaf node', function(assert) {
Expand All @@ -69,7 +72,7 @@ test('can expand and collapse all', function(assert) {

this.$('.twiddlicon-expand-all').click();

assert.equal(this.$('.jstree-anchor').length, 3, "There are 3 nodes once you expand all");
assert.equal(this.$('.jstree-anchor').length, 5, "There are 5 nodes once you expand all");

this.$('.twiddlicon-collapse-all').click();

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/gist/controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ moduleFor('controller:gist', {

beforeEach() {
this._originalConfirm = window.confirm;
this._originalAlert = window.alert;
},

afterEach() {
window.confirm = this._originalConfirm;
window.alert = this._originalAlert;
}
});

Expand Down Expand Up @@ -41,6 +43,8 @@ test('deleting a gist requires confirmation', function(assert) {
test('isPathInvalid method', function(assert) {
let controller = this.subject();

window.alert = function() {};

assert.ok(!controller.isPathInvalid('component', 'my-component'), 'can add component with valid pods path');
assert.ok(controller.isPathInvalid('component', 'myComponent'), 'cannot add component with invalid pods path');
assert.ok(!controller.isPathInvalid('component', 'some-route/my-component'), 'can add component with valid pods path');
Expand Down