Skip to content

Commit

Permalink
refactor fileTree tests so they wait for the fileTree to render
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrpalek committed Jan 29, 2016
1 parent 64e36ae commit ebbf3e5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
7 changes: 5 additions & 2 deletions app/components/file-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default Ember.Component.extend({
};

if(treeObject.isFile) {
treeDataObject.isLeaf = true;
treeDataObject.leaf = true;
treeDataObject.icon = 'glyphicon glyphicon-file light-gray';
} else {
treeDataObject.icon = 'glyphicon glyphicon-folder-open yellow';
Expand All @@ -83,7 +83,10 @@ export default Ember.Component.extend({
this.get('jsTreeActionReceiver').send('toggleNode', node.id);
},

handleReady() {
didBecomeReady() {
if(this.attrs.didBecomeReady) {
this.attrs.didBecomeReady();
}
},

hideFileTree() {
Expand Down
1 change: 1 addition & 0 deletions app/templates/components/file-tree.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
{{ember-jstree data=fileTreeData
actionReceiver=jsTreeActionReceiver
eventDidSelectNode=(action "handleSelectTreeNode")
eventDidBecomeReady=(action "didBecomeReady")
}}
44 changes: 32 additions & 12 deletions tests/integration/components/file-tree-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Ember from "ember";
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import wait from 'ember-test-helpers/wait';

moduleForComponent('file-tree', 'Integration | Component | file tree', {
integration: true,
Expand Down Expand Up @@ -39,29 +38,38 @@ moduleForComponent('file-tree', 'Integration | Component | file tree', {

this.set('model', this.gist);

this.on('openFile', () => { this.openFileCalled = true; });
this.on('hideFileTree', () => { this.hideFileTreeCalled = true; });

this.render(hbs`{{file-tree model=model
openFile=(action "openFile")
hideFileTree=(action "hideFileTree")}}`);
const waitForRender = new Ember.RSVP.Promise(resolve => {
this.set('didBecomeReady', () => {
resolve();
});
});
this.set('waitForRender', waitForRender);
}
});

test('it calls openFile when you click on a leaf node', function(assert) {
assert.expect(1);

return wait().then(() => {
this.$('.jstree-anchor').eq(0).click();
this.set('externalAction', () => {
assert.ok(true, 'openFile was called');
});

this.render(hbs`{{file-tree model=model
openFile=(action externalAction)
didBecomeReady=(action didBecomeReady)}}`);

assert.ok(this.openFileCalled, "openFile was called");
return this.get('waitForRender').then(() => {
this.$('.jstree-anchor').eq(0).click();
});
});

test('it has 2 initial nodes', function(assert) {
assert.expect(2);

return wait().then(() => {
this.render(hbs`{{file-tree model=model
didBecomeReady=(action didBecomeReady)}}`);

return this.get('waitForRender').then(() => {
assert.equal(this.$('.jstree-anchor').length, 2, "There are 2 initial nodes");

this.$('.jstree-ocl').click();
Expand All @@ -73,8 +81,20 @@ test('it has 2 initial nodes', function(assert) {
test('can expand and collapse all', function(assert) {
assert.expect(3);

this.set('externalOpenFile', () => {
assert.ok(true, 'openFile was called');
});

this.set('externalHideFileTree', () => {
assert.ok(true, 'hideFileTree was called');
});

this.render(hbs`{{file-tree model=model
openFile=(action externalOpenFile)
hideFileTree=(action externalHideFileTree)
didBecomeReady=(action didBecomeReady)}}`);

return wait().then(() => {
return this.get('waitForRender').then(() => {
assert.equal(this.$('.jstree-anchor').length, 2, "There are 2 initial nodes");

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

0 comments on commit ebbf3e5

Please sign in to comment.