forked from langflow-ai/langflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add Integration with starter-projects Endpoint and Vector Stor…
…e Test (langflow-ai#3599) * ✨ (App.tsx): Add useGetStarterProjectsQuery hook to fetch starter projects data 📝 (constants.ts): Add STARTER_PROJECTS constant to define the endpoint for starter projects API 📝 (use-get-starter-projects.ts): Create useGetStarterProjectsQuery hook to fetch starter projects data 📝 (index.tsx): Add AppWrapperPage test for drag and drop functionality with starter projects data 📝 (starter-projects.spec.ts): Add end-to-end test for drag and drop functionality with starter projects data * ✨ (starter-projects.spec.ts): update test description to be more descriptive and specific about the test scenario * ♻️ (App.tsx): remove unused useGetStarterProjectsQuery hook to clean up code and improve readability * 🔧 (App.tsx): remove unused import useGetStarterProjectsQuery to clean up code and improve readability
- Loading branch information
1 parent
71a1d6c
commit a4ecfda
Showing
4 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/frontend/src/controllers/API/queries/starter-projects/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./use-get-starter-projects"; |
44 changes: 44 additions & 0 deletions
44
src/frontend/src/controllers/API/queries/starter-projects/use-get-starter-projects.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useDarkStore } from "@/stores/darkStore"; | ||
import { useQueryFunctionType } from "@/types/api"; | ||
import { api } from "../../api"; | ||
import { getURL } from "../../helpers/constants"; | ||
import { UseRequestProcessor } from "../../services/request-processor"; | ||
|
||
export interface IStarterProjectsDataArray { | ||
name: string; | ||
last_used_at: string | null; | ||
total_uses: number; | ||
is_active: boolean; | ||
id: string; | ||
api_key: string; | ||
user_id: string; | ||
created_at: string; | ||
} | ||
|
||
interface IApiQueryResponse { | ||
total_count: number; | ||
user_id: string; | ||
api_keys: Array<IStarterProjectsDataArray>; | ||
} | ||
|
||
export const useGetStarterProjectsQuery: useQueryFunctionType< | ||
undefined, | ||
IApiQueryResponse | ||
> = (_, options) => { | ||
const { query } = UseRequestProcessor(); | ||
|
||
const getStarterProjectsFn = async () => { | ||
return await api.get<IApiQueryResponse>(`${getURL("STARTER_PROJECTS")}/`); | ||
}; | ||
|
||
const responseFn = async () => { | ||
const { data } = await getStarterProjectsFn(); | ||
return data; | ||
}; | ||
|
||
const queryResult = query(["useGetStarterProjectsQuery"], responseFn, { | ||
...options, | ||
}); | ||
|
||
return queryResult; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
const { test, expect } = require("@playwright/test"); | ||
|
||
test("vector store from starter projects should have its connections and nodes on the flow", async ({ | ||
page, | ||
request, | ||
}) => { | ||
const response = await request.get("/api/v1/starter-projects"); | ||
expect(response.status()).toBe(200); | ||
const responseBody = await response.json(); | ||
|
||
const astraStarterProject = responseBody.find((project) => { | ||
if (project.data.nodes) { | ||
return project.data.nodes.some((node) => node.id.includes("Astra")); | ||
} | ||
}); | ||
|
||
await page.route("**/api/v1/flows/", async (route) => { | ||
if (route.request().method() === "GET") { | ||
try { | ||
const response = await route.fetch(); | ||
const flowsData = await response.json(); | ||
|
||
const modifiedFlows = flowsData.map((flow) => { | ||
if (flow.name === "Vector Store RAG" && flow.user_id === null) { | ||
return { | ||
...flow, | ||
data: astraStarterProject?.data, | ||
}; | ||
} | ||
return flow; | ||
}); | ||
|
||
const modifiedResponse = JSON.stringify(modifiedFlows); | ||
|
||
route.fulfill({ | ||
status: response.status(), | ||
headers: response.headers(), | ||
body: modifiedResponse, | ||
}); | ||
} catch (error) { | ||
console.error("Error in route handler:", error); | ||
} | ||
} else { | ||
// If not a GET request, continue without modifying | ||
await route.continue(); | ||
} | ||
}); | ||
|
||
await page.goto("/"); | ||
|
||
await page.waitForSelector('[data-testid="mainpage_title"]', { | ||
timeout: 30000, | ||
}); | ||
|
||
await page.waitForSelector('[id="new-project-btn"]', { | ||
timeout: 30000, | ||
}); | ||
|
||
let modalCount = 0; | ||
try { | ||
const modalTitleElement = await page?.getByTestId("modal-title"); | ||
if (modalTitleElement) { | ||
modalCount = await modalTitleElement.count(); | ||
} | ||
} catch (error) { | ||
modalCount = 0; | ||
} | ||
|
||
while (modalCount === 0) { | ||
await page.getByText("New Project", { exact: true }).click(); | ||
await page.waitForTimeout(3000); | ||
modalCount = await page.getByTestId("modal-title")?.count(); | ||
} | ||
|
||
await page.getByRole("heading", { name: "Vector Store RAG" }).click(); | ||
await page.waitForSelector('[title="fit view"]', { | ||
timeout: 100000, | ||
}); | ||
|
||
await page.getByTitle("fit view").click(); | ||
await page.getByTitle("zoom out").click(); | ||
|
||
const edges = await page.locator(".react-flow__edge-interaction").count(); | ||
const nodes = await page.getByTestId("div-generic-node").count(); | ||
|
||
const edgesFromServer = astraStarterProject?.data.edges.length; | ||
const nodesFromServer = astraStarterProject?.data.nodes.length; | ||
|
||
expect(edges).toBe(edgesFromServer); | ||
expect(nodes).toBe(nodesFromServer); | ||
}); |