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

Create conversation part reopened component #1684

Closed
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
22 changes: 22 additions & 0 deletions app/components/conversations/conversation-part-reopened.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Component from '@ember/component';
import { inject as service } from '@ember/service';
import { computed, get } from '@ember/object';
import { alias } from '@ember/object/computed';

export default Component.extend({

author: null,

classNames: ['conversation-part', 'conversation-part--reopened'],
classNameBindings: ['isSelf:conversation-part-reopened--is-self'],

reopenedAt: null,

currentUser: service(),

isSelf: computed('author', 'user', function() {
return get(this, 'author.id') === get(this, 'user.id');
}),

user: alias('currentUser.user')
});
1 change: 1 addition & 0 deletions app/models/conversation-part.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default Model.extend({
readAt: attr(),
updatedAt: attr(),
closedAt: attr(),
reopenedAt: attr(),

author: belongsTo('user', { async: true }),
conversation: belongsTo('conversation', { async: true })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="conversation-part-reopened__message-wrapper">
<div class="conversation-part-reopened__timestamps-wrapper">
<div class="conversation-part-reopened__timestamps">
<span data-test-reopened-at>
{{#if isSelf}}
You reopened this {{moment-from-now reopendAt interval=60000}}
{{else}}
{{author.username}} reopened this {{moment-from-now reopenedAt interval=60000}}
{{/if}}
</span>
</div>
</div>
</div>
19 changes: 12 additions & 7 deletions app/templates/components/conversations/conversation-thread.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@
{{#each conversation.conversationParts as |conversationPart|}}
{{#if conversationPart.isLoaded}}
{{#if (eq conversationPart.partType 'Closed')}}
{{conversation/conversation-part-closed
author=conversationPart.author
closedAt=conversationPart.insertedAt
{{conversations/conversation-part-closed
author=conversationPart.author
closedAt=conversationPart.insertedAt
}}
{{else if (eq conversationPart.partType 'Reopened')}}
{{conversations/conversation-part-reopened
author=conversationPart.author
reopenedAt=conversationPart.insertedAt
}}
{{else}}
{{conversations/conversation-part-comment
author=conversationPart.author
body=conversationPart.body
readAt=conversationPart.readAt
sentAt=conversationPart.insertedAt
author=conversationPart.author
body=conversationPart.body
readAt=conversationPart.readAt
sentAt=conversationPart.insertedAt
}}
{{/if}}
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import { set } from '@ember/object';
import { run } from '@ember/runloop';
import PageObject from 'ember-cli-page-object';
import component from 'code-corps-ember/tests/pages/components/conversations/conversation-part-closed';
import stubService from 'code-corps-ember/tests/helpers/stub-service';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import { set } from '@ember/object';
import PageObject from 'ember-cli-page-object';
import component from 'code-corps-ember/tests/pages/components/conversations/conversation-part-reopened';
import stubService from 'code-corps-ember/tests/helpers/stub-service';
import moment from 'moment';

let page = PageObject.create(component);

function renderPage() {
page.render(hbs`
{{conversations/conversation-part--reopened
author=author
reopenedAt=reopenedAt
}}
`);
}

moduleForComponent('conversations/conversation-part-reopened', 'Integration | Component | conversations/conversation part reopened', {
integration: true,
beforeEach() {
page.setContext(this);
},
afterEach() {
page.removeContext();
}
});

test('if current user reopens message, "You reopened this" is rendered', function(assert) {
assert.expect(1);

let user = {
id: 1,
username: 'testuser'
};
set(this, 'author', user);
stubService(this, 'current-user', { user });

let twoMinutesAgo = moment().subtract(2, 'minutes');
let twoMinutesAgoFriendly = twoMinutesAgo.from();
set(this, 'reopenedAt', twoMinutesAgo);

renderPage();

let text = `You reopened this ${twoMinutesAgoFriendly}`;
assert.equal(page.reopenedAt.text, text, 'The reopened at timestamp is rendered');
});

test('if someone other than the current user reopens the message, "Author.username reopened this at" is rendered', function(assert) {
assert.expect(1);

let user = {
id: 1,
username: 'currentuser'
};
stubService(this, 'current-user', { user });

let author = {
id: 2,
username: 'authoruser'
};
set(this, 'author', author);

let twoMinutesAgo = moment().subtract(2, 'minutes');
let twoMinutesAgoFriendly = twoMinutesAgo.from();
set(this, 'reopenedAt', twoMinutesAgo);

renderPage();

let text = `${author.username} reopened this ${twoMinutesAgoFriendly}`;
assert.equal(page.reopenedAt.text, text, 'The reopened at timestamp is rendered');
});