@@ -2,32 +2,88 @@ import { render, click } from "@ember/test-helpers";
2
2
import { setupRenderingTest } from "dummy/tests/helpers" ;
3
3
import { hbs } from "ember-cli-htmlbars" ;
4
4
import { module , test } from "qunit" ;
5
+ import { fake } from "sinon" ;
5
6
6
7
module ( "Integration | Component | document-delete-button" , function ( hooks ) {
7
8
setupRenderingTest ( hooks ) ;
8
9
10
+ hooks . beforeEach ( function ( ) {
11
+ this . owner . lookup ( "service:router" ) . transitionTo = fake ( ) ;
12
+ } ) ;
13
+
9
14
test ( "delete document" , async function ( assert ) {
10
15
this . document = {
11
16
id : 1 ,
12
17
title : "Test" ,
13
- destroyRecord ( ) { } ,
18
+ destroyRecord ( ) {
19
+ assert . step ( "destroy test" ) ;
20
+ } ,
14
21
} ;
15
22
16
23
this . onCancel = ( ) => assert . step ( "cancel" ) ;
17
24
this . onConfirm = ( ) => assert . step ( "confirm" ) ;
18
25
19
26
await render ( hbs `
20
27
<DocumentDeleteButton
21
- @document={{this.document}}
28
+ @docsToDelete={{this.document}}
29
+ @onConfirm={{this.onConfirm}}
30
+ @onCancel={{this.onCancel}}
31
+ as |showDialog|
32
+ >
33
+ <button
34
+ {{on "click" showDialog}}
35
+ data-test-delete
36
+ type="button"
37
+ >
38
+ Delete
39
+ </button>
40
+ </DocumentDeleteButton>
41
+ ` ) ;
42
+
43
+ await click ( "[data-test-delete]" ) ;
44
+ await click ( "[data-test-delete-cancel]" ) ;
45
+
46
+ await click ( "[data-test-delete]" ) ;
47
+ await click ( "[data-test-delete-confirm]" ) ;
48
+
49
+ assert . verifySteps ( [ "cancel" , "confirm" , "destroy test" ] ) ;
50
+ } ) ;
51
+
52
+ test ( "delete document multiple" , async function ( assert ) {
53
+ this . documents = [
54
+ {
55
+ id : 1 ,
56
+ title : "Test" ,
57
+ destroyRecord ( ) {
58
+ assert . step ( "destroy test" ) ;
59
+ } ,
60
+ } ,
61
+ {
62
+ id : 2 ,
63
+ title : "Bar" ,
64
+ destroyRecord ( ) {
65
+ assert . step ( "destroy bar" ) ;
66
+ } ,
67
+ } ,
68
+ ] ;
69
+
70
+ this . onCancel = ( ) => assert . step ( "cancel" ) ;
71
+ this . onConfirm = ( ) => assert . step ( "confirm" ) ;
72
+
73
+ await render ( hbs `
74
+ <DocumentDeleteButton
75
+ @docsToDelete={{this.documents}}
22
76
@onConfirm={{this.onConfirm}}
23
77
@onCancel={{this.onCancel}}
24
78
as |showDialog|
25
79
>
26
80
<button
27
- {{on "click" showDialog}}
28
- data-test-delete
29
- type="button"
30
- >Delete</button>
81
+ {{on "click" showDialog}}
82
+ data-test-delete
83
+ type="button"
84
+ >
85
+ Delete
86
+ </button>
31
87
</DocumentDeleteButton>
32
88
` ) ;
33
89
@@ -37,6 +93,6 @@ module("Integration | Component | document-delete-button", function (hooks) {
37
93
await click ( "[data-test-delete]" ) ;
38
94
await click ( "[data-test-delete-confirm]" ) ;
39
95
40
- assert . verifySteps ( [ "cancel" , "confirm" ] ) ;
96
+ assert . verifySteps ( [ "cancel" , "confirm" , "destroy test" , "destroy bar" ] ) ;
41
97
} ) ;
42
98
} ) ;
0 commit comments