Skip to content

Commit

Permalink
test(asset-bundle): add "assetBundle asset node" and "load assetBundl…
Browse files Browse the repository at this point in the history
…e" related test cases
  • Loading branch information
yyc-git committed May 6, 2019
1 parent b80fb75 commit d113c47
Show file tree
Hide file tree
Showing 16 changed files with 521 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ let reducer = (action, state) =>

let render =
({state, send}: ReasonReact.self('a, 'b, 'c), (closeFunc, submitFunc)) => {
Js.log("render sissssssss");
let languageType =
LanguageEditorService.unsafeGetType |> StateLogicService.getEditorState;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,20 @@ module Method = {
assetTreeChildrenNodeArr
|> Js.Array.filter(node => node |> TextureNodeAssetService.isTextureNode);

let assetBundleAssetTreeChildrenNodeArr =
assetTreeChildrenNodeArr
|> Js.Array.filter(node =>
node |> AssetBundleNodeAssetService.isAssetBundleNode
);

ArrayService.fastConcatArrays([|
_sortByName(folderAssetTreeChildrenNodeArr, engineState),
_sortByName(wdbAssetTreeChildrenNodeArr, engineState),
_sortByName(materialAssetTreeChildrenNodeArr, engineState),
_sortByName(scriptEventFunctionAssetTreeChildrenNodeArr, engineState),
_sortByName(scriptAttributeAssetTreeChildrenNodeArr, engineState),
_sortByName(textureAssetTreeChildrenNodeArr, engineState),
_sortByName(assetBundleAssetTreeChildrenNodeArr, engineState),
|]);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ let _handleAssetWDBType =
(editorState, engineState) |> resolve;
});

/* TODO test */
let _handleAssetAssetBundleType =
(
(fileName, assetBundleArrayBuffer),
Expand All @@ -135,7 +134,12 @@ let _handleAssetAssetBundleType =
selectedFolderNodeInAssetTree,
AssetBundleNodeAssetService.buildNode(
~nodeId=assetBundleNodeId,
~name=FileNameService.getBaseName(fileName),
~name=
OperateTreeAssetLogicService.getUniqueNodeName(
FileNameService.getBaseName(fileName),
selectedFolderNodeInAssetTree,
engineState,
),
~assetBundle=assetBundleArrayBuffer,
~type_=
switch (FileNameService.getExtName(fileName)) {
Expand Down
24 changes: 23 additions & 1 deletion src/service/record/editor/asset/AssetBundleNodeAssetService.re
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ let getTypeStr = ({type_}: assetBundleNodeData) =>
| WAB => "WAB"
};

let getNodeData = node =>
switch (node) {
| AssetBundleNode(_, nodeData) => nodeData
| _ =>
WonderLog.Log.fatal(
LogUtils.buildFatalMessage(
~description={j|should be assetBundle node|j},
~reason="",
~solution={j||j},
~params={j||j},
),
)
};

let buildNodeData = (~name, ~assetBundle, ~type_) => {
name,
assetBundle,
Expand All @@ -23,4 +37,12 @@ let buildNode = (~nodeId, ~name, ~assetBundle, ~type_) =>
let buildNodeByNodeData = (~nodeId, ~nodeData) =>
AssetBundleNode(nodeId, nodeData);

let rename = (~name, ~nodeData): assetBundleNodeData => {...nodeData, name};
let rename = (~name, ~nodeData): assetBundleNodeData => {...nodeData, name};

let isAssetBundleNode = node =>
switch (node) {
| AssetBundleNode(_, _) => true
| _ => false
};

let getAssetBundle = node => getNodeData(node).assetBundle;
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MainEditorAssetHeader->load assetBundle test load asset bundle fix bug if load the same asset bundle in the same dir, should handle their name to be unique 1`] = `
<article
className="wonder-asset-assetChildren"
>
<article
className="wonder-asset-fileBox "
onClick={[Function]}
>
<div
className="box-image"
>
<img
onDragStart={[Function]}
src="./public/img/assetBundle.png"
/>
</div>
<div
className="item-text "
>
<span>
A
</span>
</div>
</article>
<article
className="wonder-asset-fileBox "
onClick={[Function]}
>
<div
className="box-image"
>
<img
onDragStart={[Function]}
src="./public/img/assetBundle.png"
/>
</div>
<div
className="item-text "
>
<span>
A 1
</span>
</div>
</article>
</article>
`;

exports[`MainEditorAssetHeader->load assetBundle test load asset bundle should add to asset children 1`] = `
<article
className="wonder-asset-assetChildren"
>
<article
className="wonder-asset-fileBox "
onClick={[Function]}
>
<div
className="box-image"
>
<img
onDragStart={[Function]}
src="./public/img/assetBundle.png"
/>
</div>
<div
className="item-text "
>
<span>
A
</span>
</div>
</article>
</article>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MainEditorAssetHeader->remove assetBundle
select assetBundle;
click remove-button;
should remove it from assetTreeRoot 1`] = `
<article
className="wonder-asset-assetChildren"
/>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
open Wonder_jest;

open Expect;

open Expect.Operators;

open Sinon;

open Js.Promise;

let _ =
describe("MainEditorAssetHeader->load assetBundle", () => {
let sandbox = getSandboxDefaultVal();

beforeEach(() => {
sandbox := createSandbox();

MainEditorSceneTool.initState(~sandbox, ());
MainEditorAssetTool.buildFakeFileReader();
});

afterEach(() => restoreSandbox(refJsObjToSandbox(sandbox^)));

describe("test load asset bundle", () => {
testPromise("should add to asset children", () =>
MainEditorAssetUploadTool.loadOneAssetBundle(~fileName="A.rab", ())
|> then_(uploadedAssetBundleNodeId =>
BuildComponentTool.buildAssetChildrenNode()
|> ReactTestTool.createSnapshotAndMatch
|> resolve
)
);

testPromise("should store assetBundle arrayBuffer", () => {
let assetBundle = Js.Typed_array.ArrayBuffer.make(20);

MainEditorAssetUploadTool.loadOneAssetBundle(
~fileName="A.rab",
~assetBundle,
(),
)
|> then_(uploadedAssetBundleNodeId =>
MainEditorAssetAssetBundleNodeTool.getAssetBundle(
uploadedAssetBundleNodeId,
)
|> StateLogicService.getEditorState
|> expect == assetBundle
|> resolve
);
});

describe("fix bug", () =>
testPromise(
"if load the same asset bundle in the same dir, should handle their name to be unique",
() =>
MainEditorAssetUploadTool.loadOneAssetBundle(~fileName="A.rab", ())
|> then_(uploadedAssetBundleNodeId =>
MainEditorAssetUploadTool.loadOneAssetBundle(
~fileName="A.rab",
(),
)
|> then_(uploadedAssetBundleNodeId =>
BuildComponentTool.buildAssetChildrenNode()
|> ReactTestTool.createSnapshotAndMatch
|> resolve
)
)
)
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
open Wonder_jest;

open Expect;

open Expect.Operators;

open Sinon;

open Js.Promise;

let _ =
describe("MainEditorAssetHeader->remove assetBundle", () => {
let sandbox = getSandboxDefaultVal();

beforeEach(() => {
sandbox := createSandbox();
MainEditorSceneTool.initState(~sandbox, ());
MainEditorAssetTool.buildFakeFileReader();
});

afterEach(() => restoreSandbox(refJsObjToSandbox(sandbox^)));

describe(
{|
select assetBundle;
click remove-button;
|},
() =>
testPromise("should remove it from assetTreeRoot", () =>
MainEditorAssetUploadTool.loadOneAssetBundle()
|> then_(uploadedAssetBundleNodeId => {
MainEditorAssetHeaderOperateNodeTool.removeAssetBundleNode(
~assetBundleNodeId=uploadedAssetBundleNodeId,
(),
);

BuildComponentTool.buildAssetChildrenNode()
|> ReactTestTool.createSnapshotAndMatch
|> resolve;
})
)
);
});
10 changes: 10 additions & 0 deletions test/integration/asset/tool/MainEditorAssetAssetBundleNodeTool.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let getName = (nodeId, editorState) =>
AssetBundleNodeAssetService.getNodeName(
OperateTreeAssetEditorService.unsafeFindNodeById(nodeId, editorState)
|> AssetBundleNodeAssetService.getNodeData,
);

let getAssetBundle = (nodeId, editorState) =>
AssetBundleNodeAssetService.getAssetBundle(
OperateTreeAssetEditorService.unsafeFindNodeById(nodeId, editorState),
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ let selectMaterialNode =

let selectFolderNode =
(~nodeId, ~event=Obj.magic(-1), ~dispatchFunc=TestTool.getDispatch(), ()) =>
FileBox.Method.onSelect(nodeId, dispatchFunc, event);

let selectAssetBundleNode =
(~nodeId, ~event=Obj.magic(-1), ~dispatchFunc=TestTool.getDispatch(), ()) =>
FileBox.Method.onSelect(nodeId, dispatchFunc, event);
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ let removeScriptAttributeNode =
) =>
removeNode(~dispatchFunc, ~uiState, ~nodeId=scriptAttributeNodeId, ());

let removeAssetBundleNode =
(
~dispatchFunc=TestTool.getDispatch(),
~uiState=TestTool.buildEmptyAppState(),
~assetBundleNodeId,
(),
) =>
removeNode(~dispatchFunc, ~uiState, ~nodeId=assetBundleNodeId, ());

let removeFolderNode =
(
~dispatchFunc=TestTool.getDispatch(),
Expand Down
18 changes: 18 additions & 0 deletions test/integration/asset/tool/MainEditorAssetUploadTool.re
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,22 @@ let loadOneGLTFZip =
BaseEventTool.buildGLTFZipFileEvent(fileName),
)
|> then_(() => uploadedWDBNodeId |> resolve);
};

let loadOneAssetBundle =
(
~uiState=TestTool.buildEmptyAppState(),
~dispatchFunc=TestTool.getDispatch(),
~fileName="A.rab",
~assetBundle=Js.Typed_array.ArrayBuffer.make(10),
(),
) => {
let uploadedWDBNodeId = MainEditorAssetIdTool.getNewAssetId();

AssetHeaderFileLoadEventHandler.MakeEventHandler.pushUndoStackWithNoCopyEngineState(
(uiState, dispatchFunc),
WonderBsJszip.Zip.create,
BaseEventTool.buildAssetBundleFileEvent(fileName, assetBundle),
)
|> then_(() => uploadedWDBNodeId |> resolve);
};
Loading

0 comments on commit d113c47

Please sign in to comment.