mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add spec for ext_url filter, refactor
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
Darkswarm.filter "ext_url", () ->
|
||||
Darkswarm.filter "ext_url", ->
|
||||
urlPattern = /^https?:\/\//
|
||||
(url, prefix) ->
|
||||
if (!url)
|
||||
return url
|
||||
if (url.match(urlPattern))
|
||||
return url
|
||||
if !url || url.match(urlPattern)
|
||||
url
|
||||
else
|
||||
return prefix + url
|
||||
prefix + url
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
describe "ensuring absolute URL", ->
|
||||
filter = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
inject ($filter) ->
|
||||
filter = $filter 'ext_url'
|
||||
|
||||
it "returns null when no URL given", ->
|
||||
expect(filter(null, "http://")).toBeNull()
|
||||
|
||||
it "returns the URL as-is for http URLs", ->
|
||||
expect(filter("http://example.com", "http://")).toEqual "http://example.com"
|
||||
|
||||
it "returns the URL as-is for https URLs", ->
|
||||
expect(filter("https://example.com", "https://")).toEqual "https://example.com"
|
||||
|
||||
it "returns with URL with prefix added when a relative URL is given", ->
|
||||
expect(filter("example.com", "http://")).toEqual "http://example.com"
|
||||
Reference in New Issue
Block a user