fantonangeli commented on code in PR #2478:
URL: 
https://github.com/apache/incubator-kie-tools/pull/2478#discussion_r1701634388


##########
packages/runtime-tools-swf-enveloped-components/tests/components/WorkflowDefinitionList.test.tsx:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as React from "react";
+import { render, waitFor, screen, fireEvent, act } from 
"@testing-library/react";
+import "@testing-library/jest-dom";
+import WorkflowDefinitionList from 
"@kie-tools/runtime-tools-swf-enveloped-components/dist/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList";
+import { WorkflowDefinition } from 
"@kie-tools/runtime-tools-swf-gateway-api/dist/types";
+
+const mockGetWorkflowDefinitionsQuery = jest.fn();
+const mockSetWorkflowDefinitionList = jest.fn();
+const mockOpenWorkflowForm = jest.fn();
+const mockOpenTriggerCloudEvent = jest.fn();
+const mockSetWorkflowDefinitionFilter = jest.fn();
+const mockGetWorkflowDefinitionFilter = jest.fn();
+
+const mockDriver = {
+  getWorkflowDefinitionsQuery: mockGetWorkflowDefinitionsQuery,

Review Comment:
   to make the code more clear you can simply declare:
   `getWorkflowDefinitionsQuery: jest.fn(),`
   
   Then in the tests you refer to the mock function with:
   `mockDriver.getWorkflowDefinitionsQuery`
   
   The same for the other mocks in `mockDriver`



##########
packages/runtime-tools-swf-enveloped-components/tests/components/WorkflowDefinitionList.test.tsx:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as React from "react";
+import { render, waitFor, screen, fireEvent, act } from 
"@testing-library/react";
+import "@testing-library/jest-dom";
+import WorkflowDefinitionList from 
"@kie-tools/runtime-tools-swf-enveloped-components/dist/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList";
+import { WorkflowDefinition } from 
"@kie-tools/runtime-tools-swf-gateway-api/dist/types";
+
+const mockGetWorkflowDefinitionsQuery = jest.fn();
+const mockSetWorkflowDefinitionList = jest.fn();
+const mockOpenWorkflowForm = jest.fn();
+const mockOpenTriggerCloudEvent = jest.fn();
+const mockSetWorkflowDefinitionFilter = jest.fn();
+const mockGetWorkflowDefinitionFilter = jest.fn();
+
+const mockDriver = {
+  getWorkflowDefinitionsQuery: mockGetWorkflowDefinitionsQuery,
+  openWorkflowForm: mockOpenWorkflowForm,
+  openTriggerCloudEvent: mockOpenTriggerCloudEvent,
+  setWorkflowDefinitionFilter: mockSetWorkflowDefinitionFilter,
+  getWorkflowDefinitionFilter: mockGetWorkflowDefinitionFilter,
+};
+
+const sampleWorkflowDefinitions = [
+  { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+  { workflowName: "Test Workflow 2", endpoint: "/endpoint2", serviceUrl: 
"http://example.com/2"; },
+];
+
+const doQuery = async (): Promise<void> => {
+  const response: WorkflowDefinition[] = await 
mockDriver.getWorkflowDefinitionsQuery();
+  mockSetWorkflowDefinitionList(response);
+};
+
+describe("doQuery", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should call setWorkflowDefinitionList and setIsLoading correctly on 
success", async () => {
+    const mockResponse: WorkflowDefinition[] = [
+      { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+    ];
+    mockGetWorkflowDefinitionsQuery.mockResolvedValue(mockResponse);
+    await doQuery();
+    expect(mockSetWorkflowDefinitionList).toHaveBeenCalledWith(mockResponse);
+  });
+});
+
+describe("WorkflowDefinitionList component", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should fetch and set workflow definitions correctly", async () => {
+    
mockGetWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+    render(
+      <WorkflowDefinitionList
+        isEnvelopeConnectedToChannel={true}
+        driver={mockDriver}
+        ouiaId="test-ouia-id"
+        ouiaSafe={true}
+      />
+    );
+
+    await waitFor(() => {
+      expect(mockGetWorkflowDefinitionsQuery).toHaveBeenCalled();
+    });
+  });
+});
+
+describe("WorkflowDefinitionList component", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+  test("should maintain filter after refresh", async () => {
+    
mockGetWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+
+    const component = render(
+      <WorkflowDefinitionList
+        isEnvelopeConnectedToChannel={true}
+        driver={mockDriver}
+        ouiaId="test-ouia-id"
+        ouiaSafe={true}
+      />
+    );
+
+    mockGetWorkflowDefinitionFilter.mockResolvedValue(["Test Workflow 1"]);
+    await act(async () => {
+      await mockDriver.setWorkflowDefinitionFilter(["Test Workflow 1"]);
+    });
+
+    expect(mockDriver.setWorkflowDefinitionFilter).toHaveBeenCalledWith(["Test 
Workflow 1"]);
+    await (() => {
+      const filteredElement = 
component.getByTestId("workflow-definition-list-with-filter");
+      expect(filteredElement).toBeInTheDocument();
+    });
+
+    
mockGetWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+    await act(async () => {
+      await mockDriver.getWorkflowDefinitionsQuery();
+    });
+
+    expect(mockDriver.setWorkflowDefinitionFilter).toHaveBeenCalledWith(["Test 
Workflow 1"]);
+    await (() => {

Review Comment:
   This part of code is also not executed like in my previous comment.



##########
packages/runtime-tools-swf-enveloped-components/tests/components/WorkflowDefinitionList.test.tsx:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as React from "react";
+import { render, waitFor, screen, fireEvent, act } from 
"@testing-library/react";
+import "@testing-library/jest-dom";
+import WorkflowDefinitionList from 
"@kie-tools/runtime-tools-swf-enveloped-components/dist/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList";
+import { WorkflowDefinition } from 
"@kie-tools/runtime-tools-swf-gateway-api/dist/types";
+
+const mockGetWorkflowDefinitionsQuery = jest.fn();
+const mockSetWorkflowDefinitionList = jest.fn();
+const mockOpenWorkflowForm = jest.fn();
+const mockOpenTriggerCloudEvent = jest.fn();
+const mockSetWorkflowDefinitionFilter = jest.fn();
+const mockGetWorkflowDefinitionFilter = jest.fn();
+
+const mockDriver = {
+  getWorkflowDefinitionsQuery: mockGetWorkflowDefinitionsQuery,
+  openWorkflowForm: mockOpenWorkflowForm,
+  openTriggerCloudEvent: mockOpenTriggerCloudEvent,
+  setWorkflowDefinitionFilter: mockSetWorkflowDefinitionFilter,
+  getWorkflowDefinitionFilter: mockGetWorkflowDefinitionFilter,
+};
+
+const sampleWorkflowDefinitions = [
+  { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+  { workflowName: "Test Workflow 2", endpoint: "/endpoint2", serviceUrl: 
"http://example.com/2"; },
+];
+
+const doQuery = async (): Promise<void> => {
+  const response: WorkflowDefinition[] = await 
mockDriver.getWorkflowDefinitionsQuery();
+  mockSetWorkflowDefinitionList(response);
+};
+
+describe("doQuery", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should call setWorkflowDefinitionList and setIsLoading correctly on 
success", async () => {
+    const mockResponse: WorkflowDefinition[] = [
+      { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+    ];
+    mockGetWorkflowDefinitionsQuery.mockResolvedValue(mockResponse);
+    await doQuery();
+    expect(mockSetWorkflowDefinitionList).toHaveBeenCalledWith(mockResponse);
+  });
+});
+
+describe("WorkflowDefinitionList component", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should fetch and set workflow definitions correctly", async () => {
+    
mockGetWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+    render(
+      <WorkflowDefinitionList
+        isEnvelopeConnectedToChannel={true}
+        driver={mockDriver}
+        ouiaId="test-ouia-id"
+        ouiaSafe={true}
+      />
+    );
+
+    await waitFor(() => {
+      expect(mockGetWorkflowDefinitionsQuery).toHaveBeenCalled();
+    });
+  });
+});
+
+describe("WorkflowDefinitionList component", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+  test("should maintain filter after refresh", async () => {
+    
mockGetWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+
+    const component = render(
+      <WorkflowDefinitionList
+        isEnvelopeConnectedToChannel={true}
+        driver={mockDriver}
+        ouiaId="test-ouia-id"
+        ouiaSafe={true}
+      />
+    );
+
+    mockGetWorkflowDefinitionFilter.mockResolvedValue(["Test Workflow 1"]);
+    await act(async () => {
+      await mockDriver.setWorkflowDefinitionFilter(["Test Workflow 1"]);
+    });
+
+    expect(mockDriver.setWorkflowDefinitionFilter).toHaveBeenCalledWith(["Test 
Workflow 1"]);
+    await (() => {

Review Comment:
   This part of code is not executed.
   If you add, for instance, the code below the tests are still green
   `expect(0).toBe(2);` 



##########
packages/runtime-tools-swf-enveloped-components/tests/components/WorkflowDefinitionList.test.tsx:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as React from "react";
+import { render, waitFor, screen, fireEvent, act } from 
"@testing-library/react";
+import "@testing-library/jest-dom";
+import WorkflowDefinitionList from 
"@kie-tools/runtime-tools-swf-enveloped-components/dist/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList";
+import { WorkflowDefinition } from 
"@kie-tools/runtime-tools-swf-gateway-api/dist/types";
+
+const mockGetWorkflowDefinitionsQuery = jest.fn();
+const mockSetWorkflowDefinitionList = jest.fn();
+const mockOpenWorkflowForm = jest.fn();
+const mockOpenTriggerCloudEvent = jest.fn();
+const mockSetWorkflowDefinitionFilter = jest.fn();
+const mockGetWorkflowDefinitionFilter = jest.fn();
+
+const mockDriver = {
+  getWorkflowDefinitionsQuery: mockGetWorkflowDefinitionsQuery,
+  openWorkflowForm: mockOpenWorkflowForm,
+  openTriggerCloudEvent: mockOpenTriggerCloudEvent,
+  setWorkflowDefinitionFilter: mockSetWorkflowDefinitionFilter,
+  getWorkflowDefinitionFilter: mockGetWorkflowDefinitionFilter,
+};
+
+const sampleWorkflowDefinitions = [
+  { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+  { workflowName: "Test Workflow 2", endpoint: "/endpoint2", serviceUrl: 
"http://example.com/2"; },
+];
+
+const doQuery = async (): Promise<void> => {
+  const response: WorkflowDefinition[] = await 
mockDriver.getWorkflowDefinitionsQuery();
+  mockSetWorkflowDefinitionList(response);
+};
+
+describe("doQuery", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should call setWorkflowDefinitionList and setIsLoading correctly on 
success", async () => {
+    const mockResponse: WorkflowDefinition[] = [
+      { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+    ];
+    mockGetWorkflowDefinitionsQuery.mockResolvedValue(mockResponse);
+    await doQuery();
+    expect(mockSetWorkflowDefinitionList).toHaveBeenCalledWith(mockResponse);
+  });
+});
+
+describe("WorkflowDefinitionList component", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });

Review Comment:
   We can remove these lines and merge the 2 describes
   
   ```suggestion
   
   ```



##########
packages/runtime-tools-swf-enveloped-components/src/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList.tsx:
##########
@@ -84,6 +89,12 @@ const WorkflowDefinitionList: 
React.FC<WorkflowDefinitionListProps & OUIAProps>
     await driver.setWorkflowDefinitionFilter(filterWorkflowNames);
   };
 
+  const doRefresh = async (): Promise<void> => {
+    setIsLoading(true);
+    setFilterWorkflowNames([...filterWorkflowNames]);

Review Comment:
   I guess this doesn't do much and we can remove it
   ```suggestion
       setFilterWorkflowNames([...filterWorkflowNames]);
   ```



##########
packages/runtime-tools-swf-enveloped-components/tests/components/WorkflowDefinitionList.test.tsx:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as React from "react";
+import { render, waitFor, screen, fireEvent, act } from 
"@testing-library/react";
+import "@testing-library/jest-dom";
+import WorkflowDefinitionList from 
"@kie-tools/runtime-tools-swf-enveloped-components/dist/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList";
+import { WorkflowDefinition } from 
"@kie-tools/runtime-tools-swf-gateway-api/dist/types";
+
+const mockGetWorkflowDefinitionsQuery = jest.fn();
+const mockSetWorkflowDefinitionList = jest.fn();
+const mockOpenWorkflowForm = jest.fn();
+const mockOpenTriggerCloudEvent = jest.fn();
+const mockSetWorkflowDefinitionFilter = jest.fn();
+const mockGetWorkflowDefinitionFilter = jest.fn();
+
+const mockDriver = {
+  getWorkflowDefinitionsQuery: mockGetWorkflowDefinitionsQuery,
+  openWorkflowForm: mockOpenWorkflowForm,
+  openTriggerCloudEvent: mockOpenTriggerCloudEvent,
+  setWorkflowDefinitionFilter: mockSetWorkflowDefinitionFilter,
+  getWorkflowDefinitionFilter: mockGetWorkflowDefinitionFilter,
+};
+
+const sampleWorkflowDefinitions = [
+  { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+  { workflowName: "Test Workflow 2", endpoint: "/endpoint2", serviceUrl: 
"http://example.com/2"; },
+];
+
+const doQuery = async (): Promise<void> => {
+  const response: WorkflowDefinition[] = await 
mockDriver.getWorkflowDefinitionsQuery();
+  mockSetWorkflowDefinitionList(response);
+};
+
+describe("doQuery", () => {

Review Comment:
   We can remove this block of describe as we cannot test the real `doQuery` 
inside the component and also the `doQuery()` implementation in this file.



##########
packages/runtime-tools-swf-enveloped-components/tests/components/WorkflowDefinitionList.test.tsx:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as React from "react";
+import { render, waitFor, screen, fireEvent, act } from 
"@testing-library/react";
+import "@testing-library/jest-dom";
+import WorkflowDefinitionList from 
"@kie-tools/runtime-tools-swf-enveloped-components/dist/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList";
+import { WorkflowDefinition } from 
"@kie-tools/runtime-tools-swf-gateway-api/dist/types";
+
+const mockGetWorkflowDefinitionsQuery = jest.fn();
+const mockSetWorkflowDefinitionList = jest.fn();
+const mockOpenWorkflowForm = jest.fn();
+const mockOpenTriggerCloudEvent = jest.fn();
+const mockSetWorkflowDefinitionFilter = jest.fn();
+const mockGetWorkflowDefinitionFilter = jest.fn();
+
+const mockDriver = {
+  getWorkflowDefinitionsQuery: mockGetWorkflowDefinitionsQuery,
+  openWorkflowForm: mockOpenWorkflowForm,
+  openTriggerCloudEvent: mockOpenTriggerCloudEvent,
+  setWorkflowDefinitionFilter: mockSetWorkflowDefinitionFilter,
+  getWorkflowDefinitionFilter: mockGetWorkflowDefinitionFilter,
+};
+
+const sampleWorkflowDefinitions = [
+  { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+  { workflowName: "Test Workflow 2", endpoint: "/endpoint2", serviceUrl: 
"http://example.com/2"; },
+];
+
+const doQuery = async (): Promise<void> => {
+  const response: WorkflowDefinition[] = await 
mockDriver.getWorkflowDefinitionsQuery();
+  mockSetWorkflowDefinitionList(response);
+};
+
+describe("doQuery", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should call setWorkflowDefinitionList and setIsLoading correctly on 
success", async () => {
+    const mockResponse: WorkflowDefinition[] = [
+      { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+    ];
+    mockGetWorkflowDefinitionsQuery.mockResolvedValue(mockResponse);
+    await doQuery();
+    expect(mockSetWorkflowDefinitionList).toHaveBeenCalledWith(mockResponse);
+  });
+});
+
+describe("WorkflowDefinitionList component", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should fetch and set workflow definitions correctly", async () => {
+    
mockGetWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+    render(
+      <WorkflowDefinitionList
+        isEnvelopeConnectedToChannel={true}
+        driver={mockDriver}
+        ouiaId="test-ouia-id"
+        ouiaSafe={true}
+      />
+    );
+
+    await waitFor(() => {
+      expect(mockGetWorkflowDefinitionsQuery).toHaveBeenCalled();
+    });
+  });
+});
+
+describe("WorkflowDefinitionList component", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+  test("should maintain filter after refresh", async () => {

Review Comment:
   In this test I would do these actions to test:
   - verify "Test Workflow 1" is in the document
     `      expect(component.queryByText("Test Workflow 
1")).toBeInTheDocument();`
   - verify "Test Workflow 2" is in the document
   - set the filter to "Test Workflow 1" (if you need you can add the 
`data-testid` in the real component)
     example: 
https://github.com/apache/incubator-kie-tools/blob/6697b9d6be9320d54a92d9c5d72c71f22e922493/packages/uniforms-patternfly/tests/DateField.test.tsx#L96
   - click on "Apply filter" (data-testid: "apply-filter")
   - verify "Test Workflow 2" is NOT in the document
   `      expect(component.queryByText("Test Workflow 
2")).not.toBeInTheDocument();`
   - click on refresh button (data-testid: "refresh")
   - verify "Test Workflow 2" is NOT in the document
   
   In the next comments, I review the single parts of the code.



##########
packages/runtime-tools-swf-enveloped-components/tests/components/WorkflowDefinitionList.test.tsx:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as React from "react";
+import { render, waitFor, screen, fireEvent, act } from 
"@testing-library/react";
+import "@testing-library/jest-dom";
+import WorkflowDefinitionList from 
"@kie-tools/runtime-tools-swf-enveloped-components/dist/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList";
+import { WorkflowDefinition } from 
"@kie-tools/runtime-tools-swf-gateway-api/dist/types";
+
+const mockGetWorkflowDefinitionsQuery = jest.fn();
+const mockSetWorkflowDefinitionList = jest.fn();
+const mockOpenWorkflowForm = jest.fn();
+const mockOpenTriggerCloudEvent = jest.fn();
+const mockSetWorkflowDefinitionFilter = jest.fn();
+const mockGetWorkflowDefinitionFilter = jest.fn();
+
+const mockDriver = {
+  getWorkflowDefinitionsQuery: mockGetWorkflowDefinitionsQuery,
+  openWorkflowForm: mockOpenWorkflowForm,
+  openTriggerCloudEvent: mockOpenTriggerCloudEvent,
+  setWorkflowDefinitionFilter: mockSetWorkflowDefinitionFilter,
+  getWorkflowDefinitionFilter: mockGetWorkflowDefinitionFilter,
+};
+
+const sampleWorkflowDefinitions = [
+  { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+  { workflowName: "Test Workflow 2", endpoint: "/endpoint2", serviceUrl: 
"http://example.com/2"; },
+];
+
+const doQuery = async (): Promise<void> => {
+  const response: WorkflowDefinition[] = await 
mockDriver.getWorkflowDefinitionsQuery();
+  mockSetWorkflowDefinitionList(response);
+};
+
+describe("doQuery", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should call setWorkflowDefinitionList and setIsLoading correctly on 
success", async () => {
+    const mockResponse: WorkflowDefinition[] = [
+      { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+    ];
+    mockGetWorkflowDefinitionsQuery.mockResolvedValue(mockResponse);
+    await doQuery();
+    expect(mockSetWorkflowDefinitionList).toHaveBeenCalledWith(mockResponse);
+  });
+});
+
+describe("WorkflowDefinitionList component", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should fetch and set workflow definitions correctly", async () => {
+    
mockGetWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+    render(
+      <WorkflowDefinitionList
+        isEnvelopeConnectedToChannel={true}
+        driver={mockDriver}
+        ouiaId="test-ouia-id"
+        ouiaSafe={true}
+      />
+    );
+
+    await waitFor(() => {
+      expect(mockGetWorkflowDefinitionsQuery).toHaveBeenCalled();

Review Comment:
   We can add this to verify all the workflows are showed
   ```suggestion
         expect(mockGetWorkflowDefinitionsQuery).toHaveBeenCalled();
         expect(component.queryByText("Test Workflow 2")).toBeInTheDocument();
   ```



##########
packages/runtime-tools-swf-enveloped-components/tests/components/WorkflowDefinitionList.test.tsx:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as React from "react";
+import { render, waitFor, screen, fireEvent, act } from 
"@testing-library/react";
+import "@testing-library/jest-dom";
+import WorkflowDefinitionList from 
"@kie-tools/runtime-tools-swf-enveloped-components/dist/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList";
+import { WorkflowDefinition } from 
"@kie-tools/runtime-tools-swf-gateway-api/dist/types";
+
+const mockGetWorkflowDefinitionsQuery = jest.fn();
+const mockSetWorkflowDefinitionList = jest.fn();
+const mockOpenWorkflowForm = jest.fn();
+const mockOpenTriggerCloudEvent = jest.fn();
+const mockSetWorkflowDefinitionFilter = jest.fn();
+const mockGetWorkflowDefinitionFilter = jest.fn();
+
+const mockDriver = {
+  getWorkflowDefinitionsQuery: mockGetWorkflowDefinitionsQuery,
+  openWorkflowForm: mockOpenWorkflowForm,
+  openTriggerCloudEvent: mockOpenTriggerCloudEvent,
+  setWorkflowDefinitionFilter: mockSetWorkflowDefinitionFilter,
+  getWorkflowDefinitionFilter: mockGetWorkflowDefinitionFilter,
+};
+
+const sampleWorkflowDefinitions = [
+  { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+  { workflowName: "Test Workflow 2", endpoint: "/endpoint2", serviceUrl: 
"http://example.com/2"; },
+];
+
+const doQuery = async (): Promise<void> => {
+  const response: WorkflowDefinition[] = await 
mockDriver.getWorkflowDefinitionsQuery();
+  mockSetWorkflowDefinitionList(response);
+};
+
+describe("doQuery", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should call setWorkflowDefinitionList and setIsLoading correctly on 
success", async () => {
+    const mockResponse: WorkflowDefinition[] = [
+      { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+    ];
+    mockGetWorkflowDefinitionsQuery.mockResolvedValue(mockResponse);
+    await doQuery();
+    expect(mockSetWorkflowDefinitionList).toHaveBeenCalledWith(mockResponse);
+  });
+});
+
+describe("WorkflowDefinitionList component", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should fetch and set workflow definitions correctly", async () => {
+    
mockGetWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+    render(
+      <WorkflowDefinitionList
+        isEnvelopeConnectedToChannel={true}
+        driver={mockDriver}
+        ouiaId="test-ouia-id"
+        ouiaSafe={true}
+      />
+    );
+
+    await waitFor(() => {
+      expect(mockGetWorkflowDefinitionsQuery).toHaveBeenCalled();
+    });
+  });
+});
+
+describe("WorkflowDefinitionList component", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+  test("should maintain filter after refresh", async () => {
+    
mockGetWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+
+    const component = render(
+      <WorkflowDefinitionList
+        isEnvelopeConnectedToChannel={true}
+        driver={mockDriver}
+        ouiaId="test-ouia-id"
+        ouiaSafe={true}
+      />
+    );
+
+    mockGetWorkflowDefinitionFilter.mockResolvedValue(["Test Workflow 1"]);
+    await act(async () => {
+      await mockDriver.setWorkflowDefinitionFilter(["Test Workflow 1"]);

Review Comment:
   This has no effect on the page as the workflows definition list is filtered 
by the filterWorkflowNames state.
   I think we can remove all the calls and expect to 
`setWorkflowDefinitionFilter` from the test.
   Please correct me if I'm wrong.



##########
packages/runtime-tools-swf-enveloped-components/tests/components/WorkflowDefinitionList.test.tsx:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as React from "react";
+import { render, waitFor, screen, fireEvent, act } from 
"@testing-library/react";
+import "@testing-library/jest-dom";
+import WorkflowDefinitionList from 
"@kie-tools/runtime-tools-swf-enveloped-components/dist/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList";
+import { WorkflowDefinition } from 
"@kie-tools/runtime-tools-swf-gateway-api/dist/types";
+
+const mockGetWorkflowDefinitionsQuery = jest.fn();
+const mockSetWorkflowDefinitionList = jest.fn();
+const mockOpenWorkflowForm = jest.fn();
+const mockOpenTriggerCloudEvent = jest.fn();
+const mockSetWorkflowDefinitionFilter = jest.fn();
+const mockGetWorkflowDefinitionFilter = jest.fn();
+
+const mockDriver = {
+  getWorkflowDefinitionsQuery: mockGetWorkflowDefinitionsQuery,
+  openWorkflowForm: mockOpenWorkflowForm,
+  openTriggerCloudEvent: mockOpenTriggerCloudEvent,
+  setWorkflowDefinitionFilter: mockSetWorkflowDefinitionFilter,
+  getWorkflowDefinitionFilter: mockGetWorkflowDefinitionFilter,
+};
+
+const sampleWorkflowDefinitions = [
+  { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+  { workflowName: "Test Workflow 2", endpoint: "/endpoint2", serviceUrl: 
"http://example.com/2"; },
+];
+
+const doQuery = async (): Promise<void> => {
+  const response: WorkflowDefinition[] = await 
mockDriver.getWorkflowDefinitionsQuery();
+  mockSetWorkflowDefinitionList(response);
+};
+
+describe("doQuery", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should call setWorkflowDefinitionList and setIsLoading correctly on 
success", async () => {
+    const mockResponse: WorkflowDefinition[] = [
+      { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl: 
"http://example.com/1"; },
+    ];
+    mockGetWorkflowDefinitionsQuery.mockResolvedValue(mockResponse);
+    await doQuery();
+    expect(mockSetWorkflowDefinitionList).toHaveBeenCalledWith(mockResponse);
+  });
+});
+
+describe("WorkflowDefinitionList component", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+
+  test("should fetch and set workflow definitions correctly", async () => {
+    
mockGetWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+    render(
+      <WorkflowDefinitionList
+        isEnvelopeConnectedToChannel={true}
+        driver={mockDriver}
+        ouiaId="test-ouia-id"
+        ouiaSafe={true}
+      />
+    );
+
+    await waitFor(() => {
+      expect(mockGetWorkflowDefinitionsQuery).toHaveBeenCalled();
+    });
+  });
+});
+
+describe("WorkflowDefinitionList component", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
+  test("should maintain filter after refresh", async () => {
+    
mockGetWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+
+    const component = render(
+      <WorkflowDefinitionList
+        isEnvelopeConnectedToChannel={true}
+        driver={mockDriver}
+        ouiaId="test-ouia-id"
+        ouiaSafe={true}
+      />
+    );
+
+    mockGetWorkflowDefinitionFilter.mockResolvedValue(["Test Workflow 1"]);

Review Comment:
   In the current logic of the page `driver.getWorkflowDefinitionsQuery()` 
always returns all the elements and then they are filtered client-side.
   I think it's better to use `sampleWorkflowDefinitions` as a resolved value, 
to keep the test following the real logic.
   ```suggestion
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to