2022-10-04 01:22:41 +00:00
|
|
|
import { render } from "@testing-library/react";
|
|
|
|
import React from "react";
|
|
|
|
import "@testing-library/jest-dom";
|
|
|
|
import { SquiggleChart } from "../src/index";
|
|
|
|
import { SqProject } from "@quri/squiggle-lang";
|
|
|
|
|
2022-10-07 00:18:13 +00:00
|
|
|
test("Creates and cleans up source", async () => {
|
2022-10-04 01:22:41 +00:00
|
|
|
const project = SqProject.create();
|
|
|
|
|
2022-10-04 02:38:15 +00:00
|
|
|
const { unmount } = render(
|
|
|
|
<SquiggleChart code={"normal(0, 1)"} project={project} />
|
|
|
|
);
|
2022-10-05 00:57:32 +00:00
|
|
|
|
2022-10-04 02:38:15 +00:00
|
|
|
expect(project.getSourceIds().length).toBe(1);
|
2022-10-04 01:22:41 +00:00
|
|
|
|
2022-10-04 02:38:15 +00:00
|
|
|
const sourceId = project.getSourceIds()[0];
|
|
|
|
expect(project.getSource(sourceId)).toBe("normal(0, 1)");
|
2022-10-04 01:22:41 +00:00
|
|
|
|
|
|
|
unmount();
|
2022-10-04 02:38:15 +00:00
|
|
|
expect(project.getSourceIds().length).toBe(0);
|
|
|
|
expect(project.getSource(sourceId)).toBe(undefined);
|
|
|
|
});
|
2022-10-07 00:18:13 +00:00
|
|
|
|
|
|
|
test("Creates and cleans up source and imports", async () => {
|
|
|
|
const project = SqProject.create();
|
|
|
|
|
|
|
|
const { unmount } = render(
|
|
|
|
<SquiggleChart
|
|
|
|
code={"normal($x, 1)"}
|
|
|
|
project={project}
|
|
|
|
jsImports={{ x: 3 }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(project.getSourceIds().length).toBe(2);
|
|
|
|
|
|
|
|
unmount();
|
|
|
|
expect(project.getSourceIds()).toStrictEqual([]);
|
|
|
|
});
|