From 0efd93086a384cb4a09ec541395eb1456c297965 Mon Sep 17 00:00:00 2001 From: Gaurav Munjal Date: Tue, 22 Sep 2015 18:42:06 -0400 Subject: [PATCH] Fix tree does not go more than one level --- app/components/file-tree.js | 20 +++++++++++++------ .../integration/components/file-tree-test.js | 13 +++++++----- tests/unit/gist/controller-test.js | 4 ++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/app/components/file-tree.js b/app/components/file-tree.js index 05c30f5f..9140eba7 100644 --- a/app/components/file-tree.js +++ b/app/components/file-tree.js @@ -24,7 +24,8 @@ export default Ember.Component.extend({ text: fileName, parent: parentPath, icon: "glyphicon glyphicon-file light-gray", - path: path + path: path, + leaf: true }; }); @@ -32,18 +33,25 @@ export default Ember.Component.extend({ 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) { @@ -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; } diff --git a/tests/integration/components/file-tree-test.js b/tests/integration/components/file-tree-test.js index 2a214bd9..d3febef4 100644 --- a/tests/integration/components/file-tree-test.js +++ b/tests/integration/components/file-tree-test.js @@ -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 @@ -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) { @@ -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(); diff --git a/tests/unit/gist/controller-test.js b/tests/unit/gist/controller-test.js index 3565d2cc..d0f6e87e 100644 --- a/tests/unit/gist/controller-test.js +++ b/tests/unit/gist/controller-test.js @@ -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; } }); @@ -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');