mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
Before there was an issue with the remote_toggle_controller tests, which contains two tests. If you commented out one test and ran the other it would pass and vice versa but if both tests were uncommented only the first test would ever pass, the second one would fail. See https://github.com/openfoodfoundation/openfoodnetwork/pull/8805#discussion_r801464322 Co-authored-by: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com>
63 lines
2.0 KiB
JavaScript
63 lines
2.0 KiB
JavaScript
/**
|
|
* @jest-environment jsdom
|
|
*/
|
|
|
|
import { Application } from "stimulus";
|
|
import stripe_cards_controller from "../../../app/webpacker/controllers/stripe_cards_controller";
|
|
|
|
describe("StripeCardsController", () => {
|
|
beforeAll(() => {
|
|
const application = Application.start();
|
|
application.register("stripe-cards", stripe_cards_controller);
|
|
});
|
|
|
|
beforeEach(() => {
|
|
document.body.innerHTML = `<div data-controller="stripe-cards">
|
|
<select data-action="change->stripe-cards#onSelectCard" id="select">
|
|
<option value="">Blank</option>
|
|
<option value="1">Card #1</option>
|
|
<option value="2">Card #2</option>
|
|
</select>
|
|
<div data-stripe-cards-target="stripeelements" id="stripeelements" >
|
|
<input type="hidden" id="input_1">
|
|
</div>
|
|
</div>`;
|
|
});
|
|
describe("#connect", () => {
|
|
it("initialize with the right display state", () => {
|
|
const select = document.getElementById("select");
|
|
select.value = "";
|
|
select.dispatchEvent(new Event("change"));
|
|
expect(document.getElementById("stripeelements").style.display).toBe(
|
|
"block"
|
|
);
|
|
});
|
|
});
|
|
describe("#selectCard", () => {
|
|
it("fill the right payment container", () => {
|
|
const select = document.getElementById("select");
|
|
select.value = "1";
|
|
select.dispatchEvent(new Event("change"));
|
|
|
|
expect(document.getElementById("stripeelements").style.display).toBe(
|
|
"none"
|
|
);
|
|
expect(document.getElementById("input_1").disabled).toBe(true);
|
|
|
|
select.value = "2";
|
|
select.dispatchEvent(new Event("change"));
|
|
expect(document.getElementById("stripeelements").style.display).toBe(
|
|
"none"
|
|
);
|
|
expect(document.getElementById("input_1").disabled).toBe(true);
|
|
|
|
select.value = "";
|
|
select.dispatchEvent(new Event("change"));
|
|
expect(document.getElementById("stripeelements").style.display).toBe(
|
|
"block"
|
|
);
|
|
expect(document.getElementById("input_1").disabled).toBe(false);
|
|
});
|
|
});
|
|
});
|