Skip to content

Commit 2880943

Browse files
committed
Include tests for checkStatus.
1 parent 5866d4a commit 2880943

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

tests/qunit/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<script src="https://code.jquery.com/qunit/qunit-2.0.0.js"></script>
1313
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
1414
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
15+
<script src="https://cdn.jsdelivr.net/jquery.mockjax/2.2.0/jquery.mockjax.min.js"></script>
1516
<script src="../../src/js/handlebars.js"></script>
1617
<script src="../../src/js/run.js"></script>
1718

tests/qunit/test-run.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ QUnit.test( 'reset elements', function( assert ) {
2424

2525
fixture.append( '<div id="standardMode">Hello this is text.</div>' );
2626
fixture.append( '<textarea id="testResults">This is some more text!</textarea>' );
27+
fixture.append( '<div id="wpe-progress-count"></div>' );
2728

2829
resetDisplay();
2930

3031
assert.ok( '' === $( '#testResults' ).text(), 'testResults is empty' );
3132
assert.ok( '' === $( '#standardMode' ).html(), 'standardMode is empty' );
33+
assert.ok( '' === $( '#wpe-progress-count' ).text(), 'wpe-progress-count is empty' );
3234
});
3335

3436
QUnit.module( 'displayReport' );
@@ -72,3 +74,61 @@ QUnit.test( 'Render test fail', function( assert ) {
7274
assert.ok( $('.wpe-results-card').length == 7, 'There are 7 results.' );
7375
assert.ok( $('#standardMode').text().includes( 'Your WordPress install is not PHP 5.5 compatible.' ), 'Test did not pass.' );
7476
});
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

Comments
 (0)