|
1 | 1 | import { window, TreeView } from "vscode"; |
2 | 2 | import { CodeQLCliServer } from "../../../../../src/codeql-cli/cli"; |
3 | | -import { ExternalApiUsage } from "../../../../../src/data-extensions-editor/external-api-usage"; |
| 3 | +import { |
| 4 | + CallClassification, |
| 5 | + ExternalApiUsage, |
| 6 | +} from "../../../../../src/data-extensions-editor/external-api-usage"; |
4 | 7 | import { ModelDetailsPanel } from "../../../../../src/data-extensions-editor/model-details/model-details-panel"; |
5 | 8 | import { DatabaseItem } from "../../../../../src/databases/local-databases"; |
6 | 9 | import { mockedObject } from "../../../utils/mocking.helpers"; |
@@ -39,4 +42,57 @@ describe("ModelDetailsPanel", () => { |
39 | 42 | expect(mockTreeView.badge?.value).toBe(1); |
40 | 43 | }); |
41 | 44 | }); |
| 45 | + |
| 46 | + describe("revealItem", () => { |
| 47 | + let mockTreeView: TreeView<unknown>; |
| 48 | + |
| 49 | + const hideModeledApis: boolean = false; |
| 50 | + const dbItem = mockedObject<DatabaseItem>({ |
| 51 | + getSourceLocationPrefix: () => "test", |
| 52 | + }); |
| 53 | + const usage = { |
| 54 | + classification: "unknown" as CallClassification, |
| 55 | + label: "test", |
| 56 | + url: { |
| 57 | + uri: "test", |
| 58 | + startLine: 1, |
| 59 | + startColumn: 1, |
| 60 | + endLine: 1, |
| 61 | + endColumn: 1, |
| 62 | + }, |
| 63 | + }; |
| 64 | + |
| 65 | + beforeEach(() => { |
| 66 | + mockTreeView = { |
| 67 | + reveal: jest.fn(), |
| 68 | + } as unknown as TreeView<unknown>; |
| 69 | + jest.spyOn(window, "createTreeView").mockReturnValue(mockTreeView); |
| 70 | + }); |
| 71 | + |
| 72 | + it("should reveal the correct item in the tree view", async () => { |
| 73 | + const externalApiUsages = mockedObject<ExternalApiUsage[]>([ |
| 74 | + { |
| 75 | + usages: [usage], |
| 76 | + }, |
| 77 | + ]); |
| 78 | + |
| 79 | + const panel = new ModelDetailsPanel(mockCliServer); |
| 80 | + await panel.setState(externalApiUsages, dbItem, hideModeledApis); |
| 81 | + |
| 82 | + await panel.revealItem(usage); |
| 83 | + |
| 84 | + expect(mockTreeView.reveal).toHaveBeenCalledWith(usage); |
| 85 | + }); |
| 86 | + |
| 87 | + it("should do nothing if usage cannot be found", async () => { |
| 88 | + const externalApiUsages = mockedObject<ExternalApiUsage[]>([]); |
| 89 | + |
| 90 | + const panel = new ModelDetailsPanel(mockCliServer); |
| 91 | + await panel.setState(externalApiUsages, dbItem, hideModeledApis); |
| 92 | + |
| 93 | + await panel.revealItem(usage); |
| 94 | + |
| 95 | + expect(mockTreeView.reveal).not.toHaveBeenCalled(); |
| 96 | + }); |
| 97 | + }); |
42 | 98 | }); |
0 commit comments