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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ var EmberApp = require('ember-cli/lib/broccoli/ember-app');

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

// 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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* jshint ignore:start */
import { test } from 'qunit';
import moduleForAcceptance from 'tajpado/tests/helpers/module-for-acceptance';
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();

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

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

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

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

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

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

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

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

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

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

andThen(function() {
assert.equal(page.errorCount, '0', 'Starts the game without errors.');
assert.equal(page.errorMarkCount, 0, 'No error marks.');
assert.equal(page.errorCount, '0', 'Starts the game without errors.');
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.errorMarkCount, 0);
});
assert.equal(page.errorCount, '1', 'The text is case sensitive, b is not equal B.');
assert.equal(page.errorMarkCount, 0);

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

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

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

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

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

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
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { create, text, visitable, count, attribute } from 'tajpado/tests/page-object';

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

value(c) {
keyEvent(selector, 'keypress', c.charCodeAt(0));
value(text) {
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('/'),
visitActivity: visitable('/activities/:activity_id'),

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

0 comments on commit 6638a26

Please sign in to comment.