Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some initial tests for {{#if}} and {{#unless}} #12912

Merged
merged 3 commits into from
Feb 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/ember-glimmer/tests/integration/helpers/concat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { set } from 'ember-metal/property_set';

moduleFor('Helpers test: {{concat}}', class extends RenderingTest {

['@test htmlbars it concats static arguments']() {
['@test it concats static arguments']() {
this.render(`{{concat "foo" " " "bar" " " "baz"}}`);
this.assertText('foo bar baz');
}
Expand All @@ -16,6 +16,10 @@ moduleFor('Helpers test: {{concat}}', class extends RenderingTest {

this.assertText('onetwo');

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

this.assertText('onetwo');

this.inZone(() => set(this.context, 'first', 'three'));

this.assertText('threetwo');
Expand All @@ -35,6 +39,10 @@ moduleFor('Helpers test: {{concat}}', class extends RenderingTest {

this.assertText('onetwothreefour');

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

this.assertText('onetwothreefour');

this.inZone(() => {
set(this.context, 'first', 'five');
set(this.context, 'third', 'six');
Expand All @@ -53,6 +61,10 @@ moduleFor('Helpers test: {{concat}}', class extends RenderingTest {

this.assertText('Truthy!');

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

this.assertText('Truthy!');

this.inZone(() => set(this.context, 'first', 'three'));

this.assertText('False');
Expand Down
145 changes: 145 additions & 0 deletions packages/ember-glimmer/tests/integration/syntax/if-unless-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { RenderingTest, moduleFor } from '../../utils/test-case';
import { set } from 'ember-metal/property_set';

moduleFor('Syntax test: {{#if}}', class extends RenderingTest {

['@test The `{{#if}}` syntax renders and hides the given block based on the conditional']() {
this.render(`{{#if cond1}}1{{/if}}{{#if cond2}}2{{/if}}`, { cond1: true, cond2: false });
this.assertText('1');

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

this.assertText('1');

this.inZone(() => set(this.context, 'cond1', false));

this.assertText('');

this.inZone(() => {
set(this.context, 'cond1', true);
set(this.context, 'cond2', true);
});

this.assertText('12');

this.inZone(() => {
set(this.context, 'cond1', true);
set(this.context, 'cond2', false);
});

this.assertText('1');
}

['@test The `{{#if}}` syntax renders the corresponding block based on the conditional']() {
this.render(`{{#if cond1}}T1{{else}}F1{{/if}}{{#if cond2}}T2{{else}}F2{{/if}}`, { cond1: true, cond2: false });
this.assertText('T1F2');

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

this.assertText('T1F2');

this.inZone(() => set(this.context, 'cond1', false));

this.assertText('F1F2');

this.inZone(() => {
set(this.context, 'cond1', true);
set(this.context, 'cond2', true);
});

this.assertText('T1T2');

this.inZone(() => {
set(this.context, 'cond1', true);
set(this.context, 'cond2', false);
});

this.assertText('T1F2');
}

['@test The `{{#if}}` syntax works with syntax renders the corresponding block based on the conditional']() {
this.render(`{{#if cond1}}T1{{else}}F1{{/if}}{{#if cond2}}T2{{else}}F2{{/if}}`, { cond1: true, cond2: false });
this.assertText('T1F2');

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

this.assertText('T1F2');

this.inZone(() => set(this.context, 'cond1', false));

this.assertText('F1F2');

this.inZone(() => {
set(this.context, 'cond1', true);
set(this.context, 'cond2', true);
});

this.assertText('T1T2');

this.inZone(() => {
set(this.context, 'cond1', true);
set(this.context, 'cond2', false);
});

this.assertText('T1F2');
}

});

moduleFor('Syntax test: {{#unless}}', class extends RenderingTest {

['@test The `{{#unless}}` syntax renders and hides the given block based on the conditional']() {
this.render(`{{#unless cond1}}1{{/unless}}{{#unless cond2}}2{{/unless}}`, { cond1: true, cond2: false });
this.assertText('2');

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

this.assertText('2');

this.inZone(() => set(this.context, 'cond2', true));

this.assertText('');

this.inZone(() => {
set(this.context, 'cond1', false);
set(this.context, 'cond2', false);
});

this.assertText('12');

this.inZone(() => {
set(this.context, 'cond1', true);
set(this.context, 'cond2', false);
});

this.assertText('2');
}

['@test The `{{#unless}}` syntax renders the corresponding block based on the conditional']() {
this.render(`{{#unless cond1}}F1{{else}}T1{{/unless}}{{#unless cond2}}F2{{else}}T2{{/unless}}`, { cond1: true, cond2: false });
this.assertText('T1F2');

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

this.assertText('T1F2');

this.inZone(() => set(this.context, 'cond1', false));

this.assertText('F1F2');

this.inZone(() => {
set(this.context, 'cond1', true);
set(this.context, 'cond2', true);
});

this.assertText('T1T2');

this.inZone(() => {
set(this.context, 'cond1', true);
set(this.context, 'cond2', false);
});

this.assertText('T1F2');
}

});
1 change: 1 addition & 0 deletions packages/ember-htmlbars/tests/integration/syntax