mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-15 23:57:48 +00:00
Move hiding logic to stimulus controller
This ensures morphed flashes hide like other flashes (eg in bulk order actions). I wanted to write a spec to prove it, but Capybara doesn't support mocking setTimeout and I didn't want to use sleep.
I've made it optional because this controller is shared with the shop frontend ([supposedly](5ef34347a3), although angular seems to override it).
This commit is contained in:
34
spec/javascripts/stimulus/flash_controller_test.js
Normal file
34
spec/javascripts/stimulus/flash_controller_test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
|
||||
import { Application } from "stimulus";
|
||||
import flash_controller from "../../../app/webpacker/controllers/flash_controller";
|
||||
|
||||
describe("FlashController", () => {
|
||||
beforeAll(() => {
|
||||
const application = Application.start();
|
||||
application.register("flash", flash_controller);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = `
|
||||
<div id="element" data-controller='flash' data-flash-auto-close-value='true'></div>
|
||||
`;
|
||||
|
||||
});
|
||||
|
||||
describe("autoClose", () => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
it("is cleared after about 5 seconds", () => {
|
||||
let element = document.getElementById("element");
|
||||
expect(element).not.toBe(null);
|
||||
|
||||
jest.advanceTimersByTime(5500);
|
||||
|
||||
element = document.getElementById("element");
|
||||
expect(element).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user