@@ -24,11 +24,13 @@ QUnit.test( 'reset elements', function( assert ) {
24
24
25
25
fixture . append ( '<div id="standardMode">Hello this is text.</div>' ) ;
26
26
fixture . append ( '<textarea id="testResults">This is some more text!</textarea>' ) ;
27
+ fixture . append ( '<div id="wpe-progress-count"></div>' ) ;
27
28
28
29
resetDisplay ( ) ;
29
30
30
31
assert . ok ( '' === $ ( '#testResults' ) . text ( ) , 'testResults is empty' ) ;
31
32
assert . ok ( '' === $ ( '#standardMode' ) . html ( ) , 'standardMode is empty' ) ;
33
+ assert . ok ( '' === $ ( '#wpe-progress-count' ) . text ( ) , 'wpe-progress-count is empty' ) ;
32
34
} ) ;
33
35
34
36
QUnit . module ( 'displayReport' ) ;
@@ -72,3 +74,61 @@ QUnit.test( 'Render test fail', function( assert ) {
72
74
assert . ok ( $ ( '.wpe-results-card' ) . length == 7 , 'There are 7 results.' ) ;
73
75
assert . ok ( $ ( '#standardMode' ) . text ( ) . includes ( 'Your WordPress install is not PHP 5.5 compatible.' ) , 'Test did not pass.' ) ;
74
76
} ) ;
77
+
78
+ QUnit . module ( 'checkStatus' ) ;
79
+
80
+ QUnit . test ( 'Test checkStatus progress' , function ( assert ) {
81
+ // This will be an async test since it involves callbacks.
82
+ var done = assert . async ( ) ;
83
+ var fixture = $ ( '#qunit-fixture' ) ;
84
+ fixture . append ( '<div id="wpe-progress-count"></div>' ) ;
85
+
86
+ // Define our mock URL.
87
+ ajaxurl = '/checkStatus/progress/' ;
88
+
89
+ // Mock the ajax call.
90
+ $ . mockjax ( {
91
+ url : ajaxurl ,
92
+ responseTime : 0 ,
93
+ responseText : '{"status":"1","count":"1","total":"17","progress":94.1176470588,"results":"0"}' ,
94
+ data : function ( response ) { // Check the data posted to our mock.
95
+ assert . ok ( 'wpephpcompat_check_status' === response . action , 'Correct action called.' ) ;
96
+ return true ;
97
+ } ,
98
+ onAfterComplete : function ( ) { // Check the results of checkStatus();
99
+ assert . ok ( $ ( '#wpe-progress-count' ) . text ( ) === '16/17' , 'Progress count is correct.' ) ;
100
+ // Clear the next queued checkStatus call.
101
+ clearTimeout ( timer ) ;
102
+ // End the test.
103
+ done ( ) ;
104
+ }
105
+ } ) ;
106
+
107
+ // Actually run the function.
108
+ checkStatus ( ) ;
109
+ } ) ;
110
+
111
+ QUnit . test ( 'Test checkStatus done' , function ( assert ) {
112
+ var done = assert . async ( ) ;
113
+ var fixture = $ ( '#qunit-fixture' ) ;
114
+ fixture . append ( '<div id="wpe-progress"><div id="wpe-progress-count"></div></div>' ) ;
115
+
116
+ ajaxurl = '/checkStatus/done/' ;
117
+
118
+ $ . mockjax ( {
119
+ url : ajaxurl ,
120
+ responseTime : 0 ,
121
+ responseText : '{"status":"1","count":"17","total":"17","progress":100,"results":"done"}' ,
122
+ data : function ( response ) {
123
+ assert . ok ( 'wpephpcompat_check_status' === response . action , 'Correct action called.' ) ;
124
+ return true ;
125
+ } ,
126
+ onAfterComplete : function ( ) {
127
+ assert . ok ( ! $ ( '#wpe-progress' ) . is ( ':visible' ) , 'Progress div is hidden.' ) ;
128
+ clearTimeout ( timer ) ;
129
+ done ( ) ;
130
+ }
131
+ } ) ;
132
+
133
+ checkStatus ( ) ;
134
+ } ) ;
0 commit comments