Skip to content

Commit

Permalink
feat(): createThemePage only create snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
SailorF committed Oct 28, 2022
1 parent 232e9d6 commit 72b38b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 441 deletions.
279 changes: 10 additions & 269 deletions bricks/next-builder/src/data-providers/CreateThemePage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ import {
InstanceApi_getDetail,
} from "@next-sdk/cmdb-sdk";
import { PasteBricks } from "./PasteBricks";
import { CreateThemePage, LayoutEnums } from "./CreateThemePage";
import { CreateThemePage } from "./CreateThemePage";

jest.mock("./PasteBricks");
jest.mock("@next-sdk/cmdb-sdk");
jest.mock("@next-sdk/next-builder-sdk");

(InstanceApi_createInstance as jest.Mock).mockImplementation((objectId) => {
switch (objectId) {
case "STORYBOARD_TEMPLATE":
return {
instanceId: "tpl-a",
id: "T-1",
};
case "STORYBOARD_SNIPPET":
return {
instanceId: "snippet-a",
Expand All @@ -31,21 +26,6 @@ jest.mock("@next-sdk/next-builder-sdk");

(InstanceApi_getDetail as jest.Mock).mockImplementation((objectId) => {
switch (objectId) {
case "STORYBOARD_TEMPLATE":
return {
proxy: "proxy",
state: "state",
children: [
{
id: "T-001",
instanceId: "t-001",
},
{
id: "T-002",
instanceId: "t-002",
},
],
};
case "STORYBOARD_SNIPPET":
return {
context: "context",
Expand Down Expand Up @@ -86,39 +66,12 @@ describe("CreateThemePage", () => {
name: "首页",
},
},
layoutType: LayoutEnums.HEADER_THROUGH_SIDEBAR,
sourceProjectId: "source-projectid",
})
).toEqual(true);
expect(InstanceApi_createInstance).toBeCalledTimes(5);
expect(InstanceApi_createInstance).toBeCalledTimes(2);
expect(InstanceApi_createInstance).toHaveBeenNthCalledWith(
1,
"STORYBOARD_TEMPLATE",
{
project: "project-a",
appId: "app-a",
templateId: `tpl-page-home`,
proxy: JSON.stringify({
slots: {
header: {
ref: "view",
refSlot: "header",
},
sider: {
ref: "view",
refSlot: "sider",
},
content: {
ref: "view",
refSlot: "content",
},
},
}),
type: "custom-template",
}
);
expect(InstanceApi_createInstance).toHaveBeenNthCalledWith(
2,
"STORYBOARD_SNIPPET",
{
project: "project-a",
Expand All @@ -129,43 +82,10 @@ describe("CreateThemePage", () => {
en: "My Layout",
zh: "My Layout",
},
layerType: "layout",
}
);
expect(InstanceApi_createInstance).toHaveBeenNthCalledWith(
3,
"STORYBOARD_BRICK",
{
appId: "app-a",
brick: `tpl-page-home`,
type: "brick",
mountPoint: "bricks",
parent: "snippet-a",
}
);
expect(InstanceApi_createInstance).toHaveBeenNthCalledWith(
4,
"STORYBOARD_BRICK",
{
appId: "app-a",
brick: `basic-bricks.easy-view`,
properties: JSON.stringify({
gridAreas: {
header: [1, 1, 2, 3],
sider: [2, 1, 3, 2],
content: [2, 2, 3, 3],
},
gridTemplateColumns: ["auto", "1fr"],
gridTemplateRows: ["var(--app-bar-height)", "auto"],
}),
ref: "view",
type: "brick",
mountPoint: "bricks",
parent: "tpl-a",
}
);
expect(InstanceApi_createInstance).toHaveBeenNthCalledWith(
5,
2,
"STORYBOARD_THEME_PAGE",
{
project: "project-a",
Expand All @@ -180,153 +100,12 @@ describe("CreateThemePage", () => {
name: "首页",
},
},
template: "tpl-a",
snippet: "snippet-a",
layoutType: LayoutEnums.HEADER_THROUGH_SIDEBAR,
}
);
});

it.each<[LayoutEnums, unknown]>([
[
LayoutEnums.HEADER_THROUGH_SIDEBAR,
{
appId: "app-a",
brick: `basic-bricks.easy-view`,
properties: JSON.stringify({
gridAreas: {
header: [1, 1, 2, 3],
sider: [2, 1, 3, 2],
content: [2, 2, 3, 3],
},
gridTemplateColumns: ["auto", "1fr"],
gridTemplateRows: ["var(--app-bar-height)", "auto"],
}),
ref: "view",
type: "brick",
mountPoint: "bricks",
parent: "tpl-a",
},
],
[
LayoutEnums.SIDEBAR_THROUGH_HEADER,
{
appId: "app-a",
brick: `basic-bricks.easy-view`,
properties: JSON.stringify({
gridAreas: {
header: [1, 2, 2, 3],
sider: [1, 1, 3, 2],
content: [2, 2, 3, 3],
},
gridTemplateColumns: ["auto", "1fr"],
gridTemplateRows: ["var(--app-bar-height)", "auto"],
}),
ref: "view",
type: "brick",
mountPoint: "bricks",
parent: "tpl-a",
},
],
[
LayoutEnums.HEADER,
{
appId: "app-a",
brick: `basic-bricks.easy-view`,
properties: JSON.stringify({
gridAreas: {
header: [1, 1, 2, 3],
content: [2, 1, 3, 3],
},
gridTemplateRows: ["var(--app-bar-height)", "auto"],
}),
ref: "view",
type: "brick",
mountPoint: "bricks",
parent: "tpl-a",
},
],
[
LayoutEnums.SIDEBAR_LEFT,
{
appId: "app-a",
brick: `basic-bricks.easy-view`,
properties: JSON.stringify({
gridAreas: {
sider: [1, 1, 3, 1],
content: [1, 2, 3, 3],
},
gridTemplateColumns: ["auto", "1fr"],
}),
ref: "view",
type: "brick",
mountPoint: "bricks",
parent: "tpl-a",
},
],
[
LayoutEnums.SIDEBAR_RIGHT,
{
appId: "app-a",
brick: `basic-bricks.easy-view`,
properties: JSON.stringify({
gridAreas: {
content: [1, 1, 3, 1],
sider: [1, 2, 3, 3],
},
gridTemplateColumns: ["auto", "1fr"],
}),
ref: "view",
type: "brick",
mountPoint: "bricks",
parent: "tpl-a",
},
],
[
LayoutEnums.NULL,
{
appId: "app-a",
brick: `basic-bricks.easy-view`,
properties: JSON.stringify({
gridAreas: {
content: [1, 1, 3, 3],
},
}),
ref: "view",
type: "brick",
mountPoint: "bricks",
parent: "tpl-a",
},
],
])(
"should work when layoutList or layoutType",
async (layoutType, result) => {
await CreateThemePage({
projectId: "project-a",
appId: "app-a",
pageTypeId: "home",
name: "My Layout",
thumbnail: "fun.png",
locales: {
en: {
name: "Home",
},
zh: {
name: "首页",
},
},
layoutType: layoutType,
});

expect(InstanceApi_createInstance).toHaveBeenNthCalledWith(
4,
"STORYBOARD_BRICK",
result
);
}
);

it("should work then use theme template create", async () => {
it("should work then use theme snippet create", async () => {
expect(
await CreateThemePage({
projectId: "project-a",
Expand All @@ -343,12 +122,6 @@ describe("CreateThemePage", () => {
},
},
pageTemplate: {
template: [
{
id: "B-001",
instanceId: "abc",
},
],
snippet: [
{
id: "B-001",
Expand All @@ -360,27 +133,14 @@ describe("CreateThemePage", () => {
})
).toBe(true);

expect(InstanceApi_getDetail).toBeCalledTimes(2);
expect(InstanceApi_getDetail).toBeCalledTimes(1);

expect(InstanceApi_createInstance).toBeCalledTimes(3);
expect(InstanceApi_createInstance).toBeCalledTimes(2);

expect(PasteBricks).toBeCalledTimes(4);
expect(PasteBricks).toBeCalledTimes(2);

expect(InstanceApi_createInstance).toHaveBeenNthCalledWith(
1,
"STORYBOARD_TEMPLATE",
{
project: "project-a",
appId: "app-a",
templateId: `tpl-page-home`,
proxy: "proxy",
state: "state",
type: "custom-template",
}
);

expect(InstanceApi_createInstance).toHaveBeenNthCalledWith(
2,
"STORYBOARD_SNIPPET",
{
project: "project-a",
Expand All @@ -391,36 +151,19 @@ describe("CreateThemePage", () => {
en: "My Layout",
zh: "My Layout",
},
layerType: "layout",
context: "context",
}
);

expect(PasteBricks).toHaveBeenNthCalledWith(1, {
newAppId: "app-a",
newParentBrickId: "T-1",
sourceBrickId: "T-001",
newProjectInstanceId: "project-a",
sourceBrickInstanceId: "t-001",
sourceProjectInstanceId: "source-projectid",
});
expect(PasteBricks).toHaveBeenNthCalledWith(2, {
newAppId: "app-a",
newParentBrickId: "T-1",
sourceBrickId: "T-002",
newProjectInstanceId: "project-a",
sourceBrickInstanceId: "t-002",
sourceProjectInstanceId: "source-projectid",
});
expect(PasteBricks).toHaveBeenNthCalledWith(3, {
newAppId: "app-a",
newParentBrickId: "S-1",
sourceBrickId: "S-001",
newProjectInstanceId: "project-a",
sourceBrickInstanceId: "s-001",
sourceProjectInstanceId: "source-projectid",
});
expect(PasteBricks).toHaveBeenNthCalledWith(4, {
expect(PasteBricks).toHaveBeenNthCalledWith(2, {
newAppId: "app-a",
newParentBrickId: "S-1",
sourceBrickId: "S-002",
Expand All @@ -430,7 +173,7 @@ describe("CreateThemePage", () => {
});

expect(InstanceApi_createInstance).toHaveBeenNthCalledWith(
3,
2,
"STORYBOARD_THEME_PAGE",
{
project: "project-a",
Expand All @@ -445,7 +188,6 @@ describe("CreateThemePage", () => {
name: "首页",
},
},
template: "tpl-a",
snippet: "snippet-a",
}
);
Expand All @@ -468,15 +210,14 @@ describe("CreateThemePage", () => {
},
},
pageTemplate: {
template: [],
snippet: [],
},
})
).toBe(true);

expect(InstanceApi_getDetail).toBeCalledTimes(0);

expect(InstanceApi_createInstance).toBeCalledTimes(3);
expect(InstanceApi_createInstance).toBeCalledTimes(2);

expect(PasteBricks).toBeCalledTimes(0);
});
Expand Down

0 comments on commit 72b38b0

Please sign in to comment.