-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3][corvid-types][Deprecate Codemodel] Allow storing additional compo…
…nent event handlers in runtime (#64)
- Loading branch information
Dolev Hadar
authored
Aug 31, 2021
1 parent
1fa4dee
commit fe904e0
Showing
2 changed files
with
54 additions
and
1 deletion.
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
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,42 @@ | ||
import eventHandlersService from "../../src/dynamicTypes/eventHandlersService"; | ||
|
||
describe("eventHandlersService", () => { | ||
it("should allow getting a $w component event handlers", () => { | ||
const buttonHandlers = eventHandlersService.getComponentEventHandlers( | ||
"$w.Button" | ||
); | ||
expect(buttonHandlers).toHaveLength(6); | ||
|
||
const onClickHandler = buttonHandlers?.find( | ||
handler => handler.name === "onClick" | ||
); | ||
expect(onClickHandler).not.toBe(undefined); | ||
}); | ||
|
||
it("should allow adding component event handlers in runtime", () => { | ||
eventHandlersService.registerComponentEventHandlers("MyComponent", [ | ||
{ | ||
name: "CustomEvent", | ||
origin: "MyComponent", | ||
description: "My custom event", | ||
kind: "function", | ||
type: "customEvent", | ||
handlerArgs: [ | ||
{ | ||
name: "arg", | ||
type: "string" | ||
} | ||
] | ||
} | ||
]); | ||
const handlers = eventHandlersService.getComponentEventHandlers( | ||
"MyComponent" | ||
); | ||
expect(handlers).toHaveLength(1); | ||
|
||
const customHandler = handlers?.find( | ||
handler => handler.name === "CustomEvent" | ||
); | ||
expect(customHandler).not.toBe(undefined); | ||
}); | ||
}); |