-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathliquid-if-test.js
88 lines (77 loc) · 3.04 KB
/
liquid-if-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* global sinon */
import Ember from "ember";
import moduleForIntegration from "../../helpers/module-for-integration";
import { test } from "ember-qunit";
moduleForIntegration('Integration: liquid-if');
test('it should render', function(assert) {
this.set('person', 'Tom');
this.render(`
{{#liquid-if isReady}}
{{person}} is ready
{{else}}
{{person}} is not ready
{{/liquid-if}}
`); // }}`)
assert.equal(this.$().text().trim(), 'Tom is not ready');
this.set('person', 'Yehuda');
assert.equal(this.$().text().trim(), 'Yehuda is not ready');
this.set('isReady', true);
assert.equal(this.$().text().trim(), 'Yehuda is ready');
});
test('it should work without else block', function(assert) {
this.render("{{#liquid-if isReady}}Hi{{/liquid-if}}");
assert.equal(this.$('.liquid-child').length, 0);
this.set('isReady', true);
assert.equal(this.$('.liquid-child').length, 1);
assert.equal(this.$().text().trim(), 'Hi');
});
test("it should support static class name", function(assert) {
this.render('{{#liquid-if isReady class="foo"}}hi{{/liquid-if}}');
assert.equal(this.$('.liquid-container.foo').length, 1, 'found class foo');
});
test("it should support dynamic class name", function(assert) {
this.set('foo', 'bar');
this.render('{{#liquid-if isReady class=foo}}hi{{/liquid-if}}');
assert.equal(this.$('.liquid-container.bar').length, 1, 'found class bar');
});
test("it should update dynamic class name", function(assert) {
this.set('foo', 'bar');
this.render('{{#liquid-if isReady class=foo}}hi{{/liquid-if}}');
this.set('foo', 'bar2');
assert.equal(this.$('.liquid-container.bar2').length, 1, 'found class bar2');
});
test("it should support liquid-unless", function(assert) {
this.set('isReady', true);
this.render('{{#liquid-unless isReady}}A{{else}}B{{/liquid-unless}}');
assert.equal(this.$().text().trim(), 'B');
this.set('isReady', false);
assert.equal(this.$().text().trim(), 'A');
});
test('liquid-if should match correct helper name', function(assert) {
var tmap = this.container.lookup('service:liquid-fire-transitions');
var dummyAnimation = function(){ return Ember.RSVP.resolve(); };
tmap.map(function() {
this.transition(
this.inHelper('liquid-if'),
this.use(dummyAnimation)
);
});
sinon.spy(tmap, 'transitionFor');
this.render('{{#liquid-if isReady}}A{{else}}B{{/liquid-if}}');
this.set('isReady', true);
assert.equal(tmap.transitionFor.lastCall.returnValue.animation.handler, dummyAnimation);
});
test('liquid-unless should match correct helper name', function(assert) {
var tmap = this.container.lookup('service:liquid-fire-transitions');
var dummyAnimation = function(){ return Ember.RSVP.resolve(); };
tmap.map(function() {
this.transition(
this.inHelper('liquid-unless'),
this.use(dummyAnimation)
);
});
sinon.spy(tmap, 'transitionFor');
this.render('{{#liquid-unless isReady}}A{{else}}B{{/liquid-unless}}');
this.set('isReady', true);
assert.equal(tmap.transitionFor.lastCall.returnValue.animation.handler, dummyAnimation);
});