test_preview_page.js 2.9 KB

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