'use strict'; const Hexo = require('hexo'); const hexo = new Hexo(); function btoa(str) { return Buffer.from(str).toString('base64'); } describe('next-url', () => { const nextUrl = require('../../scripts/helpers/next-url').bind(hexo); before(() => { hexo.config.url = 'https://example.com'; hexo.url_for = require('hexo/dist/plugins/helper/url_for').bind(hexo); }); it('text', () => { nextUrl('/child/', 'Text').should.eql('Text'); }); it('icon', () => { nextUrl('/child/', '').should.eql(''); }); it('class', () => { nextUrl('/child/', 'Text', { class: 'theme-link' }).should.eql('Text'); }); it('external', () => { nextUrl('https://theme-next.js.org', 'Text').should.eql('Text'); }); it('decodeURI', () => { (() => nextUrl('https://theme-next.js.org', 'A % B')).should.not.throw(); }); it('exturl enabled', () => { hexo.theme.exturl = true; const encoded = btoa('https://theme-next.js.org'); nextUrl('https://theme-next.js.org', 'Text').should.eql(`Text`); }); it('class with exturl enabled', () => { hexo.theme.exturl = true; const encoded = btoa('https://theme-next.js.org'); nextUrl('https://theme-next.js.org', 'Text', { class: 'theme-link' }).should.eql(`Text`); }); });