helper.test.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. describe('test/app/extend/helper.test.js', () => {
  11. it('ValidTemplateCode test', function () {
  12. const ctx = app.mockContext();
  13. assert(ctx.helper.ValidTemplateCode('z') === true);
  14. assert(ctx.helper.ValidTemplateCode('Z') === true);
  15. assert(ctx.helper.ValidTemplateCode('-') === false);
  16. assert(ctx.helper.ValidTemplateCode('1') === false);
  17. assert(ctx.helper.ValidTemplateCode('z1') === true);
  18. assert(ctx.helper.ValidTemplateCode('z1-') === false);
  19. assert(ctx.helper.ValidTemplateCode('zav') === true);
  20. assert(ctx.helper.ValidTemplateCode('z1-e') === true);
  21. assert(ctx.helper.ValidTemplateCode('z1-e-1') === true);
  22. });
  23. it('ValidTemplateIndexCode test', function () {
  24. const ctx = app.mockContext();
  25. assert(ctx.helper.ValidTemplateIndexCode('z2-d-d-1~z2-d-d-5 高填方路段处理 同z2-d-c-1~z2-d-c-5') === false);
  26. });
  27. it('validMatchCode test', function () {
  28. const ctx = app.mockContext();
  29. assert(ctx.helper.validMatchCode('1-1-1'));
  30. assert(ctx.helper.validMatchCode('1-1-X'));
  31. assert(ctx.helper.validMatchCode('1-X-1'));
  32. assert(!ctx.helper.validMatchCode('1-1-'));
  33. assert(!ctx.helper.validMatchCode('X-1-1'));
  34. assert(!ctx.helper.validMatchCode('1-人-1'));
  35. });
  36. it('loadJsonFile test', function () {
  37. const ctx = app.mockContext();
  38. const vJ = ctx.helper.loadJsonFile(app.baseDir + '/test/app/extend/test.json');
  39. assert(vJ.bills);
  40. assert(vJ.properties);
  41. });
  42. it('operationJson test', function () {
  43. const ctx = app.mockContext();
  44. let testjson = {name: 'hello'};
  45. const result = ctx.helper.operationJson(testjson,'ok','world');
  46. assert(result.ok === 'world');
  47. });
  48. });