test_preview_page.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * Created by Tony on 2018/4/8.
  3. */
  4. let test = require('tape');
  5. const JpcEx = require("../../../modules/reports/rpt_component/jpc_ex");
  6. const JV = require("../../../modules/reports/rpt_component/jpc_value_define");
  7. let config = require("../../../config/config.js");
  8. config.setupDb(process.env.NODE_ENV);
  9. let mongoose = require("mongoose");
  10. let fileUtils = require("../../../modules/common/fileUtils");
  11. let path = require('path');
  12. let dbm = require("../../../config/db/db_manager");
  13. let rpt_cfg = require('./rpt_cfg');
  14. dbm.connect(process.env.NODE_ENV);
  15. //统一引用models
  16. fileUtils.getGlobbedFiles('../../../modules/all_models/*.js').forEach(function(modelPath) {
  17. require(path.resolve(modelPath));
  18. });
  19. let cfgCacheUtil = require("../../../config/cacheCfg");
  20. cfgCacheUtil.setupDftCache();
  21. let fsUtil = require("../../../public/fsUtil");
  22. // let demoPrjId = - 1;
  23. // let demoRptId = 275; //重庆09年建筑 09表
  24. // let demoRptId = 229; //重庆09年建筑 封2表
  25. // let demoRptId = 28; //09 重庆养护2018
  26. let demoRptId = 68; //01-2 重庆养护2018
  27. let pagesize = "A4";
  28. // demoPrjId = 720; //QA: DW3
  29. // demoPrjId = 1626; //QA:
  30. //*/
  31. // let userId_Leng = "59cdf14a0034a1000ba52b97"; //小冷User Id 换成_id了
  32. let userId_Leng = "5c3ffa9aa0a92732f41216e0"; //小冷User Id (养护的)
  33. let userId_Dft = userId_Leng;
  34. /*/
  35. let userId_Dft = "595328da1934dc327cad08eb";
  36. //*/
  37. let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
  38. let fs = require('fs');
  39. //设置Date Format函数
  40. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  41. eval(data);
  42. });
  43. //*
  44. test('测试 - 预览: ', function (t) {
  45. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  46. if (rptTpl) {
  47. try {
  48. let printCom = JpcEx.createNew();
  49. let defProperties = rpt_cfg;
  50. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  51. printCom.initialize(rptTpl);
  52. let pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
  53. if (pageRst) {
  54. fsUtil.writeObjToFile(pageRst, "D:/GitHome/YangHuCost/tmp/previewPageResult.jsp");
  55. t.pass('pass with succeed!');
  56. t.end();
  57. } else {
  58. console.log("oh! no pages were created!");
  59. t.pass('pass with no page!');
  60. t.end();
  61. }
  62. } catch (ex) {
  63. console.log(ex);
  64. t.pass('pass with exception!');
  65. t.end();
  66. }
  67. } else {
  68. t.pass('no template was found!');
  69. t.end();
  70. }
  71. });
  72. });
  73. //*/
  74. test('close the connection', function (t) {
  75. setTimeout(function () {
  76. mongoose.disconnect();
  77. t.pass('closing db connection');
  78. t.end();
  79. }, 1000);
  80. // mongoose.disconnect();
  81. // t.pass('closing db connection');
  82. // t.end();
  83. });