mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-11 03:40:20 +00:00
Create an updateinput controller
- that update the targets input value to the value stored in data attribute - Add tests
This commit is contained in:
committed by
Nihal M. Kelanthodika
parent
49e93a6125
commit
786b198f4d
30
spec/javascripts/stimulus/update_controller_test.js
Normal file
30
spec/javascripts/stimulus/update_controller_test.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
|
||||
import { Application } from "stimulus";
|
||||
import updateinput_controller from "../../../app/webpacker/controllers/updateinput_controller";
|
||||
|
||||
describe("updateInput controller", () => {
|
||||
describe("#update", () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = `<form data-controller="updateinput">
|
||||
<input id="input" type="hidden" value="false" data-updateinput-target="input" />
|
||||
<div id="submit" data-action="click->updateinput#update" data-updateinput-value="true" />
|
||||
</form>`;
|
||||
|
||||
const application = Application.start();
|
||||
application.register("updateinput", updateinput_controller);
|
||||
});
|
||||
|
||||
it("update the input value", () => {
|
||||
const submit = document.getElementById("submit");
|
||||
const input = document.getElementById("input");
|
||||
expect(input.value).toBe("false");
|
||||
|
||||
submit.click();
|
||||
|
||||
expect(input.value).toBe("true");
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user