Replace toggle_button_disable ctrller with generic toggle_control ctrller

- add enableIfPresent method in toggle_control_controller.js to handle enabling on toggle
- add testing in the corresponding spec
- replace in view previous ctrler with intended generic toggle-control
This commit is contained in:
cyrillefr
2024-01-16 18:46:55 +01:00
parent dd502f0883
commit 8eb5ac990e
3 changed files with 38 additions and 3 deletions

View File

@@ -61,4 +61,31 @@ describe("ToggleControlController", () => {
});
});
});
describe("#enableIfPresent", () => {
describe("with input", () => {
beforeEach(() => {
document.body.innerHTML = `<div data-controller="toggle-control">
<input id="input" value="" data-action="input->toggle-control#enableIfPresent" />
<input id="control" data-toggle-control-target="control">
</div>`;
});
it("Enables when input is filled", () => {
input.value = "a"
input.dispatchEvent(new Event("input"));
expect(control.disabled).toBe(false);
});
it("Disables when input is emptied", () => {
input.value = "test"
input.dispatchEvent(new Event("input"));
input.value = ""
input.dispatchEvent(new Event("input"));
expect(control.disabled).toBe(true);
});
});
});
});