@@ -3,15 +3,14 @@ import { render, fireEvent, waitFor } from '@testing-library/react';
3
3
import userEvent from '@testing-library/user-event' ;
4
4
import '@testing-library/jest-dom' ;
5
5
import SourceConfiguration from './SourceConfiguration' ;
6
- import { FileFormatResponse } from '../../types' ;
7
- import { separator } from '../../constants' ;
6
+ import { FileFormatResponse , ImporterFileTypes } from '../../types' ;
8
7
9
8
describe ( 'SourceConfiguration Component' , ( ) => {
10
9
const mockSetFileFormat = jest . fn ( ) ;
11
10
const mockFileFormat : FileFormatResponse = {
12
11
quoteChar : '"' ,
13
12
recordSeparator : '\\n' ,
14
- type : 'csv' ,
13
+ type : ImporterFileTypes . EXCEL ,
15
14
hasHeader : true ,
16
15
fieldSeparator : ',' ,
17
16
status : 0
@@ -22,27 +21,59 @@ describe('SourceConfiguration Component', () => {
22
21
} ) ;
23
22
24
23
it ( 'should render the component' , ( ) => {
25
- const { getByText, getAllByRole } = render (
24
+ const { getByText } = render (
26
25
< SourceConfiguration fileFormat = { mockFileFormat } setFileFormat = { mockSetFileFormat } />
27
26
) ;
28
27
expect ( getByText ( 'Configure source' ) ) . toBeInTheDocument ( ) ;
29
- expect ( getAllByRole ( 'combobox' ) ) . toHaveLength ( 5 ) ;
30
28
} ) ;
31
29
32
- it ( 'calls setFileFormat on option change' , async ( ) => {
30
+ it ( 'should call setFileFormat on option change' , async ( ) => {
33
31
const { getByText, getAllByRole } = render (
34
32
< SourceConfiguration fileFormat = { mockFileFormat } setFileFormat = { mockSetFileFormat } />
35
33
) ;
36
34
37
35
const selectElement = getAllByRole ( 'combobox' ) [ 0 ] ;
38
36
await userEvent . click ( selectElement ) ;
39
- fireEvent . click ( getByText ( separator [ 3 ] . label ) ) ;
37
+ fireEvent . click ( getByText ( 'CSV' ) ) ;
40
38
41
39
await waitFor ( ( ) =>
42
40
expect ( mockSetFileFormat ) . toHaveBeenCalledWith ( {
43
41
...mockFileFormat ,
44
- fieldSeparator : separator [ 3 ] . value
42
+ type : ImporterFileTypes . CSV
45
43
} )
46
44
) ;
47
45
} ) ;
46
+
47
+ it ( 'should show fieldSepator and other downdown when fileType is CSV' , ( ) => {
48
+ const { getAllByRole, getByText } = render (
49
+ < SourceConfiguration
50
+ fileFormat = { { ...mockFileFormat , type : ImporterFileTypes . CSV } }
51
+ setFileFormat = { mockSetFileFormat }
52
+ />
53
+ ) ;
54
+
55
+ const selectElement = getAllByRole ( 'combobox' ) ;
56
+
57
+ expect ( selectElement ) . toHaveLength ( 5 ) ;
58
+ expect ( getByText ( 'File Type' ) ) . toBeInTheDocument ( ) ;
59
+ expect ( getByText ( 'Has Header' ) ) . toBeInTheDocument ( ) ;
60
+ expect ( getByText ( 'Field Separator' ) ) . toBeInTheDocument ( ) ;
61
+ expect ( getByText ( 'Record Separator' ) ) . toBeInTheDocument ( ) ;
62
+ expect ( getByText ( 'Quote Character' ) ) . toBeInTheDocument ( ) ;
63
+ } ) ;
64
+
65
+ it ( 'should not show fieldSepator and other downdown when fileType is not CSV' , ( ) => {
66
+ const { getAllByRole, getByText, queryByText } = render (
67
+ < SourceConfiguration fileFormat = { mockFileFormat } setFileFormat = { mockSetFileFormat } />
68
+ ) ;
69
+
70
+ const selectElement = getAllByRole ( 'combobox' ) ;
71
+
72
+ expect ( selectElement ) . toHaveLength ( 2 ) ;
73
+ expect ( getByText ( 'File Type' ) ) . toBeInTheDocument ( ) ;
74
+ expect ( getByText ( 'Has Header' ) ) . toBeInTheDocument ( ) ;
75
+ expect ( queryByText ( 'Field Separator' ) ) . not . toBeInTheDocument ( ) ;
76
+ expect ( queryByText ( 'Record Separator' ) ) . not . toBeInTheDocument ( ) ;
77
+ expect ( queryByText ( 'Quote Character' ) ) . not . toBeInTheDocument ( ) ;
78
+ } ) ;
48
79
} ) ;
0 commit comments