mirror of
				https://github.com/MontFerret/ferret.git
				synced 2025-10-30 23:37:40 +02:00 
			
		
		
		
	Fixed WAIT_CLASS args validation (#192)
This commit is contained in:
		
							
								
								
									
										54
									
								
								e2e/pages/dynamic/components/pages/events/clickable.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								e2e/pages/dynamic/components/pages/events/clickable.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| const e = React.createElement; | ||||
|  | ||||
| export default class ClickableComponent extends React.PureComponent { | ||||
|     constructor(props) { | ||||
|         super(props); | ||||
|  | ||||
|         this.state = { | ||||
|             clicked: false | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     handleClick() { | ||||
|         let timeout = 500; | ||||
|  | ||||
|         if (this.props.randomTimeout) { | ||||
|             timeout = Math.ceil(Math.random() * 1000 * 10); | ||||
|         } | ||||
|  | ||||
|         setTimeout(() => { | ||||
|             this.setState({ | ||||
|                 clicked: !this.state.clicked | ||||
|             }) | ||||
|         }, timeout) | ||||
|     } | ||||
|  | ||||
|     render() { | ||||
|         const btnId = `${this.props.id}-btn`; | ||||
|         const contentId = `${this.props.id}-content`; | ||||
|         const classNames = ["alert"]; | ||||
|  | ||||
|         if (this.state.clicked) { | ||||
|             classNames.push("alert-success"); | ||||
|         } | ||||
|  | ||||
|         return e("div", {className: "card"}, [ | ||||
|             e("div", { className: "card-header"}, [ | ||||
|                 e("button", { | ||||
|                     id: btnId, | ||||
|                     className: "btn btn-primary", | ||||
|                     onClick: this.handleClick.bind(this) | ||||
|                 }, [ | ||||
|                     "Toggle class" | ||||
|                 ]) | ||||
|             ]), | ||||
|             e("div", { className: "card-body"}, [ | ||||
|                 e("div", { id: contentId, className: classNames.join(" ")}, [ | ||||
|                     e("p", null, [ | ||||
|                         "Lorem ipsum dolor sit amet." | ||||
|                     ]) | ||||
|                 ]) | ||||
|             ]) | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @@ -22,31 +22,26 @@ export default class HoverableComponent extends React.PureComponent { | ||||
|     } | ||||
|  | ||||
|     render() { | ||||
|         const children = []; | ||||
|         children.push( | ||||
|             e("p", null, [ | ||||
|                 e("a", { | ||||
|         let content; | ||||
|  | ||||
|         if (this.state.hovered) { | ||||
|             content =  e("p", { id: "hoverable-content"}, [ | ||||
|                 "Lorem ipsum dolor sit amet." | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         return e("div", { className: "card"}, [ | ||||
|             e("div", {className: "card-header"}, [ | ||||
|                 e("button", { | ||||
|                     id: "hoverable-btn", | ||||
|                     className: "btn btn-primary", | ||||
|                     href: "#", | ||||
|                     onMouseEnter: this.handleMouseEnter.bind(this), | ||||
|                     onMouseLeave: this.handleMouseLeave.bind(this) | ||||
|                 }, [ | ||||
|                     "Hoverable link" | ||||
|                 ]), | ||||
|             ]) | ||||
|         ); | ||||
|  | ||||
|         if (this.state.hovered) { | ||||
|             children.push( | ||||
|                 e("div", null, [ | ||||
|                     e("div", { id: "hoverable-content", className: "card card-body"}, [ | ||||
|                         "Lorem ipsum dolor sit amet." | ||||
|                     ]) | ||||
|                     "Show content" | ||||
|                 ]) | ||||
|             ) | ||||
|         } | ||||
|  | ||||
|         return e("div", null, children); | ||||
|             ]), | ||||
|             e("div", {className: "card-body"}, content) | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @@ -1,12 +1,19 @@ | ||||
| import Hoverable from "./hoverable.js"; | ||||
| import Clickable from "./clickable.js"; | ||||
|  | ||||
| const e = React.createElement; | ||||
|  | ||||
| export default class EventsPage extends React.Component { | ||||
|     render() { | ||||
|         return e("div", { className: "row", id: "page-events" }, [ | ||||
|             e("div", { className: "col-lg-12"}, [ | ||||
|                 e(Hoverable) | ||||
|             e("div", { className: "col-lg-4"}, [ | ||||
|                 e(Hoverable), | ||||
|             ]), | ||||
|             e("div", { className: "col-lg-4"}, [ | ||||
|                 e(Clickable, { id: "wait-class" }) | ||||
|             ]), | ||||
|             e("div", { className: "col-lg-4"}, [ | ||||
|                 e(Clickable, { id: "wait-class-random", randomTimeout: true }) | ||||
|             ]) | ||||
|         ]) | ||||
|     } | ||||
|   | ||||
							
								
								
									
										14
									
								
								e2e/tests/doc_wait_class_d.fql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								e2e/tests/doc_wait_class_d.fql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| LET url = @dynamic + "?redirect=/events" | ||||
| LET doc = DOCUMENT(url, true) | ||||
|  | ||||
| WAIT_ELEMENT(doc, "#page-events") | ||||
|  | ||||
| // with fixed timeout | ||||
| CLICK(doc, "#wait-class-btn") | ||||
| WAIT_CLASS(doc, "#wait-class-content", "alert-success") | ||||
|  | ||||
| // with random timeout | ||||
| CLICK(doc, "#wait-class-random-btn") | ||||
| WAIT_CLASS(doc, "#wait-class-random-content", "alert-success", 10000) | ||||
|  | ||||
| RETURN "" | ||||
							
								
								
									
										20
									
								
								e2e/tests/el_wait_class_d.fql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								e2e/tests/el_wait_class_d.fql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| LET url = @dynamic + "?redirect=/events" | ||||
| LET doc = DOCUMENT(url, true) | ||||
|  | ||||
| WAIT_ELEMENT(doc, "#page-events") | ||||
|  | ||||
| // with fixed timeout | ||||
| LET b1 = ELEMENT(doc, "#wait-class-btn") | ||||
| LET c1 = ELEMENT(doc, "#wait-class-content") | ||||
|  | ||||
| CLICK(b1) | ||||
| WAIT_CLASS(c1, "alert-success") | ||||
|  | ||||
| // with random timeout | ||||
| LET b2 = ELEMENT(doc, "#wait-class-random-btn") | ||||
| LET c2 = ELEMENT(doc, "#wait-class-random-content") | ||||
|  | ||||
| CLICK(b2) | ||||
| WAIT_CLASS(c2, "alert-success", 10000) | ||||
|  | ||||
| RETURN "" | ||||
| @@ -43,6 +43,13 @@ func WaitClass(_ context.Context, args ...core.Value) (core.Value, error) { | ||||
| 	// lets figure out what is passed as 1st argument | ||||
| 	switch args[0].(type) { | ||||
| 	case *dynamic.HTMLDocument: | ||||
| 		// revalidate args with more accurate amount | ||||
| 		err := core.ValidateArgs(args, 3, 4) | ||||
|  | ||||
| 		if err != nil { | ||||
| 			return values.None, err | ||||
| 		} | ||||
|  | ||||
| 		// class | ||||
| 		err = core.ValidateType(args[2], core.StringType) | ||||
|  | ||||
| @@ -86,7 +93,7 @@ func WaitClass(_ context.Context, args ...core.Value) (core.Value, error) { | ||||
| 				return values.None, err | ||||
| 			} | ||||
|  | ||||
| 			timeout = args[3].(values.Int) | ||||
| 			timeout = args[2].(values.Int) | ||||
| 		} | ||||
|  | ||||
| 		return values.None, el.WaitForClass(class, timeout) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user