|
@@ -264,6 +264,138 @@ describe('test/app/service/report_memory.test.js', () => {
|
|
|
assert(a === codeIndex[i]);
|
|
|
});
|
|
|
});
|
|
|
+ it('test filter', function* () {
|
|
|
+ const ctx = app.mockContext(mockData);
|
|
|
+ const orgData = {
|
|
|
+ test: [
|
|
|
+ {a: 'aaa', b: 0, c: true, order: 1},
|
|
|
+ {a: 'aaa', b: 1, c: false, order: 2},
|
|
|
+ {a: 'aaa', b: 2, c: false, order: 3},
|
|
|
+ {a: 'bbb', b: 3, c: true, order: 4},
|
|
|
+ {a: 'bbb', b: null, c: true, order: 5},
|
|
|
+ {a: 'ccc', b: 0, c: false, order: 6},
|
|
|
+ {a: 'ccc', b: -1, c: false, order: 7},
|
|
|
+ {a: 'ddd', b: 8, c: true, order: 8},
|
|
|
+ ]
|
|
|
+ };
|
|
|
+ let data, result;
|
|
|
+
|
|
|
+ // test boolean;
|
|
|
+ const b1 = {
|
|
|
+ table: 'test',
|
|
|
+ condition: [{ field: "c", type: "bool", value: 'false'}]
|
|
|
+ };
|
|
|
+ data = JSON.parse(JSON.stringify(orgData));
|
|
|
+ reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], b1);
|
|
|
+ result = ctx.helper._.map(data.test, 'order');
|
|
|
+ assert(ctx.helper._.isEqual(result, [2, 3, 6, 7]));
|
|
|
+
|
|
|
+ const b2 = {
|
|
|
+ table: 'test',
|
|
|
+ condition: [{ field: "c", type: "bool", value: 'true'}]
|
|
|
+ };
|
|
|
+ data = JSON.parse(JSON.stringify(orgData));
|
|
|
+ reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], b2);
|
|
|
+ result = ctx.helper._.map(data.test, 'order');
|
|
|
+ assert(ctx.helper._.isEqual(result, [1, 4, 5, 8]));
|
|
|
+
|
|
|
+ // test number
|
|
|
+ const n1 = {
|
|
|
+ table: 'test',
|
|
|
+ condition: [{ field: "b", type: "num", operate: 'non-zero'}]
|
|
|
+ };
|
|
|
+ data = JSON.parse(JSON.stringify(orgData));
|
|
|
+ reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n1);
|
|
|
+ result = ctx.helper._.map(data.test, 'order');
|
|
|
+ assert(ctx.helper._.isEqual(result, [2, 3, 4, 7, 8]));
|
|
|
+
|
|
|
+ const n2 = {
|
|
|
+ table: 'test',
|
|
|
+ condition: [{ field: "b", type: "num", operate: '=', value: 1}]
|
|
|
+ };
|
|
|
+ data = JSON.parse(JSON.stringify(orgData));
|
|
|
+ reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n2);
|
|
|
+ result = ctx.helper._.map(data.test, 'order');
|
|
|
+ assert(ctx.helper._.isEqual(result, [2]));
|
|
|
+
|
|
|
+ const n3 = {
|
|
|
+ table: 'test',
|
|
|
+ condition: [{ field: "b", type: "num", operate: '>', value: 1}]
|
|
|
+ };
|
|
|
+ data = JSON.parse(JSON.stringify(orgData));
|
|
|
+ reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n3);
|
|
|
+ result = ctx.helper._.map(data.test, 'order');
|
|
|
+ assert(ctx.helper._.isEqual(result, [3, 4, 8]));
|
|
|
+
|
|
|
+ const n4 = {
|
|
|
+ table: 'test',
|
|
|
+ condition: [{ field: "b", type: "num", operate: '>=', value: 1}]
|
|
|
+ };
|
|
|
+ data = JSON.parse(JSON.stringify(orgData));
|
|
|
+ reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n4);
|
|
|
+ result = ctx.helper._.map(data.test, 'order');
|
|
|
+ assert(ctx.helper._.isEqual(result, [2, 3, 4, 8]));
|
|
|
+
|
|
|
+ const n5 = {
|
|
|
+ table: 'test',
|
|
|
+ condition: [{ field: "b", type: "num", operate: '<', value: 1}]
|
|
|
+ };
|
|
|
+ data = JSON.parse(JSON.stringify(orgData));
|
|
|
+ reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n5);
|
|
|
+ result = ctx.helper._.map(data.test, 'order');
|
|
|
+ assert(ctx.helper._.isEqual(result, [1, 6, 7]));
|
|
|
+
|
|
|
+ const n6 = {
|
|
|
+ table: 'test',
|
|
|
+ condition: [{ field: "b", type: "num", operate: '<=', value: 1}]
|
|
|
+ };
|
|
|
+ data = JSON.parse(JSON.stringify(orgData));
|
|
|
+ reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], n6);
|
|
|
+ result = ctx.helper._.map(data.test, 'order');
|
|
|
+ assert(ctx.helper._.isEqual(result, [1, 2, 6, 7]));
|
|
|
+
|
|
|
+ // string
|
|
|
+ const s1 = {
|
|
|
+ table: 'test',
|
|
|
+ condition: [{ field: "a", type: "str", operate: '=', value: 'aaa'}]
|
|
|
+ };
|
|
|
+ data = JSON.parse(JSON.stringify(orgData));
|
|
|
+ reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s1);
|
|
|
+ result = ctx.helper._.map(data.test, 'order');
|
|
|
+ assert(ctx.helper._.isEqual(result, [1, 2, 3]));
|
|
|
+
|
|
|
+ const s2 = {
|
|
|
+ table: 'test',
|
|
|
+ condition: [{ field: "a", type: "str", operate: 'part', value: 'b'}]
|
|
|
+ };
|
|
|
+ data = JSON.parse(JSON.stringify(orgData));
|
|
|
+ reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s2);
|
|
|
+ result = ctx.helper._.map(data.test, 'order');
|
|
|
+ assert(ctx.helper._.isEqual(result, [4, 5]));
|
|
|
+
|
|
|
+ const s3 = {
|
|
|
+ table: 'test',
|
|
|
+ condition: [{ field: "a", type: "str", operate: 'enum', value: ['ccc', 'ddd']}]
|
|
|
+ };
|
|
|
+ data = JSON.parse(JSON.stringify(orgData));
|
|
|
+ reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], s3);
|
|
|
+ result = ctx.helper._.map(data.test, 'order');
|
|
|
+ assert(ctx.helper._.isEqual(result, [6, 7, 8]));
|
|
|
+
|
|
|
+ // mix
|
|
|
+ const m1 = {
|
|
|
+ table: 'test',
|
|
|
+ condition: [
|
|
|
+ { field: "c", type: "bool", value: 'true'},
|
|
|
+ { field: "b", type: "num", operate: 'non-zero'},
|
|
|
+ { field: "a", type: "str", operate: 'enum', value: ['aaa', 'ddd']},
|
|
|
+ ]
|
|
|
+ };
|
|
|
+ data = JSON.parse(JSON.stringify(orgData));
|
|
|
+ reportDataAnalysis.analysisObj.filter.fun(ctx, data, [], m1);
|
|
|
+ result = ctx.helper._.map(data.test, 'order');
|
|
|
+ assert(ctx.helper._.isEqual(result, [8]));
|
|
|
+ });
|
|
|
// it('test gatherChapter custom', function* () {
|
|
|
// const ctx = app.mockContext(mockData);
|
|
|
//
|
|
@@ -317,7 +449,7 @@ describe('test/app/service/report_memory.test.js', () => {
|
|
|
const ctx = app.mockContext(mockData);
|
|
|
|
|
|
const define = reportDataAnalysis.analysisDefine;
|
|
|
- assert(define.length === 5);
|
|
|
+ assert(define.length === 7);
|
|
|
assert(define[0].key === 'changeSort');
|
|
|
assert(define[0].name === reportDataAnalysis.analysisObj.changeSort.name);
|
|
|
assert(define[0].hint === reportDataAnalysis.analysisObj.changeSort.hint);
|
|
@@ -328,20 +460,20 @@ describe('test/app/service/report_memory.test.js', () => {
|
|
|
assert(define[2].name === reportDataAnalysis.analysisObj.sortGcl.name);
|
|
|
assert(define[2].hint === reportDataAnalysis.analysisObj.sortGcl.hint);
|
|
|
|
|
|
- const x = {
|
|
|
- count: 7,
|
|
|
- gclSum: {
|
|
|
- name: '第100章至700章清单合计',
|
|
|
- order: 1,
|
|
|
- },
|
|
|
- custom: [
|
|
|
- {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2},
|
|
|
- {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
|
|
|
- {name: '计日工合计', node_type: '计日工', order: 4},
|
|
|
- {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', node_type: '暂列金额', order: 5},
|
|
|
- {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
|
|
|
- ],
|
|
|
- };
|
|
|
- ctx.helper.saveBufferFile(JSON.stringify(x, "", "\t"), ctx.app.baseDir + '/mem_stage_pos.json');
|
|
|
+ // const x = {
|
|
|
+ // count: 7,
|
|
|
+ // gclSum: {
|
|
|
+ // name: '第100章至700章清单合计',
|
|
|
+ // order: 1,
|
|
|
+ // },
|
|
|
+ // custom: [
|
|
|
+ // {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2},
|
|
|
+ // {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
|
|
|
+ // {name: '计日工合计', node_type: '计日工', order: 4},
|
|
|
+ // {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', node_type: '暂列金额', order: 5},
|
|
|
+ // {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
|
|
|
+ // ],
|
|
|
+ // };
|
|
|
+ // ctx.helper.saveBufferFile(JSON.stringify(x, "", "\t"), ctx.app.baseDir + '/mem_stage_pos.json');
|
|
|
});
|
|
|
});
|