2022-10-08 05:23:58 +00:00
|
|
|
import { render, screen } from "@testing-library/react";
|
2022-09-30 05:19:49 +00:00
|
|
|
import React from "react";
|
|
|
|
import "@testing-library/jest-dom";
|
2022-10-10 03:23:04 +00:00
|
|
|
import {
|
|
|
|
SquiggleChart,
|
|
|
|
SquiggleEditor,
|
|
|
|
SquigglePlayground,
|
|
|
|
} from "../src/index";
|
2022-10-08 05:23:58 +00:00
|
|
|
import { SqProject } from "@quri/squiggle-lang";
|
2022-09-30 00:22:14 +00:00
|
|
|
|
2022-10-08 05:23:58 +00:00
|
|
|
test("Chart logs nothing on render", async () => {
|
2022-09-30 05:19:49 +00:00
|
|
|
const { unmount } = render(<SquiggleChart code={"normal(0, 1)"} />);
|
|
|
|
unmount();
|
2022-09-30 00:22:14 +00:00
|
|
|
|
2022-10-04 01:22:41 +00:00
|
|
|
expect(console.log).not.toBeCalled();
|
2022-09-30 05:19:49 +00:00
|
|
|
expect(console.warn).not.toBeCalled();
|
|
|
|
expect(console.error).not.toBeCalled();
|
|
|
|
});
|
2022-10-08 05:23:58 +00:00
|
|
|
|
|
|
|
test("Editor logs nothing on render", async () => {
|
|
|
|
const { unmount } = render(<SquiggleEditor code={"normal(0, 1)"} />);
|
|
|
|
unmount();
|
|
|
|
|
|
|
|
expect(console.log).not.toBeCalled();
|
|
|
|
expect(console.warn).not.toBeCalled();
|
|
|
|
expect(console.error).not.toBeCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Project dependencies work in editors", async () => {
|
|
|
|
const project = SqProject.create();
|
|
|
|
|
|
|
|
render(<SquiggleEditor code={"x = 1"} project={project} />);
|
|
|
|
const source = project.getSourceIds()[0];
|
2022-10-10 03:23:04 +00:00
|
|
|
const { container } = render(
|
2022-10-08 05:23:58 +00:00
|
|
|
<SquiggleEditor code={"x + 1"} project={project} continues={[source]} />
|
|
|
|
);
|
2022-10-10 03:23:04 +00:00
|
|
|
expect(container).toHaveTextContent("2");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Project dependencies work in playgrounds", async () => {
|
|
|
|
const project = SqProject.create();
|
|
|
|
project.setSource("depend", "x = 1");
|
|
|
|
|
|
|
|
render(
|
|
|
|
<SquigglePlayground
|
|
|
|
code={"x + 1"}
|
|
|
|
project={project}
|
|
|
|
continues={["depend"]}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
// We must await here because SquigglePlayground loads results asynchronously
|
|
|
|
expect(await screen.findByRole("status")).toHaveTextContent("2");
|
2022-10-08 05:23:58 +00:00
|
|
|
});
|