Skip to content

Commit bd719ee

Browse files
committed
chore: update failing tests
1 parent 4ba971d commit bd719ee

2 files changed

Lines changed: 50 additions & 8 deletions

File tree

src/components/MessageInput/__tests__/EditMessageForm.test.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,27 @@ const fileUploadUrl = 'http://www.getstream.io'; // real url, because ImageAttac
9191
const getImage = () => new File(['content'], filename, { type: 'image/png' });
9292
const getFile = (name = filename) => new File(['content'], name, { type: 'text/plain' });
9393

94+
/** Matches Channel.sendFile / sendImage (uri, name?, contentType?, user?, axiosRequestConfig?). */
95+
const expectChannelUploadSendFile = (spy, file) => {
96+
expect(spy).toHaveBeenCalledWith(
97+
file,
98+
undefined,
99+
undefined,
100+
undefined,
101+
expect.objectContaining({ onUploadProgress: expect.any(Function) }),
102+
);
103+
};
104+
105+
const expectChannelUploadSendImage = (spy, image) => {
106+
expect(spy).toHaveBeenCalledWith(
107+
image,
108+
undefined,
109+
undefined,
110+
undefined,
111+
expect.objectContaining({ onUploadProgress: expect.any(Function) }),
112+
);
113+
};
114+
94115
const sendMessageMock = jest.fn();
95116
const editMock = jest.fn();
96117
const mockAddNotification = jest.fn();
@@ -440,8 +461,8 @@ describe(`EditMessageForm`, () => {
440461
});
441462
const filenameTexts = await screen.findAllByTitle(filename);
442463
await waitFor(() => {
443-
expect(sendFileSpy).toHaveBeenCalledWith(file);
444-
expect(sendImageSpy).toHaveBeenCalledWith(image);
464+
expectChannelUploadSendFile(sendFileSpy, file);
465+
expectChannelUploadSendImage(sendImageSpy, image);
445466
expect(screen.getByTestId(IMAGE_PREVIEW_TEST_ID)).toBeInTheDocument();
446467
expect(screen.getByTestId(FILE_PREVIEW_TEST_ID)).toBeInTheDocument();
447468
filenameTexts.forEach((filenameText) => expect(filenameText).toBeInTheDocument());
@@ -512,7 +533,7 @@ describe(`EditMessageForm`, () => {
512533
dropFile(file, formElement);
513534
});
514535
await waitFor(() => {
515-
expect(sendImageSpy).toHaveBeenCalledWith(file);
536+
expectChannelUploadSendImage(sendImageSpy, file);
516537
});
517538
const results = await axe(container);
518539
expect(results).toHaveNoViolations();
@@ -579,7 +600,7 @@ describe(`EditMessageForm`, () => {
579600
act(() => dropFile(file, formElement));
580601

581602
await waitFor(() => {
582-
expect(sendFileSpy).toHaveBeenCalledWith(file);
603+
expectChannelUploadSendFile(sendFileSpy, file);
583604
});
584605

585606
sendFileSpy.mockImplementationOnce(() => Promise.resolve({ file }));
@@ -590,7 +611,7 @@ describe(`EditMessageForm`, () => {
590611

591612
await waitFor(() => {
592613
expect(sendFileSpy).toHaveBeenCalledTimes(2);
593-
expect(sendFileSpy).toHaveBeenCalledWith(file);
614+
expectChannelUploadSendFile(sendFileSpy, file);
594615
});
595616
await axeNoViolations(container);
596617
});

src/components/MessageInput/__tests__/MessageInput.test.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ const fileUploadUrl = 'http://www.getstream.io'; // real url, because ImageAttac
7979
const getImage = () => new File(['content'], filename, { type: 'image/png' });
8080
const getFile = (name = filename) => new File(['content'], name, { type: 'text/plain' });
8181

82+
/** Matches Channel.sendFile / sendImage (uri, name?, contentType?, user?, axiosRequestConfig?). */
83+
const expectChannelUploadSendFile = (spy, file) => {
84+
expect(spy).toHaveBeenCalledWith(
85+
file,
86+
undefined,
87+
undefined,
88+
undefined,
89+
expect.objectContaining({ onUploadProgress: expect.any(Function) }),
90+
);
91+
};
92+
93+
const expectChannelUploadSendImage = (spy, image) => {
94+
expect(spy).toHaveBeenCalledWith(
95+
image,
96+
undefined,
97+
undefined,
98+
undefined,
99+
expect.objectContaining({ onUploadProgress: expect.any(Function) }),
100+
);
101+
};
102+
82103
const sendMessageMock = jest.fn();
83104
const mockAddNotification = jest.fn();
84105

@@ -411,8 +432,8 @@ describe(`MessageInputFlat`, () => {
411432
});
412433
const filenameTexts = await screen.findAllByTitle(filename);
413434
await waitFor(() => {
414-
expect(sendFileSpy).toHaveBeenCalledWith(file);
415-
expect(sendImageSpy).toHaveBeenCalledWith(image);
435+
expectChannelUploadSendFile(sendFileSpy, file);
436+
expectChannelUploadSendImage(sendImageSpy, image);
416437
expect(screen.getByTestId(IMAGE_PREVIEW_TEST_ID)).toBeInTheDocument();
417438
expect(screen.getByTestId(FILE_PREVIEW_TEST_ID)).toBeInTheDocument();
418439
filenameTexts.forEach((filenameText) => expect(filenameText).toBeInTheDocument());
@@ -483,7 +504,7 @@ describe(`MessageInputFlat`, () => {
483504
dropFile(file, formElement);
484505
});
485506
await waitFor(() => {
486-
expect(sendImageSpy).toHaveBeenCalledWith(file);
507+
expectChannelUploadSendImage(sendImageSpy, file);
487508
});
488509
const results = await axe(container);
489510
expect(results).toHaveNoViolations();

0 commit comments

Comments
 (0)