add some and refactor add-env-var tests
This commit is contained in:
parent
cc0bed2974
commit
99f828ef65
|
@ -1,6 +1,6 @@
|
|||
<form {{action "save" on="submit"}}>
|
||||
<div class="form-elem">
|
||||
{{input value=name class="env-name" on="key-press" action="nameChanged" placeholder="Name"}}
|
||||
{{input value=name class="env-name" on="key-up" action="nameChanged" placeholder="Name"}}
|
||||
{{#if nameIsBlank }}
|
||||
<p class="form-error-message">Name cannot be blank</p>
|
||||
{{/if}}
|
||||
|
|
7
tests/helpers/fill-in.js
Normal file
7
tests/helpers/fill-in.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
export default function (elem, text, event = 'keyup') {
|
||||
var e = $.Event(event);
|
||||
e.which = 50;
|
||||
elem.val(text);
|
||||
elem.trigger(e);
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
import { moduleForComponent, test } from 'ember-qunit';
|
||||
import hbs from 'htmlbars-inline-precompile';
|
||||
import fillIn from '../../helpers/fill-in';
|
||||
|
||||
|
||||
moduleForComponent('add-env-var', 'Integration | Component | add env-var', {
|
||||
|
@ -8,7 +9,7 @@ moduleForComponent('add-env-var', 'Integration | Component | add env-var', {
|
|||
});
|
||||
|
||||
test('it adds an env var on submit', function(assert) {
|
||||
assert.expect(5);
|
||||
assert.expect(6);
|
||||
|
||||
var store = this.container.lookup('store:main');
|
||||
assert.equal(store.all('envVar').get('length'), 0, 'precond: store should be empty');
|
||||
|
@ -22,15 +23,8 @@ test('it adds an env var on submit', function(assert) {
|
|||
|
||||
this.render(hbs`{{add-env-var repo=repo}}`);
|
||||
|
||||
this.$('.env-name').val('FOO');
|
||||
var e = $.Event("keyup");
|
||||
e.which = 50;
|
||||
this.$('.env-name').trigger(e);
|
||||
|
||||
this.$('.env-value').val('bar');
|
||||
e = $.Event("keyup");
|
||||
e.which = 50;
|
||||
this.$('.env-value').trigger(e);
|
||||
fillIn(this.$('.env-name'), 'FOO');
|
||||
fillIn(this.$('.env-value'), 'bar');
|
||||
|
||||
this.$('.form-submit').click();
|
||||
|
||||
|
@ -41,6 +35,7 @@ test('it adds an env var on submit', function(assert) {
|
|||
assert.equal(envVar.get('name'), 'FOO', 'name should be set for the env var');
|
||||
assert.equal(envVar.get('value'), 'bar', 'value should be set for the env var');
|
||||
assert.equal(envVar.get('repo.slug'), 'travis-ci/travis-web', 'repo should be set for the env var');
|
||||
assert.ok(!envVar.get('public'), 'env var should be private');
|
||||
});
|
||||
|
||||
test('it shows an error if no name is present', function(assert) {
|
||||
|
@ -55,9 +50,40 @@ test('it shows an error if no name is present', function(assert) {
|
|||
|
||||
assert.ok(this.$('.form-error-message').length, 'the error message should be displayed');
|
||||
|
||||
var e = $.Event("keypress");
|
||||
e.which = 50;
|
||||
this.$('.env-name').trigger(e);
|
||||
fillIn(this.$('.env-name'), 'FOO');
|
||||
fillIn(this.$('.env-value'), 'bar');
|
||||
|
||||
assert.ok(!this.$('.form-error-message').length, 'the error message should be removed after value is changed');
|
||||
});
|
||||
});
|
||||
|
||||
test('it adds a public env var on submit', function(assert) {
|
||||
assert.expect(6);
|
||||
|
||||
var store = this.container.lookup('store:main');
|
||||
assert.equal(store.all('envVar').get('length'), 0, 'precond: store should be empty');
|
||||
|
||||
var repo;
|
||||
Ember.run(function() {
|
||||
repo = store.push('repo', {id: 1, slug: 'travis-ci/travis-web'});
|
||||
});
|
||||
|
||||
this.set('repo', repo);
|
||||
|
||||
this.render(hbs`{{add-env-var repo=repo}}`);
|
||||
|
||||
fillIn(this.$('.env-name'), 'FOO');
|
||||
fillIn(this.$('.env-value'), 'bar');
|
||||
|
||||
this.$('.switch').click();
|
||||
|
||||
this.$('.form-submit').click();
|
||||
|
||||
assert.equal(store.all('envVar').get('length'), 1, 'env var should be added to store');
|
||||
|
||||
var envVar = store.all('envVar').objectAt(0);
|
||||
|
||||
assert.equal(envVar.get('name'), 'FOO', 'name should be set for the env var');
|
||||
assert.equal(envVar.get('value'), 'bar', 'value should be set for the env var');
|
||||
assert.equal(envVar.get('repo.slug'), 'travis-ci/travis-web', 'repo should be set for the env var');
|
||||
assert.ok(envVar.get('public'), 'env var should be public');
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user