2015-10-14 14:34:32 +03:00
|
|
|
/* jshint expr:true */
|
|
|
|
import { expect } from 'chai';
|
|
|
|
import {
|
|
|
|
describeComponent,
|
|
|
|
it
|
|
|
|
} from 'ember-mocha';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import Ember from 'ember';
|
|
|
|
import DS from 'ember-data';
|
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
const {
|
|
|
|
Object: EmberObject
|
|
|
|
} = Ember;
|
|
|
|
const {Errors} = DS;
|
|
|
|
|
2015-10-14 14:34:32 +03:00
|
|
|
describeComponent(
|
|
|
|
'gh-validation-status-container',
|
|
|
|
'Integration: Component: gh-validation-status-container',
|
|
|
|
{
|
|
|
|
integration: true
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
beforeEach(function () {
|
2016-06-11 19:52:36 +03:00
|
|
|
let testObject = EmberObject.create();
|
2015-10-14 14:34:32 +03:00
|
|
|
testObject.set('name', 'Test');
|
|
|
|
testObject.set('hasValidated', []);
|
2016-06-11 19:52:36 +03:00
|
|
|
testObject.set('errors', Errors.create());
|
2015-10-14 14:34:32 +03:00
|
|
|
|
|
|
|
this.set('testObject', testObject);
|
|
|
|
});
|
|
|
|
|
|
|
|
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}}
|
|
|
|
`);
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has success class when valid', function () {
|
|
|
|
this.get('testObject.hasValidated').push('name');
|
|
|
|
|
|
|
|
this.render(hbs`
|
|
|
|
{{#gh-validation-status-container class="gh-test" property="name" errors=testObject.errors hasValidated=testObject.hasValidated}}
|
|
|
|
{{/gh-validation-status-container}}
|
|
|
|
`);
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has error class when invalid', function () {
|
|
|
|
this.get('testObject.hasValidated').push('name');
|
|
|
|
this.get('testObject.errors').add('name', 'has error');
|
|
|
|
|
|
|
|
this.render(hbs`
|
|
|
|
{{#gh-validation-status-container class="gh-test" property="name" errors=testObject.errors hasValidated=testObject.hasValidated}}
|
|
|
|
{{/gh-validation-status-container}}
|
|
|
|
`);
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
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}}
|
|
|
|
`);
|
|
|
|
expect(this.$('.gh-test')).to.have.length(1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|