From 8e33519df1223b7cffac9c70c4d8b6784b8e04b4 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Tue, 17 Nov 2020 21:56:23 +0100 Subject: [PATCH] fixed x and empty select on dialog (#220) * fixed x and empty select on dialog fixes: #210 * make button disabled when nothing is selected --- src/client-scopes/add/MapperDialog.tsx | 10 ++++--- .../add/__tests__/MapperDialog.test.tsx | 24 ++++++++++++---- .../__snapshots__/MapperDialog.test.tsx.snap | 28 ++++++++++--------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/client-scopes/add/MapperDialog.tsx b/src/client-scopes/add/MapperDialog.tsx index d8ba827921..680f5a3d2e 100644 --- a/src/client-scopes/add/MapperDialog.tsx +++ b/src/client-scopes/add/MapperDialog.tsx @@ -65,6 +65,9 @@ export const AddMapperDialog = (props: AddMapperDialogProps) => { setRows([...allRows.filter((row) => !nameFilter.includes(row.item.name))]); } + const selectedRows = rows + .filter((row) => row.selected) + .map((row) => row.item); const isBuiltIn = !!props.filter; return ( @@ -72,17 +75,16 @@ export const AddMapperDialog = (props: AddMapperDialogProps) => { variant={ModalVariant.medium} title={t("chooseAMapperType")} isOpen={props.open} + onClose={props.toggleDialog} actions={ isBuiltIn ? [ ); }; - it("should return empty array when selecting nothing", () => { - const onConfirm = jest.fn(); + it("should have disabled add button when nothing is selected", () => { const container = mount( - + {}} /> ); container.find("button#open").simulate("click"); expect(container).toMatchSnapshot(); - container.find("button#modal-confirm").simulate("click"); - expect(onConfirm).toBeCalledWith([]); + const button = container.find("button#modal-confirm"); + expect(button.hasClass("pf-m-disabled")).toBe(true); }); it("should return array with selected build in protocol mapping", () => { @@ -74,4 +73,17 @@ describe("", () => { serverInfo.protocolMapperTypes[protocol][0] ); }); + + it("should close the dialog on 'X' click", () => { + const container = mount( + {}} /> + ); + + expect(container.find("button#open").text()).toBe("Show"); + container.find("button#open").simulate("click"); + expect(container.find("button#open").text()).toBe("Hide"); + container.find('button[aria-label="Close"]').simulate("click"); + + expect(container.find("button#open").text()).toBe("Show"); + }); }); diff --git a/src/client-scopes/add/__tests__/__snapshots__/MapperDialog.test.tsx.snap b/src/client-scopes/add/__tests__/__snapshots__/MapperDialog.test.tsx.snap index caf40430c3..aaebb63237 100644 --- a/src/client-scopes/add/__tests__/__snapshots__/MapperDialog.test.tsx.snap +++ b/src/client-scopes/add/__tests__/__snapshots__/MapperDialog.test.tsx.snap @@ -1,14 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` should return empty array when selecting nothing 1`] = ` +exports[` should have disabled add button when nothing is selected 1`] = ` should return empty array when selecting nothing 1`] = Array [ @@ -19157,7 +19159,7 @@ exports[` should return selected protocol mapping type on click 1 onClick={[Function]} type="button" > - Show + Hide