Skip to content

Commit 818cd93

Browse files
authored
Merge pull request #1645 from code-corps/reopen-action
Add reopen action
2 parents d4acb33 + 8b9c061 commit 818cd93

6 files changed

Lines changed: 69 additions & 2 deletions

File tree

app/controllers/project/conversations.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export default Controller.extend({
66
close(conversation) {
77
set(conversation, 'status', 'closed');
88
return conversation.save();
9+
},
10+
11+
reopen(conversation) {
12+
set(conversation, 'status', 'open');
13+
return conversation.save();
914
}
1015
}
1116
});

app/templates/components/conversations/conversation-list-item-with-user.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<span data-test-close-link class="conversation-list-item__close-link" {{action close conversation bubbles=false}}>
2424
{{fa-icon "check"}}<span>Close</span>
2525
</span>
26+
{{else if (eq conversation.status 'closed')}}
27+
<span data-test-reopen-link class="conversation-list-item__reopen-link" {{action reopen conversation bubbles=false}}>
28+
{{fa-icon "inbox"}}<span>Reopen</span>
29+
</span>
2630
{{/if}}
2731
</div>
2832
{{/link-to}}

app/templates/project/conversations.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
{{conversations/conversation-list-item-with-user
1313
conversation=conversation
1414
close=(action 'close')
15+
reopen=(action 'reopen')
1516
}}
1617
{{else}}
1718
<div class="conversations__empty">

tests/acceptance/project-conversations-test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,26 @@ test('Project admin can close a conversation', function(assert) {
170170
assert.equal(server.schema.conversations.first().status, 'closed', 'Conversation was closed.');
171171
});
172172
});
173+
174+
test('Project admin can reopen a conversation', function(assert) {
175+
assert.expect(1);
176+
177+
let { project, user } = server.create('project-user', { role: 'admin' });
178+
authenticateSession(this.application, { user_id: user.id });
179+
180+
let message = server.create('message', { project });
181+
server.create('conversation', { status: 'closed', message, user });
182+
183+
page.visit({
184+
organization: project.organization.slug,
185+
project: project.slug
186+
});
187+
188+
andThen(() => {
189+
page.conversations(0).reopenButton.click();
190+
});
191+
192+
andThen(() => {
193+
assert.equal(server.schema.conversations.first().status, 'open', 'Conversation was reopened.');
194+
});
195+
});

tests/integration/components/conversations/conversation-list-item-with-user-test.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function renderPage() {
1111
page.render(hbs`
1212
{{conversations/conversation-list-item-with-user
1313
close=onClose
14+
reopen=onReopen
1415
conversation=conversation
1516
}}
1617
`);
@@ -21,14 +22,15 @@ moduleForComponent('conversations/conversation-list-item-with-user', 'Integratio
2122
beforeEach() {
2223
page.setContext(this);
2324
set(this, 'onClose', () => {});
25+
set(this, 'onReopen', () => {});
2426
},
2527
afterEach() {
2628
page.removeContext();
2729
}
2830
});
2931

3032
test('it renders the conversation details', function(assert) {
31-
assert.expect(4);
33+
assert.expect(5);
3234

3335
let user = {
3436
name: 'Test User',
@@ -37,6 +39,7 @@ test('it renders the conversation details', function(assert) {
3739
};
3840

3941
let conversation = {
42+
status: 'open',
4043
updatedAt: moment().subtract(2, 'days'),
4144
user
4245
};
@@ -49,10 +52,11 @@ test('it renders the conversation details', function(assert) {
4952
assert.equal(page.target.name.text, user.name, 'The target user name renders');
5053
assert.equal(page.target.username.text, user.username, 'Their username renders');
5154
assert.equal(page.updatedAt.text, '2 days ago', 'The updated at timestamp renders');
55+
assert.equal(page.closeButton.text, 'Close', 'Close button text is correct');
5256
});
5357

5458
test('it does not render close button when conversation is closed', function(assert) {
55-
assert.expect(1);
59+
assert.expect(3);
5660

5761
let user = {
5862
username: 'testuser'
@@ -68,6 +72,8 @@ test('it does not render close button when conversation is closed', function(ass
6872
renderPage();
6973

7074
assert.notOk(page.closeButton.isVisible, 'Close button is hidden');
75+
assert.ok(page.reopenButton.isVisible, 'Reopen button is visible');
76+
assert.equal(page.reopenButton.text, 'Reopen', 'Reopen button text is correct');
7177
});
7278

7379
test('it calls bound action when clicking close button', function(assert) {
@@ -93,3 +99,27 @@ test('it calls bound action when clicking close button', function(assert) {
9399

94100
page.closeButton.click();
95101
});
102+
103+
test('it calls bound action when clicking reopen button', function(assert) {
104+
assert.expect(1);
105+
106+
let user = {
107+
username: 'testuser'
108+
};
109+
110+
let conversation = {
111+
id: '1',
112+
status: 'closed',
113+
user
114+
};
115+
116+
set(this, 'conversation', conversation);
117+
118+
set(this, 'onReopen', (c) => {
119+
assert.equal(c, conversation, 'Action was called with correct argument');
120+
});
121+
122+
renderPage();
123+
124+
page.reopenButton.click();
125+
});

tests/pages/components/conversations/conversation-list-item-with-user.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export default {
2424
scope: '[data-test-close-link]'
2525
},
2626

27+
reopenButton: {
28+
scope: '[data-test-reopen-link]'
29+
},
30+
2731
updatedAt: {
2832
scope: '[data-test-updated-at]'
2933
}

0 commit comments

Comments
 (0)