-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Action Parameters attributes case-insensitive (#571)
Even though this is not the "recommended way" to specify the data attributes for the params it's to match the existing behaviour of Actions, Controllers, Targets and Values. Resolves #561
- Loading branch information
Showing
3 changed files
with
67 additions
and
5 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
62 changes: 62 additions & 0 deletions
62
src/tests/modules/core/action_params_case_insensitive_tests.ts
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,62 @@ | ||
import ActionParamsTests from "./action_params_tests" | ||
|
||
export default class ActionParamsCaseInsensitiveTests extends ActionParamsTests { | ||
identifier = ["CamelCase", "AnotherOne"] | ||
fixtureHTML = ` | ||
<div data-controller="CamelCase AnotherOne"> | ||
<button data-CamelCase-id-param="123" | ||
data-CamelCase-multi-word-example-param="/path" | ||
data-CamelCase-active-param="true" | ||
data-CamelCase-inactive-param="false" | ||
data-CamelCase-empty-param="" | ||
data-CamelCase-payload-param='${JSON.stringify({value: 1})}' | ||
data-CamelCase-param-something="not-reported" | ||
data-Something-param="not-reported" | ||
data-AnotherOne-id-param="234"> | ||
<div id="nested"></div> | ||
</button> | ||
</div> | ||
<div id="outside"></div> | ||
` | ||
expectedParamsForCamelCase = { | ||
id: 123, | ||
multiWordExample: "/path", | ||
payload: { | ||
value: 1 | ||
}, | ||
active: true, | ||
empty: "", | ||
inactive: false | ||
} | ||
|
||
async "test clicking on the element does return its params"() { | ||
this.actionValue = "click->CamelCase#log" | ||
await this.nextFrame | ||
await this.triggerEvent(this.buttonElement, "click") | ||
|
||
this.assertActions( | ||
{ identifier: "CamelCase", params: this.expectedParamsForCamelCase }, | ||
) | ||
} | ||
|
||
async "test global event return element params where the action is defined"() { | ||
this.actionValue = "keydown@window->CamelCase#log" | ||
await this.nextFrame | ||
await this.triggerEvent("#outside", "keydown") | ||
|
||
this.assertActions( | ||
{ identifier: "CamelCase", params: this.expectedParamsForCamelCase }, | ||
) | ||
} | ||
|
||
async "test passing params to namespaced controller"() { | ||
this.actionValue = "click->CamelCase#log click->AnotherOne#log2" | ||
await this.nextFrame | ||
await this.triggerEvent(this.buttonElement, "click") | ||
|
||
this.assertActions( | ||
{ identifier: "CamelCase", params: this.expectedParamsForCamelCase }, | ||
{ identifier: "AnotherOne", params: { id: 234 } }, | ||
) | ||
} | ||
} |
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