File size: 2,159 Bytes
c8cad77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// @vitest-environment jsdom
import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { expect, test } from "vitest";

import MergeDatasetsDialog from "./MergeDatasetsDialog";

test("opens with the browsed local dataset retained as the first merge source", async () => {
  Object.assign(globalThis, {
    IS_REACT_ACT_ENVIRONMENT: true,
    ResizeObserver: class {
      observe() {}
      unobserve() {}
      disconnect() {}
    },
  });
  Element.prototype.scrollIntoView = () => {};
  const host = document.createElement("div");
  document.body.append(host);
  const root = createRoot(host);

  try {
    await act(async () => {
      root.render(
        <MergeDatasetsDialog
          datasets={[
            { repo_id: "local/browsed", source: "local", last_modified: "", private: false },
            { repo_id: "local/additional", source: "local", last_modified: "", private: false },
          ]}
          selectedRepoId="local/browsed"
          open
          onOpenChange={() => {}}
          onMerge={async () => {}}
        />,
      );
    });

    expect(document.body.textContent).toContain("local/browsed is included");
    expect(document.body.textContent).not.toContain("local/additional");
    expect(document.body.textContent).toContain("Select at least one additional dataset.");
    const mergeButton = [...document.body.querySelectorAll("button")].find((button) =>
      button.textContent?.includes("Merge datasets"),
    ) as HTMLButtonElement;
    expect(mergeButton.disabled).toBe(true);

    const addButton = [...document.body.querySelectorAll("button")].find((button) =>
      button.textContent?.includes("Add dataset"),
    ) as HTMLButtonElement;
    await act(async () => {
      addButton.dispatchEvent(new MouseEvent("pointerdown", { bubbles: true }));
      addButton.click();
    });
    expect(document.body.querySelector("[cmdk-input]")).not.toBeNull();
    expect(document.body.textContent).toContain("local/additional");
    expect(document.body.textContent).not.toContain("Create new dataset");
  } finally {
    await act(async () => root.unmount());
    host.remove();
  }
});