mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-19 17:01:13 +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:
116
src/Utils/GalleryUtils.test.ts
Normal file
116
src/Utils/GalleryUtils.test.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import * as GalleryUtils from "./GalleryUtils";
|
||||
import { JunoClient, IGalleryItem } from "../Juno/JunoClient";
|
||||
import { ExplorerStub } from "../Explorer/OpenActionsStubs";
|
||||
import { HttpStatusCodes } from "../Common/Constants";
|
||||
import { GalleryTab, SortBy } from "../Explorer/Controls/NotebookGallery/GalleryViewerComponent";
|
||||
|
||||
const galleryItem: 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("GalleryUtils", () => {
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
it("downloadItem shows dialog in standalone gallery", () => {
|
||||
const setDialogProps = jest.fn().mockImplementation();
|
||||
|
||||
GalleryUtils.downloadItem({ setDialogProps }, undefined, undefined, galleryItem, undefined);
|
||||
|
||||
expect(setDialogProps).toBeCalled();
|
||||
});
|
||||
|
||||
it("downloadItem shows dialog in data explorer", () => {
|
||||
const setDialogProps = jest.fn().mockImplementation();
|
||||
const container = new ExplorerStub();
|
||||
container.showOkCancelModalDialog = jest.fn().mockImplementation();
|
||||
|
||||
GalleryUtils.downloadItem({ setDialogProps }, container, undefined, galleryItem, undefined);
|
||||
|
||||
expect(setDialogProps).not.toBeCalled();
|
||||
expect(container.showOkCancelModalDialog).toBeCalled();
|
||||
});
|
||||
|
||||
it("favoriteItem favorites item", async () => {
|
||||
const container = new ExplorerStub();
|
||||
const junoClient = new JunoClient();
|
||||
junoClient.favoriteNotebook = jest
|
||||
.fn()
|
||||
.mockReturnValue(Promise.resolve({ status: HttpStatusCodes.OK, data: galleryItem }));
|
||||
const onComplete = jest.fn().mockImplementation();
|
||||
|
||||
await GalleryUtils.favoriteItem(container, junoClient, galleryItem, onComplete);
|
||||
|
||||
expect(junoClient.favoriteNotebook).toBeCalledWith(galleryItem.id);
|
||||
expect(onComplete).toBeCalledWith(galleryItem);
|
||||
});
|
||||
|
||||
it("unfavoriteItem unfavorites item", async () => {
|
||||
const container = new ExplorerStub();
|
||||
const junoClient = new JunoClient();
|
||||
junoClient.unfavoriteNotebook = jest
|
||||
.fn()
|
||||
.mockReturnValue(Promise.resolve({ status: HttpStatusCodes.OK, data: galleryItem }));
|
||||
const onComplete = jest.fn().mockImplementation();
|
||||
|
||||
await GalleryUtils.unfavoriteItem(container, junoClient, galleryItem, onComplete);
|
||||
|
||||
expect(junoClient.unfavoriteNotebook).toBeCalledWith(galleryItem.id);
|
||||
expect(onComplete).toBeCalledWith(galleryItem);
|
||||
});
|
||||
|
||||
it("deleteItem shows dialog in data explorer", () => {
|
||||
const container = new ExplorerStub();
|
||||
container.showOkCancelModalDialog = jest.fn().mockImplementation();
|
||||
|
||||
GalleryUtils.deleteItem(container, undefined, galleryItem, undefined);
|
||||
|
||||
expect(container.showOkCancelModalDialog).toBeCalled();
|
||||
});
|
||||
|
||||
it("getGalleryViewerProps gets gallery viewer props correctly", () => {
|
||||
const selectedTab: GalleryTab = GalleryTab.OfficialSamples;
|
||||
const sortBy: SortBy = SortBy.MostDownloaded;
|
||||
const searchText = "my-complicated%20search%20query!!!";
|
||||
|
||||
const response = GalleryUtils.getGalleryViewerProps(
|
||||
`?${GalleryUtils.GalleryViewerParams.SelectedTab}=${GalleryTab[selectedTab]}&${GalleryUtils.GalleryViewerParams.SortBy}=${SortBy[sortBy]}&${GalleryUtils.GalleryViewerParams.SearchText}=${searchText}`
|
||||
);
|
||||
|
||||
expect(response).toEqual({
|
||||
selectedTab,
|
||||
sortBy,
|
||||
searchText: decodeURIComponent(searchText)
|
||||
});
|
||||
});
|
||||
|
||||
it("getNotebookViewerProps gets notebook viewer props correctly", () => {
|
||||
const notebookUrl = "https%3A%2F%2Fnotebook.url";
|
||||
const galleryItemId = "1234-abcd-efgh";
|
||||
|
||||
const response = GalleryUtils.getNotebookViewerProps(
|
||||
`?${GalleryUtils.NotebookViewerParams.NotebookUrl}=${notebookUrl}&${GalleryUtils.NotebookViewerParams.GalleryItemId}=${galleryItemId}`
|
||||
);
|
||||
|
||||
expect(response).toEqual({
|
||||
notebookUrl: decodeURIComponent(notebookUrl),
|
||||
galleryItemId
|
||||
});
|
||||
});
|
||||
|
||||
it("getTabTitle returns correct title for official samples", () => {
|
||||
expect(GalleryUtils.getTabTitle(GalleryTab.OfficialSamples)).toBe("Official samples");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user