UNPKG

isv-page-json-to-xtpl

Version:

abs 将页面 json 转换成 html

156 lines (126 loc) 3.49 kB
var pageJsonToXtpl = require('../index'); var fs = require('fs'); var fixtures = require('./fixtures/kimi'); const chai = require('chai'); const expect = chai.expect; const sinon = require('sinon'); const co = require('co'); function getJson(url) { var testJson = fs.readFileSync(url); return JSON.parse(testJson.toString()); } describe('render mods test', ()=> { describe('#renderModulesNoAir()', ()=> { it('return html', (done)=> { const modules = fixtures.modules; co(function*() { pageJsonToXtpl.setType('kissy'); const content = yield pageJsonToXtpl.renderModulesNoAir({modules}); expect(content).to.be.a('string'); expect(content).to.have.string('section'); expect(content).to.have.string('$.use'); done(); }) }); }); describe('#renderModules()', ()=> { it('return html', (done)=> { var config = { "layout": { "version": "v1", "modules": fixtures.modules } }; co(function*() { pageJsonToXtpl.setType('kissy'); const d = yield pageJsonToXtpl.renderModules(config); // console.log(d); done(); }); }) }); }); describe('solution', ()=> { describe('#renderSolution()', ()=> { it('should render solution', (done)=> { const solution = { assets: fixtures.solutionAssets }; pageJsonToXtpl.setType('kissy'); return pageJsonToXtpl.renderSolution(solution).then( function(content) { expect(content).to.have.string('<script>'); done(); } ); }) }); }); describe('run', ()=> { describe('#run()', ()=> { it('return html', (done)=> { co(function*() { var pageData = { "spmA": "spmA", "spmB": "spmB", "keywords": [ "demo" ], "description": "demo", "title": "demo", "layout": { "version": "v1", "modules": fixtures.modules }, "abs": { "solution": { "default":{ assets: fixtures.solutionAssets, "terminalType": "mobile", "language": "zh-cn", "charset": "utf8" } } } }; pageJsonToXtpl.setType('kissy'); var html = yield pageJsonToXtpl.run(pageData); // console.log(html); done(); }); }); it('return pc html', (done)=> { co(function*() { var pageData = { "spmA": "spmA", "spmB": "spmB", "keywords": [ "demo" ], "description": "demo", "title": "demo", "layout": { "version": "v1", "modules": fixtures.modules }, "abs": { "solution": { "default":{ assets: fixtures.solutionAssets, "terminalType": "mobile", "language": "zh-cn", "charset": "utf8" } } } }; pageJsonToXtpl.setType('kissy'); var html = yield pageJsonToXtpl.run(pageData,{terminalType:'pc'}); expect(html).to.be.a('object'); expect(html.success).to.be.ok; expect(html.content).to.include('weex-mod-define-min.js','kissy/k','kg/global-util','/kg/fiz-assets'); done(); }); }) }); });