Skip to content

Commit

Permalink
Use async/await in acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
san650 committed May 6, 2016
1 parent 2577f89 commit 6638a26
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 63 deletions.
4 changes: 3 additions & 1 deletion ember-cli-build.js
Expand Up @@ -4,7 +4,9 @@ var EmberApp = require('ember-cli/lib/broccoli/ember-app');


module.exports = function(defaults) { module.exports = function(defaults) {
var app = new EmberApp(defaults, { var app = new EmberApp(defaults, {
// Add options here babel: {
includePolyfill: true
}
}); });


// Use `app.import` to add additional libraries to the generated // Use `app.import` to add additional libraries to the generated
Expand Down
92 changes: 35 additions & 57 deletions tests/acceptance/ready-set-go-test.js
@@ -1,3 +1,4 @@
/* jshint ignore:start */
import { test } from 'qunit'; import { test } from 'qunit';
import moduleForAcceptance from 'tajpado/tests/helpers/module-for-acceptance'; import moduleForAcceptance from 'tajpado/tests/helpers/module-for-acceptance';
import Pretender from 'pretender'; import Pretender from 'pretender';
Expand All @@ -19,85 +20,62 @@ function setupActivity() {
}); });
} }


test('passes the activity', function(assert) { test('passes the activity', async function(assert) {
setupActivity(); setupActivity();


page.visit(); await page.visit();


andThen(function() { assert.equal(currentURL(), '/activities/1');
assert.equal(currentURL(), '/activities/1'); assert.equal(currentRouteName(), 'activity');
assert.equal(currentRouteName(), 'activity'); assert.equal(page.completed, '');
assert.equal(page.completed, ''); assert.equal(page.pending, 'aBcd');
assert.equal(page.pending, 'aBcd');
});


page.typeLetter('a'); await page.write('a');


andThen(function() { assert.equal(page.completed, 'a');
assert.equal(page.completed, 'a'); assert.equal(page.pending, 'Bcd');
assert.equal(page.pending, 'Bcd');
});


page.typeLetter('b'); await page.write('b');


andThen(function() { assert.equal(page.completed, 'a');
assert.equal(page.completed, 'a'); assert.equal(page.pending, 'Bcd', 'The match is case sensitive.');
assert.equal(page.pending, 'Bcd', 'The match is case sensitive.');
});


page.typeLetter('B'); await page.write('Bcd');
page.typeLetter('c');
page.typeLetter('d');


andThen(function() { assert.equal(page.completed, 'aBcd');
assert.equal(page.completed, 'aBcd'); assert.equal(page.pending, '');
assert.equal(page.pending, ''); assert.equal(page.activityCompletedMessage, 'Next activity');
assert.equal(page.activityCompletedMessage, 'Next activity');
});
}); });


test('count errors', function(assert) { test('count errors', async function(assert) {
setupActivity(); setupActivity();


page.visit(); await page.visit();


andThen(function() { assert.equal(page.errorCount, '0', 'Starts the game without errors.');
assert.equal(page.errorCount, '0', 'Starts the game without errors.'); assert.equal(page.errorMarkCount, 0, 'No error marks.');
assert.equal(page.errorMarkCount, 0, 'No error marks.');


page.typeLetter('a'); await page.write('a');


andThen(function() { assert.equal(page.errorCount, '0');
assert.equal(page.errorCount, '0');
});


page.typeLetter('b'); await page.write('b');


andThen(function() { assert.equal(page.errorCount, '1', 'The text is case sensitive, b is not equal B.');
assert.equal(page.errorCount, '1', 'The text is case sensitive, b is not equal B.'); assert.equal(page.errorMarkCount, 0);
assert.equal(page.errorMarkCount, 0);
});


page.typeLetter('r'); await page.write('r');


andThen(function() { assert.equal(page.errorCount, '2', 'Wrong letter.');
assert.equal(page.errorCount, '2', 'Wrong letter.'); assert.equal(page.errorMarkCount, 0);
assert.equal(page.errorMarkCount, 0);
});


page.typeLetter('B'); await page.write('B');


andThen(function() { // the error span is rendered after pass the current index
// the error span is rendered after pass the current index assert.equal(page.errorMarkCount, 1, 'Two errors in the same index.');
assert.equal(page.errorMarkCount, 1, 'Two errors in the same index.'); assert.equal(page.errorMarkTitle, 'Attempts: 2', 'Title shows: "Attempts: 2"');
assert.equal(page.errorMarkTitle, 'Attempts: 2', 'Title shows: "Attempts: 2"');
});


page.typeLetter('c'); await page.write('cd');
page.typeLetter('d');


andThen(function() { assert.equal(page.errorCount, '2', 'Game completed.');
assert.equal(page.errorCount, '2', 'Game completed.');
});
});
}); });
14 changes: 9 additions & 5 deletions tests/pages/activity.js
@@ -1,11 +1,15 @@
import { create, text, visitable, count, attribute } from 'tajpado/tests/page-object'; import { create, text, visitable, count, attribute } from 'tajpado/tests/page-object';


function typeLetter(selector) { function typeLetters(selector) {
return { return {
isDescriptor: true, isDescriptor: true,


value(c) { value(text) {
keyEvent(selector, 'keypress', c.charCodeAt(0)); for (let i = 0; i < text.length; i++) {
keyEvent(selector, 'keypress', text.charCodeAt(i));
}

return this;
} }
}; };
} }
Expand All @@ -14,11 +18,11 @@ export default create({
visit: visitable('/'), visit: visitable('/'),
visitActivity: visitable('/activities/:activity_id'), visitActivity: visitable('/activities/:activity_id'),


typeLetter: typeLetter('.activity-script-viewer'), write: typeLetters('.activity-script-viewer'),
completed: text('.activity-script-viewer .completed'), completed: text('.activity-script-viewer .completed'),
pending: text('.activity-script-viewer .pending'), pending: text('.activity-script-viewer .pending'),
activityCompletedMessage: text('.activity-completed'), activityCompletedMessage: text('.activity-completed'),
errorCount: text('.error-count'), errorCount: text('.error-count'),
errorMarkCount: count('.error-mark'), errorMarkCount: count('.error-mark'),
errorMarkTitle: attribute('title', '.error-mark') errorMarkTitle: attribute('title', '.error-mark')
}); });

0 comments on commit 6638a26

Please sign in to comment.