Files
cosmos-explorer/src/Explorer/Notebook/NotebookUtil.test.ts
2020-06-23 10:45:51 -05:00

50 lines
2.0 KiB
TypeScript

import { NotebookUtil } from "./NotebookUtil";
import * as GitHubUtils from "../../Utils/GitHubUtils";
const fileName = "file";
const notebookName = "file.ipynb";
const filePath = `folder/${fileName}`;
const notebookPath = `folder/${notebookName}`;
const gitHubFileUri = GitHubUtils.toContentUri("owner", "repo", "branch", filePath);
const gitHubNotebookUri = GitHubUtils.toContentUri("owner", "repo", "branch", notebookPath);
describe("NotebookUtil", () => {
describe("isNotebookFile", () => {
it("works for jupyter file paths", () => {
expect(NotebookUtil.isNotebookFile(filePath)).toBeFalsy();
expect(NotebookUtil.isNotebookFile(notebookPath)).toBeTruthy();
});
it("works for github file uris", () => {
expect(NotebookUtil.isNotebookFile(gitHubFileUri)).toBeFalsy();
expect(NotebookUtil.isNotebookFile(gitHubNotebookUri)).toBeTruthy();
});
});
describe("getName", () => {
it("works for jupyter file paths", () => {
expect(NotebookUtil.getName(filePath)).toEqual(fileName);
expect(NotebookUtil.getName(notebookPath)).toEqual(notebookName);
});
it("works for github file uris", () => {
expect(NotebookUtil.getName(gitHubFileUri)).toEqual(fileName);
expect(NotebookUtil.getName(gitHubNotebookUri)).toEqual(notebookName);
});
});
describe("replaceName", () => {
it("works for jupyter file paths", () => {
expect(NotebookUtil.replaceName(filePath, "newName")).toEqual(filePath.replace(fileName, "newName"));
expect(NotebookUtil.replaceName(notebookPath, "newName")).toEqual(notebookPath.replace(notebookName, "newName"));
});
it("works for github file uris", () => {
expect(NotebookUtil.replaceName(gitHubFileUri, "newName")).toEqual(gitHubFileUri.replace(fileName, "newName"));
expect(NotebookUtil.replaceName(gitHubNotebookUri, "newName")).toEqual(
gitHubNotebookUri.replace(notebookName, "newName")
);
});
});
});