You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/__test__/Database/DeepCloneObjects.test.ts

49 lines
1.9 KiB

import { Board } from "../../src/DatabaseServices/Entity/Board";
import { LayerTableRecord } from "../../src/DatabaseServices/LayerTableRecord";
import { PhysicalMaterialRecord } from "../../src/DatabaseServices/PhysicalMaterialRecord";
// 需要放在最后面,否则会循环依赖
import { Database } from "../../src/DatabaseServices/Database";
describe('DeepCloneObjects', () =>
{
const db = new Database(true, true, true);
const br = new Board;
db.ModelSpace.Append(br);
test('DeepCloneObjects的新实体和原实体图层需相同', () =>
{
expect(br.Layer === db.DefaultLayer.Id).toBeTruthy(); // 图层等于默认图层
const newLayer = new LayerTableRecord();
newLayer.Name = "新图层1";
db.LayerTable.Add(newLayer);
br.Layer = newLayer.Id;
const brs = db.DeepCloneObjects([br], db.ModelSpace) as Board[];
const newBr = brs[0];
expect(newBr.Layer === br.Layer).toBeTruthy();
expect(newBr.Layer === db.DefaultLayer.Id).toBeFalsy();
//默认图层被镜像后 应该还在默认图层
db.LayerTable.Current = newLayer.Id;
br.Layer = db.DefaultLayer.Id;
let brs2 = db.DeepCloneObjects([br], db.ModelSpace) as Board[];
expect(brs2[0].Layer === br.Layer).toBeTruthy();
});
test('DeepCloneObjects的新实体和原实体材质需相同', () =>
{
expect(br.Material === db.MaterialTable.CurBoardMtl).toBeTruthy(); // 材质等于默认材质
const newMtl = new PhysicalMaterialRecord();
newMtl.Name = "新材质1";
db.MaterialTable.Add(newMtl);
br.Material = newMtl.Id;
const brs = db.DeepCloneObjects([br], db.ModelSpace) as Board[];
const newBr = brs[0];
expect(newBr.Material === br.Material).toBeTruthy();
expect(newBr.Material === db.MaterialTable.CurBoardMtl).toBeFalsy();
});
});