Permalink
Browse files

Use async/await in acceptance tests

  • Loading branch information...
1 parent 2577f89 commit 6638a26564e41f3503886dbe36bf860b2f6d7ac1 @san650 committed May 6, 2016
Showing with 47 additions and 63 deletions.
  1. +3 −1 ember-cli-build.js
  2. +35 −57 tests/acceptance/ready-set-go-test.js
  3. +9 −5 tests/pages/activity.js
View
@@ -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
@@ -1,3 +1,4 @@
+/* jshint ignore:start */
import { test } from 'qunit';
import moduleForAcceptance from 'tajpado/tests/helpers/module-for-acceptance';
import Pretender from 'pretender';
@@ -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.');
});
@@ -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;
}
};
}
@@ -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.