Fixes #61 - Order by timestamps with tests
This commit is contained in:
parent
cc5327dbc9
commit
e568e2c528
4 changed files with 31 additions and 3 deletions
|
@ -33,7 +33,7 @@
|
||||||
<div id='contacts'></div>
|
<div id='contacts'></div>
|
||||||
</div>
|
</div>
|
||||||
<script type='text/x-tmpl-mustache' id='conversation'>
|
<script type='text/x-tmpl-mustache' id='conversation'>
|
||||||
<div class='discussion-container'></ul>
|
<div class='discussion-container'></div>
|
||||||
<div class='send-message-area'>
|
<div class='send-message-area'>
|
||||||
<div class='message-composer'>
|
<div class='message-composer'>
|
||||||
<form class='send'>
|
<form class='send'>
|
||||||
|
|
|
@ -61,7 +61,11 @@ var Whisper = Whisper || {};
|
||||||
Whisper.Threads = new (Backbone.Collection.extend({
|
Whisper.Threads = new (Backbone.Collection.extend({
|
||||||
localStorage: new Backbone.LocalStorage("Threads"),
|
localStorage: new Backbone.LocalStorage("Threads"),
|
||||||
model: Thread,
|
model: Thread,
|
||||||
comparator: 'timestamp',
|
|
||||||
|
comparator: function(m) {
|
||||||
|
return -m.get('timestamp');
|
||||||
|
},
|
||||||
|
|
||||||
findOrCreate: function(attributes) {
|
findOrCreate: function(attributes) {
|
||||||
var thread = Whisper.Threads.add(attributes, {merge: true});
|
var thread = Whisper.Threads.add(attributes, {merge: true});
|
||||||
thread.save();
|
thread.save();
|
||||||
|
@ -112,5 +116,6 @@ var Whisper = Whisper || {};
|
||||||
}
|
}
|
||||||
return this.findOrCreate(attributes);
|
return this.findOrCreate(attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
}))();
|
}))();
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -150,6 +150,7 @@
|
||||||
<script type="text/javascript" src="test.js"></script>
|
<script type="text/javascript" src="test.js"></script>
|
||||||
<script type="text/javascript" src="views/message_view_test.js"></script>
|
<script type="text/javascript" src="views/message_view_test.js"></script>
|
||||||
<script type="text/javascript" src="views/list_view_test.js"></script>
|
<script type="text/javascript" src="views/list_view_test.js"></script>
|
||||||
|
<script type="text/javascript" src="views/threads_test.js"></script>
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
22
test/views/threads_test.js
Normal file
22
test/views/threads_test.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
describe('Threads', function() {
|
||||||
|
|
||||||
|
it('should be ordered newest to oldest', function() {
|
||||||
|
// Timestamps
|
||||||
|
var today = new Date();
|
||||||
|
var tomorrow = new Date();
|
||||||
|
tomorrow.setDate(today.getDate()+1);
|
||||||
|
|
||||||
|
// Add threads
|
||||||
|
Whisper.Threads.add({ timestamp: today });
|
||||||
|
Whisper.Threads.add({ timestamp: tomorrow });
|
||||||
|
|
||||||
|
var models = Whisper.Threads.models;
|
||||||
|
var firstTimestamp = models[0].get('timestamp').getTime();
|
||||||
|
var secondTimestamp = models[1].get('timestamp').getTime();
|
||||||
|
|
||||||
|
// Compare timestamps
|
||||||
|
assert(firstTimestamp > secondTimestamp);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue