-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
120 lines (91 loc) · 4.21 KB
/
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* global describe, it */
var ok = function(a,b){
//FIXME hgp normally provided by the qunit helper
};
(function () {
'use strict';
// Run before each test case.
beforeEach(function () {
// Put the application into a known state, and destroy the defaultStore.
// Be careful about DS.Model instances stored in App; they'll be invalid
// after this.
// This is broken in some versions of Ember and Ember Data, see:
// https://github.com/emberjs/data/issues/847
Ember.run(function () {
//Concertember.reset();
});
// Display an error if asynchronous operations are queued outside of
// Ember.run. You need this if you want to stay sane.
Ember.testing = true;
});
// Run after each test case.
afterEach(function () {
Ember.testing = false;
});
// Optional: Clean up after our last test so you can try out the app
// in the jsFiddle. This isn't normally required.
/** after(function () {
Ember.run(function () {
Concertember.reset();
});
});**/
describe('The Concerts controller', function () {
//emq.globalize();
Concertember.setupForTesting();
Concertember.injectTestHelpers();
it('should have an empty new concert at the beginning', function () {
Ember.run(function () {
// Won't actually load until the end of the run-block.
//http://stackoverflow.com/questions/19716232/how-to-unit-test-controller-which-uses-this-getstore
var ctrl = Concertember.__container__.lookup('controller:concert');
/**ctrl = Concertember.ConcertController.create({
// We need a container to test views with linkTo.
container: Concertember.__container__,
content: {}
});**/
var newConcert = ctrl.get('newConcert');
chai.expect(newConcert).to.not.be.undefined;
chai.expect(newConcert.artist).to.equal('');
Concertember.reset();
});
});
it('should have one loveconcert at the beginning', function (done) {
var allConcerts;
Ember.run(function () {
// Won't actually load until the end of the run-block.
//http://stackoverflow.com/questions/19716232/how-to-unit-test-controller-which-uses-this-getstore
var ctrl = Concertember.__container__.lookup('controller:concert');
ctrl.store.find('concerts', 'concerts_1').then(function (concerts) {
allConcerts = concerts.get('allConcerts').then(function (allConcerts) {
chai.expect(allConcerts).to.not.be.undefined;
chai.expect(allConcerts.content.length).to.equal(1);
done();
});
});
Concertember.reset();
});
});
it('should add one loveconcert ', function (done) {
Ember.run(function () {
// Won't actually load until the end of the run-block.
//http://stackoverflow.com/questions/19716232/how-to-unit-test-controller-which-uses-this-getstore
var ctrl = Concertember.__container__.lookup('controller:concert');
ctrl.get('newConcert').artist = "test";
ctrl.get('newConcert').venue = "testVenue";
ctrl.get('newConcert').dateString = "10.01.2015";
ctrl.send('addConcert');
var concerts;
ctrl.store.find('concerts', 'concerts_1').then(function (_concerts) {
concerts=_concerts;
concerts.get('allConcerts').then(function (allConcerts){
chai.expect(allConcerts).to.not.be.undefined;
chai.expect(allConcerts.content.length).to.equal(2);
//Ugly hack to prevent ember data from fiddling with 'inflight objects' something async happening here
//Concertember.reset();
done();
});
});
});
});
});
})();