@@ -4,7 +4,6 @@ import { run } from '@ember/runloop';
44import RSVP from 'rsvp' ;
55import { moduleForComponent , test } from 'ember-qunit' ;
66import hbs from 'htmlbars-inline-precompile' ;
7- import wait from 'ember-test-helpers/wait' ;
87import stubService from 'code-corps-ember/tests/helpers/stub-service' ;
98import {
109 getFlashMessageCount ,
@@ -96,9 +95,7 @@ let selectedCategory = {
9695 description : 'You want to help society.'
9796} ;
9897
99- test ( 'it works for selecting unselected categories' , function ( assert ) {
100- let done = assert . async ( ) ;
101-
98+ test ( 'it works for selecting unselected categories' , async function ( assert ) {
10299 assert . expect ( 5 ) ;
103100
104101 stubService ( this , 'user-categories' , mockUserCategoriesService ) ;
@@ -111,17 +108,12 @@ test('it works for selecting unselected categories', function(assert) {
111108 assert . equal ( page . description . text , 'You want to help technology.' , 'Correct description is rendered.' ) ;
112109 assert . equal ( page . button . text , 'Technology' , 'Button text is rendered correctly' ) ;
113110
114- page . button . click ( ) ;
111+ await page . button . click ( ) ;
115112
116- wait ( ) . then ( ( ) => {
117- assert . ok ( page . icon . classContains ( 'technology--selected' ) , 'is selected' ) ;
118- done ( ) ;
119- } ) ;
113+ assert . ok ( page . icon . classContains ( 'technology--selected' ) , 'is selected' ) ;
120114} ) ;
121115
122116test ( 'it works for removing selected categories' , function ( assert ) {
123- let done = assert . async ( ) ;
124-
125117 assert . expect ( 3 ) ;
126118
127119 stubService ( this , 'user-categories' , mockUserCategoriesService ) ;
@@ -134,15 +126,10 @@ test('it works for removing selected categories', function(assert) {
134126
135127 page . button . click ( ) ;
136128
137- wait ( ) . then ( ( ) => {
138- assert . ok ( page . icon . classContains ( 'society' ) , 'is unselected' ) ;
139- done ( ) ;
140- } ) ;
129+ assert . ok ( page . icon . classContains ( 'society' ) , 'is unselected' ) ;
141130} ) ;
142131
143132test ( 'it creates a flash message on an error when adding' , function ( assert ) {
144- let done = assert . async ( ) ;
145-
146133 assert . expect ( 4 ) ;
147134
148135 stubService ( this , 'user-categories' , mockUserCategoriesServiceForErrors ) ;
@@ -152,25 +139,17 @@ test('it creates a flash message on an error when adding', function(assert) {
152139
153140 page . button . click ( ) ;
154141
155- wait ( ) . then ( ( ) => {
156- assert . ok ( page . button . unchecked , 'Operation failed. Button is rendered as unchecked.' ) ;
157-
158- assert . equal ( getFlashMessageCount ( this ) , 1 , 'One message is shown' ) ;
142+ assert . ok ( page . button . unchecked , 'Operation failed. Button is rendered as unchecked.' ) ;
159143
160- let flash = getFlashMessageAt ( 0 , this ) ;
161- let actualOptions = getProperties ( flash , 'fixed' , 'sticky' , 'timeout' , 'type' ) ;
162- let expectedOptions = { fixed : true , sticky : false , timeout : 5000 , type : 'danger' } ;
163- assert . deepEqual ( actualOptions , expectedOptions , 'Proper message was set' ) ;
164-
165- assert . ok ( flash . message . indexOf ( unselectedCategory . name ) !== - 1 , 'Message text includes the category name' ) ;
166-
167- done ( ) ;
168- } ) ;
144+ assert . equal ( getFlashMessageCount ( this ) , 1 , 'One message is shown' ) ;
145+ let flash = getFlashMessageAt ( 0 , this ) ;
146+ let actualOptions = getProperties ( flash , 'fixed' , 'sticky' , 'timeout' , 'type' ) ;
147+ let expectedOptions = { fixed : true , sticky : false , timeout : 5000 , type : 'danger' } ;
148+ assert . deepEqual ( actualOptions , expectedOptions , 'Proper message was set' ) ;
149+ assert . ok ( flash . message . indexOf ( unselectedCategory . name ) !== - 1 , 'Message text includes the category name' ) ;
169150} ) ;
170151
171152test ( 'it creates a flash message on an error when removing' , function ( assert ) {
172- let done = assert . async ( ) ;
173-
174153 assert . expect ( 4 ) ;
175154
176155 stubService ( this , 'user-categories' , mockUserCategoriesServiceForErrors ) ;
@@ -180,58 +159,46 @@ test('it creates a flash message on an error when removing', function(assert) {
180159
181160 page . button . click ( ) ;
182161
183- wait ( ) . then ( ( ) => {
184- assert . ok ( page . button . checked , 'Operation failed. Button is rendered as checked.' ) ;
185-
186- assert . equal ( getFlashMessageCount ( this ) , 1 , 'One message is shown.' ) ;
162+ assert . ok ( page . button . checked , 'Operation failed. Button is rendered as checked.' ) ;
187163
188- let flash = getFlashMessageAt ( 0 , this ) ;
189- let actualOptions = getProperties ( flash , 'fixed' , 'sticky' , 'timeout' , 'type' ) ;
190- let expectedOptions = { fixed : true , sticky : false , timeout : 5000 , type : 'danger' } ;
191- assert . deepEqual ( actualOptions , expectedOptions , 'Proper message was set' ) ;
192-
193- assert . ok ( flash . message . indexOf ( selectedCategory . name ) !== - 1 , 'Message text includes the category name' ) ;
194-
195- done ( ) ;
196- } ) ;
164+ assert . equal ( getFlashMessageCount ( this ) , 1 , 'One message is shown.' ) ;
165+ let flash = getFlashMessageAt ( 0 , this ) ;
166+ let actualOptions = getProperties ( flash , 'fixed' , 'sticky' , 'timeout' , 'type' ) ;
167+ let expectedOptions = { fixed : true , sticky : false , timeout : 5000 , type : 'danger' } ;
168+ assert . deepEqual ( actualOptions , expectedOptions , 'Proper message was set' ) ;
169+ assert . ok ( flash . message . indexOf ( selectedCategory . name ) !== - 1 , 'Message text includes the category name' ) ;
197170} ) ;
198171
199- test ( 'it sets and unsets loading state when adding' , function ( assert ) {
200- let done = assert . async ( ) ;
201-
172+ test ( 'it sets and unsets loading state when adding' , async function ( assert ) {
202173 assert . expect ( 2 ) ;
203174
204175 stubService ( this , 'user-categories' , mockUserCategoriesService ) ;
205176 this . set ( 'category' , unselectedCategory ) ;
206177
207178 renderPage ( ) ;
208179
209- page . button . click ( ) ;
180+ let result = page . button . click ( ) ;
210181
211182 assert . ok ( page . button . spinning , 'Button is rendering as busy.' ) ;
212183
213- wait ( ) . then ( ( ) => {
214- assert . ok ( page . button . checked , 'Operation worked. Button is rendered as checked.' ) ;
215- done ( ) ;
216- } ) ;
217- } ) ;
184+ await result ;
218185
219- test ( 'it sets and unsets loading state when removing' , function ( assert ) {
220- let done = assert . async ( ) ;
186+ assert . ok ( page . button . checked , 'Operation worked. Button is rendered as checked.' ) ;
187+ } ) ;
221188
189+ test ( 'it sets and unsets loading state when removing' , async function ( assert ) {
222190 assert . expect ( 2 ) ;
223191
224192 stubService ( this , 'user-categories' , mockUserCategoriesService ) ;
225193 this . set ( 'category' , selectedCategory ) ;
226194
227195 renderPage ( ) ;
228196
229- page . button . click ( ) ;
197+ let result = page . button . click ( ) ;
230198
231199 assert . ok ( page . button . spinning , 'Button is rendering as busy.' ) ;
232200
233- wait ( ) . then ( ( ) => {
234- assert . ok ( page . button . unchecked , 'Operation worked. Button is rendered as unchecked.' ) ;
235- done ( ) ;
236- } ) ;
201+ await result ;
202+
203+ assert . ok ( page . button . unchecked , 'Operation worked. Button is rendered as unchecked.' ) ;
237204} ) ;
0 commit comments