template_node.test.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict';
  2. /**
  3. * 指标节点业务逻辑 单元测试
  4. *
  5. * @author Mai
  6. * @data 2018/4/20
  7. * @version
  8. */
  9. const { app, assert } = require('egg-mock/bootstrap');
  10. // excel解析
  11. const excel = require('node-xlsx');
  12. const paramConst = require('../../../app/const/template_param');
  13. describe('test/app/service/template_node.test.js', () => {
  14. it('_parseSheetData test xls File', function () {
  15. const ctx = app.mockContext();
  16. const fileName = app.baseDir + '/test/app/service/test.xls';
  17. const sheets = excel.parse(fileName);
  18. const nodes = [], indexes = [], params = [];
  19. for (const sheet of sheets) {
  20. ctx.service.templateNode._parseSheetData(sheet, nodes, indexes, params);
  21. }
  22. assert(nodes.length === 5);
  23. assert(indexes.length === 42);
  24. assert(params.length === 59);
  25. });
  26. it('_parseSheetData test xlsx File', function () {
  27. const ctx = app.mockContext();
  28. const fileName = app.baseDir + '/test/app/service/test.xlsx';
  29. const sheets = excel.parse(fileName);
  30. const nodes = [], indexes = [], params = [];
  31. for (const sheet of sheets) {
  32. ctx.service.templateNode._parseSheetData(sheet, nodes, indexes, params);
  33. }
  34. assert(nodes.length === 3);
  35. assert(indexes.length === 12);
  36. assert(params.length === 21);
  37. });
  38. it('importData test xls File', function* () {
  39. const ctx = app.mockContext();
  40. const fileName = app.baseDir + '/test/app/service/test.xls';
  41. const sheets = excel.parse(fileName), templateId = 0;
  42. yield ctx.service.templateNode.importData(sheets, templateId);
  43. const nodes = yield ctx.service.templateNode.getAllDataByCondition({where: {template_id: templateId}});
  44. assert(nodes.length === 5);
  45. const indexes = yield ctx.service.templateIndex.getAllDataByCondition({where: {template_id: templateId}});
  46. assert(indexes.length === 42);
  47. const params = yield ctx.service.templateParam.getAllDataByCondition({where: {template_id: templateId}});
  48. assert(params.length === 57);
  49. });
  50. it('importData test xlsx File', function* () {
  51. const ctx = app.mockContext();
  52. const fileName = app.baseDir + '/test/app/service/test.xlsx';
  53. const sheets = excel.parse(fileName), templateId = 0;
  54. yield ctx.service.templateNode.importData(sheets, templateId);
  55. const nodes = yield ctx.service.templateNode.getAllDataByCondition({where: {template_id: templateId}});
  56. assert(nodes.length === 3);
  57. const indexes = yield ctx.service.templateIndex.getAllDataByCondition({where: {template_id: templateId}});
  58. assert(indexes.length === 12);
  59. const params = yield ctx.service.templateParam.getAllDataByCondition({where: {template_id: templateId}});
  60. assert(params.length === 31);
  61. });
  62. });