testRpt.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Created by Tony on 2017/3/17.
  3. */
  4. var test = require('tape');
  5. var mongoose = require('mongoose');
  6. var JV = require('../../../modules/reports/rpt_component/Jpc_ValueDefine');
  7. var Template = require('../../../modules/reports/models/rpt_template');
  8. var TemplateData = require('../../../modules/reports/models/rpt_temp_data');
  9. var JpcEx = require('../../../modules/reports/rpt_component/JpcEx');
  10. var rptUtil = require("../../../modules/reports/util/rpt_util");
  11. test('test get report pages function: ', function (t) {
  12. rptUtil.setReportDefaultCache();
  13. t.pass('just pass for cache setup!');
  14. t.end();
  15. });
  16. test('test get report pages function: ', function (t) {
  17. var grp_id = "SC";
  18. var tpl_id = "07_1";
  19. var pageSize = "A4";
  20. var rptTpl = null, tplData = null;
  21. Template.getPromise(grp_id, tpl_id).then(function(rst) {
  22. //console.log(rst);
  23. rptTpl = rst;
  24. console.log(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
  25. t.equal(rptTpl != null, true);
  26. return TemplateData.getPromise(tpl_id);
  27. }).then(function(rst){
  28. //console.log(rst);
  29. tplData = rst;
  30. t.equal(tplData != null, true);
  31. if (tplData) {
  32. var printCom = JpcEx.createNew();
  33. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
  34. var defProperties = rptUtil.getReportDefaultCache();
  35. printCom.initialize(rptTpl);
  36. printCom.analyzeData(rptTpl, tplData, defProperties);
  37. var maxPages = printCom.totalPages;
  38. var pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
  39. t.equal(pageRst != null, true);
  40. }
  41. t.end();
  42. }).catch(function (err) {
  43. console.log("err: " + err);
  44. t.end();
  45. })
  46. });
  47. test('finish', function (t) {
  48. mongoose.disconnect();
  49. t.pass('closing db connection');
  50. t.end();
  51. });