Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Commit

Permalink
Rely on serverside API to provide error handling. Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Boxall committed Jan 8, 2013
1 parent eb59c93 commit 1f27104
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
9 changes: 4 additions & 5 deletions api/resizeImages.js
Expand Up @@ -19,20 +19,19 @@ var $ = Mobify.$
var bits = [defaults.host];

if (defaults.projectName) {
var projectId = "project-" + defaults.projectName;
bits.push(projectId);
bits.push("project-" + defaults.projectName);
}

if (options.cacheHours && !isNaN(parseInt(options.cacheHours)) ) {
bits.push('c' + parseInt(options.cacheHours))
if (options.cacheHours) {
bits.push('c' + options.cacheHours);
}

if (options.format) {
bits.push(options.format + (options.quality || ''));
}

if (options.maxWidth) {
bits.push(options.maxWidth)
bits.push(options.maxWidth);

if (options.maxHeight) {
bits.push(options.maxHeight);
Expand Down
48 changes: 21 additions & 27 deletions tests/index.html
Expand Up @@ -449,20 +449,14 @@ <h2 id="qunit-userAgent"></h2>
equal(got, vow);
});


test('Mobify.getImageURL cached string', function() {
expect(2);

var got = Mobify.getImageURL('http://test/image.jpg')
, vow = '//ir0.mobify.com/http://test/image.jpg';

equal(got, vow);

got = Mobify.getImageURL('http://test/image.jpg', {maxWidth: 320,cacheHours:'8'});
vow = '//ir0.mobify.com/c8/320/http://test/image.jpg';

equal(got, vow);
});
test('Mobify.getImageURL cached string', 2, function() {
var url = 'http://test/image.jpg';
var result1 = Mobify.getImageURL(url, {maxWidth: '320', cacheHours: '8'});
var result2 = Mobify.getImageURL(url, {maxWidth: 320, cacheHours: 8});
var expected = '//ir0.mobify.com/c8/320/' + url;
equal(result1, expected);
equal(result2, expected);
});

test('Mobify.getImageURL - projectName set on Mobify.conf.data', function() {
expect(1);
Expand All @@ -481,19 +475,19 @@ <h2 id="qunit-userAgent"></h2>

test('Mobify.getImageURL - projectName and cache expiry set', function() {
expect(1);

try {
Mobify.$.fn.resizeImages.defaults.projectName = 'testing';

got = Mobify.getImageURL('http://test/image.jpg',
got = Mobify.getImageURL('http://test/image.jpg',
{maxWidth: 320, cacheHours:8});
vow = "//ir0.mobify.com/project-testing/c8/320/http://test/image.jpg";

equal(got, vow);
} finally {
delete Mobify.$.fn.resizeImages.defaults.projectName;
}
});
});


module('enhance');
Expand Down Expand Up @@ -602,15 +596,15 @@ <h2 id="qunit-userAgent"></h2>

urlmatch = Mobify.urlmatch;

/*
* Takes a path, an urlmatch path expression or regular expression and an
* expectation about whether these should match and calls qunit's
* `equal()` on the result of running urlmatch with the given expression
/*
* Takes a path, an urlmatch path expression or regular expression and an
* expectation about whether these should match and calls qunit's
* `equal()` on the result of running urlmatch with the given expression
* window.location faked to the given path on http://a.com/
*/
testUrlMatch = function(path, expression, expected) {
var match, matched, symbol, url;

// Set up urlmatch with a mocked window object with a mocked location object
// set to `url`
url = "http://a.com" + path;
Expand All @@ -620,10 +614,10 @@ <h2 id="qunit-userAgent"></h2>
matched = !!match();
symbol = (expected != false ? "☑": "☒");

expression = (typeof expression === 'string' ?
expression = (typeof expression === 'string' ?
'"' + expression + '"' : expression);

equal(matched, expected,
equal(matched, expected,
symbol + " : " + path + " : " + expression);
};

Expand Down Expand Up @@ -657,7 +651,7 @@ <h2 id="qunit-userAgent"></h2>
testUrlMatch("/abb/c", "/a.b/c", false);
testUrlMatch("/aab/c", "/a+b/*/", false);
testUrlMatch("/a$b/c", "/a$b/*", true);

// RegExp test suite
testUrlMatch("/a", /a/, true);
testUrlMatch("/a/", /^\/a\//, true);
Expand All @@ -667,9 +661,9 @@ <h2 id="qunit-userAgent"></h2>
testUrlMatch("/a/some/other/other/stuff/b/", /^\/a.*b(\/)?$/, true)

// Things other than path expressions and RegExps
equal(urlmatch({}), false,
equal(urlmatch({}), false,
"passing the empty object to urlmatch makes it return false");
equal(urlmatch("/a/b/c")(5), false,
equal(urlmatch("/a/b/c")(5), false,
"passing a number to urlmatch makes it return false");
}); //test

Expand Down

0 comments on commit 1f27104

Please sign in to comment.