2022-07-16 23:28:13 +05:30
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2021-01-03 14:25:43 +05:30
|
|
|
import { loadStartupCSS } from '~/behaviors/load_startup_css';
|
|
|
|
|
|
|
|
describe('behaviors/load_startup_css', () => {
|
|
|
|
let loadListener;
|
|
|
|
|
|
|
|
const setupListeners = () => {
|
|
|
|
document
|
|
|
|
.querySelectorAll('link')
|
2021-03-08 18:12:59 +05:30
|
|
|
.forEach((x) => x.addEventListener('load', () => loadListener(x)));
|
2021-01-03 14:25:43 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
loadListener = jest.fn();
|
|
|
|
|
|
|
|
setHTMLFixture(`
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
<link media="print" src="./lorem-print.css" />
|
|
|
|
<link media="print" src="./ipsum-print.css" />
|
|
|
|
<link media="all" src="./dolar-all.css" />
|
|
|
|
`);
|
|
|
|
|
|
|
|
setupListeners();
|
|
|
|
|
|
|
|
loadStartupCSS();
|
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('does nothing at first', () => {
|
|
|
|
expect(loadListener).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('on window load', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
window.dispatchEvent(new Event('load'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches load to the print links', () => {
|
|
|
|
expect(loadListener.mock.calls.map(([el]) => el.getAttribute('src'))).toEqual([
|
|
|
|
'./lorem-print.css',
|
|
|
|
'./ipsum-print.css',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|