From 582d581edf4da0019ffc09e11523c4a51e7c8823 Mon Sep 17 00:00:00 2001 From: Laurent Nguyen Date: Tue, 23 Jul 2024 12:09:56 +0200 Subject: [PATCH] Fix unit tests --- .../DocumentsTabV2/DocumentsTabV2.test.tsx | 18 +++++++++++++----- .../DocumentsTableComponent.test.tsx | 5 +++++ .../__snapshots__/DocumentsTabV2.test.tsx.snap | 6 ++++++ .../DocumentsTableComponent.test.tsx.snap | 12 ++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.test.tsx b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.test.tsx index bdf0549a5..692dc43cd 100644 --- a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.test.tsx +++ b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.test.tsx @@ -13,13 +13,14 @@ import { SAVE_BUTTON_ID, UPDATE_BUTTON_ID, UPLOAD_BUTTON_ID, + addStringsNoDuplicate, buildQuery, getDiscardExistingDocumentChangesButtonState, getDiscardNewDocumentChangesButtonState, getSaveExistingDocumentButtonState, getSaveNewDocumentButtonState, getTabsButtons, - showPartitionKey + showPartitionKey, } from "Explorer/Tabs/DocumentsTabV2/DocumentsTabV2"; import { ReactWrapper, ShallowWrapper, mount, shallow } from "enzyme"; import * as ko from "knockout"; @@ -68,7 +69,7 @@ jest.mock("Explorer/Controls/Dialog", () => ({ useDialog: { getState: jest.fn(() => ({ showOkCancelModalDialog: (title: string, subText: string, okLabel: string, onOk: () => void) => onOk(), - showOkModalDialog: () => { }, + showOkModalDialog: () => {}, })), }, })); @@ -339,7 +340,10 @@ describe("Documents tab (noSql API)", () => { const createMockProps = (): IDocumentsTabComponentProps => ({ isPreferredApiMongoDB: false, documentIds: [], - collection: undefined, + collection: { + id: ko.observable("collectionId"), + databaseId: "databaseId", + } as ViewModels.CollectionBase, partitionKey: { kind: "Hash", paths: ["/foo"], version: 2 }, onLoadStartKey: 0, tabTitle: "", @@ -477,6 +481,10 @@ describe("Documents tab (noSql API)", () => { describe("Documents tab", () => { it("should add strings to array without duplicate", () => { - addStringsNoDuplicates(test this); + const array1 = ["a", "b", "c"]; + const array2 = ["b", "c", "d"]; + + const array3 = addStringsNoDuplicate(array1, array2); + expect(array3).toEqual(["a", "b", "c", "d"]); }); -}); \ No newline at end of file +}); diff --git a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.test.tsx b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.test.tsx index 4b396a3fa..9d004391b 100644 --- a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.test.tsx +++ b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.test.tsx @@ -1,6 +1,7 @@ import { TableRowId } from "@fluentui/react-components"; import { mount } from "enzyme"; import React from "react"; +import * as ViewModels from "../../../Contracts/ViewModels"; import { DocumentsTableComponent, IDocumentsTableComponentProps } from "./DocumentsTableComponent"; const PARTITION_KEY_HEADER = "partitionKey"; @@ -25,6 +26,10 @@ describe("DocumentsTableComponent", () => { partitionKeyHeaders: [PARTITION_KEY_HEADER], }, isSelectionDisabled: false, + collection: { + databaseId: "db", + id: ((): string => "coll") as ko.Observable, + } as ViewModels.CollectionBase, }); it("should render documents and partition keys in header", () => { diff --git a/src/Explorer/Tabs/DocumentsTabV2/__snapshots__/DocumentsTabV2.test.tsx.snap b/src/Explorer/Tabs/DocumentsTabV2/__snapshots__/DocumentsTabV2.test.tsx.snap index a8e1ceda4..9e661bd3c 100644 --- a/src/Explorer/Tabs/DocumentsTabV2/__snapshots__/DocumentsTabV2.test.tsx.snap +++ b/src/Explorer/Tabs/DocumentsTabV2/__snapshots__/DocumentsTabV2.test.tsx.snap @@ -527,6 +527,12 @@ exports[`Documents tab (noSql API) when rendered should render the page 1`] = ` } >