Skip to content

Commit

Permalink
feat: 增加获取原mip链接方法-对应cacheUrl (#293)
Browse files Browse the repository at this point in the history
* feat: 增加获取原mip链接方法-对应cacheUrl

* feat: 增加单测

* feat: 修改版本号
  • Loading branch information
jennyliang220 authored Apr 2, 2018
1 parent 9060946 commit 46b1f90
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mip",
"version": "1.0.78",
"version": "1.0.79",
"description": "mobile instant page",
"main": "dist/mip.js",
"dependencies": {},
Expand Down
10 changes: 10 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,19 @@ define(function (require) {
return uri;
}

/**
* 获取页面原mip url,可以将页面mip-cache url处理为原页面
*
* @return {string} 原mip页URL
*/
function getOriginalUrl() {
return parseCacheUrl(window.location.href);
}

return {
parseCacheUrl: parseCacheUrl,
makeCacheUrl: makeCacheUrl,
getOriginalUrl: getOriginalUrl,
fn: fn,
dom: require('./dom/dom'),
event: require('./dom/event'),
Expand Down
16 changes: 16 additions & 0 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ define(function (require) {
expect(util.parseCacheUrl(cacheUrl)).to.equal(url);
});
});

describe('.getOriginalUrl', function () {
var stub = sinon.stub(util, "getOriginalUrl", function (str) {
return util.parseCacheUrl(str);
});

it('mip url', function () {
expect(util.getOriginalUrl('https://www.mipengine.com')).to.equal('https://www.mipengine.com');
expect(util.getOriginalUrl('http://www.mipengine.com')).to.equal('http://www.mipengine.com');
expect(util.getOriginalUrl('http://www.mipengine.com/c/index.html')).to.equal('http://www.mipengine.com/c/index.html');
});
it('mip-Cache url', function () {
expect(util.getOriginalUrl('//mipcache.bdstatic.com/c/www.mipengine.org')).to.equal('http://www.mipengine.org');
expect(util.getOriginalUrl('//mipcache.bdstatic.com/c/s/www.mipengine.org')).to.equal('https://www.mipengine.org');
});
})
});
});

Expand Down

0 comments on commit 46b1f90

Please sign in to comment.