|
|
@@ -0,0 +1,148 @@
|
|
|
+package com.usoftchina.saas.ui.test;
|
|
|
+
|
|
|
+import com.usoftchina.saas.ui.po.Component;
|
|
|
+import com.usoftchina.saas.ui.po.View;
|
|
|
+import com.usoftchina.saas.ui.service.ComponentService;
|
|
|
+import com.usoftchina.saas.ui.service.ViewService;
|
|
|
+import com.usoftchina.saas.utils.JsonUtils;
|
|
|
+import org.junit.After;
|
|
|
+import org.junit.Before;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author yingp
|
|
|
+ * @date 2018/10/10
|
|
|
+ */
|
|
|
+@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
+@SpringBootTest
|
|
|
+public class ViewServiceTest {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ViewService viewService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ComponentService componentService;
|
|
|
+
|
|
|
+ private String viewName = "test.form";
|
|
|
+
|
|
|
+ @Before
|
|
|
+ public void generateData() {
|
|
|
+ viewData();
|
|
|
+ part1Data();
|
|
|
+ part2Data();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void viewData() {
|
|
|
+ View view = new View();
|
|
|
+ view.setName(viewName);
|
|
|
+ view.setDescription("测试表单");
|
|
|
+
|
|
|
+ Map<String, Object> config = new HashMap<>(2);
|
|
|
+ config.put("xtype", "container");
|
|
|
+ config.put("layout", "vbox");
|
|
|
+ view.setConfig(config);
|
|
|
+
|
|
|
+ view = viewService.save(view);
|
|
|
+
|
|
|
+ System.out.println(JsonUtils.toJsonString(view));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void part1Data() {
|
|
|
+ Component part1 = new Component();
|
|
|
+ part1.setViewName(viewName);
|
|
|
+ part1.setOrderNum(1);
|
|
|
+ part1.setDescription("抬头Form");
|
|
|
+ Map<String, Object> part1Config = new HashMap<>(3);
|
|
|
+ part1Config.put("xtype", "form");
|
|
|
+ part1Config.put("height", 180);
|
|
|
+ part1Config.put("layout", "column");
|
|
|
+ part1.setConfig(part1Config);
|
|
|
+ part1 = componentService.save(part1);
|
|
|
+ System.out.println(JsonUtils.toJsonString(part1));
|
|
|
+
|
|
|
+ Component field1 = new Component();
|
|
|
+ field1.setViewName(viewName);
|
|
|
+ field1.setOrderNum(1);
|
|
|
+ field1.setDescription("编号");
|
|
|
+ field1.setParentId(part1.get_id());
|
|
|
+ Map<String, Object> field1Config = new HashMap<>(4);
|
|
|
+ field1Config.put("xtype", "textfield");
|
|
|
+ field1Config.put("name", "code");
|
|
|
+ field1Config.put("columnWidth", 0.25);
|
|
|
+ field1Config.put("fieldLabel", "编号");
|
|
|
+ field1.setConfig(field1Config);
|
|
|
+ componentService.save(field1);
|
|
|
+
|
|
|
+ Component field2 = new Component();
|
|
|
+ field2.setViewName(viewName);
|
|
|
+ field2.setOrderNum(2);
|
|
|
+ field2.setDescription("单据日期");
|
|
|
+ field2.setParentId(part1.get_id());
|
|
|
+ Map<String, Object> field2Config = new HashMap<>(3);
|
|
|
+ field2Config.put("xtype", "textfield");
|
|
|
+ field1Config.put("name", "docDate");
|
|
|
+ field2Config.put("columnWidth", 0.25);
|
|
|
+ field2Config.put("fieldLabel", "单据日期");
|
|
|
+ field2.setConfig(field2Config);
|
|
|
+ componentService.save(field2);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void part2Data() {
|
|
|
+ Component part2 = new Component();
|
|
|
+ part2.setViewName(viewName);
|
|
|
+ part2.setOrderNum(2);
|
|
|
+ part2.setDescription("明细Grid");
|
|
|
+ part2.setChildrenProperty("columns");
|
|
|
+ Map<String, Object> part2Config = new HashMap<>(3);
|
|
|
+ part2Config.put("xtype", "grid");
|
|
|
+ part2Config.put("flex", 1);
|
|
|
+ part2Config.put("title", "商品清单");
|
|
|
+ part2.setConfig(part2Config);
|
|
|
+ part2 = componentService.save(part2);
|
|
|
+ System.out.println(JsonUtils.toJsonString(part2));
|
|
|
+
|
|
|
+ Component col1 = new Component();
|
|
|
+ col1.setViewName(viewName);
|
|
|
+ col1.setOrderNum(1);
|
|
|
+ col1.setDescription("商品编号");
|
|
|
+ col1.setParentId(part2.get_id());
|
|
|
+ Map<String, Object> col1Config = new HashMap<>(4);
|
|
|
+ col1Config.put("xtype", "triggercolumn");
|
|
|
+ col1Config.put("dataIndex", "pr_code");
|
|
|
+ col1Config.put("text", "商品编号");
|
|
|
+ col1.setConfig(col1Config);
|
|
|
+ componentService.save(col1);
|
|
|
+
|
|
|
+ Component col2 = new Component();
|
|
|
+ col2.setViewName(viewName);
|
|
|
+ col2.setOrderNum(2);
|
|
|
+ col2.setDescription("单位");
|
|
|
+ col2.setParentId(part2.get_id());
|
|
|
+ Map<String, Object> col2Config = new HashMap<>(3);
|
|
|
+ col2Config.put("xtype", "gridcolumn");
|
|
|
+ col2Config.put("dataIndex", "pr_unit");
|
|
|
+ col2Config.put("text", "单位");
|
|
|
+ col2.setConfig(col2Config);
|
|
|
+ componentService.save(col2);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void getViewConfig() {
|
|
|
+ Object config = viewService.getDeepConfig(viewName);
|
|
|
+ System.out.println(JsonUtils.toJsonString(config));
|
|
|
+ // {"layout":"vbox","xtype":"container","items":[{"layout":"column","xtype":"form","height":180,"items":[{"name":"code","columnWidth":0.25,"xtype":"textfield","fieldLabel":"编号"},{"columnWidth":0.25,"xtype":"textfield","fieldLabel":"单据日期"}]},{"title":"商品清单","flex":1,"xtype":"grid","columns":[{"dataIndex":"pr_code","xtype":"triggercolumn","text":"商品编号"},{"dataIndex":"pr_unit","xtype":"gridcolumn","text":"单位"}]}]}
|
|
|
+ }
|
|
|
+
|
|
|
+ @After
|
|
|
+ public void deleteData() {
|
|
|
+ componentService.deleteByView(viewName);
|
|
|
+ viewService.deleteView(viewName);
|
|
|
+ }
|
|
|
+}
|