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

get_client_rects_spec.js « dom_shims « __helpers__ « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e7b8f1e235bf6dc6d611138f14d66d3d1ce32141 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const createTestElement = () => {
  const element = document.createElement('div');

  element.textContent = 'Hello World!';

  return element;
};

describe('DOM patch for getClientRects', () => {
  let origHtml;
  let el;

  beforeEach(() => {
    origHtml = document.body.innerHTML;
    el = createTestElement();
  });

  afterEach(() => {
    document.body.innerHTML = origHtml;
  });

  describe('toBeVisible matcher', () => {
    describe('when not attached to document', () => {
      it('does not match', () => {
        expect(el).not.toBeVisible();
      });
    });

    describe('when attached to document', () => {
      beforeEach(() => {
        document.body.appendChild(el);
      });

      it('matches', () => {
        expect(el).toBeVisible();
      });
    });

    describe('with parent and attached to document', () => {
      let parentEl;

      beforeEach(() => {
        parentEl = createTestElement();
        parentEl.appendChild(el);
        document.body.appendChild(parentEl);
      });

      it('matches', () => {
        expect(el).toBeVisible();
      });

      describe.each`
        style
        ${{ display: 'none' }}
        ${{ visibility: 'hidden' }}
      `('with style $style', ({ style }) => {
        it('does not match when applied to element', () => {
          Object.assign(el.style, style);

          expect(el).not.toBeVisible();
        });

        it('does not match when applied to parent', () => {
          Object.assign(parentEl.style, style);

          expect(el).not.toBeVisible();
        });
      });
    });
  });
});