mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Delete now ununsed stimulus controller toggle_button_disabled
- also delete one comment about replacing this controller with another
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
import { Controller } from "stimulus";
|
||||
|
||||
// Since Rails 7 it adds "data-disabled-with" property to submit, you'll need to add
|
||||
// 'data-disable-with="false' for this to function as expected, ie:
|
||||
//
|
||||
// <input id="test-submit" type="submit" data-disable-with="false" data-toggle-button-disabled-target="button"/>
|
||||
//
|
||||
export default class extends Controller {
|
||||
static targets = ["button"];
|
||||
|
||||
connect() {
|
||||
if (this.hasButtonTarget) {
|
||||
this.buttonTarget.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
inputIsChanged(e) {
|
||||
if (e.target.value !== "") {
|
||||
this.buttonTarget.disabled = false;
|
||||
} else {
|
||||
this.buttonTarget.disabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ export default class extends Controller {
|
||||
target.disabled = !enable;
|
||||
});
|
||||
}
|
||||
//todo: can a new method disableIfBlank replace ButtonDisabledController?
|
||||
//todo: can a new method toggleDisplay replace ToggleController?
|
||||
//todo: can toggleDisplay with optional chevron-target replace RemoteToggleController?
|
||||
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
|
||||
import { Application } from "stimulus"
|
||||
import toggle_button_disabled_controller from "../../../app/webpacker/controllers/toggle_button_disabled_controller"
|
||||
|
||||
describe("ButtonEnableToggleController", () => {
|
||||
beforeAll(() => {
|
||||
const application = Application.start()
|
||||
application.register("toggle-button-disabled", toggle_button_disabled_controller)
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = `
|
||||
<form id="test-form" data-controller="toggle-button-disabled">
|
||||
<input id="test-input" type="input" data-action="input->toggle-button-disabled#inputIsChanged" />
|
||||
<input
|
||||
id="test-submit"
|
||||
type="submit"
|
||||
data-disable-with="false"
|
||||
data-toggle-button-disabled-target="button"
|
||||
/>
|
||||
</form>
|
||||
`
|
||||
})
|
||||
|
||||
describe("#connect", () => {
|
||||
it("disables the target submit button", () => {
|
||||
const submit = document.getElementById("test-submit")
|
||||
expect(submit.disabled).toBe(true)
|
||||
})
|
||||
|
||||
describe("when no button present", () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = `
|
||||
<form id="test-form" data-controller="toggle-button-disabled">
|
||||
<input id="test-input" type="input" data-action="input->toggle-button-disabled#inputIsChanged" />
|
||||
</form>
|
||||
`
|
||||
})
|
||||
|
||||
// I am not sure if it's possible to manually trigger the loading/connect of the controller to
|
||||
// try catch the error, so leaving as this. It will break if the missing target isn't handled
|
||||
// properly
|
||||
it("doesn't break", () => {})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#formIsChanged", () => {
|
||||
let input
|
||||
let submit
|
||||
|
||||
beforeEach(() => {
|
||||
input = document.getElementById("test-input")
|
||||
submit = document.getElementById("test-submit")
|
||||
})
|
||||
|
||||
describe("when the input value is not empty", () => {
|
||||
it("enables the target button", () => {
|
||||
input.value = "test"
|
||||
input.dispatchEvent(new Event("input"));
|
||||
|
||||
expect(submit.disabled).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the input value is empty", () => {
|
||||
it("disables the target button", () => {
|
||||
// setting up state where target button is enabled
|
||||
input.value = "test"
|
||||
input.dispatchEvent(new Event("input"));
|
||||
|
||||
input.value = ""
|
||||
input.dispatchEvent(new Event("input"));
|
||||
|
||||
expect(submit.disabled).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user