Skip to content

Commit cf461eb

Browse files
committed
Tests (#256, #259, #260, #263)
- Update browserWrapper permissions for clipboard - update codeGraph locators - Tests for canvas - improve canvas analyze script - Update getProjectResponse to include missing src value
1 parent 123cda5 commit cf461eb

File tree

5 files changed

+125
-11
lines changed

5 files changed

+125
-11
lines changed

e2e/config/testData.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ export const specialCharacters: { character: string; expectedRes: boolean }[] =
1313
...categorizeCharacters(['%', '*', '(', ')', '-', '[', ']', '{', '}', ';', ':', '"', '|', '~'], false),
1414
...categorizeCharacters(['!', '@', '$', '^', '_', '=', '+', "'", ',', '.', '<', '>', '/', '?', '\\', '`', '&', '#'], true)
1515
];
16+
17+
export const nodesPath: { firstNode: string; secondNode: string }[] = [
18+
{ firstNode: "import_data", secondNode: "add_edge" },
19+
{ firstNode: "test_kg_delete", secondNode: "list_graphs" },
20+
];

e2e/infra/ui/browserWrapper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export default class BrowserWrapper {
1313
if (!this.browser) {
1414
this.browser = await chromium.launch();
1515
}
16-
if (!this.context) {
17-
this.context = await this.browser.newContext();
18-
}
16+
this.context = await this.browser.newContext({
17+
permissions: ['clipboard-read', 'clipboard-write'],
18+
});
1919
if (!this.page) {
2020
this.page = await this.context.newPage();
2121
}

e2e/logic/POM/codeGraph.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Locator, Page } from "playwright";
22
import BasePage from "../../infra/ui/basePage";
33
import { delay, waitToBeEnabled } from "../utils";
4-
import { analyzeCanvasWithLocator, CanvasAnalysisResult } from "../canvasAnalysis";
4+
import { analyzeCanvasNodes, CanvasAnalysisResult } from "../canvasAnalysis";
55

66
export default class CodeGraph extends BasePage {
77
/* NavBar Locators*/
@@ -188,6 +188,10 @@ export default class CodeGraph extends BasePage {
188188
return (itemId: string) => this.page.locator(`//div[@data-name='metrics-panel']/p[${itemId}]`);
189189
}
190190

191+
private get nodedetailsPanelID(): Locator {
192+
return this.page.locator("//div[@data-name='node-details-panel']/main/div[1]/p[2]");
193+
}
194+
191195
/* NavBar functionality */
192196
async clickOnFalkorDbLogo(): Promise<Page> {
193197
await this.page.waitForLoadState('networkidle');
@@ -348,6 +352,7 @@ export default class CodeGraph extends BasePage {
348352
}
349353

350354
async selectSearchBarOptionBtn(buttonNum: string): Promise<void> {
355+
await delay(1000);
351356
await this.searchBarOptionBtn(buttonNum).click();
352357
}
353358

@@ -370,7 +375,7 @@ export default class CodeGraph extends BasePage {
370375

371376
async getCanvasAnalysis(): Promise<CanvasAnalysisResult> {
372377
await delay(2000);
373-
return await analyzeCanvasWithLocator(this.canvasElement);
378+
return await analyzeCanvasNodes(this.canvasElement);
374379
}
375380

376381
async clickZoomIn(): Promise<void> {
@@ -389,12 +394,14 @@ export default class CodeGraph extends BasePage {
389394
await this.elementMenuButton("Remove").click();
390395
}
391396

392-
async rightClickOnNode(x : number, y: number): Promise<void> {
397+
async rightClickOnNode(x: number, y: number): Promise<void> {
393398
const boundingBox = (await this.canvasElement.boundingBox())!;
394-
const adjustedX = boundingBox.x + Math.round(x);
395-
const adjustedY = boundingBox.y + Math.round(y);
399+
const devicePixelRatio = await this.page.evaluate(() => window.devicePixelRatio || 1);
400+
const adjustedX = boundingBox.x + Math.round(x * devicePixelRatio);
401+
const adjustedY = boundingBox.y + Math.round(y * devicePixelRatio);
396402
await this.page.mouse.click(adjustedX, adjustedY, { button: 'right' });
397403
}
404+
398405

399406
async selectCodeGraphCheckbox(checkbox: string): Promise<void> {
400407
await this.codeGraphCheckbox(checkbox).click();
@@ -421,13 +428,27 @@ export default class CodeGraph extends BasePage {
421428
async getNodeDetailsHeader(): Promise<string> {
422429
await this.elementMenuButton("View Node").click();
423430
const text = await this.nodedetailsPanelHeader.innerHTML();
424-
await this.nodedetailsPanelcloseBtn.click();
425431
return text;
426432
}
427433

434+
async clickOnNodeDetailsCloseBtn(): Promise<void>{
435+
await this.nodedetailsPanelcloseBtn.click();
436+
}
437+
428438
async getMetricsPanelInfo(): Promise<{nodes: string, edges: string}> {
429439
const nodes = await this.canvasMetricsPanel("1").innerHTML();
430440
const edges = await this.canvasMetricsPanel("2").innerHTML();
431441
return { nodes, edges }
432442
}
443+
444+
async clickOnCopySrcOnNode(): Promise<string> {
445+
await this.elementMenuButton("Copy src to clipboard").click();
446+
await delay(1000)
447+
return await this.page.evaluate(() => navigator.clipboard.readText());
448+
}
449+
450+
async getNodedetailsPanelID(): Promise<string> {
451+
return await this.nodedetailsPanelID.innerHTML();
452+
}
453+
433454
}

e2e/logic/api/apiResponse.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface getProjectResponse {
2121
ext?: string;
2222
name: string;
2323
path: string;
24+
src: string;
2425
doc?: string;
2526
src_end?: number;
2627
src_start?: number;

e2e/tests/codeGraph.spec.ts

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import CodeGraph from "../logic/POM/codeGraph";
44
import urls from "../config/urls.json";
55
import { GRAPH_ID, Node_Add_Edge, Node_Import_Data, PROJECT_NAME } from "../config/constants";
66
import { delay } from "../logic/utils";
7-
import { searchData, specialCharacters } from "../config/testData";
7+
import { searchData, specialCharacters, nodesPath } from "../config/testData";
88
import { CanvasAnalysisResult } from "../logic/canvasAnalysis";
99
import { ApiCalls } from "../logic/api/apiCalls";
1010

@@ -39,7 +39,6 @@ test.describe("Code graph tests", () => {
3939
const codeGraph = await browser.createNewPage(CodeGraph, urls.baseUrl);
4040
await codeGraph.selectGraph(GRAPH_ID);
4141
await codeGraph.fillSearchBar(searchInput);
42-
await delay(1000);
4342
await codeGraph.selectSearchBarOptionBtn("1");
4443
expect(await codeGraph.getSearchBarInputValue()).toBe(
4544
completedSearchInput
@@ -208,12 +207,100 @@ test.describe("Code graph tests", () => {
208207
return await codeGraph.getNodeDetailsHeader();
209208
})
210209
);
210+
await codeGraph.clickOnNodeDetailsCloseBtn();
211211
const api = new ApiCalls();
212212
const response = await api.getProject(PROJECT_NAME);
213213
const nodeExists = response.result.entities.nodes.some((node) =>
214214
result.some((resItem) => resItem.includes(node.properties.name.toUpperCase()))
215215
);
216216
expect(nodeExists).toBe(true)
217217
});
218+
219+
220+
test(`Validate copy to clipboard functionality for node and verify with api`, async () => {
221+
const codeGraph = await browser.createNewPage(CodeGraph, urls.baseUrl);
222+
await browser.setPageToFullScreen();
223+
await codeGraph.selectGraph(GRAPH_ID);
224+
await codeGraph.fillSearchBar(Node_Import_Data);
225+
await codeGraph.selectSearchBarOptionBtn("1");
226+
const analysis = await codeGraph.getCanvasAnalysis();
227+
await codeGraph.rightClickOnNode(analysis.green[0].x, analysis.green[0].y);
228+
const result = await codeGraph.clickOnCopySrcOnNode();
229+
const api = new ApiCalls();
230+
const response = await api.getProject(PROJECT_NAME);
231+
const foundNode = response.result.entities.nodes.find(node => node.properties?.name === Node_Import_Data);
232+
expect(foundNode?.properties.src).toBe(result);
233+
});
234+
235+
test(`Verify searching for node focus on correct node in canvas`, async () => {
236+
const codeGraph = await browser.createNewPage(CodeGraph, urls.baseUrl);
237+
await browser.setPageToFullScreen();
238+
await codeGraph.selectGraph(GRAPH_ID);
239+
await codeGraph.fillSearchBar(Node_Import_Data);
240+
await codeGraph.selectSearchBarOptionBtn("1");
241+
const result = await codeGraph.getCanvasAnalysis();
242+
await codeGraph.rightClickOnNode(result.green[0].x, result.green[0].y);
243+
const header = await codeGraph.getNodeDetailsHeader();
244+
await codeGraph.clickOnNodeDetailsCloseBtn();
245+
expect(header).toContain(Node_Import_Data.toUpperCase())
246+
});
247+
248+
nodesPath.forEach(({firstNode, secondNode}) => {
249+
test(`Verify successful node path connection in canvas between ${firstNode} and ${secondNode} via UI`, async () => {
250+
const codeGraph = await browser.createNewPage(CodeGraph, urls.baseUrl);
251+
await codeGraph.selectGraph(GRAPH_ID);
252+
await codeGraph.clickOnshowPathBtn();
253+
await codeGraph.insertInputForShowPath("1", firstNode);
254+
await codeGraph.insertInputForShowPath("2", secondNode);
255+
const result = await codeGraph.getCanvasAnalysis();
256+
console.log(result);
257+
258+
const res = [];
259+
for (const node of result.green) {
260+
await codeGraph.rightClickOnNode(node.x, node.y);
261+
const details = await codeGraph.getNodeDetailsHeader();
262+
await codeGraph.clickOnNodeDetailsCloseBtn();
263+
res.push(details);
264+
}
265+
console.log(res);
266+
267+
expect(res.some((item) => item.includes(firstNode.toUpperCase()))).toBe(true);
268+
expect(res.some((item) => item.includes(secondNode.toUpperCase()))).toBe(true);
269+
});
270+
})
271+
272+
test(`Validate node path connection in canvas ui and confirm via api`, async () => {
273+
const codeGraph = await browser.createNewPage(CodeGraph, urls.baseUrl);
274+
await codeGraph.selectGraph(GRAPH_ID);
275+
await codeGraph.clickOnshowPathBtn();
276+
await codeGraph.insertInputForShowPath("1", Node_Import_Data);
277+
await codeGraph.insertInputForShowPath("2", Node_Add_Edge);
278+
const result = await codeGraph.getCanvasAnalysis();
279+
280+
const res = [];
281+
for (const node of result.green) {
282+
await codeGraph.rightClickOnNode(node.x, node.y);
283+
const details = await codeGraph.getNodeDetailsHeader();
284+
const nodeID = await codeGraph.getNodedetailsPanelID();
285+
await codeGraph.clickOnNodeDetailsCloseBtn();
286+
res.push({details, nodeID});
287+
}
288+
const ids: Set<string> = new Set(
289+
res.filter(item => item.details.includes(Node_Import_Data.toUpperCase()) || item.details.includes(Node_Add_Edge.toUpperCase())).map(item => item.nodeID)
290+
);
291+
const sortedIds = Array.from(ids).map(id => parseInt(id, 10)).sort((a, b) => a - b);
292+
const api = new ApiCalls();
293+
const response = await api.showPath(PROJECT_NAME ,sortedIds[0].toString(),sortedIds[1].toString());
294+
const containsDetails = res.some(resItem =>
295+
response.result.paths.some(path =>
296+
path.some(item =>
297+
item.properties?.name
298+
? resItem.details.toUpperCase().includes(item.properties.name.toUpperCase())
299+
: false
300+
)
301+
)
302+
);
303+
expect(containsDetails).toBe(true);
304+
});
218305

219306
});

0 commit comments

Comments
 (0)