Skip to content

Commit

Permalink
Remove tests that are no longer relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
rafpaf committed May 3, 2024
1 parent 9620ede commit 86a097b
Showing 1 changed file with 0 additions and 138 deletions.
138 changes: 0 additions & 138 deletions frontend/src/metabase/browse/components/BrowseModels.unit.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import userEvent from "@testing-library/user-event";

import {
setupSearchEndpoints,
setupSettingsEndpoints,
Expand All @@ -13,8 +11,6 @@ import {
} from "metabase-types/api/mocks";
import { createMockSetupState } from "metabase-types/store/mocks";

import { BROWSE_MODELS_LOCALSTORAGE_KEY } from "../constants";

import { BrowseModels } from "./BrowseModels";

const renderBrowseModels = (modelCount: number) => {
Expand Down Expand Up @@ -221,42 +217,6 @@ describe("BrowseModels", () => {
expect(await screen.findByText("No models here yet")).toBeInTheDocument();
});

it("displays collection groups", async () => {
renderBrowseModels(10);
expect(await screen.findByText("Alpha")).toBeInTheDocument();
expect(await screen.findByText("Beta")).toBeInTheDocument();
expect(await screen.findByText("Charlie")).toBeInTheDocument();
expect(await screen.findByText("Delta")).toBeInTheDocument();
});

it("displays models in collections by default", () => {
const modelCount = 22;
renderBrowseModels(modelCount);
expect(screen.queryByText("No models here yet")).not.toBeInTheDocument();
assertThatModelsExist(0, modelCount - 1);
});

it("can collapse collections to hide models within them", async () => {
renderBrowseModels(10);
await userEvent.click(await screen.findByLabelText("collapse Alpha"));
expect(screen.queryByText("Model 0")).not.toBeInTheDocument();
expect(screen.queryByText("Model 1")).not.toBeInTheDocument();
expect(screen.queryByText("Model 2")).not.toBeInTheDocument();

await userEvent.click(await screen.findByLabelText("collapse Beta"));
expect(screen.queryByText("Model 3")).not.toBeInTheDocument();
expect(screen.queryByText("Model 4")).not.toBeInTheDocument();
expect(screen.queryByText("Model 5")).not.toBeInTheDocument();
});

it("can expand a collection to see models within it", async () => {
renderBrowseModels(10);
await userEvent.click(await screen.findByLabelText("collapse Alpha"));
expect(screen.queryByText("Model 0")).not.toBeInTheDocument();
await userEvent.click(await screen.findByLabelText("expand Alpha"));
expect(await screen.findByText("Model 0")).toBeInTheDocument();
});

it("displays the Our Analytics collection if it has a model", async () => {
renderBrowseModels(25);
await screen.findByText("Alpha");
Expand All @@ -265,102 +225,4 @@ describe("BrowseModels", () => {
expect(await screen.findByText("Model 21")).toBeInTheDocument();
expect(await screen.findByText("Model 22")).toBeInTheDocument();
});

it("shows the first six models in a collection by default", async () => {
renderBrowseModels(9999);
expect(await screen.findByText("100 models")).toBeInTheDocument();
expect(await screen.findByText("Show all")).toBeInTheDocument();
assertThatModelsExist(300, 305);
});

it("can show more than 6 models by clicking 'Show all'", async () => {
renderBrowseModels(9999);
await screen.findByText("6 of 100");
expect(screen.queryByText("Model 350")).not.toBeInTheDocument();
await userEvent.click(await screen.findByText("Show all"));
assertThatModelsExist(300, 399);
});

it("can show less than all models by clicking 'Show less'", async () => {
renderBrowseModels(9999);
expect(screen.queryByText("Model 399")).not.toBeInTheDocument();
await userEvent.click(await screen.findByText("Show all"));
await screen.findByText("Model 301");
expect(screen.getByText("Model 399")).toBeInTheDocument();
await userEvent.click(await screen.findByText("Show less"));
await screen.findByText("Model 301");
expect(screen.queryByText("Model 399")).not.toBeInTheDocument();
});

it("persists show-all state when expanding and collapsing collections", async () => {
renderBrowseModels(9999);
await userEvent.click(screen.getByText("Show all"));
expect(await screen.findByText("Model 301")).toBeInTheDocument();
expect(screen.getByText("Model 399")).toBeInTheDocument();

await userEvent.click(screen.getByLabelText("collapse Grande"));
expect(screen.queryByText("Model 301")).not.toBeInTheDocument();
expect(screen.queryByText("Model 399")).not.toBeInTheDocument();

await userEvent.click(screen.getByLabelText("expand Grande"));
expect(await screen.findByText("Model 301")).toBeInTheDocument();
expect(screen.getByText("Model 399")).toBeInTheDocument();
});

describe("local storage", () => {
it("persists the expanded state of collections in local storage", async () => {
renderBrowseModels(10);
await userEvent.click(await screen.findByLabelText("collapse Alpha"));
expect(screen.queryByText("Model 0")).not.toBeInTheDocument();
expect(localStorage.getItem(BROWSE_MODELS_LOCALSTORAGE_KEY)).toEqual(
JSON.stringify({ 99: { expanded: false, showAll: false } }),
);
});

it("loads the collapsed state of collections from local storage", async () => {
localStorage.setItem(
BROWSE_MODELS_LOCALSTORAGE_KEY,
JSON.stringify({ 99: { expanded: false, showAll: false } }),
);
renderBrowseModels(10);
expect(screen.queryByText("Model 0")).not.toBeInTheDocument();
});

it("persists the 'show all' state of collections in local storage", async () => {
renderBrowseModels(9999);
await userEvent.click(await screen.findByText("Show all"));
await screen.findByText("Model 399");
expect(localStorage.getItem(BROWSE_MODELS_LOCALSTORAGE_KEY)).toEqual(
JSON.stringify({ 7: { expanded: true, showAll: true } }),
);
});

it("loads the 'show all' state of collections from local storage", async () => {
localStorage.setItem(
BROWSE_MODELS_LOCALSTORAGE_KEY,
JSON.stringify({ 7: { expanded: true, showAll: true } }),
);
renderBrowseModels(9999);
expect(await screen.findByText("Show less")).toBeInTheDocument();
assertThatModelsExist(300, 399);
});

it("can deal with invalid local storage data", async () => {
localStorage.setItem(BROWSE_MODELS_LOCALSTORAGE_KEY, "{invalid json[[[}");
renderBrowseModels(10);
expect(await screen.findByText("Model 0")).toBeInTheDocument();
await userEvent.click(await screen.findByLabelText("collapse Alpha"));
expect(screen.queryByText("Model 0")).not.toBeInTheDocument();
// ignores invalid data and persists the new state
expect(localStorage.getItem(BROWSE_MODELS_LOCALSTORAGE_KEY)).toEqual(
JSON.stringify({ 99: { expanded: false, showAll: false } }),
);
});
});
});

function assertThatModelsExist(startId: number, endId: number) {
for (let i = startId; i <= endId; i++) {
expect(screen.getByText(`Model ${i}`)).toBeInTheDocument();
}
}

0 comments on commit 86a097b

Please sign in to comment.