Skip to content

Commit

Permalink
Sort converation parts by insertedAt:asc
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Dec 27, 2017
1 parent 48325ed commit 50c0c12
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Expand Up @@ -8,7 +8,7 @@
sentAt=conversation.message.insertedAt
}}
{{/if}}
{{#each conversation.conversationParts as |conversationPart|}}
{{#each (sort-by "insertedAt:asc" conversation.conversationParts) as |conversationPart|}}
{{#if conversationPart.isLoaded}}
{{conversations/conversation-part
author=conversationPart.author
Expand Down
Expand Up @@ -60,21 +60,21 @@ test('it delays rendering head until loaded', function(assert) {
assert.equal(page.conversationParts().count, 0, 'No part is rendered.');
});

test('it renders each conversation part', function(assert) {
test('it renders each conversation part, sorted by insertedAt', function(assert) {
assert.expect(4);

let conversationParts = [
{ isLoaded: true, body: 'foo 1' },
{ isLoaded: true, body: 'foo 2' },
{ isLoaded: true, body: 'foo 3' }
{ isLoaded: true, body: 'foo 1', insertedAt: new Date('2017-11-01') },
{ isLoaded: true, body: 'foo 2', insertedAt: new Date('2017-12-01') },
{ isLoaded: true, body: 'foo 3', insertedAt: new Date('2017-10-01') }
];
set(this, 'conversation', { conversationParts });
renderPage();

assert.equal(page.conversationParts().count, 3, 'Each part is rendered.');
assert.equal(page.conversationParts(0).body.text, 'foo 1', 'Part 1 is rendered correctly.');
assert.equal(page.conversationParts(1).body.text, 'foo 2', 'Part 2 is rendered correctly.');
assert.equal(page.conversationParts(2).body.text, 'foo 3', 'Part 3 is rendered correctly.');
assert.equal(page.conversationParts(1).body.text, 'foo 1', 'Part 1 is rendered second to last.');
assert.equal(page.conversationParts(2).body.text, 'foo 2', 'Part 2 is rendered last (newest).');
assert.equal(page.conversationParts(0).body.text, 'foo 3', 'Part 3 is rendered first (earliest date).');
});

test('it delays rendering conversation parts not yet loaded', function(assert) {
Expand Down

0 comments on commit 50c0c12

Please sign in to comment.