Skip to content

Commit

Permalink
[Glimmer2] Remove block params test and migrate relevant rests to cur…
Browse files Browse the repository at this point in the history
…ly-components and with-test
  • Loading branch information
Joel Kang committed Mar 28, 2016
1 parent e35e8b4 commit 4737b98
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,88 @@ moduleFor('Components test: curly components', class extends RenderingTest {
this.assertComponentElement(this.firstChild, { content: 'hello' });
}

['@test it can yield internal and external properties positionally']() {
let instance;

let FooBarComponent = Component.extend({
init() {
this._super(...arguments);
instance = this;
},
greeting: 'hello'
});

this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{yield greeting greetee.firstName}}' });

this.render('{{#foo-bar greetee=person as |greeting name|}}{{name}} {{person.lastName}}, {{greeting}}{{/foo-bar}}', {
person: {
firstName: 'Joel',
lastName: 'Kang'
}
});

this.assertComponentElement(this.firstChild, { content: 'Joel Kang, hello' });

this.runTask(() => this.rerender());

this.assertComponentElement(this.firstChild, { content: 'Joel Kang, hello' });

this.runTask(() => set(this.context, 'person', { firstName: 'Dora', lastName: 'the Explorer' }));

this.assertComponentElement(this.firstChild, { content: 'Dora the Explorer, hello' });

this.runTask(() => set(instance, 'greeting', 'hola'));

this.assertComponentElement(this.firstChild, { content: 'Dora the Explorer, hola' });

this.runTask(() => {
set(instance, 'greeting', 'hello');
set(this.context, 'person', {
firstName: 'Joel',
lastName: 'Kang'
});
});

this.assertComponentElement(this.firstChild, { content: 'Joel Kang, hello' });
}

['@test #11519 - block param infinite loop']() {
let instance;
let FooBarComponent = Component.extend({
init() {
this._super(...arguments);
instance = this;
},
danger: 0
});

this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{danger}}{{yield danger}}' });

// On initial render, create streams. The bug will not have manifested yet, but at this point
// we have created streams that create a circular invalidation.
this.render(`{{#foo-bar as |dangerBlockParam|}}{{/foo-bar}}`);

this.assertText('0');

// Trigger a non-revalidating re-render. The yielded block will not be dirtied
// nor will block param streams, and thus no infinite loop will occur.
this.runTask(() => this.rerender());

this.assertText('0');

// Trigger a revalidation, which will cause an infinite loop without the fix
// in place. Note that we do not see the infinite loop is in testing mode,
// because a deprecation warning about re-renders is issued, which Ember
// treats as an exception.
this.runTask(() => set(instance, 'danger', 1));

this.assertText('1');

this.runTask(() => set(instance, 'danger', 0));

this.assertText('0');
}

['@test the component and its child components are destroyed'](assert) {
let destroyed = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0 };

Expand Down
56 changes: 56 additions & 0 deletions packages/ember-glimmer/tests/integration/syntax/with-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { set } from 'ember-metal/property_set';
import { A as emberA } from 'ember-runtime/system/native_array';
import { moduleFor, RenderingTest } from '../../utils/test-case';
import { TogglingSyntaxConditionalsTest } from '../../utils/shared-conditional-tests';
import { strip } from '../../utils/abstract-test-case';

moduleFor('Syntax test: {{#with}}', class extends TogglingSyntaxConditionalsTest {

Expand Down Expand Up @@ -292,4 +293,59 @@ moduleFor('Syntax test: Multiple {{#with as}} helpers', class extends RenderingT
this.assertText('Los Pivots');
}

['@test nested {{#with}} blocks should have access to root context']() {
this.render(strip`
{{name}}
{{#with committer1.name as |name|}}
[{{name}}
{{#with committer2.name as |name|}}
[{{name}}]
{{/with}}
{{name}}]
{{/with}}
{{name}}
{{#with committer2.name as |name|}}
[{{name}}
{{#with committer1.name as |name|}}
[{{name}}]
{{/with}}
{{name}}]
{{/with}}
{{name}}
`, {
name: 'ebryn',
committer1: { name: 'trek' },
committer2: { name: 'machty' }
});

this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn');

this.runTask(() => this.rerender());

this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn');

this.runTask(() => set(this.context, 'name', 'chancancode'));

this.assertText('chancancode[trek[machty]trek]chancancode[machty[trek]machty]chancancode');

this.runTask(() => set(this.context, 'committer1', { name: 'krisselden' }));

this.assertText('chancancode[krisselden[machty]krisselden]chancancode[machty[krisselden]machty]chancancode');

this.runTask(() => {
set(this.context, 'committer1.name', 'wycats');
set(this.context, 'committer2', { name: 'rwjblue' });
});

this.assertText('chancancode[wycats[rwjblue]wycats]chancancode[rwjblue[wycats]rwjblue]chancancode');

this.runTask(() => {
set(this.context, 'name', 'ebryn');
set(this.context, 'committer1', { name: 'trek' });
set(this.context, 'committer2', { name: 'machty' });
});

this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn');
}

});
164 changes: 0 additions & 164 deletions packages/ember-htmlbars/tests/integration/block_params_test.js

This file was deleted.

0 comments on commit 4737b98

Please sign in to comment.