1
1
import { set } from '@ember/object' ;
2
2
import { moduleForComponent , test } from 'ember-qunit' ;
3
3
import hbs from 'htmlbars-inline-precompile' ;
4
+ import PageObject from 'ember-cli-page-object' ;
5
+ import donationGoalsActivation from 'code-corps-ember/tests/pages/component/donation-goals-activation' ;
6
+
7
+ let page = PageObject . create ( donationGoalsActivation ) ;
8
+
9
+ function renderPage ( ) {
10
+ page . render ( hbs `
11
+ {{donation-goals-activation
12
+ activateDonations=activateDonationsHandler
13
+ canActivateDonations=canActivateDonations
14
+ }}
15
+ ` ) ;
16
+ }
4
17
5
18
function setHandlers ( context , { activateDonationsHandler = function ( ) { } } = { } ) {
6
19
set ( context , 'activateDonationsHandler' , activateDonationsHandler ) ;
@@ -9,7 +22,11 @@ function setHandlers(context, { activateDonationsHandler = function() {} } = {})
9
22
moduleForComponent ( 'donation-goals-activation' , 'Integration | Component | donation goals activation' , {
10
23
integration : true ,
11
24
beforeEach ( ) {
25
+ page . setContext ( this ) ;
12
26
setHandlers ( this ) ;
27
+ } ,
28
+ afterEach ( ) {
29
+ page . removeContext ( ) ;
13
30
}
14
31
} ) ;
15
32
@@ -23,28 +40,19 @@ test('it allows activating donations if canActivateDonations is true', function(
23
40
setHandlers ( this , { activateDonationsHandler } ) ;
24
41
set ( this , 'canActivateDonations' , true ) ;
25
42
26
- this . render ( hbs `
27
- {{donation-goals-activation
28
- activateDonations=activateDonationsHandler
29
- canActivateDonations=canActivateDonations
30
- }}
31
- ` ) ;
43
+ renderPage ( ) ;
32
44
33
- assert . equal ( this . $ ( '.activate-donations' ) . length , 1 , 'The "activate donations" button is rendered' ) ;
45
+ assert . ok ( page . activateDonationsButton . isVisible , 'The "activate donations" button is rendered' ) ;
34
46
35
- this . $ ( '.activate-donations' ) . click ( ) ;
47
+ page . activateDonationsButton . click ( ) ;
36
48
} ) ;
37
49
38
50
test ( 'it prevents activating donations if canActivateDonations is false' , function ( assert ) {
39
51
assert . expect ( 1 ) ;
40
52
41
53
set ( this , 'canActivateDonations' , false ) ;
42
54
43
- this . render ( hbs `
44
- {{donation-goals-activation
45
- canActivateDonations=canActivateDonations
46
- }}
47
- ` ) ;
55
+ renderPage ( ) ;
48
56
49
- assert . equal ( this . $ ( '.activate-donations' ) . length , 0 , 'The "activate donations" button is not rendered' ) ;
57
+ assert . notOk ( page . activateDonationsButton . isVisible , 'The "activate donations" button is not rendered' ) ;
50
58
} ) ;
0 commit comments