11import { set } from '@ember/object' ;
22import { moduleForComponent , test } from 'ember-qunit' ;
33import 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+ }
417
518function setHandlers ( context , { activateDonationsHandler = function ( ) { } } = { } ) {
619 set ( context , 'activateDonationsHandler' , activateDonationsHandler ) ;
@@ -9,7 +22,11 @@ function setHandlers(context, { activateDonationsHandler = function() {} } = {})
922moduleForComponent ( 'donation-goals-activation' , 'Integration | Component | donation goals activation' , {
1023 integration : true ,
1124 beforeEach ( ) {
25+ page . setContext ( this ) ;
1226 setHandlers ( this ) ;
27+ } ,
28+ afterEach ( ) {
29+ page . removeContext ( ) ;
1330 }
1431} ) ;
1532
@@ -23,28 +40,19 @@ test('it allows activating donations if canActivateDonations is true', function(
2340 setHandlers ( this , { activateDonationsHandler } ) ;
2441 set ( this , 'canActivateDonations' , true ) ;
2542
26- this . render ( hbs `
27- {{donation-goals-activation
28- activateDonations=activateDonationsHandler
29- canActivateDonations=canActivateDonations
30- }}
31- ` ) ;
43+ renderPage ( ) ;
3244
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' ) ;
3446
35- this . $ ( '.activate-donations' ) . click ( ) ;
47+ page . activateDonationsButton . click ( ) ;
3648} ) ;
3749
3850test ( 'it prevents activating donations if canActivateDonations is false' , function ( assert ) {
3951 assert . expect ( 1 ) ;
4052
4153 set ( this , 'canActivateDonations' , false ) ;
4254
43- this . render ( hbs `
44- {{donation-goals-activation
45- canActivateDonations=canActivateDonations
46- }}
47- ` ) ;
55+ renderPage ( ) ;
4856
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' ) ;
5058} ) ;
0 commit comments