mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
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:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user