-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3687 from p-/display-max-steps-local-path-query
Display length of shortest path in local results UI
- Loading branch information
Showing
6 changed files
with
191 additions
and
4 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
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
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
38 changes: 38 additions & 0 deletions
38
extensions/ql-vscode/src/view/results/__tests__/AlertTablePathRow.spec.tsx
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,38 @@ | ||
import { render as reactRender, screen } from "@testing-library/react"; | ||
import type { Props } from "../AlertTablePathRow"; | ||
import { AlertTablePathRow } from "../AlertTablePathRow"; | ||
import { createMockResults } from "../../../../test/factories/results/mockresults"; | ||
|
||
describe(AlertTablePathRow.name, () => { | ||
const render = (props?: Props) => { | ||
const mockRef = { current: null } as React.RefObject<HTMLTableRowElement>; | ||
const results = createMockResults(); | ||
const threadFlow = results[0]?.codeFlows?.[0]?.threadFlows?.[0]; | ||
|
||
if (!threadFlow) { | ||
throw new Error("ThreadFlow is undefined"); | ||
} | ||
reactRender( | ||
<AlertTablePathRow | ||
resultIndex={1} | ||
selectedItem={undefined} | ||
selectedItemRef={mockRef} | ||
path={threadFlow} | ||
pathIndex={0} | ||
currentPathExpanded={true} | ||
databaseUri={"dbUri"} | ||
sourceLocationPrefix="src" | ||
userSettings={{ shouldShowProvenance: false }} | ||
updateSelectionCallback={jest.fn()} | ||
toggleExpanded={jest.fn()} | ||
{...props} | ||
/>, | ||
); | ||
}; | ||
|
||
it("renders number of steps", () => { | ||
render(); | ||
|
||
expect(screen.getByText("Path (3 steps)")).toBeInTheDocument(); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
extensions/ql-vscode/src/view/results/__tests__/AlertTableResultRow.spec.tsx
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,33 @@ | ||
import { render as reactRender, screen } from "@testing-library/react"; | ||
import { AlertTableResultRow } from "../AlertTableResultRow"; | ||
import type { Props } from "../AlertTableResultRow"; | ||
import { createMockResults } from "../../../../test/factories/results/mockresults"; | ||
|
||
describe(AlertTableResultRow.name, () => { | ||
const render = (props?: Props) => { | ||
const mockRef = { current: null } as React.RefObject<HTMLTableRowElement>; | ||
const results = createMockResults(); | ||
|
||
reactRender( | ||
<AlertTableResultRow | ||
result={results[0]} | ||
expanded={new Set()} | ||
resultIndex={1} | ||
selectedItem={undefined} | ||
selectedItemRef={mockRef} | ||
databaseUri={"dbUri"} | ||
sourceLocationPrefix="src" | ||
userSettings={{ shouldShowProvenance: false }} | ||
updateSelectionCallback={jest.fn()} | ||
toggleExpanded={jest.fn()} | ||
{...props} | ||
/>, | ||
); | ||
}; | ||
|
||
it("renders shortest path badge", () => { | ||
render(); | ||
|
||
expect(screen.getByTitle("Shortest path")).toHaveTextContent("3"); | ||
}); | ||
}); |
104 changes: 104 additions & 0 deletions
104
extensions/ql-vscode/test/factories/results/mockresults.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,104 @@ | ||
import type { Result } from "sarif"; | ||
|
||
export function createMockResults(): Result[] { | ||
return [ | ||
{ | ||
ruleId: "java/sql-injection", | ||
ruleIndex: 0, | ||
rule: { id: "java/sql-injection", index: 0 }, | ||
message: { | ||
text: "This query depends on a [user-provided value](1).", | ||
}, | ||
locations: [ | ||
{ | ||
physicalLocation: { | ||
artifactLocation: { | ||
uri: "src/main/java/org/example/HelloController.java", | ||
uriBaseId: "%SRCROOT%", | ||
index: 0, | ||
}, | ||
region: { startLine: 15, startColumn: 29, endColumn: 56 }, | ||
}, | ||
}, | ||
], | ||
partialFingerprints: { | ||
primaryLocationLineHash: "87e2d3cc5b365094:1", | ||
primaryLocationStartColumnFingerprint: "16", | ||
}, | ||
codeFlows: [ | ||
{ | ||
threadFlows: [ | ||
{ | ||
locations: [ | ||
{ | ||
location: { | ||
physicalLocation: { | ||
artifactLocation: { | ||
uri: "src/main/java/org/example/HelloController.java", | ||
uriBaseId: "%SRCROOT%", | ||
index: 0, | ||
}, | ||
region: { | ||
startLine: 13, | ||
startColumn: 25, | ||
endColumn: 54, | ||
}, | ||
}, | ||
message: { text: "id : String" }, | ||
}, | ||
}, | ||
{ | ||
location: { | ||
physicalLocation: { | ||
artifactLocation: { | ||
uri: "file:/", | ||
index: 5, | ||
}, | ||
region: { | ||
startLine: 13, | ||
startColumn: 25, | ||
endColumn: 54, | ||
}, | ||
}, | ||
message: { text: "id : String" }, | ||
}, | ||
}, | ||
{ | ||
location: { | ||
physicalLocation: { | ||
artifactLocation: { | ||
uri: "src/main/java/org/example/HelloController.java", | ||
uriBaseId: "%SRCROOT%", | ||
index: 0, | ||
}, | ||
region: { | ||
startLine: 15, | ||
startColumn: 29, | ||
endColumn: 56, | ||
}, | ||
}, | ||
message: { text: "... + ..." }, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
relatedLocations: [ | ||
{ | ||
id: 1, | ||
physicalLocation: { | ||
artifactLocation: { | ||
uri: "src/main/java/org/example/HelloController.java", | ||
uriBaseId: "%SRCROOT%", | ||
index: 0, | ||
}, | ||
region: { startLine: 13, startColumn: 25, endColumn: 54 }, | ||
}, | ||
message: { text: "user-provided value" }, | ||
}, | ||
], | ||
}, | ||
]; | ||
} |