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

index_spec.js « sketch « blob « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cd12d5e17a8dc565e262d017e8560ab07c6ae2ec (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import JSZip from 'jszip';
import SketchLoader from '~/blob/sketch';

jest.mock('jszip');

describe('Sketch viewer', () => {
  preloadFixtures('static/sketch_viewer.html');

  beforeEach(() => {
    loadFixtures('static/sketch_viewer.html');
  });

  describe('with error message', () => {
    beforeEach(done => {
      jest.spyOn(SketchLoader.prototype, 'getZipFile').mockImplementation(
        () =>
          new Promise((resolve, reject) => {
            reject();
            done();
          }),
      );

      return new SketchLoader(document.getElementById('js-sketch-viewer'));
    });

    it('renders error message', () => {
      expect(document.querySelector('#js-sketch-viewer p')).not.toBeNull();

      expect(document.querySelector('#js-sketch-viewer p').textContent.trim()).toContain(
        'Cannot show preview.',
      );
    });

    it('removes the loading icon', () => {
      expect(document.querySelector('.js-loading-icon')).toBeNull();
    });
  });

  describe('success', () => {
    beforeEach(done => {
      const loadAsyncMock = {
        files: {
          'previews/preview.png': {
            async: jest.fn(),
          },
        },
      };

      loadAsyncMock.files['previews/preview.png'].async.mockImplementation(
        () =>
          new Promise(resolve => {
            resolve('foo');
            done();
          }),
      );

      jest.spyOn(SketchLoader.prototype, 'getZipFile').mockResolvedValue();
      jest.spyOn(JSZip, 'loadAsync').mockResolvedValue(loadAsyncMock);
      return new SketchLoader(document.getElementById('js-sketch-viewer'));
    });

    it('does not render error message', () => {
      expect(document.querySelector('#js-sketch-viewer p')).toBeNull();
    });

    it('removes the loading icon', () => {
      expect(document.querySelector('.js-loading-icon')).toBeNull();
    });

    it('renders preview img', () => {
      const img = document.querySelector('#js-sketch-viewer img');

      expect(img).not.toBeNull();
      expect(img.classList.contains('img-fluid')).toBeTruthy();
    });

    it('renders link to image', () => {
      const img = document.querySelector('#js-sketch-viewer img');
      const link = document.querySelector('#js-sketch-viewer a');

      expect(link.href).toBe(img.src);
      expect(link.target).toBe('_blank');
    });
  });
});