2015-10-14 14:34:32 +03:00
|
|
|
/* jshint expr:true */
|
2016-11-14 16:16:51 +03:00
|
|
|
import {expect} from 'chai';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {setupComponentTest} from 'ember-mocha';
|
2015-10-14 14:34:32 +03:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2016-06-30 13:21:47 +03:00
|
|
|
import EmberObject from 'ember-object';
|
2015-10-14 14:34:32 +03:00
|
|
|
import DS from 'ember-data';
|
2017-01-31 22:27:11 +03:00
|
|
|
import wait from 'ember-test-helpers/wait';
|
2015-10-14 14:34:32 +03:00
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
const {Errors} = DS;
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('Integration: Component: gh-validation-status-container', function () {
|
|
|
|
setupComponentTest('gh-validation-status-container', {
|
2015-10-14 14:34:32 +03:00
|
|
|
integration: true
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-10-14 14:34:32 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
let testObject = EmberObject.create();
|
|
|
|
testObject.set('name', 'Test');
|
|
|
|
testObject.set('hasValidated', []);
|
|
|
|
testObject.set('errors', Errors.create());
|
2015-10-14 14:34:32 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('testObject', testObject);
|
|
|
|
});
|
2015-10-14 14:34:32 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('has no success/error class by default', function () {
|
|
|
|
this.render(hbs`
|
|
|
|
{{#gh-validation-status-container class="gh-test" property="name" errors=testObject.errors hasValidated=testObject.hasValidated}}
|
|
|
|
{{/gh-validation-status-container}}
|
|
|
|
`);
|
2017-01-31 22:27:11 +03:00
|
|
|
|
|
|
|
return wait().then(() => {
|
|
|
|
expect(this.$('.gh-test')).to.have.length(1);
|
|
|
|
expect(this.$('.gh-test').hasClass('success')).to.be.false;
|
|
|
|
expect(this.$('.gh-test').hasClass('error')).to.be.false;
|
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-10-14 14:34:32 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('has success class when valid', function () {
|
|
|
|
this.get('testObject.hasValidated').push('name');
|
2015-10-14 14:34:32 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
this.render(hbs`
|
|
|
|
{{#gh-validation-status-container class="gh-test" property="name" errors=testObject.errors hasValidated=testObject.hasValidated}}
|
|
|
|
{{/gh-validation-status-container}}
|
|
|
|
`);
|
2017-01-31 22:27:11 +03:00
|
|
|
|
|
|
|
return wait().then(() => {
|
|
|
|
expect(this.$('.gh-test')).to.have.length(1);
|
|
|
|
expect(this.$('.gh-test').hasClass('success')).to.be.true;
|
|
|
|
expect(this.$('.gh-test').hasClass('error')).to.be.false;
|
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-10-14 14:34:32 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('has error class when invalid', function () {
|
|
|
|
this.get('testObject.hasValidated').push('name');
|
|
|
|
this.get('testObject.errors').add('name', 'has error');
|
2015-10-14 14:34:32 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
this.render(hbs`
|
|
|
|
{{#gh-validation-status-container class="gh-test" property="name" errors=testObject.errors hasValidated=testObject.hasValidated}}
|
|
|
|
{{/gh-validation-status-container}}
|
|
|
|
`);
|
2017-01-31 22:27:11 +03:00
|
|
|
|
|
|
|
return wait().then(() => {
|
|
|
|
expect(this.$('.gh-test')).to.have.length(1);
|
|
|
|
expect(this.$('.gh-test').hasClass('success')).to.be.false;
|
|
|
|
expect(this.$('.gh-test').hasClass('error')).to.be.true;
|
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-10-14 14:34:32 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('still renders if hasValidated is undefined', function () {
|
|
|
|
this.set('testObject.hasValidated', undefined);
|
|
|
|
|
|
|
|
this.render(hbs`
|
|
|
|
{{#gh-validation-status-container class="gh-test" property="name" errors=testObject.errors hasValidated=testObject.hasValidated}}
|
|
|
|
{{/gh-validation-status-container}}
|
|
|
|
`);
|
2017-01-31 22:27:11 +03:00
|
|
|
|
|
|
|
return wait().then(() => {
|
|
|
|
expect(this.$('.gh-test')).to.have.length(1);
|
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|