Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from cibernox/make-it-work-in-acceptance
Acceptance test tentative API
- Loading branch information
Showing
13 changed files
with
232 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function visit() { | ||
if (!window.visit) { | ||
throw new Error('visit is only available during acceptance tests'); | ||
} | ||
|
||
return window.visit(...arguments); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Ember from 'ember'; | ||
const { run, RSVP } = Ember; | ||
|
||
export function waitUntil(callback, { timeout = 1000 } = {}) { | ||
return new RSVP.Promise(function(resolve, reject) { | ||
let value = run(callback); | ||
if (value) { | ||
resolve(value); | ||
return; | ||
} | ||
let time = 0; | ||
let tick = function() { | ||
time += 10; | ||
let value = run(callback); | ||
if (value) { | ||
resolve(value); | ||
} else if (time < timeout) { | ||
setTimeout(tick, 10); | ||
} else { | ||
reject('waitUntil timed out'); | ||
} | ||
}; | ||
setTimeout(tick, 10); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { test } from 'qunit'; | ||
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | ||
import { visit, click, find, fillIn, waitUntil } from 'ember-native-dom-helpers/test-support/helpers'; | ||
|
||
moduleForAcceptance('Acceptance | usage in acceptance', { | ||
beforeEach() { | ||
window.server.timing = 300; | ||
} | ||
}); | ||
|
||
if (window.jQuery) { | ||
test('Usage awaiting the world to settle', async function(assert) { | ||
await visit('/signup-example'); | ||
|
||
assert.ok(find('.signup-example-form'), 'The signup form is displayed'); | ||
await fillIn('.signup-example-form__email', 'some@email.com'); | ||
await fillIn('.signup-example-form__password', '123123'); | ||
await fillIn('.signup-example-form__password-confirmation', '123123'); | ||
await click('.signup-example-form__submit-btn'); | ||
|
||
assert.ok(find('.dashboard-example-header'), 'We are on the dashboard now'); | ||
}); | ||
|
||
test('Usage using `waitUntil` to test unsettled state', async function(assert) { | ||
await visit('/signup-example'); | ||
|
||
assert.ok(find('.signup-example-form'), 'The signup form is displayed'); | ||
fillIn('.signup-example-form__email', 'some@email.com'); | ||
fillIn('.signup-example-form__password', '123123'); | ||
fillIn('.signup-example-form__password-confirmation', '123123'); | ||
let submitPromise = click('.signup-example-form__submit-btn'); | ||
|
||
await waitUntil(() => find('.dashbord-loading-substate-header')); | ||
assert.equal(find('.dashbord-loading-substate-header').textContent.trim(), 'Loading data for your dashboard. Please be patient.'); | ||
|
||
await submitPromise; | ||
assert.ok(find('.dashboard-example-header'), 'We are on the dashboard now'); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<h1> | ||
<h1 class="dashbord-loading-substate-header"> | ||
Loading data for your dashboard. Please be patient. | ||
</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
<h1>Signup example</h1> | ||
|
||
<form {{action "signup" on="submit"}}> | ||
<form class="signup-example-form" {{action "signup" on="submit"}}> | ||
<p> | ||
Email: | ||
<input type="text" onchange={{action (mut email) value="target.value"}}> | ||
<input type="text" class="signup-example-form__email" onchange={{action (mut email) value="target.value"}}> | ||
</p> | ||
<p> | ||
Password: | ||
<input type="password" onchange={{action (mut password) value="target.value"}}> | ||
<input type="password" class="signup-example-form__password" onchange={{action (mut password) value="target.value"}}> | ||
</p> | ||
<p> | ||
Password Confirmation: | ||
<input type="password" onchange={{action (mut passwordConfirmation) value="target.value"}}> | ||
<input type="password" class="signup-example-form__password-confirmation" onchange={{action (mut passwordConfirmation) value="target.value"}}> | ||
</p> | ||
|
||
<button type="submit" disabled={{isSaving}}> | ||
<button type="submit" class="signup-example-form__submit-btn" disabled={{isSaving}}> | ||
{{if isSaving 'Loading, please wait...' 'Sign up'}} | ||
</button> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
/* eslint-env node */ | ||
|
||
let browsers = [ | ||
'ie 9', | ||
'last 1 Chrome versions', | ||
'last 1 Firefox versions', | ||
'last 1 Safari versions' | ||
]; | ||
if (process.env.EMBER_ENV === 'development') { | ||
browsers = ['last 1 Chrome versions']; | ||
} | ||
module.exports = { | ||
browsers: [ | ||
'ie 9', | ||
'last 1 Chrome versions', | ||
'last 1 Firefox versions', | ||
'last 1 Safari versions' | ||
] | ||
browsers | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import { visit } from 'ember-native-dom-helpers/test-support/helpers'; | ||
|
||
moduleForComponent('fillIn', 'Integration | Test Helper | visit', { | ||
integration: true | ||
}); | ||
|
||
test('It raises an error in integration', function(assert) { | ||
assert.throws(function() { | ||
visit('/somewhere'); | ||
}, 'visit is only available during acceptance tests'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import Ember from 'ember'; | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import { waitUntil } from 'ember-native-dom-helpers/test-support/helpers'; | ||
const { run } = Ember; | ||
|
||
moduleForComponent('wait-until', 'Integration | Test Helper | waitUntil', { | ||
integration: true | ||
}); | ||
|
||
test('It returns a promise that resolves when the given callback returns a non-falsey value', async function(assert) { | ||
setTimeout(() => run(() => this.set('timeout1', true)), 100); | ||
setTimeout(() => run(() => this.set('timeout2', true)), 200); | ||
setTimeout(() => run(() => this.set('timeout3', true)), 300); | ||
|
||
this.render(hbs` | ||
{{#if timeout1}}<span id="wait-until-step1">Step 1</span>{{/if}} | ||
{{#if timeout2}}<span id="wait-until-step2">Step 1</span>{{/if}} | ||
{{#if timeout3}}<span id="wait-until-step3">Step 1</span>{{/if}} | ||
`); | ||
|
||
assert.notOk(document.querySelector('#wait-until-step1') | ||
|| document.querySelector('#wait-until-step2') | ||
|| document.querySelector('#wait-until-step3'), | ||
'No element is rendered' | ||
); | ||
|
||
await waitUntil(() => document.querySelector('#wait-until-step1')); | ||
assert.ok(document.querySelector('#wait-until-step1'), 'The first element appeared'); | ||
assert.notOk(document.querySelector('#wait-until-step2') | ||
|| document.querySelector('#wait-until-step3'), | ||
'The second and third element are not rendered' | ||
); | ||
|
||
await waitUntil(() => document.querySelector('#wait-until-step2')); | ||
assert.ok(document.querySelector('#wait-until-step1'), 'The first element appeared'); | ||
assert.ok(document.querySelector('#wait-until-step2'), 'The second element appeared'); | ||
assert.notOk(document.querySelector('#wait-until-step3'), 'The third element is not rendered'); | ||
|
||
await waitUntil(() => document.querySelector('#wait-until-step3')); | ||
assert.ok(document.querySelector('#wait-until-step1'), 'The first element appeared'); | ||
assert.ok(document.querySelector('#wait-until-step2'), 'The second element appeared'); | ||
assert.ok(document.querySelector('#wait-until-step3'), 'The third element appeared'); | ||
}); | ||
|
||
test('It waits until the given callback returns true', async function(assert) { | ||
setTimeout(() => run(() => this.set('timeout1', true)), 100); | ||
setTimeout(() => run(() => this.set('timeout2', true)), 200); | ||
setTimeout(() => run(() => this.set('timeout3', true)), 300); | ||
|
||
this.render(hbs` | ||
{{#if timeout1}}<span id="wait-until-step1">Step 1</span>{{/if}} | ||
{{#if timeout2}}<span id="wait-until-step2">Step 1</span>{{/if}} | ||
{{#if timeout3}}<span id="wait-until-step3">Step 1</span>{{/if}} | ||
`); | ||
|
||
assert.notOk(document.querySelector('#wait-until-step1') | ||
|| document.querySelector('#wait-until-step2') | ||
|| document.querySelector('#wait-until-step3'), | ||
'No element is rendered' | ||
); | ||
|
||
await waitUntil(() => document.querySelector('#wait-until-step1')); | ||
assert.ok(document.querySelector('#wait-until-step1'), 'The first element appeared'); | ||
assert.notOk(document.querySelector('#wait-until-step2') | ||
|| document.querySelector('#wait-until-step3'), | ||
'The second and third element are not rendered' | ||
); | ||
|
||
await waitUntil(() => document.querySelector('#wait-until-step2')); | ||
assert.ok(document.querySelector('#wait-until-step1'), 'The first element appeared'); | ||
assert.ok(document.querySelector('#wait-until-step2'), 'The second element appeared'); | ||
assert.notOk(document.querySelector('#wait-until-step3'), 'The third element is not rendered'); | ||
|
||
await waitUntil(() => document.querySelector('#wait-until-step3')); | ||
assert.ok(document.querySelector('#wait-until-step1'), 'The first element appeared'); | ||
assert.ok(document.querySelector('#wait-until-step2'), 'The second element appeared'); | ||
assert.ok(document.querySelector('#wait-until-step3'), 'The third element appeared'); | ||
}); | ||
|
||
test('It was a default timeout of 1 second', async function(assert) { | ||
assert.expect(2); | ||
this.render(hbs``); | ||
let initialTime = +new Date(); | ||
try { | ||
await waitUntil(() => document.querySelector('#wait-until-step1')); | ||
} catch(e) { | ||
let finalTime = +new Date(); | ||
assert.equal(e, 'waitUntil timed out'); | ||
let elapsedTime = finalTime - initialTime; | ||
assert.ok(elapsedTime >= 1000 && elapsedTime <= 1500, 'The default timeout is 1s'); | ||
} | ||
}); | ||
|
||
test('The default timeout can be adjusted using passing options as a second argument', async function(assert) { | ||
assert.expect(2); | ||
this.render(hbs``); | ||
let initialTime = +new Date(); | ||
try { | ||
await waitUntil(() => document.querySelector('#wait-until-step1'), { timeout: 2000 }); | ||
} catch(e) { | ||
let finalTime = +new Date(); | ||
assert.equal(e, 'waitUntil timed out'); | ||
let elapsedTime = finalTime - initialTime; | ||
assert.ok(elapsedTime >= 2000 && elapsedTime <= 2500, 'The timeout was set to 2s'); | ||
} | ||
}); | ||
|
||
test('The promise resolved with the return value of the callback', async function(assert) { | ||
assert.expect(1); | ||
this.render(hbs`<span id="wait-until-thing"></span>`); | ||
let element = await waitUntil(() => document.querySelector('#wait-until-thing')); | ||
assert.equal(element.id, 'wait-until-thing', 'waitUntil resoleved with the DOM element'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters