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

upload_dropzone_field_spec.js « components « edit « integrations « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 36e20db002213fcbccfdccfcac52f0e71655b423 (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
87
88
import { mount } from '@vue/test-utils';
import { GlAlert } from '@gitlab/ui';
import { nextTick } from 'vue';

import UploadDropzoneField from '~/integrations/edit/components/upload_dropzone_field.vue';
import UploadDropzone from '~/vue_shared/components/upload_dropzone/upload_dropzone.vue';
import { mockField } from '../mock_data';

describe('UploadDropzoneField', () => {
  let wrapper;

  const contentsInputName = 'service[app_store_private_key]';
  const fileNameInputName = 'service[app_store_private_key_file_name]';

  const createComponent = (props) => {
    wrapper = mount(UploadDropzoneField, {
      propsData: {
        ...mockField,
        ...props,
        name: contentsInputName,
        label: 'Input Label',
        fileInputName: fileNameInputName,
      },
    });
  };

  const findGlAlert = () => wrapper.findComponent(GlAlert);
  const findUploadDropzone = () => wrapper.findComponent(UploadDropzone);
  const findFileContentsHiddenInput = () => wrapper.find(`input[name="${contentsInputName}"]`);
  const findFileNameHiddenInput = () => wrapper.find(`input[name="${fileNameInputName}"]`);

  describe('template', () => {
    it('adds the expected file inputFieldName', () => {
      createComponent();

      expect(findUploadDropzone().props('inputFieldName')).toBe('service[dropzone_file_name]');
    });

    it('adds a disabled, hidden text input for the file contents', () => {
      createComponent();

      expect(findFileContentsHiddenInput().attributes('name')).toBe(contentsInputName);
      expect(findFileContentsHiddenInput().attributes('disabled')).toBeDefined();
    });

    it('adds a disabled, hidden text input for the file name', () => {
      createComponent();

      expect(findFileNameHiddenInput().attributes('name')).toBe(fileNameInputName);
      expect(findFileNameHiddenInput().attributes('disabled')).toBeDefined();
    });
  });

  describe('clearError', () => {
    it('clears uploadError when called', async () => {
      createComponent();

      expect(findGlAlert().exists()).toBe(false);

      findUploadDropzone().vm.$emit('error');
      await nextTick();

      expect(findGlAlert().exists()).toBe(true);
      expect(findGlAlert().text()).toBe(
        'Error: You are trying to upload something other than an allowed file.',
      );

      findGlAlert().vm.$emit('dismiss');
      await nextTick();

      expect(findGlAlert().exists()).toBe(false);
    });
  });

  describe('onError', () => {
    it('assigns uploadError to the supplied custom message', async () => {
      const message = 'test error message';
      createComponent({ errorMessage: message });

      findUploadDropzone().vm.$emit('error');

      await nextTick();

      expect(findGlAlert().exists()).toBe(true);
      expect(findGlAlert().text()).toBe(message);
    });
  });
});