Skip to content

Commit 2a373cb

Browse files
[ui] makes tests assertion more specific by removing expect.objectContaining (#4218)
1 parent ecc3a7a commit 2a373cb

File tree

8 files changed

+90
-87
lines changed

8 files changed

+90
-87
lines changed

desktop/core/src/desktop/js/apps/newimporter/FileImportTabs/FileImportTabs.test.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,26 @@ describe('FileImportTabs', () => {
113113
const finishButton = screen.getByText('Finish Import');
114114
fireEvent.click(finishButton);
115115

116+
const expectedFormData = new FormData();
117+
expectedFormData.append(
118+
'source',
119+
JSON.stringify({
120+
inputFormat: 'local',
121+
path: '/test/path/file.csv',
122+
sourceType: 'hive'
123+
})
124+
);
125+
expectedFormData.append(
126+
'destination',
127+
JSON.stringify({
128+
outputFormat: 'table',
129+
nonDefaultLocation: '/test/path/file.csv',
130+
name: 'default.file',
131+
sourceType: 'hive'
132+
})
133+
);
116134
await waitFor(() => {
117-
expect(mockSave).toHaveBeenCalledWith(expect.any(FormData));
135+
expect(mockSave).toHaveBeenCalledWith(expectedFormData);
118136
});
119137
});
120138

desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/DestinationSettings/DestinationSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ const DestinationSettings = ({
149149
if (selectedDatabase) {
150150
setDatabase(selectedDatabase);
151151
}
152-
} else if (!database) {
152+
} else if (!defaultValues?.database) {
153153
setDatabase(databases[0]);
154154
onChange('database', databases[0]);
155155
}

desktop/core/src/desktop/js/apps/storageBrowser/StorageDirectoryPage/StorageDirectoryActions/FileAndFolder/ChangeOwnerAndGroupModal/ChangeOwnerAndGroupModal.test.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,12 @@ describe('ChangeOwnerAndGroupModal Component', () => {
181181
fireEvent.click(getByText('Submit'));
182182

183183
await waitFor(() => {
184+
const expectedFormData = new FormData();
185+
expectedFormData.append('user', 'user1');
186+
expectedFormData.append('group', 'group1');
187+
expectedFormData.append('path', 'test/path/file1.txt');
184188
expect(mockSave).toHaveBeenCalledTimes(1);
185-
expect(mockSave).toHaveBeenCalledWith(expect.any(FormData));
189+
expect(mockSave).toHaveBeenCalledWith(expectedFormData);
186190
});
187191
});
188192

desktop/core/src/desktop/js/apps/storageBrowser/StorageDirectoryPage/StorageDirectoryActions/FileAndFolder/ChangePermissionModal/ChangePermissionModal.test.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ describe('ChangePermissionModal Component', () => {
5757
<ChangePermissionModal
5858
isOpen={true}
5959
files={mockFiles}
60-
setLoading={jest.fn()}
6160
onSuccess={mockOnSuccess}
6261
onError={mockOnError}
6362
onClose={mockOnClose}
@@ -81,7 +80,6 @@ describe('ChangePermissionModal Component', () => {
8180
<ChangePermissionModal
8281
isOpen={true}
8382
files={mockFiles}
84-
setLoading={jest.fn()}
8583
onSuccess={mockOnSuccess}
8684
onError={mockOnError}
8785
onClose={mockOnClose}
@@ -105,7 +103,6 @@ describe('ChangePermissionModal Component', () => {
105103
<ChangePermissionModal
106104
isOpen={true}
107105
files={mockFiles}
108-
setLoading={jest.fn()}
109106
onSuccess={mockOnSuccess}
110107
onError={mockOnError}
111108
onClose={mockOnClose}
@@ -115,8 +112,14 @@ describe('ChangePermissionModal Component', () => {
115112
fireEvent.click(getByText('Submit'));
116113

117114
waitFor(() => {
115+
const expectedFormData = new FormData();
116+
expectedFormData.append(
117+
'permission',
118+
'{"user_read":true,"user_write":true,"user_execute":true,"group_read":true,"group_write":true,"group_execute":true,"other_read":true,"other_write":true,"other_execute":true}'
119+
);
120+
expectedFormData.append('path', 'test/path/file1.txt');
118121
expect(mockSave).toHaveBeenCalledTimes(1);
119-
expect(mockSave).toHaveBeenCalledWith(expect.any(FormData));
122+
expect(mockSave).toHaveBeenCalledWith(expectedFormData);
120123
});
121124
});
122125

@@ -129,7 +132,6 @@ describe('ChangePermissionModal Component', () => {
129132
<ChangePermissionModal
130133
isOpen={true}
131134
files={mockFiles}
132-
setLoading={jest.fn()}
133135
onSuccess={mockOnSuccess}
134136
onError={mockOnError}
135137
onClose={mockOnClose}
@@ -150,7 +152,6 @@ describe('ChangePermissionModal Component', () => {
150152
<ChangePermissionModal
151153
isOpen={true}
152154
files={mockFiles}
153-
setLoading={jest.fn()}
154155
onSuccess={mockOnSuccess}
155156
onError={mockOnError}
156157
onClose={mockOnClose}
@@ -167,7 +168,6 @@ describe('ChangePermissionModal Component', () => {
167168
<ChangePermissionModal
168169
isOpen={true}
169170
files={mockFiles}
170-
setLoading={jest.fn()}
171171
onSuccess={mockOnSuccess}
172172
onError={mockOnError}
173173
onClose={mockOnClose}
@@ -183,7 +183,6 @@ describe('ChangePermissionModal Component', () => {
183183
<ChangePermissionModal
184184
isOpen={true}
185185
files={mockFiles}
186-
setLoading={jest.fn()}
187186
onSuccess={mockOnSuccess}
188187
onError={mockOnError}
189188
onClose={mockOnClose}

desktop/core/src/desktop/js/apps/storageBrowser/StorageDirectoryPage/StorageDirectoryActions/FileAndFolder/CompressionModal/CompressionModal.test.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ describe('CompressionModal Component', () => {
5858
const mockOnSuccess = jest.fn();
5959
const mockOnError = jest.fn();
6060
const mockOnClose = jest.fn();
61-
const setLoading = jest.fn();
6261

6362
beforeEach(() => {
6463
jest.clearAllMocks();
@@ -69,7 +68,6 @@ describe('CompressionModal Component', () => {
6968
<CompressionModal
7069
isOpen={true}
7170
files={mockFiles}
72-
setLoading={setLoading}
7371
onSuccess={mockOnSuccess}
7472
onError={mockOnError}
7573
onClose={mockOnClose}
@@ -88,7 +86,6 @@ describe('CompressionModal Component', () => {
8886
<CompressionModal
8987
isOpen={true}
9088
files={mockFiles}
91-
setLoading={setLoading}
9289
onSuccess={mockOnSuccess}
9390
onError={mockOnError}
9491
onClose={mockOnClose}
@@ -106,7 +103,6 @@ describe('CompressionModal Component', () => {
106103
<CompressionModal
107104
isOpen={true}
108105
files={mockFiles}
109-
setLoading={setLoading}
110106
onSuccess={mockOnSuccess}
111107
onError={mockOnError}
112108
onClose={mockOnClose}
@@ -131,7 +127,6 @@ describe('CompressionModal Component', () => {
131127
<CompressionModal
132128
isOpen={true}
133129
files={mockFiles}
134-
setLoading={setLoading}
135130
onSuccess={mockOnSuccess}
136131
onError={mockOnError}
137132
onClose={mockOnClose}
@@ -150,7 +145,6 @@ describe('CompressionModal Component', () => {
150145
<CompressionModal
151146
isOpen={true}
152147
files={mockFiles}
153-
setLoading={setLoading}
154148
onSuccess={mockOnSuccess}
155149
onError={mockOnError}
156150
onClose={mockOnClose}
@@ -171,7 +165,6 @@ describe('CompressionModal Component', () => {
171165
<CompressionModal
172166
isOpen={true}
173167
files={mockFiles}
174-
setLoading={setLoading}
175168
onSuccess={mockOnSuccess}
176169
onError={mockOnError}
177170
onClose={mockOnClose}

desktop/core/src/desktop/js/utils/hooks/useFileUpload/useChunkUpload.test.tsx

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,13 @@ describe('useChunkUpload', () => {
292292
mockQueueCallback(mockChunk);
293293

294294
await waitFor(() => {
295-
expect(mockUpdateFileVariables.mock.calls).toEqual(
296-
expect.arrayContaining([
297-
[mockFile.uuid, { status: FileStatus.Uploading }],
298-
[
299-
mockFile.uuid,
300-
{
301-
status: FileStatus.Failed,
302-
error: new Error('Upload server ran out of space. Try again later.')
303-
}
304-
]
305-
])
306-
);
295+
expect(mockUpdateFileVariables).toHaveBeenCalledWith(mockFile.uuid, {
296+
status: FileStatus.Uploading
297+
});
298+
expect(mockUpdateFileVariables).toHaveBeenCalledWith(mockFile.uuid, {
299+
status: FileStatus.Failed,
300+
error: new Error('Upload server ran out of space. Try again later.')
301+
});
307302
});
308303
expect(mockSave).not.toHaveBeenCalled();
309304
});
@@ -379,14 +374,11 @@ describe('useChunkUpload', () => {
379374
})
380375
);
381376

382-
expect(mockLoadData).toHaveBeenCalledWith(
383-
GET_TASKS_URL,
384-
expect.objectContaining({
385-
pollInterval: 5000,
386-
skip: true,
387-
onSuccess: expect.any(Function)
388-
})
389-
);
377+
expect(mockLoadData).toHaveBeenCalledWith(GET_TASKS_URL, {
378+
pollInterval: 5000,
379+
skip: true,
380+
onSuccess: expect.any(Function)
381+
});
390382

391383
mockIsAllChunksOfFileUploaded.mockReturnValue(true);
392384
mockSave
@@ -399,14 +391,11 @@ describe('useChunkUpload', () => {
399391
});
400392

401393
await waitFor(() => {
402-
expect(mockLoadData).toHaveBeenCalledWith(
403-
GET_TASKS_URL,
404-
expect.objectContaining({
405-
pollInterval: 5000,
406-
skip: false,
407-
onSuccess: expect.any(Function)
408-
})
409-
);
394+
expect(mockLoadData).toHaveBeenCalledWith(GET_TASKS_URL, {
395+
pollInterval: 5000,
396+
skip: false,
397+
onSuccess: expect.any(Function)
398+
});
410399
});
411400
});
412401

@@ -561,7 +550,7 @@ describe('useChunkUpload', () => {
561550
})
562551
);
563552

564-
expect(useQueueProcessor).toHaveBeenCalledWith(expect.any(Function), {
553+
expect(useQueueProcessor).toHaveBeenCalledWith(mockQueueCallback, {
565554
concurrentProcess: DEFAULT_CONCURRENT_MAX_CONNECTIONS
566555
});
567556
});
@@ -593,12 +582,9 @@ describe('useChunkUpload', () => {
593582
expect(mockUpdateFileVariables).toHaveBeenCalledWith(mockFile.uuid, {
594583
status: FileStatus.Uploading
595584
});
596-
expect(mockUpdateFileVariables).toHaveBeenCalledWith(
597-
mockFile.uuid,
598-
expect.objectContaining({
599-
progress: 75
600-
})
601-
);
585+
expect(mockUpdateFileVariables).toHaveBeenCalledWith(mockFile.uuid, {
586+
progress: 75
587+
});
602588
});
603589
});
604590

0 commit comments

Comments
 (0)