Use correct property when determining display URL

Closes #5574
This commit is contained in:
Jason Williams 2015-07-17 10:23:29 -05:00
parent 0659300a23
commit 00ede73105
2 changed files with 104 additions and 1 deletions

View File

@ -19,7 +19,7 @@ export default Ember.TextField.extend({
// if we have a relative url, create the absolute url to be displayed in the input
// if (this.get('isRelative')) {
if (!validator.isURL(url) && this.get('value').indexOf('mailto:') !== 0) {
if (!validator.isURL(url) && url.indexOf('mailto:') !== 0) {
url = joinUrlParts(baseUrl, url);
}

View File

@ -0,0 +1,103 @@
/* jshint expr:true */
import Ember from 'ember';
import {expect} from 'chai';
import {
describeComponent,
it
} from 'ember-mocha';
describeComponent(
'gh-navitem-url-input',
'GhNavitemUrlInputComponent',
{},
function () {
it('renders', function () {
var component = this.subject();
expect(component._state).to.equal('preRender');
this.render();
expect(component._state).to.equal('inDOM');
});
it('renders correctly with a URL that matches the base URL', function () {
var component = this.subject({
baseUrl: 'http://example.com/'
});
Ember.run(function () {
component.set('value', 'http://example.com/');
});
this.render();
expect(this.$().val()).to.equal('http://example.com/');
});
it('renders correctly with a relative URL', function () {
var component = this.subject({
baseUrl: 'http://example.com/'
});
Ember.run(function () {
component.set('value', '/go/docs');
});
this.render();
expect(this.$().val()).to.equal('/go/docs');
});
it('renders correctly with a mailto URL', function () {
var component = this.subject({
baseUrl: 'http://example.com/'
});
Ember.run(function () {
component.set('value', 'mailto:someone@example.com');
});
this.render();
expect(this.$().val()).to.equal('mailto:someone@example.com');
});
it('identifies a URL as relative', function () {
var component = this.subject({
baseUrl: 'http://example.com/',
url: '/go/docs'
});
this.render();
expect(component.get('isRelative')).to.be.ok;
Ember.run(function () {
component.set('value', 'http://example.com/go/docs');
});
expect(component.get('isRelative')).to.not.be.ok;
});
it('identifies a URL as the base URL', function () {
var component = this.subject({
baseUrl: 'http://example.com/'
});
this.render();
Ember.run(function () {
component.set('value', 'http://example.com/');
});
expect(component.get('isBaseUrl')).to.be.ok;
Ember.run(function () {
component.set('value', 'http://example.com/go/');
});
expect(component.get('isBaseUrl')).to.not.be.ok;
});
}
);