From 0203bd96746ecc00cbbb9b0116c6fa86dbe1dc83 Mon Sep 17 00:00:00 2001 From: Laurent Nguyen Date: Mon, 6 May 2024 17:04:23 +0200 Subject: [PATCH] More improvements to table unit tests --- .../DocumentsTableComponent.test.tsx | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.test.tsx b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.test.tsx index da5d6be04..fa2c0bd3e 100644 --- a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.test.tsx +++ b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.test.tsx @@ -7,12 +7,11 @@ const PARTITION_KEY_HEADER = "partitionKey"; const ID_HEADER = "id"; describe("DocumentsTableComponent", () => { - const createMockProps = (): IDocumentsTableComponentProps => ({ items: [ { [ID_HEADER]: "1", [PARTITION_KEY_HEADER]: "pk1" }, { [ID_HEADER]: "2", [PARTITION_KEY_HEADER]: "pk2" }, - { [ID_HEADER]: "3", [PARTITION_KEY_HEADER]: "pk3" } + { [ID_HEADER]: "3", [PARTITION_KEY_HEADER]: "pk3" }, ], onItemClicked: (index: number): void => { index; @@ -23,12 +22,12 @@ describe("DocumentsTableComponent", () => { selectedRows: new Set(), size: { height: 0, - width: 0 + width: 0, }, columnHeaders: { idHeader: ID_HEADER, - partitionKeyHeaders: [PARTITION_KEY_HEADER] - } + partitionKeyHeaders: [PARTITION_KEY_HEADER], + }, }); let wrapper: ReactWrapper; @@ -43,15 +42,35 @@ describe("DocumentsTableComponent", () => { }); it("should show id and partition key(s) in header", () => { - expect(wrapper.find(".fui-TableHeader").findWhere(node => node.text() === ID_HEADER).exists()).toBeTruthy(); - expect(wrapper.find(".fui-TableHeader").findWhere(node => node.text() === PARTITION_KEY_HEADER).exists()).toBeTruthy(); + expect( + wrapper + .find(".fui-TableHeader") + .findWhere((node) => node.text() === ID_HEADER) + .exists(), + ).toBeTruthy(); + expect( + wrapper + .find(".fui-TableHeader") + .findWhere((node) => node.text() === PARTITION_KEY_HEADER) + .exists(), + ).toBeTruthy(); }); it("should show documents", () => { const rows = wrapper.find(".fui-TableBody .fui-TableRow"); expect(rows.length).toBe(3); - expect(rows.at(1).findWhere(node => node.text() === "2").exists()).toBeTruthy(); - expect(rows.at(1).findWhere(node => node.text() === "pk2").exists()).toBeTruthy(); + expect( + rows + .at(1) + .findWhere((node) => node.text() === "2") + .exists(), + ).toBeTruthy(); + expect( + rows + .at(1) + .findWhere((node) => node.text() === "pk2") + .exists(), + ).toBeTruthy(); }); }); @@ -61,8 +80,8 @@ describe("DocumentsTableComponent", () => { }); it("should clear selection when clicking on row", () => { - const onSelectedRowsChange = jest.fn().mockName('onSelectedRowsChange'); - const onItemClicked = jest.fn().mockName('onItemClicked'); + const onSelectedRowsChange = jest.fn().mockName("onSelectedRowsChange"); + const onItemClicked = jest.fn().mockName("onItemClicked"); const props: IDocumentsTableComponentProps = { ...createMockProps(), @@ -71,7 +90,7 @@ describe("DocumentsTableComponent", () => { onItemClicked, }; wrapper = mount(); - const cell = wrapper.find(".fui-TableBody .fui-TableCell").findWhere(node => node.text() === "2"); + const cell = wrapper.find(".fui-TableBody .fui-TableCell").findWhere((node) => node.text() === "2"); // const cell = wrapper.find(".fui-TableBody .fui-TableCell").findWhere(node => node.text() === "2" && node.type() === "function"); // const cell = wrapper.find("[title~=\"2\"]"); cell.at(4).simulate("click"); @@ -81,4 +100,3 @@ describe("DocumentsTableComponent", () => { }); }); }); -