Skip to content

Commit e656510

Browse files
snewcomerbegedin
authored andcommitted
Add window confirm for archive task close #1551 #1578
1 parent 5731845 commit e656510

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

app/components/task/archive-task.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import Component from '@ember/component';
22
import { alias } from '@ember/object/computed';
3+
import { get } from '@ember/object';
34
import EmberCan from 'ember-can';
45

56
export default Component.extend({
67
classNames: ['archive-task'],
78

89
// auto-assigns 'task' property from component as ability 'model'
910
ability: EmberCan.computed.ability('task'),
10-
canArchive: alias('ability.canArchive')
11+
canArchive: alias('ability.canArchive'),
12+
13+
actions: {
14+
archiveTask() {
15+
if (window.confirm(`Are you sure you want to archive this task? Archiving this task will remove it from your ${get(this, 'task.taskList.title')} task list.`)) {
16+
get(this, 'archiveTask')();
17+
}
18+
}
19+
}
1120
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{#if task.archived}}
22
<span class="task-sidebar-action">{{fa-icon "archive"}} Archived</span>
33
{{else if canArchive}}
4-
<a class="task-sidebar-action" {{action (action archiveTask)}}>{{fa-icon "archive"}} Archive</a>
4+
<a class="task-sidebar-action" {{action (action "archiveTask")}}>{{fa-icon "archive"}} Archive</a>
55
{{/if}}

tests/integration/components/task/archive-task-test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import hbs from 'htmlbars-inline-precompile';
33
import PageObject from 'ember-cli-page-object';
44
import component from 'code-corps-ember/tests/pages/components/task/archive-task';
55
import { Ability } from 'ember-can';
6+
import sinon from 'sinon';
67

78
let page = PageObject.create(component);
89

@@ -26,7 +27,12 @@ moduleForComponent('task/archive-task', 'Integration | Component | task/archive
2627
});
2728

2829
test('can archive if user has ability', function(assert) {
29-
assert.expect(1);
30+
assert.expect(2);
31+
32+
let stub = sinon.stub(window, 'confirm').callsFake(() => {
33+
assert.ok(true, 'Confirmation prompt was called.');
34+
return true;
35+
});
3036

3137
let task = { archived: false };
3238
this.set('task', task);
@@ -39,6 +45,8 @@ test('can archive if user has ability', function(assert) {
3945
renderPage();
4046

4147
page.archiveLink.click();
48+
49+
stub.restore();
4250
});
4351

4452
test('cannot archive if user does not have ability', function(assert) {

0 commit comments

Comments
 (0)