|
| 1 | +import * as React from "react"; |
| 2 | +import { render as reactRender, screen } from "@testing-library/react"; |
| 3 | +import { createMethod } from "../../../../test/factories/data-extension/method-factories"; |
| 4 | +import { InProgressMethods } from "../../../model-editor/shared/in-progress-methods"; |
| 5 | +import { Mode } from "../../../model-editor/shared/mode"; |
| 6 | +import { |
| 7 | + ModeledMethodDataGrid, |
| 8 | + ModeledMethodDataGridProps, |
| 9 | +} from "../ModeledMethodDataGrid"; |
| 10 | + |
| 11 | +describe(ModeledMethodDataGrid.name, () => { |
| 12 | + const method1 = createMethod({ |
| 13 | + library: "sql2o", |
| 14 | + libraryVersion: "1.6.0", |
| 15 | + signature: "org.sql2o.Connection#createQuery(String)", |
| 16 | + packageName: "org.sql2o", |
| 17 | + typeName: "Connection", |
| 18 | + methodName: "createQuery", |
| 19 | + methodParameters: "(String)", |
| 20 | + supported: false, |
| 21 | + }); |
| 22 | + const method2 = createMethod({ |
| 23 | + library: "sql2o", |
| 24 | + libraryVersion: "1.6.0", |
| 25 | + signature: "org.sql2o.Query#executeScalar(Class)", |
| 26 | + packageName: "org.sql2o", |
| 27 | + typeName: "Query", |
| 28 | + methodName: "executeScalar", |
| 29 | + methodParameters: "(Class)", |
| 30 | + supported: false, |
| 31 | + }); |
| 32 | + const method3 = createMethod({ |
| 33 | + library: "sql2o", |
| 34 | + libraryVersion: "1.6.0", |
| 35 | + signature: "org.sql2o.Sql2o#open()", |
| 36 | + packageName: "org.sql2o", |
| 37 | + typeName: "Sql2o", |
| 38 | + methodName: "open", |
| 39 | + methodParameters: "()", |
| 40 | + supported: true, |
| 41 | + }); |
| 42 | + const onChange = jest.fn(); |
| 43 | + |
| 44 | + const render = (props: Partial<ModeledMethodDataGridProps> = {}) => |
| 45 | + reactRender( |
| 46 | + <ModeledMethodDataGrid |
| 47 | + packageName="sql2o" |
| 48 | + methods={[method1, method2, method3]} |
| 49 | + modeledMethods={{ |
| 50 | + [method1.signature]: { |
| 51 | + ...method1, |
| 52 | + type: "sink", |
| 53 | + input: "Argument[0]", |
| 54 | + output: "", |
| 55 | + kind: "jndi-injection", |
| 56 | + provenance: "df-generated", |
| 57 | + }, |
| 58 | + }} |
| 59 | + modifiedSignatures={new Set([method1.signature])} |
| 60 | + inProgressMethods={new InProgressMethods()} |
| 61 | + mode={Mode.Application} |
| 62 | + hideModeledMethods={false} |
| 63 | + onChange={onChange} |
| 64 | + {...props} |
| 65 | + />, |
| 66 | + ); |
| 67 | + |
| 68 | + it("renders the modeled and unmodeled rows", () => { |
| 69 | + render(); |
| 70 | + |
| 71 | + expect(screen.getAllByTestId("modelable-method-row")).toHaveLength(2); |
| 72 | + expect(screen.queryByTestId("unmodelable-method-row")).toBeInTheDocument(); |
| 73 | + }); |
| 74 | + |
| 75 | + it("renders the modeled rows when hideModeledMethods is set", () => { |
| 76 | + render({ |
| 77 | + hideModeledMethods: true, |
| 78 | + }); |
| 79 | + |
| 80 | + expect(screen.getAllByTestId("modelable-method-row")).toHaveLength(2); |
| 81 | + expect( |
| 82 | + screen.queryByTestId("unmodelable-method-row"), |
| 83 | + ).not.toBeInTheDocument(); |
| 84 | + expect( |
| 85 | + screen.getByText("And 1 method modeled in other CodeQL packs"), |
| 86 | + ).toBeInTheDocument(); |
| 87 | + }); |
| 88 | + |
| 89 | + it("does not render rows when no methods are modelable", () => { |
| 90 | + render({ |
| 91 | + methods: [method3], |
| 92 | + modifiedSignatures: new Set(), |
| 93 | + hideModeledMethods: true, |
| 94 | + }); |
| 95 | + |
| 96 | + expect( |
| 97 | + screen.queryByTestId("modelable-method-row"), |
| 98 | + ).not.toBeInTheDocument(); |
| 99 | + expect( |
| 100 | + screen.queryByTestId("unmodelable-method-row"), |
| 101 | + ).not.toBeInTheDocument(); |
| 102 | + expect( |
| 103 | + screen.getByText("1 method modeled in other CodeQL packs"), |
| 104 | + ).toBeInTheDocument(); |
| 105 | + }); |
| 106 | +}); |
0 commit comments