This is an automated email from the ASF dual-hosted git repository.
fantonangeli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git
The following commit(s) were added to refs/heads/main by this push:
new d894745b909 kie-tools#2428: [serverless-workflow-dev-ui-webapp] The
reload button doesn't fetch data (#2478)
d894745b909 is described below
commit d894745b909434a3be5f8ac78779664f17ad3ca2
Author: Kumar Aditya Raj <[email protected]>
AuthorDate: Thu Aug 8 18:01:23 2024 +0530
kie-tools#2428: [serverless-workflow-dev-ui-webapp] The reload button
doesn't fetch data (#2478)
---
.../jest.config.js | 13 +++-
.../package.json | 1 +
.../WorkflowDefinitionList.tsx | 29 ++++---
.../WorkflowDefinitionListToolbar.tsx | 8 +-
.../__mocks__/styleMock.js} | 12 +--
.../components/WorkflowDefinitionList.test.tsx | 90 ++++++++++++++++++++++
.../{jest.config.js => tests/jest.setup.ts} | 12 +--
pnpm-lock.yaml | 53 +++++++------
8 files changed, 156 insertions(+), 62 deletions(-)
diff --git a/packages/runtime-tools-swf-enveloped-components/jest.config.js
b/packages/runtime-tools-swf-enveloped-components/jest.config.js
index e2963bba168..b4ae71727d8 100644
--- a/packages/runtime-tools-swf-enveloped-components/jest.config.js
+++ b/packages/runtime-tools-swf-enveloped-components/jest.config.js
@@ -17,14 +17,25 @@
* under the License.
*/
-const { config, babelTransform, typescriptTransform } =
require("@kie-tools/jest-base/jest.config");
+const {
+ styleMock,
+ config,
+ babelTransform,
+ typescriptTransform,
+ jestSetupPath,
+} = require("@kie-tools/jest-base/jest.config");
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
...config,
testEnvironment: "jsdom",
+ moduleNameMapper: {
+ ...styleMock,
+ },
transform: {
...babelTransform,
...typescriptTransform,
},
+ transformIgnorePatterns: [],
+ setupFilesAfterEnv: [jestSetupPath],
};
diff --git a/packages/runtime-tools-swf-enveloped-components/package.json
b/packages/runtime-tools-swf-enveloped-components/package.json
index c8e25d10ae9..30574956755 100644
--- a/packages/runtime-tools-swf-enveloped-components/package.json
+++ b/packages/runtime-tools-swf-enveloped-components/package.json
@@ -70,6 +70,7 @@
"@kie-tools/root-env": "workspace:*",
"@kie-tools/tsconfig": "workspace:*",
"@testing-library/jest-dom": "^6.4.6",
+ "@testing-library/react": "^12.1.5",
"@types/babel__standalone": "^7.1.7",
"@types/jest": "^29.5.12",
"@types/jest-when": "^3.5.5",
diff --git
a/packages/runtime-tools-swf-enveloped-components/src/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList.tsx
b/packages/runtime-tools-swf-enveloped-components/src/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList.tsx
index 3daf331a1bd..b8ebf7510bf 100644
---
a/packages/runtime-tools-swf-enveloped-components/src/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList.tsx
+++
b/packages/runtime-tools-swf-enveloped-components/src/workflowDefinitions/envelope/components/WorkflowDefinitionList/WorkflowDefinitionList.tsx
@@ -45,6 +45,18 @@ const WorkflowDefinitionList:
React.FC<WorkflowDefinitionListProps & OUIAProps>
const [filterWorkflowNames, setFilterWorkflowNames] = useState<string[]>([]);
const [error, setError] = useState<string>();
+ const doQuery = async (): Promise<void> => {
+ try {
+ const response: WorkflowDefinition[] = await
driver.getWorkflowDefinitionsQuery();
+ setWorkflowDefinitionList(response);
+ setIsLoading(false);
+ } catch (err) {
+ setError(err.errorMessage);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
useEffect(() => {
if (!isEnvelopeConnectedToChannel) {
setIsLoading(true);
@@ -57,16 +69,9 @@ const WorkflowDefinitionList:
React.FC<WorkflowDefinitionListProps & OUIAProps>
}, [isEnvelopeConnectedToChannel]);
const init = async (): Promise<void> => {
- try {
- const response = await driver.getWorkflowDefinitionsQuery();
- const workflowDefinitionFilter = await
driver.getWorkflowDefinitionFilter();
- setFilterWorkflowNames(workflowDefinitionFilter);
- setWorkflowDefinitionList(response);
- setIsLoading(false);
- } catch (errorContent) {
- setError(errorContent);
- }
+ doQuery();
};
+
const columns: DataTableColumn[] = [
getColumn("workflowName", `Workflow Name`),
getColumn("endpoint", "Endpoint"),
@@ -84,6 +89,11 @@ const WorkflowDefinitionList:
React.FC<WorkflowDefinitionListProps & OUIAProps>
await driver.setWorkflowDefinitionFilter(filterWorkflowNames);
};
+ const doRefresh = async (): Promise<void> => {
+ setIsLoading(true);
+ doQuery();
+ };
+
const filterWorkflowDefinition = (): WorkflowDefinition[] => {
if (filterWorkflowNames.length === 0) {
return workflowDefinitionList;
@@ -109,6 +119,7 @@ const WorkflowDefinitionList:
React.FC<WorkflowDefinitionListProps & OUIAProps>
filterWorkflowNames={filterWorkflowNames}
setFilterWorkflowNames={setFilterWorkflowNames}
applyFilter={applyFilter}
+ doRefresh={doRefresh}
/>
<Divider />
<DataTable
diff --git
a/packages/runtime-tools-swf-enveloped-components/src/workflowDefinitions/envelope/components/WorkflowDefinitionListToolbar/WorkflowDefinitionListToolbar.tsx
b/packages/runtime-tools-swf-enveloped-components/src/workflowDefinitions/envelope/components/WorkflowDefinitionListToolbar/WorkflowDefinitionListToolbar.tsx
index 1bc51c16495..40cc1dc2b24 100644
---
a/packages/runtime-tools-swf-enveloped-components/src/workflowDefinitions/envelope/components/WorkflowDefinitionListToolbar/WorkflowDefinitionListToolbar.tsx
+++
b/packages/runtime-tools-swf-enveloped-components/src/workflowDefinitions/envelope/components/WorkflowDefinitionListToolbar/WorkflowDefinitionListToolbar.tsx
@@ -39,6 +39,7 @@ interface WorkflowDefinitionListToolbarProps {
setFilterWorkflowNames: React.Dispatch<React.SetStateAction<string[]>>;
applyFilter: () => void;
onOpenTriggerCloudEvent?: () => void;
+ doRefresh: () => void;
}
enum Category {
@@ -52,6 +53,7 @@ const WorkflowDefinitionListToolbar:
React.FC<WorkflowDefinitionListToolbarProps
onOpenTriggerCloudEvent,
ouiaSafe,
ouiaId,
+ doRefresh,
}) => {
const [workflowNameInput, setWorkflowNameInput] = useState<string>("");
@@ -60,11 +62,6 @@ const WorkflowDefinitionListToolbar:
React.FC<WorkflowDefinitionListToolbarProps
setFilterWorkflowNames([]);
};
- const doRefresh = (): void => {
- setFilterWorkflowNames([...filterWorkflowNames]);
- applyFilter();
- };
-
const onEnterClicked = (event: React.KeyboardEvent<EventTarget>): void => {
/* istanbul ignore else */
if (event.key === "Enter") {
@@ -112,6 +109,7 @@ const WorkflowDefinitionListToolbar:
React.FC<WorkflowDefinitionListToolbarProps
onKeyPress={onEnterClicked}
placeholder={`Filter by workflow name`}
value={workflowNameInput}
+ data-testid="workflow-filter-input"
/>
</InputGroup>
</ToolbarFilter>
diff --git a/packages/runtime-tools-swf-enveloped-components/jest.config.js
b/packages/runtime-tools-swf-enveloped-components/tests/__mocks__/styleMock.js
similarity index 73%
copy from packages/runtime-tools-swf-enveloped-components/jest.config.js
copy to
packages/runtime-tools-swf-enveloped-components/tests/__mocks__/styleMock.js
index e2963bba168..4bd939113b0 100644
--- a/packages/runtime-tools-swf-enveloped-components/jest.config.js
+++
b/packages/runtime-tools-swf-enveloped-components/tests/__mocks__/styleMock.js
@@ -17,14 +17,4 @@
* under the License.
*/
-const { config, babelTransform, typescriptTransform } =
require("@kie-tools/jest-base/jest.config");
-
-/** @type {import('ts-jest').JestConfigWithTsJest} */
-module.exports = {
- ...config,
- testEnvironment: "jsdom",
- transform: {
- ...babelTransform,
- ...typescriptTransform,
- },
-};
+module.exports = {};
diff --git
a/packages/runtime-tools-swf-enveloped-components/tests/components/WorkflowDefinitionList.test.tsx
b/packages/runtime-tools-swf-enveloped-components/tests/components/WorkflowDefinitionList.test.tsx
new file mode 100644
index 00000000000..6226790263e
--- /dev/null
+++
b/packages/runtime-tools-swf-enveloped-components/tests/components/WorkflowDefinitionList.test.tsx
@@ -0,0 +1,90 @@
+/*
+ * 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";
+
+const mockDriver = {
+ getWorkflowDefinitionsQuery: jest.fn(),
+ openWorkflowForm: jest.fn(),
+ openTriggerCloudEvent: jest.fn(),
+ setWorkflowDefinitionFilter: jest.fn(),
+ getWorkflowDefinitionFilter: jest.fn(),
+};
+
+const sampleWorkflowDefinitions = [
+ { workflowName: "Test Workflow 1", endpoint: "/endpoint1", serviceUrl:
"http://example.com/1" },
+ { workflowName: "Test Workflow 2", endpoint: "/endpoint2", serviceUrl:
"http://example.com/2" },
+];
+
+describe("WorkflowDefinitionList component", () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ test("should fetch and set workflow definitions correctly", async () => {
+
mockDriver.getWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+ const component = render(
+ <WorkflowDefinitionList
+ isEnvelopeConnectedToChannel={true}
+ driver={mockDriver}
+ ouiaId="test-ouia-id"
+ ouiaSafe={true}
+ />
+ );
+
+ await waitFor(() => {
+ expect(mockDriver.getWorkflowDefinitionsQuery).toHaveBeenCalled();
+ expect(component.queryByText("Test Workflow 1")).toBeInTheDocument();
+ expect(component.queryByText("Test Workflow 2")).toBeInTheDocument();
+ });
+ });
+
+ test("should maintain filter after refresh", async () => {
+
mockDriver.getWorkflowDefinitionsQuery.mockResolvedValue(sampleWorkflowDefinitions);
+
+ const component = render(
+ <WorkflowDefinitionList
+ isEnvelopeConnectedToChannel={true}
+ driver={mockDriver}
+ ouiaId="test-ouia-id"
+ ouiaSafe={true}
+ />
+ );
+
+ await (async () => {
+ await mockDriver.setWorkflowDefinitionFilter();
+ });
+
+ expect(component.queryByText("Test Workflow 1")).toBeInTheDocument();
+ expect(component.queryByText("Test Workflow 2")).toBeInTheDocument();
+
+ fireEvent.change(component.getByTestId("workflow-filter-input"), {
+ target: { value: "Test Workflow 1" },
+ });
+
+ fireEvent.click(component.getByTestId("apply-filter"));
+ expect(component.queryByText("Test Workflow 2")).not.toBeInTheDocument();
+
+ fireEvent.click(component.getByTestId("refresh"));
+ expect(component.queryByText("Test Workflow 2")).not.toBeInTheDocument();
+ });
+});
diff --git a/packages/runtime-tools-swf-enveloped-components/jest.config.js
b/packages/runtime-tools-swf-enveloped-components/tests/jest.setup.ts
similarity index 73%
copy from packages/runtime-tools-swf-enveloped-components/jest.config.js
copy to packages/runtime-tools-swf-enveloped-components/tests/jest.setup.ts
index e2963bba168..1c413b1660e 100644
--- a/packages/runtime-tools-swf-enveloped-components/jest.config.js
+++ b/packages/runtime-tools-swf-enveloped-components/tests/jest.setup.ts
@@ -17,14 +17,4 @@
* under the License.
*/
-const { config, babelTransform, typescriptTransform } =
require("@kie-tools/jest-base/jest.config");
-
-/** @type {import('ts-jest').JestConfigWithTsJest} */
-module.exports = {
- ...config,
- testEnvironment: "jsdom",
- transform: {
- ...babelTransform,
- ...typescriptTransform,
- },
-};
+import "@testing-library/jest-dom";
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index f993eb74769..993df030159 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -8217,6 +8217,9 @@ importers:
'@testing-library/jest-dom':
specifier: ^6.4.6
version:
6.4.6(@jest/[email protected])(@types/[email protected])([email protected](@types/[email protected])([email protected])([email protected](@types/[email protected])([email protected])))
+ '@testing-library/react':
+ specifier: ^12.1.5
+ version: 12.1.5([email protected]([email protected]))([email protected])
'@types/babel__standalone':
specifier: ^7.1.7
version: 7.1.7
@@ -29136,7 +29139,7 @@ snapshots:
dependencies:
'@ampproject/remapping': 2.3.0
'@angular-devkit/architect': 0.1801.3([email protected])
- '@angular-devkit/build-webpack':
0.1801.3([email protected])([email protected]([email protected]))([email protected]([email protected]))
+ '@angular-devkit/build-webpack':
0.1801.3([email protected])([email protected]([email protected]))([email protected])
'@angular-devkit/core': 18.1.3([email protected])
'@angular/build':
18.1.3(@angular/[email protected](@angular/[email protected](@angular/[email protected]([email protected])([email protected])))([email protected]))(@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])
'@angular/compiler-cli':
18.1.3(@angular/[email protected](@angular/[email protected]([email protected])([email protected])))([email protected])
@@ -29150,15 +29153,15 @@ snapshots:
'@babel/preset-env': 7.24.7(@babel/[email protected])
'@babel/runtime': 7.24.7
'@discoveryjs/json-ext': 0.5.7
- '@ngtools/webpack':
18.1.3(@angular/[email protected](@angular/[email protected](@angular/[email protected]([email protected])([email protected])))([email protected]))([email protected])([email protected]([email protected]))
+ '@ngtools/webpack':
18.1.3(@angular/[email protected](@angular/[email protected](@angular/[email protected]([email protected])([email protected])))([email protected]))([email protected])([email protected])
'@vitejs/plugin-basic-ssl':
1.1.0([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]))
ansi-colors: 4.1.3
autoprefixer: 10.4.19([email protected])
- babel-loader: 9.1.3(@babel/[email protected])([email protected]([email protected]))
+ babel-loader: 9.1.3(@babel/[email protected])([email protected])
browserslist: 4.23.0
- copy-webpack-plugin: 12.0.2([email protected]([email protected]))
+ copy-webpack-plugin: 12.0.2([email protected])
critters: 0.0.24
- css-loader: 7.1.2([email protected]([email protected]))
+ css-loader: 7.1.2([email protected])
esbuild-wasm: 0.21.5
fast-glob: 3.3.2
http-proxy-middleware: 3.0.0
@@ -29167,11 +29170,11 @@ snapshots:
jsonc-parser: 3.3.1
karma-source-map-support: 1.4.0
less: 4.2.0
- less-loader: 12.2.0([email protected])([email protected]([email protected]))
- license-webpack-plugin: 4.0.2([email protected]([email protected]))
+ less-loader: 12.2.0([email protected])([email protected])
+ license-webpack-plugin: 4.0.2([email protected])
loader-utils: 3.3.1
magic-string: 0.30.10
- mini-css-extract-plugin: 2.9.0([email protected]([email protected]))
+ mini-css-extract-plugin: 2.9.0([email protected])
mrmime: 2.0.0
open: 10.1.0
ora: 5.4.1
@@ -29179,13 +29182,13 @@ snapshots:
picomatch: 4.0.2
piscina: 4.6.1
postcss: 8.4.38
- postcss-loader:
8.1.1([email protected])([email protected])([email protected]([email protected]))
+ postcss-loader: 8.1.1([email protected])([email protected])([email protected])
resolve-url-loader: 5.0.0
rxjs: 7.8.1
sass: 1.77.6
- sass-loader: 14.2.1([email protected])([email protected]([email protected]))
+ sass-loader: 14.2.1([email protected])([email protected])
semver: 7.6.2
- source-map-loader: 5.0.0([email protected]([email protected]))
+ source-map-loader: 5.0.0([email protected])
source-map-support: 0.5.21
terser: 5.29.2
tree-kill: 1.2.2
@@ -29198,7 +29201,7 @@ snapshots:
webpack-dev-middleware: 7.2.1([email protected])
webpack-dev-server: 5.0.4([email protected])
webpack-merge: 5.10.0
- webpack-subresource-integrity:
5.1.0([email protected]([email protected]))([email protected]([email protected]))
+ webpack-subresource-integrity:
5.1.0([email protected]([email protected]))([email protected])
optionalDependencies:
esbuild: 0.21.5
jest: 29.7.0(@types/[email protected])
@@ -29222,7 +29225,7 @@ snapshots:
- utf-8-validate
- webpack-cli
-
'@angular-devkit/[email protected]([email protected])([email protected]([email protected]))([email protected]([email protected]))':
+
'@angular-devkit/[email protected]([email protected])([email protected]([email protected]))([email protected])':
dependencies:
'@angular-devkit/architect': 0.1801.3([email protected])
rxjs: 7.8.1
@@ -36235,7 +36238,7 @@ snapshots:
pump: 3.0.0
tar-fs: 2.1.1
-
'@ngtools/[email protected](@angular/[email protected](@angular/[email protected](@angular/[email protected]([email protected])([email protected])))([email protected]))([email protected])([email protected]([email protected]))':
+
'@ngtools/[email protected](@angular/[email protected](@angular/[email protected](@angular/[email protected]([email protected])([email protected])))([email protected]))([email protected])([email protected])':
dependencies:
'@angular/compiler-cli':
18.1.3(@angular/[email protected](@angular/[email protected]([email protected])([email protected])))([email protected])
typescript: 5.5.3
@@ -42281,7 +42284,7 @@ snapshots:
schema-utils: 4.2.0
webpack: 5.88.2([email protected])
- [email protected](@babel/[email protected])([email protected]([email protected])):
+ [email protected](@babel/[email protected])([email protected]):
dependencies:
'@babel/core': 7.24.7
find-cache-dir: 4.0.0
@@ -43629,7 +43632,7 @@ snapshots:
serialize-javascript: 6.0.1
webpack: 5.88.2
- [email protected]([email protected]([email protected])):
+ [email protected]([email protected]):
dependencies:
fast-glob: 3.3.2
glob-parent: 6.0.2
@@ -44010,7 +44013,7 @@ snapshots:
semver: 7.5.4
webpack:
5.88.2(@swc/[email protected])([email protected]([email protected])([email protected]))
- [email protected]([email protected]([email protected])):
+ [email protected]([email protected]):
dependencies:
icss-utils: 5.1.0([email protected])
postcss: 8.4.38
@@ -48733,7 +48736,7 @@ snapshots:
dependencies:
readable-stream: 2.3.7
- [email protected]([email protected])([email protected]([email protected])):
+ [email protected]([email protected])([email protected]):
dependencies:
less: 4.2.0
optionalDependencies:
@@ -48762,7 +48765,7 @@ snapshots:
prelude-ls: 1.2.1
type-check: 0.4.0
- [email protected]([email protected]([email protected])):
+ [email protected]([email protected]):
dependencies:
webpack-sources: 3.2.3
optionalDependencies:
@@ -49221,7 +49224,7 @@ snapshots:
tapable: 2.2.1
webpack: 5.88.2(@swc/[email protected])([email protected])
- [email protected]([email protected]([email protected])):
+ [email protected]([email protected]):
dependencies:
schema-utils: 4.2.0
tapable: 2.2.1
@@ -49624,7 +49627,7 @@ snapshots:
dependencies:
growly: 1.3.0
is-wsl: 2.2.0
- semver: 7.5.4
+ semver: 7.6.2
shellwords: 0.1.1
uuid: 8.3.2
which: 2.0.2
@@ -50463,7 +50466,7 @@ snapshots:
dependencies:
postcss: 8.4.38
-
[email protected]([email protected])([email protected])([email protected]([email protected])):
+ [email protected]([email protected])([email protected])([email protected]):
dependencies:
cosmiconfig: 9.0.0([email protected])
jiti: 1.21.6
@@ -51990,7 +51993,7 @@ snapshots:
optionalDependencies:
sass: 1.77.6
- [email protected]([email protected])([email protected]([email protected])):
+ [email protected]([email protected])([email protected]):
dependencies:
neo-async: 2.6.2
optionalDependencies:
@@ -52412,7 +52415,7 @@ snapshots:
source-map-js: 0.6.2
webpack: 5.88.2
- [email protected]([email protected]([email protected])):
+ [email protected]([email protected]):
dependencies:
iconv-lite: 0.6.3
source-map-js: 1.2.0
@@ -54768,7 +54771,7 @@ snapshots:
[email protected]: {}
-
[email protected]([email protected]([email protected]))([email protected]([email protected])):
+
[email protected]([email protected]([email protected]))([email protected]):
dependencies:
typed-assert: 1.0.8
webpack: 5.92.1([email protected])
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]