test_preview_page.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Created by Tony on 2018/4/8.
  3. */
  4. let test = require('tape');
  5. import JpcEx from "../../../modules/reports/rpt_component/jpc_ex";
  6. import JV from "../../../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 = 232; //重庆09年建筑 09表
  24. // let demoRptId = 229; //重庆09年建筑 封2表
  25. let pagesize = "A4";
  26. // demoPrjId = 720; //QA: DW3
  27. // demoPrjId = 1626; //QA:
  28. //*/
  29. let userId_Leng = 1142; //小冷User Id
  30. let userId_Dft = userId_Leng;
  31. /*/
  32. let userId_Dft = 76075;
  33. //*/
  34. let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade");
  35. let fs = require('fs');
  36. //设置Date Format函数
  37. fs.readFile(__dirname.slice(0, __dirname.length - 18) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
  38. eval(data);
  39. });
  40. //*
  41. test('测试 - 预览: ', function (t) {
  42. rptTplFacade.getRptTemplate(demoRptId).then(function(rptTpl) {
  43. if (rptTpl) {
  44. try {
  45. let printCom = JpcEx.createNew();
  46. let defProperties = rpt_cfg;
  47. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pagesize;
  48. printCom.initialize(rptTpl);
  49. let pageRst = printCom.outputAsPreviewPage(rptTpl, defProperties);
  50. if (pageRst) {
  51. fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/previewPageResult.jsp");
  52. t.pass('pass with succeed!');
  53. t.end();
  54. } else {
  55. console.log("oh! no pages were created!");
  56. t.pass('pass with no page!');
  57. t.end();
  58. }
  59. } catch (ex) {
  60. console.log(ex);
  61. t.pass('pass with exception!');
  62. t.end();
  63. }
  64. } else {
  65. t.pass('no template was found!');
  66. t.end();
  67. }
  68. });
  69. });
  70. //*/
  71. test('close the connection', function (t) {
  72. setTimeout(function () {
  73. mongoose.disconnect();
  74. t.pass('closing db connection');
  75. t.end();
  76. }, 1000);
  77. // mongoose.disconnect();
  78. // t.pass('closing db connection');
  79. // t.end();
  80. });