Skip to content

Commit

Permalink
Account for null schema in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmielnik committed Apr 4, 2024
1 parent 4f5c4e9 commit 0c96d1c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
screen,
waitForLoaderToBeRemoved,
} from "__support__/ui";
import { checkNotNull } from "metabase/lib/types";
import type { Database } from "metabase-types/api";
import {
createMockDatabase,
Expand Down Expand Up @@ -164,7 +165,9 @@ describe("MetadataEditor", () => {

expect(screen.getByText(SAMPLE_DB.name)).toBeInTheDocument();
expect(screen.getByText(ORDERS_TABLE.display_name)).toBeInTheDocument();
expect(screen.queryByText(ORDERS_TABLE.schema)).not.toBeInTheDocument();
expect(
screen.queryByText(checkNotNull(ORDERS_TABLE.schema)),
).not.toBeInTheDocument();
});

it("should allow to search for a table", async () => {
Expand Down Expand Up @@ -412,10 +415,10 @@ describe("MetadataEditor", () => {

expect(screen.getByText(SAMPLE_DB_MULTI_SCHEMA.name)).toBeInTheDocument();
expect(
screen.getByText(PEOPLE_TABLE_MULTI_SCHEMA.schema),
screen.getByText(checkNotNull(PEOPLE_TABLE_MULTI_SCHEMA.schema)),
).toBeInTheDocument();
expect(
screen.getByText(REVIEWS_TABLE_MULTI_SCHEMA.schema),
screen.getByText(checkNotNull(REVIEWS_TABLE_MULTI_SCHEMA.schema)),
).toBeInTheDocument();
expect(
screen.queryByText(PEOPLE_TABLE_MULTI_SCHEMA.display_name),
Expand All @@ -425,24 +428,28 @@ describe("MetadataEditor", () => {
it("should allow to search for a schema", async () => {
await setup({ databases: [SAMPLE_DB_MULTI_SCHEMA] });

const searchValue = PEOPLE_TABLE_MULTI_SCHEMA.schema.substring(0, 3);
const searchValue = checkNotNull(
PEOPLE_TABLE_MULTI_SCHEMA.schema,
).substring(0, 3);
await userEvent.type(
screen.getByPlaceholderText("Find a schema"),
searchValue,
);

expect(
screen.getByText(PEOPLE_TABLE_MULTI_SCHEMA.schema),
screen.getByText(checkNotNull(PEOPLE_TABLE_MULTI_SCHEMA.schema)),
).toBeInTheDocument();
expect(
screen.queryByText(REVIEWS_TABLE_MULTI_SCHEMA.schema),
screen.queryByText(checkNotNull(REVIEWS_TABLE_MULTI_SCHEMA.schema)),
).not.toBeInTheDocument();
});

it("should allow to search for a table", async () => {
await setup({ databases: [SAMPLE_DB_MULTI_SCHEMA] });

await userEvent.click(screen.getByText(PEOPLE_TABLE_MULTI_SCHEMA.schema));
await userEvent.click(
screen.getByText(checkNotNull(PEOPLE_TABLE_MULTI_SCHEMA.schema)),
);
expect(
await screen.findByText(PEOPLE_TABLE_MULTI_SCHEMA.display_name),
).toBeInTheDocument();
Expand All @@ -452,10 +459,10 @@ describe("MetadataEditor", () => {

await userEvent.click(screen.getByText("Schemas"));
expect(
screen.getByText(PEOPLE_TABLE_MULTI_SCHEMA.schema),
screen.getByText(checkNotNull(PEOPLE_TABLE_MULTI_SCHEMA.schema)),
).toBeInTheDocument();
expect(
screen.getByText(REVIEWS_TABLE_MULTI_SCHEMA.schema),
screen.getByText(checkNotNull(REVIEWS_TABLE_MULTI_SCHEMA.schema)),
).toBeInTheDocument();
});
});
Expand All @@ -470,7 +477,7 @@ describe("MetadataEditor", () => {
await userEvent.click(screen.getByText(SAMPLE_DB.name));
await userEvent.click(screen.getByText(SAMPLE_DB_MULTI_SCHEMA.name));
await userEvent.click(
await screen.findByText(PEOPLE_TABLE_MULTI_SCHEMA.schema),
await screen.findByText(checkNotNull(PEOPLE_TABLE_MULTI_SCHEMA.schema)),
);
expect(
await screen.findByText(PEOPLE_TABLE_MULTI_SCHEMA.display_name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
waitForLoaderToBeRemoved,
within,
} from "__support__/ui";
import { checkNotNull } from "metabase/lib/types";
import { TYPE } from "metabase-lib/v1/types/constants";
import type {
Database,
Expand All @@ -28,6 +29,7 @@ import {
createMockFieldValues,
} from "metabase-types/api/mocks";
import {
ORDERS_ID,
createOrdersDiscountField,
createOrdersIdField,
createOrdersProductIdField,
Expand All @@ -39,7 +41,6 @@ import {
createProductsTable,
createReviewsTable,
createSampleDatabase,
ORDERS_ID,
} from "metabase-types/api/mocks/presets";

import { getMetadataRoutes } from "../../routes";
Expand Down Expand Up @@ -153,7 +154,9 @@ describe("MetadataFieldSettings", () => {
describe("breadcrumbs", () => {
it("should allow to navigate to and from field settings for a single-schema database", async () => {
await setup();
expect(screen.queryByText(ORDERS_TABLE.schema)).not.toBeInTheDocument();
expect(
screen.queryByText(checkNotNull(ORDERS_TABLE.schema)),
).not.toBeInTheDocument();

await userEvent.click(screen.getByText(ORDERS_TABLE.display_name));
await waitForLoaderToBeRemoved();
Expand Down Expand Up @@ -183,7 +186,9 @@ describe("MetadataFieldSettings", () => {
await waitForLoaderToBeRemoved();
expect(screen.getByText("General")).toBeInTheDocument();

await userEvent.click(screen.getByText(PEOPLE_TABLE_MULTI_SCHEMA.schema));
await userEvent.click(
screen.getByText(checkNotNull(PEOPLE_TABLE_MULTI_SCHEMA.schema)),
);
await userEvent.click(
screen.getByText(PEOPLE_TABLE_MULTI_SCHEMA.display_name),
);
Expand All @@ -192,7 +197,9 @@ describe("MetadataFieldSettings", () => {
expect(screen.getByText("General")).toBeInTheDocument();

await userEvent.click(screen.getByText(SAMPLE_DB_MULTI_SCHEMA.name));
await userEvent.click(screen.getByText(PEOPLE_TABLE_MULTI_SCHEMA.schema));
await userEvent.click(
screen.getByText(checkNotNull(PEOPLE_TABLE_MULTI_SCHEMA.schema)),
);
await userEvent.click(
screen.getByText(PEOPLE_TABLE_MULTI_SCHEMA.display_name),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
waitFor,
waitForLoaderToBeRemoved,
} from "__support__/ui";
import { checkNotNull } from "metabase/lib/types";
import type { Database } from "metabase-types/api";
import {
createOrdersTable,
Expand Down Expand Up @@ -122,7 +123,9 @@ describe("MetadataTableSettings", () => {
it("should allow to navigate to and from table settings in a multi-schema database", async () => {
await setup({ databases: [SAMPLE_DB_MULTI_SCHEMA] });

await userEvent.click(screen.getByText(PEOPLE_TABLE_MULTI_SCHEMA.schema));
await userEvent.click(
screen.getByText(checkNotNull(PEOPLE_TABLE_MULTI_SCHEMA.schema)),
);
await userEvent.click(
await screen.findByText(PEOPLE_TABLE_MULTI_SCHEMA.display_name),
);
Expand All @@ -132,14 +135,18 @@ describe("MetadataTableSettings", () => {
await userEvent.click(screen.getByText(SAMPLE_DB_MULTI_SCHEMA.name));
expect(await screen.findByText("2 schemas")).toBeInTheDocument();

await userEvent.click(screen.getByText(PEOPLE_TABLE_MULTI_SCHEMA.schema));
await userEvent.click(
screen.getByText(checkNotNull(PEOPLE_TABLE_MULTI_SCHEMA.schema)),
);
await userEvent.click(
screen.getByText(PEOPLE_TABLE_MULTI_SCHEMA.display_name),
);
await userEvent.click(screen.getByLabelText("Settings"));
expect(await screen.findByText("Settings")).toBeInTheDocument();

await userEvent.click(screen.getByText(PEOPLE_TABLE_MULTI_SCHEMA.schema));
await userEvent.click(
screen.getByText(checkNotNull(PEOPLE_TABLE_MULTI_SCHEMA.schema)),
);
expect(await screen.findByText("1 Queryable Table")).toBeInTheDocument();

await userEvent.click(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import userEvent from "@testing-library/user-event";

import { screen, waitForLoaderToBeRemoved } from "__support__/ui";
import { checkNotNull } from "metabase/lib/types";
import { generateSchemaId } from "metabase-lib/v1/metadata/utils/schema";

import {
setup,
SAMPLE_DATABASE,
EMPTY_DATABASE,
MULTI_SCHEMA_DATABASE,
SAMPLE_DATABASE,
SAMPLE_TABLE,
SAMPLE_TABLE_2,
SAMPLE_TABLE_3,
SAMPLE_TABLE_4,
setup,
} from "./common";

describe("DataPicker — picking raw data", () => {
Expand Down Expand Up @@ -131,7 +132,7 @@ describe("DataPicker — picking raw data", () => {
describe("given a multiple-schema database", () => {
it("respects initial value", async () => {
const table = SAMPLE_TABLE_3;
const schema = table.schema;
const schema = checkNotNull(table.schema);

await setup({
hasMultiSchemaDatabase: true,
Expand Down Expand Up @@ -160,8 +161,8 @@ describe("DataPicker — picking raw data", () => {

it("resets selected tables on schema change", async () => {
const schema1Table = SAMPLE_TABLE_3;
const schema1 = SAMPLE_TABLE_3.schema;
const schema2 = SAMPLE_TABLE_4.schema;
const schema1 = checkNotNull(SAMPLE_TABLE_3.schema);
const schema2 = checkNotNull(SAMPLE_TABLE_4.schema);

const { onChange } = await setup({ hasMultiSchemaDatabase: true });

Expand Down
5 changes: 4 additions & 1 deletion frontend/test/__support__/server-mocks/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fetchMock from "fetch-mock";
import _ from "underscore";

import { SAVED_QUESTIONS_DATABASE } from "metabase/databases/constants";
import { checkNotNull } from "metabase/lib/types";
import { isTypeFK } from "metabase-lib/v1/types/utils/isa";
import type { Database, DatabaseUsageInfo } from "metabase-types/api";

Expand Down Expand Up @@ -63,7 +64,9 @@ export function setupDatabasesEndpoints(
}

export const setupSchemaEndpoints = (db: Database) => {
const schemas = _.groupBy(db.tables ?? [], table => table.schema);
const schemas = _.groupBy(db.tables ?? [], table =>
checkNotNull(table.schema),
);
const schemaNames = Object.keys(schemas);
fetchMock.get(`path:/api/database/${db.id}/schemas`, schemaNames);
fetchMock.get(`path:/api/database/${db.id}/syncable_schemas`, schemaNames);
Expand Down

0 comments on commit 0c96d1c

Please sign in to comment.