From d5194154335d6cb30edca9b648083069faf9778c Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 10 Oct 2016 03:47:49 +0200 Subject: Squashed 'thirdparty/URI.js/' content from commit b77c167 git-subtree-dir: thirdparty/URI.js git-subtree-split: b77c167bc201575956ad409333ff032e504b8044 --- test/test_jquery.js | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 test/test_jquery.js (limited to 'test/test_jquery.js') diff --git a/test/test_jquery.js b/test/test_jquery.js new file mode 100644 index 000000000..b6ab8c1be --- /dev/null +++ b/test/test_jquery.js @@ -0,0 +1,141 @@ +(function() { + 'use strict'; + /*global document, URI, $, test, equal, ok */ + + module('jQuery.URI', { + setup: function() { + var links = [ + 'an HTTP link', + 'an HTTPS link', + 'some pdf', + 'hello world', + 'directories', + 'directories', + 'Mail me', + 'some javascript', + 'jump to anchor', + 'some jpeg', + 'some svg', + '
' + ]; + + $('
' + links.join('') + '
') + .appendTo(document.body); + $('
foo
') + .appendTo(document.body); + + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = '/nonexistant.js'; + document.getElementById('testestest').appendChild(script); + }, + teardown: function() { + var t = $('#testestest'); + t.next().remove(); + t.remove(); + } + }); + test('.uri()', function() { + var $links = $('#testestest'), + $first = $links.children().first(), + uri = $first.uri(), + _uri = URI('/hello.world'); + + ok(uri !== _uri, 'different URI instances'); + var __uri = $first.uri(_uri); + ok(uri !== _uri, 'different URI instances'); + ok(uri === __uri, 'same URI instances'); + equal($first.attr('href'), _uri.toString(), 'equal URI'); + + }); + test('filtering with :uri()', function() { + var $links = $('#testestest'); + + // find using accessor and "begins with" comparison + equal($('a:uri(href^=#anc)').length, 1, '$(selector) Anchor Link'); + equal($links.find(':uri(href^=#anc)').length, 1, '.find(selector) Anchor Link'); + + // find using accessor and "ends with" comparison + equal($(':uri(href$=.css)').length, 1, ':uri(href$=.css)'); + + // find using accessor and "contains" comparison + equal($(':uri(href *= /hello/)').length, 1, ':uri(href *= /hello/)'); + + // find using accessor and "equals" comparison + equal($links.find(':uri(protocol=https)').length, 1, ':uri(protocol=https)'); + equal($links.find(':uri(protocol=http)').length, 3, ':uri(protocol=http)'); + + // directory match with trailing slash + equal($links.find(':uri(directory *= /two/)').length, 2, ':uri(directory *= /two/)'); + + // find using URI.is() + equal($links.find(':uri(relative)').length, 5, ':uri(relative)'); + equal($links.find(':uri(is:relative)').length, 5, ':uri(is:relative)'); + equal($links.find(':uri(is: relative)').length, 5, ':uri(is:relative)'); + + // find using URI.equal() + // This syntax breaks Sizzle, probably because it's looking for a nested pseudo ":http" + //equal($links.find(':uri(equals:http://example.org/hello/foo/../world.html)').length, 1, ':uri(equals:$url$)'); + equal($links.find(':uri(equals:"http://example.org/hello/foo/../world.html")').length, 1, ':uri(equals:$url$)'); + equal($links.find(':uri(equals: "http://example.org/hello/foo/../world.html")').length, 1, ':uri(equals:$url$)'); + + // find URNs + equal($links.find(':uri(urn)').length, 2, ':uri(urn)'); + + // .is() + equal($links.children('script').is(':uri(suffix=js)'), true, '.is(\':uri(suffix=js)\')'); + equal($links.children('form').is(':uri(suffix=php)'), true, '.is(\':uri(suffix=php)\')'); + + // .has() + equal($('div').has(':uri(suffix=js)').length, 1, '.has(\':uri(suffix=js)\')'); + }); + test('.attr("href")', function() { + var $links = $('#testestest'), + $first = $links.children().first(), + first = $first.get(0), + uri = $first.uri(), + href = function(elem) { + return elem.getAttribute('href'); + }; + + if (!$.support.hrefNormalized) { + href = function(elem) { + return elem.getAttribute('href', 2); + }; + } + + ok(uri instanceof URI, 'instanceof URI'); + equal(href(first), uri.toString(), 'URI equals href'); + + // test feedback to DOM element + uri.hostname('example.com'); + ok($first.uri() === uri, 'URI persisted'); + equal(href(first), uri.toString(), 'transparent href update'); + + // test feedback from DOM element + $first.attr('href', 'http://example.net/'); + ok($first.uri() === uri, 'URI persisted'); + equal(href(first), uri.toString(), 'transparent href update'); + }); + test('.attr("uri:accessor")', function() { + var $links = $('#testestest'), + $first = $links.children().first(), + uri = $first.uri(), + href = function(elem) { + return elem.getAttribute('href'); + }; + + if (!$.support.hrefNormalized) { + href = function(elem) { + return elem.getAttribute('href', 2); + }; + } + + equal($first.attr('uri:hostname'), 'example.org', 'reading uri:hostname'); + $first.attr('uri:hostname', 'example.com'); + equal($first.attr('uri:hostname'), 'example.com', 'changed uri:hostname'); + equal($first.is(':uri(hostname=example.com)'), true, ':uri() after changed uri:hostname'); + ok($first.uri() === uri, 'URI persisted'); + }); + +})(); \ No newline at end of file -- cgit v1.2.3