Skip to content
Permalink
Browse files

Add test

  • Loading branch information...
koenbok committed Jul 15, 2015
1 parent c2f0066 commit db96a5ef5e798501503b2153be53610d456d5380
Showing with 34 additions and 8 deletions.
  1. +4 −6 framer/Utils.coffee
  2. +30 −2 test/tests/UtilsTest.coffee
@@ -300,10 +300,7 @@ Utils.isFileUrl = (url) ->
return _.startsWith(url, "file://")

Utils.isRelativeUrl = (url) ->
return true if _.startsWith(url, ".")
return true if _.startsWith(url, "./")
return true if _.startsWith(url, "../")
return false
!/^([a-zA-Z]{1,8}:\/\/).*$/.test(url)

Utils.isLocalServerUrl = (url) ->
return url.indexOf("127.0.0.1") != -1 or url.indexOf("localhost") != -1
@@ -313,9 +310,10 @@ Utils.isLocalUrl = (url) ->
return true if Utils.isLocalServerUrl(url)
return false

Utils.isLocalAssetUrl = (url) ->
Utils.isLocalAssetUrl = (url, baseUrl) ->
baseUrl ?= window.location.href
return true if Utils.isLocalUrl(url)
return true if Utils.isRelativeUrl(url) and Utils.isLocalUrl(window.location.href)
return true if Utils.isRelativeUrl(url) and Utils.isLocalUrl(baseUrl)
return false

Utils.isFramerStudio = ->
@@ -341,7 +341,35 @@ describe "Utils", ->
Utils.setValueForKeyPath(obj, "fooA.fooB.fooC", "bar")
obj.should.eql({fooA: {fooB: {fooC: "bar"}}})

describe "isFileUrl", ->
it "should work", ->
Utils.isFileUrl("file:///Users/koen/Desktop/index.html").should.equal(true)
Utils.isFileUrl("http://apple.com/index.html").should.equal(false)
Utils.isFileUrl("https://apple.com/index.html").should.equal(false)

describe "isRelativeUrl", ->
it "should work", ->
Utils.isRelativeUrl("Desktop/index.html").should.equal(true)
Utils.isRelativeUrl("/Desktop/index.html").should.equal(true)
Utils.isRelativeUrl("./Desktop/index.html").should.equal(true)
Utils.isRelativeUrl(".././Desktop/index.html").should.equal(true)
Utils.isRelativeUrl("https://apple.com/index.html").should.equal(false)



describe "isLocalServerUrl", ->
it "should work", ->
Utils.isLocalServerUrl("/Desktop/index.html").should.equal(false)
Utils.isLocalServerUrl("http://localhost/index.html").should.equal(true)
Utils.isLocalServerUrl("http://127.0.0.1/index.html").should.equal(true)
Utils.isLocalServerUrl("https://localhost/index.html").should.equal(true)
Utils.isLocalServerUrl("https://127.0.0.1/index.html").should.equal(true)
Utils.isLocalServerUrl(".././Desktop/index.html").should.equal(false)
Utils.isLocalServerUrl("https://apple.com/index.html").should.equal(false)

describe "isLocalAssetUrl", ->
it "should work", ->
Utils.isLocalAssetUrl("Desktop/index.html", "http://localhost/index.html").should.equal(true)
Utils.isLocalAssetUrl("/Desktop/index.html", "http://localhost/index.html").should.equal(true)
Utils.isLocalAssetUrl("Desktop/index.html", "http://127.0.0.1/index.html").should.equal(true)
Utils.isLocalAssetUrl("Desktop/index.html", "http://apple.com/index.html").should.equal(false)
Utils.isLocalAssetUrl("file:///Desktop/index.html", "http://apple.com/index.html").should.equal(true)
Utils.isLocalAssetUrl("http://apple.com/index.html", "http://127.0.0.1/index.html").should.equal(false)

0 comments on commit db96a5e

Please sign in to comment.
You can’t perform that action at this time.