Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: updated the workflow editor #80

Merged
merged 4 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web/src/components/createupdate/CreateUpdateWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function CreateUpdateWorkflow(props) {
const [openCreatePipeline, setOpenCreatePipeline] = useState(false);
const [asset, setAsset] = useState(null);
const [pipelines, setPipelines] = useState([]);
const [workflowPipelines, setWorkflowPipelines] = useState([]);
const [workflowPipelines, setWorkflowPipelines] = useState([null]);
const [loadedWorkflowPipelines, setLoadedWorkflowPipelines] = useState([]);
const [activeTab, setActiveTab] = useState("asset");
const [workflowIdNew, setWorkflowIDNew] = useState(workflowId);
Expand Down Expand Up @@ -76,6 +76,7 @@ export default function CreateUpdateWorkflow(props) {
};
});
setLoadedWorkflowPipelines(loadedPipelines);
setWorkflowPipelines(loadedPipelines);
setLoaded(true);
}
};
Expand Down
258 changes: 0 additions & 258 deletions web/src/components/interactive/WorkflowEditor.js

This file was deleted.

109 changes: 109 additions & 0 deletions web/src/components/interactive/WorkflowEditor.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import { render } from "@testing-library/react";
import { act } from "react-dom/test-utils";
import createWrapper from "@cloudscape-design/components/test-utils/dom";
import WorkflowEditor, { workflowPipelineToElements } from "./WorkflowEditor";
import { WorkflowContext } from "../../context/WorkflowContex";

class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}

describe("Workflow Editor", () => {
window.ResizeObserver = ResizeObserver;

it("renders", async () => {
const setAsset = jest.fn();
const setPipelines = jest.fn();
const setWorkflowPipelines = jest.fn();
const reloadPipelines = jest.fn();
const setReloadPipelines = jest.fn();
const setActiveTab = jest.fn();

const asset = {};
const pipelines: any[] = [];
const workflowPipelines: any[] = [];

render(
<WorkflowContext.Provider
value={{
asset,
setAsset,
pipelines,
setPipelines,
workflowPipelines,
setWorkflowPipelines,
reloadPipelines,
setReloadPipelines,
setActiveTab,
}}
>
<div style={{ width: "800px", height: "600px" }}>
<WorkflowEditor />
</div>
</WorkflowContext.Provider>
);
});

it("renders with wf pipeline", async () => {
const setAsset = jest.fn();
const setPipelines = jest.fn();
const setWorkflowPipelines = jest.fn();
const reloadPipelines = jest.fn();
const setReloadPipelines = jest.fn();
const setActiveTab = jest.fn();

const asset = {};
const pipelines: any[] = [];
const workflowPipelines: any[] = [null];

render(
<div style={{ width: 800, height: 800 }}>
<WorkflowContext.Provider
value={{
asset,
setAsset,
pipelines,
setPipelines,
workflowPipelines,
setWorkflowPipelines,
reloadPipelines,
setReloadPipelines,
setActiveTab,
}}
>
<WorkflowEditor />
</WorkflowContext.Provider>
</div>
);
});

it("makes elements a function of workflow pipelines", () => {
const result = workflowPipelineToElements([], "databaseid");
expect(result.find((x) => x.id === "asset0")).toBeTruthy();
expect(result.length).toEqual(1);
});

it("makes elements a function of workflow pipelines with one pipeline", () => {
const result = workflowPipelineToElements([null], "databaseid");
expect(result.find((x) => x.id === "asset0")).toBeTruthy();
expect(result.find((x) => x.id === "pipeline0")).toBeTruthy();
expect(result.length).toEqual(5);
});

it("matches the snapshot for an empty workflow pipeline list", () => {
const result = workflowPipelineToElements([null], "databaseid");
expect(result).toMatchSnapshot();
});

it("matches the snapshot for zero length pipeline list", () => {
const result = workflowPipelineToElements([], "databaseid");
expect(result).toMatchSnapshot();
});
});
Loading