Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion improvements & README initial helpers #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,24 @@
Status](https://travis-ci.org/dockyard/ember-cli-acceptance-test-helpers.svg?branch=master)](https://travis-ci.org/dockyard/ember-cli-acceptance-test-helpers)

# ember-cli-acceptance-test-helpers
A set of declarative test helpers for acceptance testing.
This Ember addon includes a set of declarative test helpers for acceptance testing.

## Installation
Install for [ember-cli](https://github.com/ember-cli/ember-cli):
`ember install ember-cli-acceptance-test-helpers`

## Helpers
### Actions
* `clickButton(buttonText)`
* `clickLink(linkText)`
* `fillInByLabel(label, value)`

### Assertions
* `assertCurrentUrl(assert, expectedUrl)`
* `assertInputHasClass(assert, label, klass)`
* `assertValueEqual(assert, label, value)`
* `assertValueNotEqual(assert, label, value)`

### Finders
* `findInputByLabel(label)`
* `findLabelByText(text)`
13 changes: 7 additions & 6 deletions test-support/helpers/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ export function assertInputHasClass(assert, label, klass) {
};
}

export function assertValueEquals(assert, label, expectedValue) {
export function assertValueEqual(assert, label, value) {
return function() {
const labelForInput = findLabelByText(label);
const value = findInputByLabel(labelForInput).val();
const actualValue = findInputByLabel(labelForInput).val();

assert.equal(value, expectedValue);
assert.equal(actualValue, value);
}
}

export function assertValueNotEqual(assert, selector, expectedValue, context = null) {
export function assertValueNotEqual(assert, label, value) {
return function() {
const value = find(selector, context).val();
const labelForInput = findLabelByText(label);
const actualValue = findInputByLabel(labelForInput).val();

assert.notEqual(value, expectedValue);
assert.notEqual(actualValue, value);
}
}
7 changes: 3 additions & 4 deletions tests/acceptance/actions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {

import {
assertCurrentUrl,
assertValueEquals,
assertValueEqual,
assertValueNotEqual
} from '../helpers/assertions';

Expand Down Expand Up @@ -53,13 +53,12 @@ test('clickLink finds a link by its text and clicks it', function(assert) {
});

test('fillInByLabel enters text into an input corresponding to a label', function(assert) {
const targetInput = 'form input.node-2';
const targetValue = 'Jane Doe';

assert.expect(2);

visit('/');
andThen(assertValueNotEqual(assert, targetInput, targetValue)); // sanity check
andThen(assertValueNotEqual(assert, 'Name', targetValue)); // sanity check
andThen(fillInByLabel('Name', targetValue));
andThen(assertValueEquals(assert, 'Name', targetValue));
andThen(assertValueEqual(assert, 'Name', targetValue));
});