Add tests for ModeledMethodDataGrid
This commit is contained in:
@@ -203,7 +203,7 @@ function ModelableMethodRow(props: Props) {
|
||||
const modelingStatus = getModelingStatus(modeledMethod, methodIsUnsaved);
|
||||
|
||||
return (
|
||||
<VSCodeDataGridRow>
|
||||
<VSCodeDataGridRow data-testid="modelable-method-row">
|
||||
<ApiOrMethodCell gridColumn={1}>
|
||||
<ModelingStatusIndicator status={modelingStatus} />
|
||||
<MethodClassifications method={method} />
|
||||
@@ -280,7 +280,7 @@ function UnmodelableMethodRow(props: Props) {
|
||||
);
|
||||
|
||||
return (
|
||||
<VSCodeDataGridRow>
|
||||
<VSCodeDataGridRow data-testid="unmodelable-method-row">
|
||||
<ApiOrMethodCell gridColumn={1}>
|
||||
<ModelingStatusIndicator status="saved" />
|
||||
<MethodName {...props.method} />
|
||||
|
||||
@@ -15,7 +15,7 @@ import { HiddenMethodsRow } from "./HiddenMethodsRow";
|
||||
|
||||
export const GRID_TEMPLATE_COLUMNS = "0.5fr 0.125fr 0.125fr 0.125fr 0.125fr";
|
||||
|
||||
type Props = {
|
||||
export type ModeledMethodDataGridProps = {
|
||||
packageName: string;
|
||||
methods: Method[];
|
||||
modeledMethods: Record<string, ModeledMethod>;
|
||||
@@ -35,7 +35,7 @@ export const ModeledMethodDataGrid = ({
|
||||
mode,
|
||||
hideModeledMethods,
|
||||
onChange,
|
||||
}: Props) => {
|
||||
}: ModeledMethodDataGridProps) => {
|
||||
const [methodsWithModelability, numHiddenMethods]: [
|
||||
Array<{ method: Method; methodCanBeModeled: boolean }>,
|
||||
number,
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import * as React from "react";
|
||||
import { render as reactRender, screen } from "@testing-library/react";
|
||||
import { createMethod } from "../../../../test/factories/data-extension/method-factories";
|
||||
import { InProgressMethods } from "../../../model-editor/shared/in-progress-methods";
|
||||
import { Mode } from "../../../model-editor/shared/mode";
|
||||
import {
|
||||
ModeledMethodDataGrid,
|
||||
ModeledMethodDataGridProps,
|
||||
} from "../ModeledMethodDataGrid";
|
||||
|
||||
describe(ModeledMethodDataGrid.name, () => {
|
||||
const method1 = createMethod({
|
||||
library: "sql2o",
|
||||
libraryVersion: "1.6.0",
|
||||
signature: "org.sql2o.Connection#createQuery(String)",
|
||||
packageName: "org.sql2o",
|
||||
typeName: "Connection",
|
||||
methodName: "createQuery",
|
||||
methodParameters: "(String)",
|
||||
supported: false,
|
||||
});
|
||||
const method2 = createMethod({
|
||||
library: "sql2o",
|
||||
libraryVersion: "1.6.0",
|
||||
signature: "org.sql2o.Query#executeScalar(Class)",
|
||||
packageName: "org.sql2o",
|
||||
typeName: "Query",
|
||||
methodName: "executeScalar",
|
||||
methodParameters: "(Class)",
|
||||
supported: false,
|
||||
});
|
||||
const method3 = createMethod({
|
||||
library: "sql2o",
|
||||
libraryVersion: "1.6.0",
|
||||
signature: "org.sql2o.Sql2o#open()",
|
||||
packageName: "org.sql2o",
|
||||
typeName: "Sql2o",
|
||||
methodName: "open",
|
||||
methodParameters: "()",
|
||||
supported: true,
|
||||
});
|
||||
const onChange = jest.fn();
|
||||
|
||||
const render = (props: Partial<ModeledMethodDataGridProps> = {}) =>
|
||||
reactRender(
|
||||
<ModeledMethodDataGrid
|
||||
packageName="sql2o"
|
||||
methods={[method1, method2, method3]}
|
||||
modeledMethods={{
|
||||
[method1.signature]: {
|
||||
...method1,
|
||||
type: "sink",
|
||||
input: "Argument[0]",
|
||||
output: "",
|
||||
kind: "jndi-injection",
|
||||
provenance: "df-generated",
|
||||
},
|
||||
}}
|
||||
modifiedSignatures={new Set([method1.signature])}
|
||||
inProgressMethods={new InProgressMethods()}
|
||||
mode={Mode.Application}
|
||||
hideModeledMethods={false}
|
||||
onChange={onChange}
|
||||
{...props}
|
||||
/>,
|
||||
);
|
||||
|
||||
it("renders the modeled and unmodeled rows", () => {
|
||||
render();
|
||||
|
||||
expect(screen.getAllByTestId("modelable-method-row")).toHaveLength(2);
|
||||
expect(screen.queryByTestId("unmodelable-method-row")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the modeled rows when hideModeledMethods is set", () => {
|
||||
render({
|
||||
hideModeledMethods: true,
|
||||
});
|
||||
|
||||
expect(screen.getAllByTestId("modelable-method-row")).toHaveLength(2);
|
||||
expect(
|
||||
screen.queryByTestId("unmodelable-method-row"),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText("And 1 method modeled in other CodeQL packs"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not render rows when no methods are modelable", () => {
|
||||
render({
|
||||
methods: [method3],
|
||||
modifiedSignatures: new Set(),
|
||||
hideModeledMethods: true,
|
||||
});
|
||||
|
||||
expect(
|
||||
screen.queryByTestId("modelable-method-row"),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByTestId("unmodelable-method-row"),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText("1 method modeled in other CodeQL packs"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user