Fix unit tests

This commit is contained in:
Laurent Nguyen 2024-07-23 12:09:56 +02:00
parent f65e7ab1d6
commit 582d581edf
4 changed files with 36 additions and 5 deletions

View File

@ -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";
@ -339,7 +340,10 @@ describe("Documents tab (noSql API)", () => {
const createMockProps = (): IDocumentsTabComponentProps => ({
isPreferredApiMongoDB: false,
documentIds: [],
collection: undefined,
collection: {
id: ko.observable<string>("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"]);
});
});

View File

@ -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<string>,
} as ViewModels.CollectionBase,
});
it("should render documents and partition keys in header", () => {

View File

@ -527,6 +527,12 @@ exports[`Documents tab (noSql API) when rendered should render the page 1`] = `
}
>
<DocumentsTableComponent
collection={
Object {
"databaseId": "databaseId",
"id": [Function],
}
}
columnHeaders={
Object {
"idHeader": "id",

View File

@ -2,6 +2,12 @@
exports[`DocumentsTableComponent should not render selection column when isSelectionDisabled is true 1`] = `
<DocumentsTableComponent
collection={
Object {
"databaseId": "db",
"id": [Function],
}
}
columnHeaders={
Object {
"idHeader": "id",
@ -994,6 +1000,12 @@ exports[`DocumentsTableComponent should not render selection column when isSelec
exports[`DocumentsTableComponent should render documents and partition keys in header 1`] = `
<DocumentsTableComponent
collection={
Object {
"databaseId": "db",
"id": [Function],
}
}
columnHeaders={
Object {
"idHeader": "id",