@farm-investimentos/front-mfe-components-vue3 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,184 +1,102 @@
1
- import { shallowMount } from '@vue/test-utils';
1
+ import { mount } from '@vue/test-utils';
2
2
 
3
3
  import MultipleFilePicker from '../index';
4
4
 
5
5
  describe('MultipleFilePicker component', () => {
6
6
  let wrapper;
7
- let component;
8
7
 
9
8
  beforeEach(() => {
10
- wrapper = shallowMount(MultipleFilePicker, {
11
- propsData: {
9
+ wrapper = mount(MultipleFilePicker, {
10
+ props: {
12
11
  maxFileSize: 1,
13
12
  maxFilesNumber: 10,
14
13
  downloadFiles: [],
15
14
  acceptedFileTypes: 'application/pdf,image/jpeg,image/jpg,image/png',
16
15
  },
16
+ global: {
17
+ mocks: {
18
+ 'farm-icon': { template: '<i></i>' },
19
+ 'farm-btn': { template: '<button><slot /></button>' },
20
+ 'farm-subtitle': { template: '<div><slot /></div>' },
21
+ 'farm-bodysmall': { template: '<span><slot /></span>' },
22
+ },
23
+ },
17
24
  });
18
- component = wrapper.vm;
19
25
  });
20
26
 
21
- test('MultipleFilePicker created', () => {
22
- expect(wrapper).toBeDefined();
27
+ test('MultipleFilePicker is created', () => {
28
+ expect(wrapper.exists()).toBe(true);
23
29
  });
24
30
 
25
31
  describe('Methods', () => {
26
- describe('handlerFunctionHighlight', () => {
27
- it('Should add class', () => {
28
- const spyObj = jest.spyOn(wrapper.vm.dropArea.classList, 'add');
29
- wrapper.vm.handlerFunctionHighlight();
30
- expect(spyObj).toHaveBeenCalled();
31
- });
32
- });
33
-
34
- describe('handlerFunctionUnhighlight', () => {
35
- it('Should add class', () => {
36
- const spyObj = jest.spyOn(wrapper.vm.dropArea.classList, 'remove');
37
- wrapper.vm.handlerFunctionUnhighlight();
38
- expect(spyObj).toHaveBeenCalled();
39
- });
40
- });
41
-
42
- describe('addListeners', () => {
43
- it('Should add listeners', () => {
44
- const spyObj = jest.spyOn(wrapper.vm.dropArea, 'addEventListener');
45
- wrapper.vm.addListeners();
46
- expect(spyObj).toHaveBeenCalled();
47
- });
48
- });
32
+ it('handleFileChange should update files and emit event', async () => {
33
+ const file = new File(['file content'], 'test.pdf', { type: 'application/pdf' });
34
+ const input = wrapper.find('input[type="file"]');
49
35
 
50
- describe('fileChange', () => {
51
- it('should open file input', () => {
52
- const file = new File([], 'test');
53
- component.fileChange([file]);
54
- expect(component.files).toEqual([file]);
36
+ Object.defineProperty(input.element, 'files', {
37
+ value: [file],
55
38
  });
39
+
40
+ await input.trigger('change');
41
+ expect(wrapper.vm.files).toHaveLength(1);
42
+ expect(wrapper.emitted().onFileChange).toBeTruthy();
56
43
  });
44
+
57
45
 
58
- describe('reset', () => {
59
- it('should reset', () => {
60
- const file = new File([], 'test');
61
- component.files = [file];
62
- component.reset();
63
- expect(component.files.length).toEqual(0);
64
- });
46
+ it('remove should remove file and emit onFileChange', () => {
47
+ wrapper.vm.files = [{ name: 'test.pdf', size: 1000 }];
48
+ wrapper.vm.remove(0);
49
+ expect(wrapper.vm.files).toHaveLength(0);
50
+ expect(wrapper.emitted().onFileChange).toBeTruthy();
65
51
  });
66
52
 
67
- describe('remove', () => {
68
- it('should remove an item and call reset method when files length is 1', () => {
69
- const spy = jest.spyOn(component, 'reset');
70
- const file = new File([], 'test');
71
- component.files = [file];
72
- component.remove(0);
73
- expect(component.files).toEqual([]);
74
- expect(spy).toHaveBeenCalled();
75
- });
76
-
77
- it('should remove an item', () => {
78
- const spy = jest.spyOn(component, 'reset');
79
- const file = new File([], 'test');
80
- const file2 = new File([], 'test2');
81
- component.files = [file, file2];
82
- component.remove(0);
83
- expect(component.files).toEqual([file2]);
84
- expect(spy).not.toHaveBeenCalled();
85
- });
86
- });
87
- describe('onDownload', () => {
88
- it('should remove an item', () => {
89
- component.onDownload(1);
90
- expect(wrapper.emitted().onDownload[0][0]).toBe(1);
91
- });
53
+ it('addMoreFiles should trigger input click', async () => {
54
+ const input = wrapper.find('input[type="file"]');
55
+ await wrapper.vm.addMoreFiles();
56
+ expect(input.exists()).toBe(true);
92
57
  });
58
+
93
59
  });
94
60
 
95
61
  describe('Computed', () => {
96
- describe('hasFiles', () => {
97
- it('should return false', () => {
98
- expect(component.hasFiles).toBeFalsy();
99
- });
100
-
101
- it('should return true when files length is more than zero', () => {
102
- component.files = [new File([], 'test')];
103
- expect(component.hasFiles).toBeTruthy();
104
- });
105
-
106
- it('should return true when files length is more than zero', async () => {
107
- await wrapper.setProps({
108
- downloadFiles: [new File([], 'test')],
109
- });
110
- expect(component.hasFiles).toBeTruthy();
111
- });
112
- });
113
- describe('filesLength', () => {
114
- it('should return files and downloadFiles length', async () => {
115
- await wrapper.setProps({
116
- downloadFiles: [new File([], 'test')],
117
- });
118
- component.files = [new File([], 'test2')];
119
- expect(component.filesLength).toBe(2);
120
- });
121
- });
122
- describe('disabledButton', () => {
123
- it('should return files and downloadFiles length', async () => {
124
- await wrapper.setProps({
125
- maxFilesNumber: 0,
126
- });
127
-
128
- expect(component.disabledButton).toBeFalsy();
129
- });
130
-
131
- it('should return files and downloadFiles length', async () => {
132
- await wrapper.setProps({
133
- maxFilesNumber: 2,
134
- downloadFiles: [new File([], 'test')],
135
- });
136
- component.files = [new File([], 'test2')];
137
-
138
- expect(component.disabledButton).toBeTruthy();
139
- });
62
+ it('hasFiles should return true if there are files', () => {
63
+ wrapper.vm.files = [{ name: 'test.pdf', size: 1000 }];
64
+ expect(wrapper.vm.hasFiles).toBe(true);
140
65
  });
141
66
 
142
- describe('canAddMoreFiles', () => {
143
- it('should return files and downloadFiles length', async () => {
144
- await wrapper.setProps({
145
- maxFilesNumber: 2,
146
- downloadFiles: [new File([], 'test')],
147
- });
148
- component.files = [new File([], 'test2')];
149
-
150
- expect(component.canAddMoreFiles).toBeFalsy();
151
- });
67
+ it('canAddMoreFiles should return false if maxFilesNumber is reached', () => {
68
+ wrapper.vm.files = Array(10).fill({ name: 'test.pdf', size: 1000 });
69
+ expect(wrapper.vm.canAddMoreFiles).toBe(false);
152
70
  });
153
71
  });
154
72
 
155
- describe('Watch', () => {
156
- describe('files', () => {
157
- it('should emit an onMaxFilesNumberWarning event when there are more files added who maxFilesNumber', () => {
158
- wrapper.vm.$options.watch.files.call(
159
- component,
160
- Array.from(Array(11).keys()).map(() => ({ type: 'image/jpeg' }))
161
- );
162
- expect(wrapper.emitted().onMaxFilesNumberWarning).toBeDefined();
163
- });
164
-
165
- it('should emit an onMaxFileSizeWarning event when one file size is bigger than maxFileSize prop', async () => {
166
- await wrapper.setProps({
167
- maxFileSize: 3,
168
- });
169
- wrapper.vm.$options.watch.files.call(component, [
170
- { size: 4145728, type: 'image/jpeg' },
171
- ]);
172
- expect(wrapper.emitted().onMaxFileSizeWarning).toBeDefined();
173
- });
174
-
175
- it('should not add invalid types files', () => {
176
- wrapper.vm.$options.watch.files.call(
177
- component,
178
- Array.from(Array(1).keys()).map(() => ({ type: 'image/test' }))
179
- );
180
- expect(component.files).toEqual([]);
181
- });
73
+ describe('Watchers', () => {
74
+ it('should emit onMaxFilesNumberWarning if maxFilesNumber is exceeded', async () => {
75
+ wrapper.setProps({ maxFilesNumber: 10 });
76
+
77
+ const files = Array(11).fill(new File(['content'], 'test.pdf', { type: 'application/pdf' }));
78
+ const input = wrapper.find('input[type="file"]');
79
+ Object.defineProperty(input.element, 'files', { value: files });
80
+
81
+ await input.trigger('change');
82
+ expect(wrapper.vm.files).toHaveLength(10);
83
+ expect(wrapper.emitted().onMaxFilesNumberWarning).toBeTruthy();
182
84
  });
85
+
86
+ it('should emit onInvalidFiles if a file exceeds maxFileSize', async () => {
87
+ wrapper.setProps({ maxFileSize: 1 });
88
+
89
+ //cria um arquivo de 3MB
90
+ const file = new File(['a'.repeat(3 * 1024 * 1024)], 'test.pdf', { type: 'application/pdf' });
91
+ const input = wrapper.find('input[type="file"]');
92
+
93
+ Object.defineProperty(input.element, 'files', { value: [file] });
94
+
95
+ await input.trigger('change');
96
+ expect(wrapper.vm.files).toHaveLength(0);
97
+ expect(wrapper.emitted().onInvalidFiles).toBeTruthy();
98
+ });
99
+
183
100
  });
101
+
184
102
  });
@@ -29,8 +29,9 @@
29
29
  <farm-icon
30
30
  color="gray"
31
31
  size="20px"
32
- >{{ icon }}</farm-icon
33
32
  >
33
+ {{ icon }}
34
+ </farm-icon>
34
35
  </button>
35
36
  <input
36
37
  v-bind="delete { ...$attrs }.class"
@@ -270,7 +270,7 @@ export const TableWithCustomHeaderAndSelect = () => ({
270
270
  headers: [
271
271
  {
272
272
  title: 'check',
273
- sortable: true,
273
+ sortable: false,
274
274
  key: 'data-table-select',
275
275
  align: 'left',
276
276
  },
@@ -0,0 +1,15 @@
1
+ .collapse-enter-active,
2
+ .collapse-leave-active {
3
+ overflow: hidden;
4
+ transition: max-height 0.5s ease;
5
+ }
6
+
7
+ .collapse-enter-from,
8
+ .collapse-leave-to {
9
+ max-height: 0;
10
+ }
11
+
12
+ .collapse-enter-to,
13
+ .collapse-leave-from {
14
+ max-height: 400px;
15
+ }