Skip to content

Commit

Permalink
test: should encode url and permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Sep 10, 2019
1 parent 64e9e2d commit 8ea4751
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/scripts/hexo/hexo.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ describe('Hexo', () => {
].join('\n')));
});

it('_generate() - should encode url', () => {
hexo.config.url = 'http://fôo.com';

hexo.theme.setView('test.swig', '{{ url }}');

hexo.extend.generator.register('test', () => ({
path: 'bár',
layout: 'test'
}));

return hexo._generate().then(() => checkStream(route.get('bár'),
'http://xn--fo-8ja.com/b%C3%A1r'));
});

it('_generate() - do nothing if it\'s generating', () => {
const spy = sinon.spy();
hexo.extend.generator.register('test', spy);
Expand Down
10 changes: 10 additions & 0 deletions test/scripts/models/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ describe('Category', () => {
return Category.removeById(data._id);
}));

it('permalink - should be encoded', () => {
hexo.config.url = 'http://fôo.com';
return Category.insert({
name: 'bár'
}).then(data => {
data.permalink.should.eql('http://xn--fo-8ja.com/' + data.path);
return Category.removeById(data._id);
});
});

it('posts - virtual', () => Post.insert([
{source: 'foo.md', slug: 'foo'},
{source: 'bar.md', slug: 'bar'},
Expand Down
11 changes: 11 additions & 0 deletions test/scripts/models/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ describe('Page', () => {
return Page.removeById(data._id);
}));

it('permalink - should be encoded', () => {
hexo.config.url = 'http://fôo.com';
return Page.insert({
source: 'foo',
path: 'bár'
}).then(data => {
data.permalink.should.eql('http://xn--fo-8ja.com/b%C3%A1r');
return Page.removeById(data._id);
});
});

it('full_source - virtual', () => Page.insert({
source: 'foo',
path: 'bar'
Expand Down
12 changes: 12 additions & 0 deletions test/scripts/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ describe('Post', () => {
});
});

it('permalink - should be encoded', () => {
hexo.config.url = 'http://fôo.com';
return Post.insert({
source: 'foo.md',
slug: 'bár'
}).then(data => {
data.permalink.should.eql('http://xn--fo-8ja.com/b%C3%A1r');
hexo.config.url = 'http://yoursite.com';
return Post.removeById(data._id);
});
});

it('permalink - virtual - when set relative_link', () => {
hexo.config.root = '/';
hexo.config.relative_link = true;
Expand Down
10 changes: 10 additions & 0 deletions test/scripts/models/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ describe('Tag', () => {
return Tag.removeById(data._id);
}));

it('permalink - should be encoded', () => {
hexo.config.url = 'http://fôo.com';
return Tag.insert({
name: 'bár'
}).then(data => {
data.permalink.should.eql('http://xn--fo-8ja.com/' + data.path);
return Tag.removeById(data._id);
});
});

it('posts - virtual', () => Post.insert([
{source: 'foo.md', slug: 'foo'},
{source: 'bar.md', slug: 'bar'},
Expand Down

0 comments on commit 8ea4751

Please sign in to comment.