Skip to content

Commit

Permalink
Merge pull request #13136 from mmun/port-each-in-tests
Browse files Browse the repository at this point in the history
[Glimmer2] Port {{#each-in}} tests
  • Loading branch information
chancancode committed Mar 21, 2016
2 parents 5c12157 + 124c5be commit e444625
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 183 deletions.
20 changes: 4 additions & 16 deletions packages/ember-glimmer/tests/integration/content-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ class DynamicContentTest extends RenderingTest {

this.assertText('hello');

// FIXME: use @mmun's assertStableRerender
this.takeSnapshot();
this.runTask(() => this.rerender());
this.assertInvariants();
this.assertStableRerender();

this.runTask(() => set(this.context, 'message', 'goodbye'));

Expand All @@ -98,10 +95,7 @@ class DynamicContentTest extends RenderingTest {

this.assertText('hello');

// FIXME: use @mmun's assertStableRerender
this.takeSnapshot();
this.runTask(() => this.rerender());
this.assertInvariants();
this.assertStableRerender();

this.runTask(() => set(this.context, 'a.b.c.d.e.f', 'goodbye'));

Expand Down Expand Up @@ -136,10 +130,7 @@ class DynamicContentTest extends RenderingTest {

this.assertText('HELLO');

// FIXME: use @mmun's assertStableRerender
this.takeSnapshot();
this.runTask(() => this.rerender());
this.assertInvariants();
this.assertStableRerender();

this.runTask(() => set(m, 'message', 'goodbye'));

Expand Down Expand Up @@ -192,10 +183,7 @@ class ContentTestGenerator {

this.assertText(expected);

// FIXME: use @mmun's assertStableRerender
this.takeSnapshot();
this.runTask(() => this.rerender());
this.assertInvariants();
this.assertStableRerender();

this.runTask(() => set(this.context, 'value', 'hello'));

Expand Down
158 changes: 158 additions & 0 deletions packages/ember-glimmer/tests/integration/syntax/each-in-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { set } from 'ember-metal/property_set';
import { strip } from '../../utils/abstract-test-case';
import { applyMixins } from '../../utils/abstract-test-case';
import { moduleFor } from '../../utils/test-case';
import {
BasicConditionalsTest,
SyntaxCondtionalTestHelpers,
TruthyGenerator,
FalsyGenerator,
// ObjectTestCases
} from '../../utils/shared-conditional-tests';

class EachInTest extends BasicConditionalsTest {

get truthyValue() { return { 'Not Empty': 1 }; }
get falsyValue() { return {}; }

}

applyMixins(EachInTest,

SyntaxCondtionalTestHelpers,

new TruthyGenerator([
// TODO: figure out what the rest of the cases are
{ foo: 1 }
]),

new FalsyGenerator([
// TODO: figure out what the rest of the cases are
{},
Object.create({ 'Not Empty': 1 }),
undefined,
null
])

// TODO(mmun): Add support for object proxies and
// include the ObjectTestCases mixin.
);

moduleFor('@htmlbars Syntax test: {{#each-in}}', class extends EachInTest {

templateFor({ cond, truthy, falsy }) {
return `{{#each-in ${cond}}}${truthy}{{else}}${falsy}{{/each-in}}`;
}

[`@test it repeats the given block for each item in the hash`]() {
this.render(strip`
<ul>
{{#each-in categories as |category count|}}
<li>{{category}}: {{count}}</li>
{{/each-in}}
</ul>
`, {
categories: {
'Smartphones': 8203,
'JavaScript Frameworks': Infinity
}
});

this.assertHTML(strip`
<ul>
<li>Smartphones: 8203</li>
<li>JavaScript Frameworks: Infinity</li>
</ul>
`);

this.assertStableRerender();

this.runTask(() => {
set(this.context, 'categories.Smartphones', 100);
set(this.context, 'categories.Tweets', 443115);

// {{#each-in}} does not currently observe internal mutations to the hash
// so we manually trigger a rerender. This behavior may change in the future.
this.rerender();
});

this.assertHTML(strip`
<ul>
<li>Smartphones: 100</li>
<li>JavaScript Frameworks: Infinity</li>
<li>Tweets: 443115</li>
</ul>
`);

this.runTask(() => set(this.context, 'categories', {
'Smartphones': 8203,
'JavaScript Frameworks': Infinity
}));

this.assertHTML(strip`
<ul>
<li>Smartphones: 8203</li>
<li>JavaScript Frameworks: Infinity</li>
</ul>
`);
}

[`@test it only iterates over an object's own properties`]() {
let protoCategories = {
'Smartphones': 8203,
'JavaScript Frameworks': Infinity
};

let categories = Object.create(protoCategories);
categories['Televisions'] = 183;
categories['Alarm Clocks'] = 999;

this.render(strip`
<ul>
{{#each-in categories as |category count|}}
<li>{{category}}: {{count}}</li>
{{/each-in}}
</ul>
`, { categories });

this.assertHTML(strip`
<ul>
<li>Televisions: 183</li>
<li>Alarm Clocks: 999</li>
</ul>
`);

this.assertStableRerender();

this.runTask(() => {
set(protoCategories, 'Robots', 666);
set(categories, 'Tweets', 443115);

// {{#each-in}} does not currently observe internal mutations to the hash
// so we manually trigger a rerender. This behavior may change in the future.
this.rerender();
});

this.assertHTML(strip`
<ul>
<li>Televisions: 183</li>
<li>Alarm Clocks: 999</li>
<li>Tweets: 443115</li>
</ul>
`);

categories = Object.create(protoCategories);
categories['Televisions'] = 183;
categories['Alarm Clocks'] = 999;

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

this.assertHTML(strip`
<ul>
<li>Televisions: 183</li>
<li>Alarm Clocks: 999</li>
</ul>
`);
}

});
6 changes: 6 additions & 0 deletions packages/ember-glimmer/tests/utils/abstract-test-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ export class TestCase {
this.assertSameNode(newSnapshot[i], oldSnapshot[i]);
}
}

assertStableRerender() {
this.takeSnapshot();
this.runTask(() => this.rerender());
this.assertInvariants();
}
}

function isMarker(node) {
Expand Down
167 changes: 0 additions & 167 deletions packages/ember-htmlbars/tests/helpers/each_in_test.js

This file was deleted.

0 comments on commit e444625

Please sign in to comment.