summaryrefslogtreecommitdiff
path: root/spec/frontend/repository/components/blob_content_viewer_spec.js
blob: b662a1d20a9a4727fac8ef2e76092d7a8239dccf (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
86
import { GlLoadingIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import BlobContent from '~/blob/components/blob_content.vue';
import BlobHeader from '~/blob/components/blob_header.vue';
import BlobContentViewer from '~/repository/components/blob_content_viewer.vue';

let wrapper;
const mockData = {
  name: 'some_file.js',
  size: 123,
  rawBlob: 'raw content',
  type: 'text',
  fileType: 'text',
  tooLarge: false,
  path: 'some_file.js',
  editBlobPath: 'some_file.js/edit',
  ideEditPath: 'some_file.js/ide/edit',
  storedExternally: false,
  rawPath: 'some_file.js',
  externalStorageUrl: 'some_file.js',
  replacePath: 'some_file.js/replace',
  deletePath: 'some_file.js/delete',
  canLock: true,
  isLocked: false,
  lockLink: 'some_file.js/lock',
  canModifyBlob: true,
  forkPath: 'some_file.js/fork',
  simpleViewer: {},
  richViewer: {},
};

function factory(path, loading = false) {
  wrapper = shallowMount(BlobContentViewer, {
    propsData: {
      path,
    },
    mocks: {
      $apollo: {
        queries: {
          blobInfo: {
            loading,
          },
        },
      },
    },
  });

  wrapper.setData({ blobInfo: mockData });
}

describe('Blob content viewer component', () => {
  const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
  const findBlobHeader = () => wrapper.find(BlobHeader);
  const findBlobContent = () => wrapper.find(BlobContent);

  afterEach(() => {
    wrapper.destroy();
  });

  beforeEach(() => {
    factory('some_file.js');
  });

  it('renders a GlLoadingIcon component', () => {
    factory('some_file.js', true);

    expect(findLoadingIcon().exists()).toBe(true);
  });

  it('renders a BlobHeader component', () => {
    expect(findBlobHeader().exists()).toBe(true);
  });

  it('renders a BlobContent component', () => {
    expect(findBlobContent().exists()).toBe(true);

    expect(findBlobContent().props('loading')).toEqual(false);
    expect(findBlobContent().props('content')).toEqual('raw content');
    expect(findBlobContent().props('isRawContent')).toBe(true);
    expect(findBlobContent().props('activeViewer')).toEqual({
      fileType: 'text',
      tooLarge: false,
      type: 'text',
    });
  });
});