Skip to content
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
17 changes: 5 additions & 12 deletions ui/src/pages/Graphs/NewGraph/NewGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,10 @@ const NewGraph: React.FC = () => {
* Function that makes an API call for Edit graph
*/
const editGraph = useCallback(async () => {
const gfc: GraphFlowInfo = { ...graphFlowInfo };
if (gfc.flow_type === FlowType.DUPLICATE) {
//Update the name if flow is Duplicate
gfc.name = name;
setGraphFlowInfo(gfc);
}
setLoading(true);
try {
const { graphId } = await createGraph(
gfc,
graphFlowInfo,
groups,
handleError,
true
Expand All @@ -172,7 +166,7 @@ const NewGraph: React.FC = () => {
setLoading(false);

if (isValid(graphId)) {
navigate(projectPaths.Graphs + gfc.name);
navigate(projectPaths.Graphs + graphFlowInfo.name);
}
}
} catch (error) {
Expand All @@ -181,7 +175,6 @@ const NewGraph: React.FC = () => {
}
}, [
graphFlowInfo,
name,
createGraph,
groups,
handleError,
Expand Down Expand Up @@ -304,10 +297,10 @@ const NewGraph: React.FC = () => {
return;
}
if (isObjectNotEmpty(graphFlowInfo) && groups) {
if (graphFlowInfo.flow_type === FlowType.CREATE) {
onCreateGraph();
} else {
if (graphFlowInfo.flow_type === FlowType.EDIT) {
validateAndEditGraph();
} else {
onCreateGraph();
}
}
}, [graphFlowInfo, groups, name, onCreateGraph, validateAndEditGraph]);
Expand Down
59 changes: 58 additions & 1 deletion ui/src/pages/Graphs/__tests__/DuplicateGraph.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,24 @@ describe("DuplicateGraphPage", () => {
validateWithFailure?: boolean;
validateWithInvalid?: boolean;
validateWithInvalidSuccess?: boolean;
createWithFailure?: boolean;
validName?: string;
}
) => {
const clickSubmitButton = async () => {
const saveGraph = screen.getByText("Save");
await userEvent.click(saveGraph);
};
vi.mocked(mockAxiosInstance.post).mockClear();
mockUseNavigate.mockClear();

await executeGraphCreationFlow(args, clickSubmitButton, {
validateWithFailure: options.validateWithFailure,
validateWithInvalid: options.validateWithInvalid,
validateWithInvalidSuccess: options.validateWithInvalidSuccess,
createWithFailure: options.createWithFailure,
validName: "ltv_graph_copy",
forceRename: true
forceRename: false
});
};

Expand Down Expand Up @@ -142,6 +147,52 @@ describe("DuplicateGraphPage", () => {
}); //Previous page
});

it("Should send an unchanged duplicate through create without force_rename and stay on the page when creation fails", async () => {
const graphInfo = duplicateGraphInfo();
const original = expectedGraphDetailResponse().graph;
mockLocationStateValue({
flow_type: FlowType.DUPLICATE,
name: graphInfo?.name,
jsGraph: graphInfo
});
await renderDuplicateGraphPage();
await pageLoadTest();
await waitFor(() => {
expect(screen.getByPlaceholderText("name")).toHaveValue(
"ltv_graph_copy"
);
});

await findAndClickButtonByRole("Next");
await executeGraphCreationFlow(
{
col_groups: original?.col_groups?.map(({ columns }) => ({
columns
})),
tables: original?.tables
} as GraphDefinition,
async () => {
await userEvent.click(screen.getByText("Save"));
},
{
createWithInvalid: true,
validName: "ltv_graph_copy",
forceRename: false
}
);

expect(mockAxiosInstance.post).not.toHaveBeenCalledWith(
"v1/graphs/",
expect.anything(),
expect.objectContaining({
params: expect.objectContaining({ force_rename: true })
})
);
expect(mockUseNavigate).not.toHaveBeenCalledWith(
`${getProjectPath("project-tests").Graphs}ltv_graph_copy`
);
});

it("Should successfully duplicate the graph and handle validation errors (failure, invalid data)", async () => {
const graphInfo = duplicateGraphInfo();
mockLocationStateValue({
Expand Down Expand Up @@ -193,6 +244,12 @@ describe("DuplicateGraphPage", () => {
validateWithInvalidSuccess: true
}
);
await duplicateGraphApiCallTest(
mockNewDeuplicateGraphResponse as GraphDefinition,
{
createWithFailure: true
}
);
await duplicateGraphApiCallTest(
mockNewDeuplicateGraphResponse as GraphDefinition,
{}
Expand Down
Loading