Skip to content

Commit

Permalink
Fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Mar 1, 2024
1 parent 164190a commit dc7367c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 3 additions & 1 deletion assets/js/phoenix_live_view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
PHX_CLIENT_ERROR_CLASS,
PHX_SERVER_ERROR_CLASS,
PHX_FEEDBACK_FOR,
PHX_FEEDBACK_GROUP,
PHX_HAS_FOCUSED,
PHX_HAS_SUBMITTED,
PHX_HOOK,
Expand Down Expand Up @@ -104,7 +105,8 @@ let serializeForm = (form, metadata, onlyNames = []) => {
for(let [key, val] of formData.entries()){
if(onlyNames.length === 0 || onlyNames.indexOf(key) >= 0){
let input = elements.find(input => input.name === key)
if(!(DOM.private(input, PHX_HAS_FOCUSED) || DOM.private(input, PHX_HAS_SUBMITTED))){
let isUnused = !(DOM.private(input, PHX_HAS_FOCUSED) || DOM.private(input, PHX_HAS_SUBMITTED))
if(isUnused && !(submitter && submitter.name == key)){
params.append(prependFormDataKey(key, "_unused_"), "")
}
params.append(key, val)
Expand Down
10 changes: 4 additions & 6 deletions assets/test/view_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ describe("View + DOM", function(){
btn.setAttribute("type", "submit")
btn.setAttribute("name", "btnName")
btn.setAttribute("value", "btnValue")
submitWithButton(btn, "increment=1&note=2&_unused_btnName=&btnName=btnValue")
submitWithButton(btn, "increment=1&note=2&btnName=btnValue")
})

test("payload includes submitter when name is provided (submitter outside form)", function(){
Expand Down Expand Up @@ -1054,9 +1054,8 @@ describe("View + Component", function(){
window.requestAnimationFrame(() => {
expect(el.querySelector(`[phx-feedback-for="${first_name.name}"`).classList.contains("phx-no-feedback")).toBeFalsy()
expect(el.querySelector(`[phx-feedback-for="${last_name.name}"`).classList.contains("phx-no-feedback")).toBeTruthy()

view.channel.nextValidate({"user[first_name]": null, "user[last_name]": null, "_target": "user[last_name]"})
DOM.putPrivate(last_name, "phx-has-focused", true)
view.pushInput(last_name, el, null, "validate", {_target: last_name.name})
window.requestAnimationFrame(() => {
expect(el.querySelector(`[phx-feedback-for="${first_name.name}"`).classList.contains("phx-no-feedback")).toBeFalsy()
Expand Down Expand Up @@ -1146,7 +1145,6 @@ describe("View + Component", function(){
expect(el.querySelector("[phx-feedback-for=\"mygroup\"]").classList.contains("phx-no-feedback")).toBeTruthy()

view.channel.nextValidate({"user[first_name]": null, "user[last_name]": null, "user[email]": null, "_target": "user[first_name]"})
DOM.putPrivate(first_name, "phx-has-focused", true)
view.pushInput(first_name, el, null, "validate", {_target: first_name.name})
window.requestAnimationFrame(() => {
expect(el.querySelector(`[phx-feedback-for="${first_name.name}"`).classList.contains("phx-no-feedback")).toBeFalsy()
Expand Down Expand Up @@ -1217,7 +1215,7 @@ describe("View + Component", function(){
window.requestAnimationFrame(() => {
expect(el.querySelector(`span[phx-feedback-for="user[first_name]"`).classList.contains("phx-no-feedback")).toBeFalsy()
expect(el.querySelector(`span[phx-feedback-for="user[allergies]"`).classList.contains("phx-no-feedback")).toBeTruthy()

DOM.putPrivate(allergies_select, "phx-has-focused", true)
view.pushInput(allergies_select, el, null, "validate", {_target: "user[allergies][]"})
window.requestAnimationFrame(() => {
Expand Down Expand Up @@ -1425,4 +1423,4 @@ describe("DOM", function(){
expect(target.checked).toEqual(true)
expect(target.id).toEqual("bar")
})
})
})

0 comments on commit dc7367c

Please sign in to comment.