Welcome to mirror list, hosted at ThFree Co, Russian Federation.

load_startup_css_spec.js « behaviors « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 81222ac5aaaa8bdb2cbab76b9c845a263fcd832f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { setHTMLFixture } from 'helpers/fixtures';
import { loadStartupCSS } from '~/behaviors/load_startup_css';

describe('behaviors/load_startup_css', () => {
  let loadListener;

  const setupListeners = () => {
    document
      .querySelectorAll('link')
      .forEach(x => x.addEventListener('load', () => loadListener(x)));
  };

  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();
  });

  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',
      ]);
    });
  });
});