This repository has been archived by the owner on Nov 11, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Created moduleForView test helper to allow testing views
- Loading branch information
Showing
12 changed files
with
201 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,9 @@ | ||
import Ember from 'ember'; | ||
import {EmberList, EmberVirtualList} from 'list-view/helper'; | ||
import {register} from 'list-view/helper'; | ||
|
||
export function initialize() { | ||
var registerHelper; | ||
if (Ember.HTMLBars) { | ||
// registerHelper was used for some 1.10-beta's and _registerHelper is for 1.10.0 final. | ||
registerHelper = Ember.HTMLBars._registerHelper || Ember.HTMLBars.registerHelper; | ||
} else { | ||
registerHelper = Ember.Handlebars.registerHelper; | ||
} | ||
registerHelper('ember-list', EmberList); | ||
registerHelper('ember-virtual-list', EmberVirtualList); | ||
} | ||
export var initialize = register; | ||
|
||
export default { | ||
name: 'list-view-helper', | ||
initialize: initialize | ||
initialize: register | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Ember from 'ember'; | ||
|
||
export default Ember.View.extend(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Ember from 'ember'; | ||
|
||
export default function generateContent(n) { | ||
var content = Ember.A(); | ||
for (var i = 0; i < n; i++) { | ||
content.push({name: "Item " + (i+1)}); | ||
} | ||
return content; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Ember from 'ember'; | ||
import TestModule from 'ember-test-helpers/test-module'; | ||
import { getResolver } from 'ember-test-helpers/test-resolver'; | ||
import { createModule } from 'qunit-module'; | ||
|
||
var TestModuleForView = TestModule.extend({ | ||
init: function(viewName, description, callbacks) { | ||
this.viewName = viewName; | ||
this._super.call(this, 'view:' + viewName, description, callbacks); | ||
this.setupSteps.push(this.setupView); | ||
}, | ||
setupView: function() { | ||
var _this = this; | ||
var resolver = getResolver(); | ||
var container = this.container; | ||
var context = this.context; | ||
var templateName = 'template:' + this.viewName; | ||
var template = resolver.resolve(templateName); | ||
if (template) { | ||
container.register(templateName, template); | ||
container.injection(this.subjectName, 'template', templateName); | ||
} | ||
context.dispatcher = Ember.EventDispatcher.create(); | ||
context.dispatcher.setup({}, '#ember-testing'); | ||
this.callbacks.render = function() { | ||
var containerView = Ember.ContainerView.create({container: container}); | ||
var view = Ember.run(function(){ | ||
var subject = context.subject(); | ||
containerView.pushObject(subject); | ||
containerView.appendTo('#ember-testing'); | ||
return subject; | ||
}); | ||
_this.teardownSteps.unshift(function() { | ||
Ember.run(function() { | ||
Ember.tryInvoke(containerView, 'destroy'); | ||
}); | ||
}); | ||
return view.$(); | ||
}; | ||
this.callbacks.append = function() { | ||
Ember.deprecate('this.append() is deprecated. Please use this.render() instead.'); | ||
return this.callbacks.render(); | ||
}; | ||
context.$ = function() { | ||
var $view = this.render(); | ||
var subject = this.subject(); | ||
if (arguments.length){ | ||
return subject.$.apply(subject, arguments); | ||
} else { | ||
return $view; | ||
} | ||
}; | ||
} | ||
}); | ||
|
||
export default function moduleForView(name, description, callbacks) { | ||
createModule(TestModuleForView, name, description, callbacks); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Ember from 'ember'; | ||
import { test } from 'ember-qunit'; | ||
import moduleForView from '../helpers/module-for-view'; | ||
import generateContent from '../helpers/generate-content'; | ||
import {register} from 'list-view/helper'; | ||
|
||
var compile = Ember.Handlebars.compile; | ||
|
||
moduleForView('test', 'list-view integration - content', { | ||
setup: function() { | ||
register(); | ||
} | ||
}); | ||
|
||
test('the ember-list helper', function(assert){ | ||
var view = this.subject({ | ||
controller: { | ||
model: generateContent(100) | ||
}, | ||
template: compile(`{{#ember-list items=model height=500 row-height=50}}{{name}}{{/ember-list}}`) | ||
}); | ||
|
||
this.render(); | ||
|
||
assert.equal(this.$('.ember-list-item-view').length, 11, "The rendered list was updated"); | ||
assert.equal(this.$('.ember-list-container').height(), 5000, "The scrollable view has the correct height"); | ||
}); | ||
|
||
test("the ember-list helper uses items=", function(assert) { | ||
|
||
var view = this.subject({ | ||
controller: { itemz: generateContent(100) }, | ||
template: compile("{{#ember-list items=itemz height=500 rowHeight=50}}{{name}}{{/ember-list}}") | ||
}); | ||
|
||
this.render(); | ||
|
||
assert.equal(this.$('.ember-list-item-view').length, 11, "The rendered list was updated"); | ||
assert.equal(this.$('.ember-list-container').height(), 5000, "The scrollable view has the correct height"); | ||
}); |