summaryrefslogtreecommitdiff
path: root/spec/frontend/blob/components/blob_content_error_spec.js
blob: 0f5885c2acf943ea709bf7697fc6c0c0e87c1967 (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
import { GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import BlobContentError from '~/blob/components/blob_content_error.vue';

import { BLOB_RENDER_ERRORS } from '~/blob/components/constants';

describe('Blob Content Error component', () => {
  let wrapper;

  function createComponent(props = {}) {
    wrapper = shallowMount(BlobContentError, {
      propsData: {
        ...props,
      },
      stubs: {
        GlSprintf,
      },
    });
  }

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

  describe('collapsed and too large blobs', () => {
    it.each`
      error                                   | reason                           | options
      ${BLOB_RENDER_ERRORS.REASONS.COLLAPSED} | ${'it is larger than 1.00 MiB'}  | ${[BLOB_RENDER_ERRORS.OPTIONS.LOAD.text, BLOB_RENDER_ERRORS.OPTIONS.DOWNLOAD.text]}
      ${BLOB_RENDER_ERRORS.REASONS.TOO_LARGE} | ${'it is larger than 10.00 MiB'} | ${[BLOB_RENDER_ERRORS.OPTIONS.DOWNLOAD.text]}
    `('renders correct reason for $error.id', ({ error, reason, options }) => {
      createComponent({
        viewerError: error.id,
      });
      expect(wrapper.text()).toContain(reason);
      options.forEach((option) => {
        expect(wrapper.text()).toContain(option);
      });
    });
  });

  describe('external blob', () => {
    it.each`
      storageType         | reason                                                     | options
      ${'lfs'}            | ${BLOB_RENDER_ERRORS.REASONS.EXTERNAL.text.lfs}            | ${[BLOB_RENDER_ERRORS.OPTIONS.DOWNLOAD.text]}
      ${'build_artifact'} | ${BLOB_RENDER_ERRORS.REASONS.EXTERNAL.text.build_artifact} | ${[BLOB_RENDER_ERRORS.OPTIONS.DOWNLOAD.text]}
      ${'default'}        | ${BLOB_RENDER_ERRORS.REASONS.EXTERNAL.text.default}        | ${[BLOB_RENDER_ERRORS.OPTIONS.DOWNLOAD.text]}
    `('renders correct reason for $storageType blob', ({ storageType, reason, options }) => {
      createComponent({
        viewerError: BLOB_RENDER_ERRORS.REASONS.EXTERNAL.id,
        blob: {
          externalStorage: storageType,
        },
      });
      expect(wrapper.text()).toContain(reason);
      options.forEach((option) => {
        expect(wrapper.text()).toContain(option);
      });
    });
  });
});