Skip to content
Snippets Groups Projects
Unverified Commit b777f58d authored by Nemanja Glumac's avatar Nemanja Glumac Committed by GitHub
Browse files

Remove readonly notebook view (#40641)

parent 564e642f
No related branches found
No related tags found
No related merge requests found
import styled from "@emotion/styled";
export const ReadOnlyNotebookContainer = styled.div`
pointer-events: none;
`;
import Notebook from "metabase/query_builder/components/notebook/Notebook";
import type Question from "metabase-lib/v1/Question";
import { ReadOnlyNotebookContainer } from "./ReadOnlyNotebook.styled";
// eslint-disable-next-line import/no-default-export -- deprecated usage
export default function ReadOnlyNotebook({ question }: { question: Question }) {
return (
<ReadOnlyNotebookContainer data-testid="read-only-notebook">
<Notebook question={question} hasVisualizeButton={false} readOnly />
</ReadOnlyNotebookContainer>
);
}
import {
setupDatabasesEndpoints,
setupSearchEndpoints,
} from "__support__/server-mocks";
import { createMockEntitiesState } from "__support__/store";
import { renderWithProviders, screen, getIcon } from "__support__/ui";
import { getMetadata } from "metabase/selectors/metadata";
import Question from "metabase-lib/v1/Question";
import type { DatasetQuery } from "metabase-types/api";
import { createMockStructuredDatasetQuery } from "metabase-types/api/mocks";
import { createSampleDatabase } from "metabase-types/api/mocks/presets";
import { createMockState } from "metabase-types/store/mocks";
import ReadOnlyNotebook from "./ReadOnlyNotebook";
const makeQuery = (options: any) => {
// we have to cast this because we have 2 incompatible DatasetQuery types
return createMockStructuredDatasetQuery({
query: options,
}) as DatasetQuery;
};
const setup = ({ query }: { query: DatasetQuery }) => {
const database = createSampleDatabase();
const state = createMockState({
entities: createMockEntitiesState({
databases: [database],
}),
});
setupDatabasesEndpoints([database]);
setupSearchEndpoints([]);
const metadata = getMetadata(state);
const card = {
dataset_query: query,
};
const question = new Question(card, metadata);
renderWithProviders(<ReadOnlyNotebook question={question} />, {
storeInitialState: state,
});
};
describe("Notebook > ReadOnlyNotebook", () => {
describe("Basic notebook functionality", () => {
it("shows filters", async () => {
const query = makeQuery({
"source-table": 1,
filter: [">", ["field", 3, null], 10],
});
setup({ query });
expect(await screen.findByText("Products")).toBeInTheDocument();
expect(
await screen.findByText("ID is greater than 10"),
).toBeInTheDocument();
});
it("shows summaries", async () => {
const query = makeQuery({
"source-table": 1,
aggregation: [["avg", ["field", 7, null]]],
breakout: [["field", 3, null]],
});
setup({ query });
expect(await screen.findByText("Products")).toBeInTheDocument();
expect(await screen.findByText("Average of Price")).toBeInTheDocument();
expect(await screen.findByText("by")).toBeInTheDocument();
expect(await screen.findByText("ID")).toBeInTheDocument();
});
it("shows order by", async () => {
const query = makeQuery({
"source-table": 1,
"order-by": [["asc", ["field", 2, null]]],
});
setup({ query });
expect(screen.getByTestId("read-only-notebook")).toBeInTheDocument();
expect(await screen.findByText("Products")).toBeInTheDocument();
expect(await screen.findByText("Sort")).toBeInTheDocument();
expect(await screen.findByText("Rating")).toBeInTheDocument();
// sort ascending shows an up arrow
expect(getIcon("arrow_up")).toBeInTheDocument();
});
it("shows limit clauses", async () => {
const query = makeQuery({
"source-table": 1,
limit: 120,
});
setup({ query });
expect(await screen.findByText("Products")).toBeInTheDocument();
expect(await screen.findByText("Row limit")).toBeInTheDocument();
const limitInput = await screen.findByPlaceholderText("Enter a limit");
expect(limitInput).toHaveValue(120);
});
});
describe("Read only features", () => {
it("shows the read-only notebook editor", async () => {
const query = makeQuery({ "source-table": 1 });
setup({ query });
expect(screen.getByTestId("read-only-notebook")).toBeInTheDocument();
expect(await screen.findByText("Products")).toBeInTheDocument();
});
it("does not show the visualize button", async () => {
const query = makeQuery({ "source-table": 1 });
setup({ query });
expect(screen.getByTestId("read-only-notebook")).toBeInTheDocument();
expect(await screen.findByText("Products")).toBeInTheDocument();
expect(screen.queryByText("Visualize")).not.toBeInTheDocument();
});
it("does not show preview buttons", async () => {
const query = makeQuery({ "source-table": 1 });
setup({ query });
expect(await screen.findByText("Products")).toBeInTheDocument();
expect(screen.queryByLabelText("play icon")).not.toBeInTheDocument();
});
it("does not show remove buttons", async () => {
const query = makeQuery({
"source-table": 1,
filter: [">", ["field", 3, null], 10],
});
setup({ query });
expect(await screen.findByText("Products")).toBeInTheDocument();
expect(
await screen.findByText("ID is greater than 10"),
).toBeInTheDocument();
expect(screen.queryByLabelText("close icon")).not.toBeInTheDocument();
});
it("does not show add buttons", async () => {
const query = makeQuery({
"source-table": 1,
filter: [">", ["field", 3, null], 10],
});
setup({ query });
expect(await screen.findByText("Products")).toBeInTheDocument();
expect(
await screen.findByText("ID is greater than 10"),
).toBeInTheDocument();
expect(screen.queryByLabelText("add icon")).not.toBeInTheDocument();
});
it("does not show dropdowns to pick columns", async () => {
const query = makeQuery({
"source-table": 1,
filter: [">", ["field", 3, null], 10],
});
setup({ query });
expect(await screen.findByText("Products")).toBeInTheDocument();
expect(
screen.queryByLabelText("chevrondown icon"),
).not.toBeInTheDocument();
});
it("does not show sections without query clauses or section add buttons", async () => {
const query = makeQuery({
"source-table": 1,
});
setup({ query });
expect(await screen.findByText("Products")).toBeInTheDocument();
expect(screen.queryByText("Filter")).not.toBeInTheDocument();
expect(screen.queryByText("Summarize")).not.toBeInTheDocument();
expect(screen.queryByText("Join data")).not.toBeInTheDocument();
expect(screen.queryByText("Custom column")).not.toBeInTheDocument();
expect(screen.queryByText("Row limit")).not.toBeInTheDocument();
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment