Skip to content

Commit

Permalink
web: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tbantle22 committed Oct 31, 2023
1 parent a672d54 commit 40fad85
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 30 deletions.
3 changes: 2 additions & 1 deletion packages/web/components/SchemaList/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ describe("test SchemaList", () => {
);

if (tables.length === 0) {
expect(await screen.findByText("No tables found on")).toBeVisible();
expect(await screen.findAllByText(params.refName)).toHaveLength(3);
expect(screen.getByText("No tables found")).toBeVisible();
} else {
tables.forEach(async table => {
expect(await screen.findByText(table)).toBeVisible();
Expand Down
6 changes: 5 additions & 1 deletion packages/web/components/SchemaList/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MockedResponse } from "@apollo/client/testing";
import { databaseDetailsMock } from "@components/util/NotDoltWrapper/mocks";
import { tableNamesMock } from "@hooks/useTableNames/mocks";
import { RefParams } from "@lib/params";

Expand All @@ -16,4 +17,7 @@ export const getQ = (tables: string[]) => {
export const mocks = (
params: RefParams,
tables: string[],
): MockedResponse[] => [tableNamesMock(params, tables)];
): MockedResponse[] => [
tableNamesMock(params, tables),
databaseDetailsMock(true, false),
];
20 changes: 19 additions & 1 deletion packages/web/components/SqlDataTable/SqlMessage/SuccessMsg.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import DoltLink from "@components/links/DoltLink";
import Link from "@components/links/Link";
import useIsDolt from "@hooks/useIsDolt";
import { SqlQueryParams } from "@lib/params";
Expand All @@ -14,7 +15,6 @@ type Props = {
};

export default function SuccessMsg(props: Props) {
const { isDolt } = useIsDolt();
const lower = props.params.q.toLowerCase();
if (isMutation(props.params.q)) {
return (
Expand All @@ -34,6 +34,18 @@ export default function SuccessMsg(props: Props) {
</div>
);
}

return <ExecutionMessage {...props} />;
}

type ExecutionProps = {
rowsLen: number;
params: SqlQueryParams;
hitRowLimit?: boolean;
};

export function ExecutionMessage(props: ExecutionProps) {
const { isDolt } = useIsDolt();
return (
<p className={css.status}>
{props.rowsLen} {pluralize(props.rowsLen, "row")} selected
Expand All @@ -43,6 +55,12 @@ export default function SuccessMsg(props: Props) {
on <span className={css.bold}>{props.params.refName}</span>
</span>
)}
{props.hitRowLimit && (
<span>
{" "}
(for unlimited query results download <DoltLink />)
</span>
)}
</p>
);
}
Expand Down
39 changes: 23 additions & 16 deletions packages/web/components/SqlDataTable/SqlMessage/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ApolloError } from "@apollo/client";
import { MockedProvider } from "@apollo/client/testing";
import { databaseDetailsMock } from "@components/util/NotDoltWrapper/mocks";
import { QueryExecutionStatus } from "@gen/graphql-types";
import { SqlQueryParams } from "@lib/params";
import { render, screen } from "@testing-library/react";
Expand Down Expand Up @@ -77,28 +79,33 @@ describe("test SqlMessage", () => {
expect(screen.getByText(/before query timed out./)).toBeVisible();
});

it("renders success message", () => {
it("renders success message", async () => {
render(
<SqlMessage
params={params}
rowsLen={1}
executionStatus={QueryExecutionStatus.Success}
/>,
<MockedProvider mocks={[databaseDetailsMock(true, false)]}>
<SqlMessage
params={params}
rowsLen={1}
executionStatus={QueryExecutionStatus.Success}
/>
</MockedProvider>,
);
expect(screen.getByText("1 row selected on")).toBeVisible();
expect(screen.getByText("master")).toBeVisible();
expect(await screen.findByText("master")).toBeVisible();
expect(screen.getByText("1 row selected")).toBeVisible();
});

it("renders row limit message", () => {
it("renders row limit message", async () => {
render(
<SqlMessage
params={params}
rowsLen={200}
executionStatus={QueryExecutionStatus.RowLimit}
/>,
<MockedProvider mocks={[databaseDetailsMock(true, false)]}>
<SqlMessage
params={params}
rowsLen={200}
executionStatus={QueryExecutionStatus.RowLimit}
/>
</MockedProvider>,
);
expect(screen.getByText(/200 rows selected on/)).toBeVisible();
expect(screen.getByText("master")).toBeVisible();

expect(await screen.findByText("master")).toBeVisible();
expect(screen.getByText(/200 rows selected/)).toBeVisible();
expect(
screen.getByText(/\(for unlimited query results download /),
).toBeVisible();
Expand Down
12 changes: 2 additions & 10 deletions packages/web/components/SqlDataTable/SqlMessage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ApolloError } from "@apollo/client";
import ErrorMsg from "@components/ErrorMsg";
import DoltLink from "@components/links/DoltLink";
import { QueryExecutionStatus } from "@gen/graphql-types";
import { isTimeoutError } from "@lib/errors/helpers";
import { SqlQueryParams } from "@lib/params";
import { isMultipleQueries } from "@lib/parseSqlQuery";
import { pluralize } from "@lib/pluralize";
import SuccessMsg from "./SuccessMsg";
import SuccessMsg, { ExecutionMessage } from "./SuccessMsg";
import TimeoutMessage from "./TimeoutMsg";
import css from "./index.module.css";
import { improveGqlError } from "./utils";
Expand Down Expand Up @@ -46,13 +44,7 @@ export default function SqlMessage(props: Props) {
case QueryExecutionStatus.Timeout:
return <TimeoutMessage {...props} />;
case QueryExecutionStatus.RowLimit:
return (
<p className={css.status}>
{props.rowsLen} {pluralize(props.rowsLen, "row")} selected on{" "}
<span className={css.bold}>{props.params.refName}</span> (for
unlimited query results download <DoltLink />)
</p>
);
return <ExecutionMessage {...props} hitRowLimit />;
case QueryExecutionStatus.Error:
default:
if (props.executionMessage && isTimeoutError(props.executionMessage)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Views/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("tests Views", () => {
</MockedProvider>,
);

const words = screen.getByText(/no saved views\. \?/i);
const words = screen.getByText(/no views\. \?/i);
const link = screen.getByRole("link");
expect(words).toBeVisible();
expect(link).toBeVisible();
Expand Down

0 comments on commit 40fad85

Please sign in to comment.