diff --git a/ghost/admin/app/components/gh-navitem-url-input.js b/ghost/admin/app/components/gh-navitem-url-input.js index 001419fb54..cf13cfc69c 100644 --- a/ghost/admin/app/components/gh-navitem-url-input.js +++ b/ghost/admin/app/components/gh-navitem-url-input.js @@ -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); } diff --git a/ghost/admin/tests/unit/components/gh-navitem-url-input-test.js b/ghost/admin/tests/unit/components/gh-navitem-url-input-test.js new file mode 100644 index 0000000000..170dd52bef --- /dev/null +++ b/ghost/admin/tests/unit/components/gh-navitem-url-input-test.js @@ -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; + }); + } +);