Skip to content

Commit

Permalink
better lifecycle hooks, failing test for multiple top level elements …
Browse files Browse the repository at this point in the history
…within a tagless component being sustained
  • Loading branch information
runspired committed Mar 17, 2016
1 parent c23077b commit bf1ccad
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion addon/components/flexi-sustain.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const component = Component.extend({
copy: false,
expires: null,

didInsertElement() {
willInsertElement() {
let element = this.element || this._renderNode;
let properties = this.getProperties('label', 'component', 'model', 'copy', 'expires');

Expand Down
4 changes: 2 additions & 2 deletions addon/lib/sustain.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ export default Obj.extend({

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

let _super = this._component.didInsertElement;
let _super = this._component.willInsertElement;

this._component.didInsertElement = () => {
this._component.willInsertElement = () => {
this.isReady();
if (_super) {
_super.call(this._component);
Expand Down
19 changes: 15 additions & 4 deletions tests/acceptance/sustain-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@ test('visiting /tests/sustain', function(assert) {
andThen(() => {
assert.equal(currentURL(), '/tests/sustain', 'We transitioned to the initial route');

assert.equal(find('h2.sustain-test').text(), 'I ought to be sustained', 'We rendered the sustain');
assert.equal(find('h2.sustain-test').eq(0).text(), 'I ought to be sustained', 'We rendered the sustain');
let id1 = find('layout.sustain-test').get(0).id;
let id2 = find('layout.sustain-test').get(1).id;
let children = find('.tagless-stuff');

assert.ok(id2, 'we found two IDs');
assert.equal(children.length, 2, 'we have two tagless children');

click('#next-sustain-test-page');

andThen(() => {
assert.equal(currentURL(), '/tests/sustain-b', 'We transitioned to the next route');

assert.equal(find('h2.sustain-test').text(), 'I ought to be sustained', 'We rendered the sustain on the next page');
let id2 = find('layout.sustain-test').get(0).id;
assert.equal(find('h2.sustain-test').eq(0).text(), 'I ought to be sustained', 'We rendered the sustain on the next page');
let id3 = find('layout.sustain-test').get(0).id;
let id4 = find('layout.sustain-test').get(1).id;
let children = find('.tagless-stuff');

assert.ok(id4, 'we found two IDs');
assert.equal(children.length, 2, 'we still have two tagless children');

assert.equal(id1, id2, 'We rendered the identical sustain');
assert.equal(id1, id3, 'We rendered the identical sustain');
assert.equal(id2, id4, 'We rendered the identical tagless sustain');
});

});
Expand Down
3 changes: 2 additions & 1 deletion tests/dummy/app/routes/tests/sustain-b/template.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
{{sustain 'tests/sustain/components/test-title'}}
{{sustain 'tests/sustain/components/test-title'}}
{{sustain 'tests/sustain/components/tagless-title'}}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default Component.extend({
this.set('willMoveEvent', true);
}),

didInsertElement() {
willInsertElement() {
this._super();
this.set('insertTriggered', true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Ember from 'ember';
import layout from './template';

export default Ember.Component.extend({
layout,
tagName: ''
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{#flexi-layout tagName="layout" class="sustain-test tagless-stuff flexi-layout"}}
<h2 class="sustain-test">I ought to be sustained</h2>
<p>If I was, the component above's ID will be identical.</p>
{{/flexi-layout}}
<div class="tagless-stuff">
<h3>More Tagless Stuff</h3>
</div>
3 changes: 2 additions & 1 deletion tests/dummy/app/routes/tests/sustain/template.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{{#link-to 'tests.sustain-b' id="next-sustain-test-page"}}Go to B{{/link-to}}
{{sustain 'tests/sustain/components/test-title'}}
{{sustain 'tests/sustain/components/test-title'}}
{{sustain 'tests/sustain/components/tagless-title'}}

0 comments on commit bf1ccad

Please sign in to comment.