mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 09:20:16 +00:00
Remove enableGallery feature flag (#68)
* Remove enableGallery feature flag * Fix bugs * Add tests to increase coverage * Move favorites functionality behind feature.enableGalleryPublish flag * Show code cells in NotebookViewer * Use cosmos db logo as persona image for sample notebook gallery cards * Update gallery card snapshot to fix test
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import ko from "knockout";
|
||||
import { HttpStatusCodes } from "../Common/Constants";
|
||||
import * as ViewModels from "../Contracts/ViewModels";
|
||||
import { IPinnedRepo, JunoClient } from "./JunoClient";
|
||||
import { IPinnedRepo, JunoClient, IGalleryItem } from "./JunoClient";
|
||||
import { config } from "../Config";
|
||||
import { getAuthorizationHeader } from "../Utils/AuthorizationUtils";
|
||||
|
||||
const sampleDatabaseAccount: ViewModels.DatabaseAccount = {
|
||||
id: "id",
|
||||
@@ -31,6 +33,23 @@ const samplePinnedRepos: IPinnedRepo[] = [
|
||||
}
|
||||
];
|
||||
|
||||
const sampleGalleryItems: IGalleryItem[] = [
|
||||
{
|
||||
id: "id",
|
||||
name: "name",
|
||||
description: "description",
|
||||
gitSha: "gitSha",
|
||||
tags: ["tag1"],
|
||||
author: "author",
|
||||
thumbnailUrl: "thumbnailUrl",
|
||||
created: "created",
|
||||
isSample: false,
|
||||
downloads: 0,
|
||||
favorites: 0,
|
||||
views: 0
|
||||
}
|
||||
];
|
||||
|
||||
describe("Pinned repos", () => {
|
||||
const junoClient = new JunoClient(ko.observable<ViewModels.DatabaseAccount>(sampleDatabaseAccount));
|
||||
|
||||
@@ -126,3 +145,231 @@ describe("GitHub", () => {
|
||||
expect(fetchUrlParams.get("client_id")).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Gallery", () => {
|
||||
const junoClient = new JunoClient(ko.observable<ViewModels.DatabaseAccount>(sampleDatabaseAccount));
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
it("getSampleNotebooks", async () => {
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
json: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.getSampleNotebooks();
|
||||
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(`${config.JUNO_ENDPOINT}/api/notebooks/gallery/samples`, undefined);
|
||||
});
|
||||
|
||||
it("getPublicNotebooks", async () => {
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
json: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.getPublicNotebooks();
|
||||
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(`${config.JUNO_ENDPOINT}/api/notebooks/gallery/public`, undefined);
|
||||
});
|
||||
|
||||
it("getNotebook", async () => {
|
||||
const id = "id";
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
json: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.getNotebook(id);
|
||||
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(`${config.JUNO_ENDPOINT}/api/notebooks/gallery/${id}`);
|
||||
});
|
||||
|
||||
it("getNotebookContent", async () => {
|
||||
const id = "id";
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
text: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.getNotebookContent(id);
|
||||
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(`${config.JUNO_ENDPOINT}/api/notebooks/gallery/${id}/content`);
|
||||
});
|
||||
|
||||
it("increaseNotebookViews", async () => {
|
||||
const id = "id";
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
json: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.increaseNotebookViews(id);
|
||||
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(`${config.JUNO_ENDPOINT}/api/notebooks/gallery/${id}/views`, {
|
||||
method: "PATCH"
|
||||
});
|
||||
});
|
||||
|
||||
it("increaseNotebookDownloadCount", async () => {
|
||||
const id = "id";
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
json: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.increaseNotebookDownloadCount(id);
|
||||
|
||||
const authorizationHeader = getAuthorizationHeader();
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(
|
||||
`${config.JUNO_ENDPOINT}/api/notebooks/${sampleDatabaseAccount.name}/gallery/${id}/downloads`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
[authorizationHeader.header]: authorizationHeader.token,
|
||||
"content-type": "application/json"
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("favoriteNotebook", async () => {
|
||||
const id = "id";
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
json: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.favoriteNotebook(id);
|
||||
|
||||
const authorizationHeader = getAuthorizationHeader();
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(
|
||||
`${config.JUNO_ENDPOINT}/api/notebooks/${sampleDatabaseAccount.name}/gallery/${id}/favorite`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
[authorizationHeader.header]: authorizationHeader.token,
|
||||
"content-type": "application/json"
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("unfavoriteNotebook", async () => {
|
||||
const id = "id";
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
json: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.unfavoriteNotebook(id);
|
||||
|
||||
const authorizationHeader = getAuthorizationHeader();
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(`${config.JUNO_ENDPOINT}/api/notebooks/gallery/${id}/unfavorite`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
[authorizationHeader.header]: authorizationHeader.token,
|
||||
"content-type": "application/json"
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("getFavoriteNotebooks", async () => {
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
json: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.getFavoriteNotebooks();
|
||||
|
||||
const authorizationHeader = getAuthorizationHeader();
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(`${config.JUNO_ENDPOINT}/api/notebooks/gallery/favorites`, {
|
||||
headers: {
|
||||
[authorizationHeader.header]: authorizationHeader.token,
|
||||
"content-type": "application/json"
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("getPublishedNotebooks", async () => {
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
json: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.getPublishedNotebooks();
|
||||
|
||||
const authorizationHeader = getAuthorizationHeader();
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(`${config.JUNO_ENDPOINT}/api/notebooks/gallery/published`, {
|
||||
headers: {
|
||||
[authorizationHeader.header]: authorizationHeader.token,
|
||||
"content-type": "application/json"
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("deleteNotebook", async () => {
|
||||
const id = "id";
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
json: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.deleteNotebook(id);
|
||||
|
||||
const authorizationHeader = getAuthorizationHeader();
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(`${config.JUNO_ENDPOINT}/api/notebooks/gallery/${id}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
[authorizationHeader.header]: authorizationHeader.token,
|
||||
"content-type": "application/json"
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("publishNotebook", async () => {
|
||||
const name = "name";
|
||||
const description = "description";
|
||||
const tags = ["tag"];
|
||||
const author = "author";
|
||||
const thumbnailUrl = "thumbnailUrl";
|
||||
const content = `{ "key": "value" }`;
|
||||
window.fetch = jest.fn().mockReturnValue({
|
||||
status: HttpStatusCodes.OK,
|
||||
json: () => undefined as any
|
||||
});
|
||||
|
||||
const response = await junoClient.publishNotebook(name, description, tags, author, thumbnailUrl, content);
|
||||
|
||||
const authorizationHeader = getAuthorizationHeader();
|
||||
expect(response.status).toBe(HttpStatusCodes.OK);
|
||||
expect(window.fetch).toBeCalledWith(`${config.JUNO_ENDPOINT}/api/notebooks/${sampleDatabaseAccount.name}/gallery`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
[authorizationHeader.header]: authorizationHeader.token,
|
||||
"content-type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
description,
|
||||
tags,
|
||||
author,
|
||||
thumbnailUrl,
|
||||
content: JSON.parse(content)
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user