XuZinan 2 年之前
父節點
當前提交
c1cce16371

+ 1 - 1
jest.config.js

@@ -3,6 +3,6 @@ module.exports = {
   preset: 'jest-puppeteer',
   globals: { // 全局变量,你可以在项目中直接使用它们
     testURL: `http://localhost:${process.env.PORT || 8000}`,
-    JWT_TOKEN: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJRCI6NywiVXNlcm5hbWUiOiJhZG1pbiIsIlBhc3N3b3JkIjoiNDI5N2Y0NGIxMzk1NTIzNTI0NWIyNDk3Mzk5ZDdhOTMiLCJEZXAiOiIxMzUiLCJleHAiOjE2NjA3NTA5MzMsImlzcyI6Imdpbi1ibG9nIn0.YG8q72a1P6bYql24gn-dIng11iDRxXsJtEXK26jbRpY'
+    JWT_TOKEN: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJRCI6NywiVXNlcm5hbWUiOiJhZG1pbiIsIlBhc3N3b3JkIjoiNDI5N2Y0NGIxMzk1NTIzNTI0NWIyNDk3Mzk5ZDdhOTMiLCJEZXAiOiIxMzUiLCJleHAiOjE2NjE0MTk5MDYsImlzcyI6Imdpbi1ibG9nIn0.YwdRc9hb9gZuCmgaHkaADONx4RrjpwAjRvnc3Z6Ev14'
   },
 };

+ 27 - 23
src/pages/PurchaseAdmin/PurchaseList/Approval/ApprovalModal.js

@@ -33,29 +33,32 @@ function AddModal(props) {
   const [type, setType] = useState({});
 
   const handleOk = () => {
-    form.validateFields().then(fieldsValue => {
-      let values = { ...fieldsValue, id: data.id };
-      values.project_name = fieldsValue.project_name;
-      values.flow_id = Number(fieldsValue.flow_id);
-      values.type_id = Number(fieldsValue.type_id);
-      // 获得flow下第一个node的id
-      values.node_id = flowList.find(item => item.id == values.flow_id).Nodes[0].id;
-      //项目分类为不为研发时
-      if (fieldsValue.type_id != 7) {
-        values.industry_id = Number(fieldsValue.industry_id);
-        let [location, location_code] = fieldsValue.location.split('##');
-        values.location = location;
-        values.location_code = location_code;
-        values.project_full_code = `${codes.type}${codes.industry}${codes.location}${codes.name}${codes.version}`;
-      }
-      if (fieldsValue.author) {
-        values.author = Number(fieldsValue.author.split('||')[0]);
-        values.author_dep_id = Number(fieldsValue.author.split('||')[1]);
-      } else {
-        values.author = null;
-      }
-      onOk(values);
-    });
+    form.validateFields().then(
+      fieldsValue => {
+        let values = { ...fieldsValue, id: data.id };
+        values.project_name = fieldsValue.project_name;
+        values.flow_id = Number(fieldsValue.flow_id);
+        values.type_id = Number(fieldsValue.type_id);
+        // 获得flow下第一个node的id
+        values.node_id = flowList.find(item => item.id == values.flow_id).Nodes[0].id;
+        //项目分类为不为研发时
+        if (fieldsValue.type_id != 7) {
+          values.industry_id = Number(fieldsValue.industry_id);
+          let [location, location_code] = fieldsValue.location.split('##');
+          values.location = location;
+          values.location_code = location_code;
+          values.project_full_code = `${codes.type}${codes.industry}${codes.location}${codes.name}${codes.version}`;
+        }
+        if (fieldsValue.author) {
+          values.author = Number(fieldsValue.author.split('||')[0]);
+          values.author_dep_id = Number(fieldsValue.author.split('||')[1]);
+        } else {
+          values.author = null;
+        }
+        onOk(values);
+      },
+      error => {}
+    );
   };
 
   const renderTreeNodes = data => {
@@ -232,6 +235,7 @@ function AddModal(props) {
 
   return (
     <Modal
+      className="addModal"
       title="项目立项"
       confirmLoading={loading}
       maskClosable={false}

+ 8 - 1
src/pages/PurchaseAdmin/PurchaseList/Approval/DetailModal.js

@@ -123,7 +123,14 @@ function DetailModal(props) {
   );
 
   return (
-    <Modal title="项目详情" width={800} visible={visible} onCancel={onClose} footer={null}>
+    <Modal
+      className="detailModal"
+      title="项目详情"
+      width={800}
+      visible={visible}
+      onCancel={onClose}
+      footer={null}
+    >
       {/* {data.type_id != 7 && renderDetail()} */}
       {renderDetail()}
       {data.audit_status != 0 && renderAuth()}

+ 36 - 0
src/pages/PurchaseAdmin/PurchaseList/Approval/test/List.test.js

@@ -0,0 +1,36 @@
+describe('List', () => {
+  beforeAll(async () => {
+    jest.setTimeout(20000);
+  });
+
+  beforeEach(async () => {
+    await page.goto(`${testURL}/bom/#/bom/home/approval/list?JWT-TOKEN=${JWT_TOKEN}`, {
+      waitUntil: 'networkidle2',
+    });
+    await page.waitFor(500);
+  });
+
+  it('list加载成功', async () => {
+    await page.waitForSelector('.ant-table');
+  });
+
+  it('新增项目窗口', async () => {
+    // await page.waitForSelector(
+    //   '.antd-pro-pages-purchase-admin-purchase-list-approval-list-btns > button'
+    // );
+    await page.click('.antd-pro-pages-purchase-admin-purchase-list-approval-list-btns > button');
+    await page.waitForSelector('.addModal');
+    await page.click('.addModal .ant-modal-close');
+  });
+
+  it('项目详情', async () => {
+    // await page.waitForSelector('.ant-table-wrapper tbody > tr:nth-child(1) > td:nth-child(10) > a');
+    await page.click('.ant-table-wrapper tbody > tr:nth-child(1) > td:nth-child(10) > a');
+    await page.waitForSelector('.detailModal');
+    await page.click('.detailModal .ant-modal-close');
+  });
+
+  xit('搜索', async () => {
+    
+  });
+});

+ 96 - 0
src/pages/PurchaseAdmin/PurchaseList/Approval/test/ListAdd.test.js

@@ -0,0 +1,96 @@
+describe('ListAdd', () => {
+  beforeAll(async () => {
+    jest.setTimeout(20000);
+  });
+
+  beforeEach(async () => {
+    await page.goto(`${testURL}/bom/#/bom/home/approval/list?JWT-TOKEN=${JWT_TOKEN}`, {
+      waitUntil: 'networkidle2',
+    });
+    await page.waitFor(500);
+  });
+
+  it('list加载成功', async () => {
+    await page.waitForSelector('.ant-table');
+  });
+
+  it('窗口打开关闭', async () => {
+    await page.click('.antd-pro-pages-purchase-admin-purchase-list-approval-list-btns > button');
+    await page.waitForSelector('.addModal');
+    await page.click('.addModal .ant-modal-close');
+    await page.waitFor(500);
+    let mask = await page.evaluate(() => document.getElementsByClassName('ant-modal-mask').length);
+    expect(mask).toBe(0);
+  });
+
+  it('取消按钮', async () => {
+    await page.click('.antd-pro-pages-purchase-admin-purchase-list-approval-list-btns > button');
+    await page.waitForSelector('.addModal');
+    await page.click('.addModal button.ant-btn.ant-btn-default');
+    await page.waitFor(500);
+    let mask = await page.evaluate(() => document.getElementsByClassName('ant-modal-mask').length);
+    expect(mask).toBe(0);
+  });
+
+  it('确定表单校验', async () => {
+    var errorList, input, error;
+    //全空
+    await page.click('.antd-pro-pages-purchase-admin-purchase-list-approval-list-btns > button');
+    await page.waitForSelector('.addModal');
+    await page.click('.addModal button.ant-btn.ant-btn-primary');
+    errorList = await page.evaluate(
+      () => document.getElementsByClassName('ant-form-item-explain-error').length
+    );
+    expect(errorList).toBe(8);
+
+    //项目简称
+    input = await page.$('#name');
+    await input.focus();
+    await page.click('.addModal button.ant-btn.ant-btn-primary');
+    await page.waitFor(500);
+    errorList = await page.evaluate(
+      () => document.getElementsByClassName('ant-form-item-explain-error').length
+    );
+    expect(errorList).toBe(6);
+    await page.waitForSelector('#name[value="VVV"]');
+    await input.click({ clickCount: 3 });
+    await input.type('11');
+    await page.click('.addModal button.ant-btn.ant-btn-primary');
+    await page.waitFor(500);
+    errorList = await page.evaluate(
+      () => document.getElementsByClassName('ant-form-item-explain-error').length
+    );
+    expect(errorList).toBe(7);
+    error = await page.evaluate(
+      () => document.getElementsByClassName('ant-form-item-explain-error')[5].innerHTML
+    );
+    expect(error).toBe('项目简称只能是英文字符');
+    await page.waitForSelector('#name[value="11V"]');
+    await input.click({ clickCount: 3 });
+    await input.type('tst');
+    await page.click('.addModal button.ant-btn.ant-btn-primary');
+    await page.waitFor(500);
+    await page.waitForSelector('#name[value="TST"]');
+
+    //项目名称
+    input = await page.$('#project_name');
+    await input.focus();
+    await input.type('页面测试');
+    await page.click('.addModal button.ant-btn.ant-btn-primary');
+    await page.waitFor(500);
+    errorList = await page.evaluate(
+      () => document.getElementsByClassName('ant-form-item-explain-error').length
+    );
+    expect(errorList).toBe(5);
+
+    //项目类别  售前
+
+/*
+    /html/body/div[4]/div/div/div/div[2]/div[1]/div/div/div[1]/div
+    /html/body/div[5]/div/div/div/div[2]/div[1]/div/div/div[1]/div
+    
+    body > div:nth-child(7) > div > div > div > div.rc-virtual-list > div.rc-virtual-list-holder > div > div > div.ant-select-item.ant-select-item-option.ant-select-item-option-active > div
+    body > div:nth-child(8) > div > div > div > div.rc-virtual-list > div.rc-virtual-list-holder > div > div > div.ant-select-item.ant-select-item-option.ant-select-item-option-active > div
+*/
+  });
+});