Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Add some tests for resolvePath
Browse files Browse the repository at this point in the history
Skip absolute paths, since those are broken
  • Loading branch information
dfreedm committed Jan 15, 2014
1 parent 0c9e446 commit 527311f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/js/resolvePath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2013 The Polymer Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/

suite('resolvePath', function() {
var assert = chai.assert;

var work = document.createElement('div');
var a = document.createElement('a');
var resolver, apResolver;

function dirname(levels) {
levels = levels || 1;
var pp = location.href.split('/');
for (var i = 0; i < levels; i++) {
pp.pop();
}
return pp.join('/');
}

// resolvePath may not remove '../', pass through an anchor to clean
function urlResolve(resolver, path) {
var junkyPath = resolver.resolvePath(path);
a.href = junkyPath;
// magical url voodoo
return a.href;
}

suiteSetup(function() {
wrap(document.body).appendChild(work);
Polymer('x-resolve');
Polymer('x-resolve-ap');
work.innerHTML = '<polymer-element name="x-resolve"></polymer-element><polymer-element name="x-resolve-ap" assetpath="foo/bar/baz/"></polymer-element>';
CustomElements.takeRecords();
resolver = document.createElement('x-resolve');
apResolver = document.createElement('x-resolve-ap');
});

suiteTeardown(function() {
wrap(document.body).removeChild(work);
});

test('relative path', function() {
assert.equal(urlResolve(resolver, 'foo.js'), dirname() + '/foo.js');
assert.equal(urlResolve(resolver, 'bar/baz'), dirname() + '/bar/baz');
assert.equal(urlResolve(resolver, '../test/foo'), dirname() + '/foo');
});

test.skip('absolute path', function() {
assert.equal(resolver.resolvePath('http://example.com/bar'), 'http://example.com/bar');
});

test('assetpath relative path', function() {
assert.equal(urlResolve(apResolver, 'foo.js'), dirname() + '/foo/bar/baz/foo.js');
assert.equal(urlResolve(apResolver, 'bar/baz'), dirname() + '/foo/bar/baz/bar/baz');
assert.equal(urlResolve(apResolver, '../test/foo'), dirname() + '/foo/bar/test/foo');
});

test.skip('assetpath absolute path', function() {
assert.equal(urlResolve(apResolver, 'http://example.com/bar'), 'http://example.com/bar');
});

});
1 change: 1 addition & 0 deletions test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<script src="js/events.js"></script>
<script src="js/styling.js"></script>
<script src="js/mdv-syntax.js"></script>
<script src="js/resolvePath.js"></script>
<!-- -->
<script>
document.addEventListener('WebComponentsReady', function() {
Expand Down

0 comments on commit 527311f

Please sign in to comment.