-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[840] Support directly writing code without
executeCode
action. (#853)
- Loading branch information
1 parent
3abd232
commit e90c7b7
Showing
5 changed files
with
72 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/runtime/src/runtime/hooks/__tests__/useEnsembleAction.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* eslint import/first: 0 */ | ||
import { act, renderHook } from "@testing-library/react"; | ||
import { ScreenContextProvider } from "@ensembleui/react-framework"; | ||
import { useEnsembleAction } from "../useEnsembleAction"; | ||
|
||
jest.mock("react-markdown", jest.fn()); | ||
jest.mock("react-router-dom"); | ||
|
||
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => ( | ||
<ScreenContextProvider | ||
context={{ | ||
widgets: { | ||
myWidget: { | ||
values: { | ||
value: 2, | ||
}, | ||
invokable: { | ||
id: "myWidget", | ||
}, | ||
}, | ||
}, | ||
data: {}, | ||
storage: {}, | ||
}} | ||
screen={{ | ||
id: "test", | ||
name: "test", | ||
body: { name: "Widget", properties: {} }, | ||
apis: [ | ||
{ | ||
name: "getDummyProductsByPaginate", | ||
method: "GET", | ||
// eslint-disable-next-line no-template-curly-in-string | ||
uri: "https://dummyjson.com/products?skip=${skip}&limit=${limit}", | ||
inputs: ["skip", "limit"], | ||
}, | ||
], | ||
}} | ||
> | ||
{children} | ||
</ScreenContextProvider> | ||
); | ||
|
||
describe("Test cases for useEnsembleAction Hook", () => { | ||
it("should return undefined when no action is provided", () => { | ||
const { result } = renderHook(() => useEnsembleAction(undefined)); | ||
|
||
expect(result.current).toBeUndefined(); | ||
}); | ||
|
||
it("should return useExecuteCode when action is a string", () => { | ||
const { result } = renderHook(() => useEnsembleAction("myWidget.value"), { | ||
wrapper, | ||
}); | ||
|
||
let execResult; | ||
|
||
act(() => { | ||
execResult = result.current?.callback(); | ||
}); | ||
expect(execResult).toBe(2); | ||
}); | ||
}); |