Files
openfoodnetwork/spec/javascripts/stimulus/update_controller_test.js
Jean-Baptiste Bellet 786b198f4d Create an updateinput controller
- that update the targets input value to the value stored in data attribute
 - Add tests
2021-10-06 15:06:56 +05:30

31 lines
940 B
JavaScript

/**
* @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");
});
});
});