From c0227826692ffdfe1f2c32b70f2b06ac3e41bd4c Mon Sep 17 00:00:00 2001 From: wangxuepeng Date: Fri, 22 Dec 2023 15:05:02 +0800 Subject: [PATCH] * Add unit test for screenModel::buildCardChart. --- module/screen/test/model/buildcardchart.php | 62 +++++++++++++++++++ module/screen/test/yaml/project_for_card.yaml | 29 +++++++++ 2 files changed, 91 insertions(+) create mode 100755 module/screen/test/model/buildcardchart.php create mode 100644 module/screen/test/yaml/project_for_card.yaml diff --git a/module/screen/test/model/buildcardchart.php b/module/screen/test/model/buildcardchart.php new file mode 100755 index 0000000000..0d299cfac4 --- /dev/null +++ b/module/screen/test/model/buildcardchart.php @@ -0,0 +1,62 @@ +#!/usr/bin/env php +config('project_for_card')->gen(50); +zdTable('story')->gen(20); +zdTable('bug')->gen(20); + +/** + +title=测试 screenModel->getchartoption(); +timeout=0 +cid=1 + +- 测试type为card以及统计方式类型为value的图表是否显示正确,目前不存在统计方式为value的图表。 @1 +- 测试type为card以及统计方式类型为count的图表是否显示正确,目前不存在统计方式为count的图表。 @1 +- 测试type为card以及统计方式类型为sum的图表是否显示正确,生成的数据项数量是否正确。 @50 + +*/ + +$screen = new screenTest(); + +function getComponetAndChart($screen, $valueType = array(), $filters = array()) +{ + global $tester; + $componets = $screen->getAllComponent($filters); + foreach($componets as $componet) + { + if(!isset($componet->sourceID)) continue; + $type = $componet->chartConfig->package == 'Tables' ? 'pivot' : 'chart'; + $table = $type == 'chart' ? TABLE_CHART : TABLE_PIVOT; + $chart = $tester->dao->select('*')->from($table)->where('id')->eq($componet->sourceID)->fetch(); + + if(!$chart) continue; + if(!empty($valueType)) + { + $setting = json_decode($chart->settings); + if($setting && isset($setting->value)) + { + if(isset($valueType['type']) && $setting->value->type != $valueType['type']) continue; + if(isset($valueType['egg']) && $setting->value->agg != $valueType['egg']) continue; + } + } + + return array($componet, $chart); + } + return array(null, null); +} + +$filter12 = array('type' => 'card'); + +list($component13, $chart13) = getComponetAndChart($screen, array('type' => 'value'), $filter12); +r(is_null($component13) || is_null($chart13)) && p('') && e(1); //测试type为card以及统计方式类型为value的图表是否显示正确,目前不存在统计方式为value的图表。 + +list($component14, $chart14) = getComponetAndChart($screen, array('type' => 'count'), $filter12); +r(is_null($component14) || is_null($chart14)) && p('') && e(1); //测试type为card以及统计方式类型为count的图表是否显示正确,目前不存在统计方式为count的图表。 + +list($component15, $chart15) = getComponetAndChart($screen, array('egg' => 'sum'), $filter12); +$screen->buildCardChart($component15, $chart15); +r($component15->option->dataset) && p('') && e('50'); //测试type为card以及统计方式类型为sum的图表是否显示正确,生成的数据项数量是否正确。 \ No newline at end of file diff --git a/module/screen/test/yaml/project_for_card.yaml b/module/screen/test/yaml/project_for_card.yaml new file mode 100644 index 0000000000..6498d7fe1a --- /dev/null +++ b/module/screen/test/yaml/project_for_card.yaml @@ -0,0 +1,29 @@ +title: table zt_project +author: Wang XuePeng +version: "1.0" +fields: + - field: type + range: sprint + - field: status + range: closed + - field: closedDate + range: "(-1M)-(w):1D" + type: timestamp + prefix: "" + postfix: "" + loop: 0 + format: "YYYY-MM-DD hh:mm:ss" + - field: end + range: "(-2M)-(w):1D" + type: timestamp + prefix: "" + postfix: "" + loop: 0 + format: "YYYY-MM-DD hh:mm:ss" + - field: realEnd + range: "(-1W)-(w):1D" + type: timestamp + prefix: "" + postfix: "" + loop: 0 + format: "YYYY-MM-DD hh:mm:ss"