|
| 1 | +import ActionParamsTests from "./action_params_tests" |
| 2 | + |
| 3 | +export default class ActionParamsCaseInsensitiveTests extends ActionParamsTests { |
| 4 | + identifier = ["CamelCase", "AnotherOne"] |
| 5 | + fixtureHTML = ` |
| 6 | + <div data-controller="CamelCase AnotherOne"> |
| 7 | + <button data-CamelCase-id-param="123" |
| 8 | + data-CamelCase-multi-word-example-param="/path" |
| 9 | + data-CamelCase-active-param="true" |
| 10 | + data-CamelCase-inactive-param="false" |
| 11 | + data-CamelCase-empty-param="" |
| 12 | + data-CamelCase-payload-param='${JSON.stringify({value: 1})}' |
| 13 | + data-CamelCase-param-something="not-reported" |
| 14 | + data-Something-param="not-reported" |
| 15 | + data-AnotherOne-id-param="234"> |
| 16 | + <div id="nested"></div> |
| 17 | + </button> |
| 18 | + </div> |
| 19 | + <div id="outside"></div> |
| 20 | + ` |
| 21 | + expectedParamsForCamelCase = { |
| 22 | + id: 123, |
| 23 | + multiWordExample: "/path", |
| 24 | + payload: { |
| 25 | + value: 1 |
| 26 | + }, |
| 27 | + active: true, |
| 28 | + empty: "", |
| 29 | + inactive: false |
| 30 | + } |
| 31 | + |
| 32 | + async "test clicking on the element does return its params"() { |
| 33 | + this.actionValue = "click->CamelCase#log" |
| 34 | + await this.nextFrame |
| 35 | + await this.triggerEvent(this.buttonElement, "click") |
| 36 | + |
| 37 | + this.assertActions( |
| 38 | + { identifier: "CamelCase", params: this.expectedParamsForCamelCase }, |
| 39 | + ) |
| 40 | + } |
| 41 | + |
| 42 | + async "test global event return element params where the action is defined"() { |
| 43 | + this.actionValue = "keydown@window->CamelCase#log" |
| 44 | + await this.nextFrame |
| 45 | + await this.triggerEvent("#outside", "keydown") |
| 46 | + |
| 47 | + this.assertActions( |
| 48 | + { identifier: "CamelCase", params: this.expectedParamsForCamelCase }, |
| 49 | + ) |
| 50 | + } |
| 51 | + |
| 52 | + async "test passing params to namespaced controller"() { |
| 53 | + this.actionValue = "click->CamelCase#log click->AnotherOne#log2" |
| 54 | + await this.nextFrame |
| 55 | + await this.triggerEvent(this.buttonElement, "click") |
| 56 | + |
| 57 | + this.assertActions( |
| 58 | + { identifier: "CamelCase", params: this.expectedParamsForCamelCase }, |
| 59 | + { identifier: "AnotherOne", params: { id: 234 } }, |
| 60 | + ) |
| 61 | + } |
| 62 | +} |
0 commit comments