UNPKG

isv-page-json-to-xtpl

Version:

abs 将页面 json 转换成 html

97 lines (78 loc) 2.13 kB
var pageJsonToXtpl = require('../index'); var fs = require('fs'); var fixtures = require('./fixtures/rx'); const chai = require('chai'); const expect = chai.expect; const sinon = require('sinon'); const co = require('co'); // pageJsonToXtpl.type = 'rx'; function getJson(url) { var testJson = fs.readFileSync(url); return JSON.parse(testJson.toString()); } describe('render mods test', ()=> { describe('#renderModulesNoAir()', ()=> { it('return html', (done)=> { var modules = fixtures.modules; co(function*() { pageJsonToXtpl.setType('rx'); const content = yield pageJsonToXtpl.renderModulesNoAir(modules); expect(content).to.have.string('RxInit'); done(); }) }); }); describe('#renderModules()', ()=> { it('return html', (done)=> { const config = { "layout": { "version": "v1", "modules": fixtures.modules }, assets:fixtures.solutionAssets }; co(function*() { pageJsonToXtpl.setType('rx'); const content = yield pageJsonToXtpl.renderModules(config); // console.log(content); done(); }) }) }); }); describe('solution', ()=> { describe('#renderSolution()', ()=> { it('should render solution', (done)=> { const solution = { assets: fixtures.solutionAssets }; pageJsonToXtpl.setType('rx'); return pageJsonToXtpl.renderSolution(solution).then( function(d) { // console.log(d); done(); } ); }) }); }); describe('run', ()=> { // 根据assets进行渲染分类 pageJsonToXtpl.setTypeByAssets(fixtures.solutionAssets); describe('#run()', ()=> { it('return mobile html', (done)=> { co(function*() { var html = yield pageJsonToXtpl.run(fixtures.pageData); // console.log(html); done(); }); }); it('return pc html', (done)=> { co(function*() { var html = yield pageJsonToXtpl.run(fixtures.pageData,{terminalType:'pc'}); // console.log(html); done(); }); }) }); });