Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Update file upload unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
rpaschoal committed May 10, 2019
1 parent cc787a2 commit 564539c
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/spec/ng-chat.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1545,8 +1545,8 @@ describe('NgChat', () => {
expect(spy).not.toHaveBeenCalled();
});

it('Exercise for "onFileChosen" event', () => {
let mockedFileMessageServerResponse = new FileMessage();
it('Should filter by file instance id and upload file when a file upload "onFileChosen" event is triggered', () => {
const mockedFileMessageServerResponse = new FileMessage();

spyOn(MockableFileUploadAdapter.prototype, 'uploadFile').and.callFake(() => {
// At this stage the 'isUploadingFile' should be true
Expand All @@ -1555,16 +1555,16 @@ describe('NgChat', () => {
return of(mockedFileMessageServerResponse);
});
spyOn(MockableAdapter.prototype, 'sendMessage');
let scrollSpy = spyOn(subject, 'scrollChatWindow');
const scrollSpy = spyOn(subject, 'scrollChatWindow');

let chattingTo = new User();
const chattingTo = new User();
chattingTo.id = 88;

let chatWindow = new Window(chattingTo, false, false);
const chatWindow = new Window(chattingTo, false, false);

let fakeFile = new File([''], 'filename', { type: 'text/html' });
const fakeFile = new File([''], 'filename', { type: 'text/html' });

let fakeFileElement = {
const fakeFileElement = {
nativeElement:
{
id: `ng-chat-file-upload-${chattingTo.id}`,
Expand All @@ -1573,7 +1573,17 @@ describe('NgChat', () => {
}
}

subject.nativeFileInputs = [fakeFileElement];
// Should be filtered and ignored
const anotherFakeFileElement = {
nativeElement:
{
id: `ng-chat-file-upload-${123}`,
value: 'test',
files: []
}
}

subject.nativeFileInputs = [anotherFakeFileElement, fakeFileElement];
subject.fileUploadAdapter = new MockableFileUploadAdapter();

subject.onFileChosen(chatWindow);
Expand All @@ -1586,6 +1596,7 @@ describe('NgChat', () => {
expect(scrollSpy).toHaveBeenCalledTimes(1);
expect(scrollSpy.calls.mostRecent().args[1]).toBe(ScrollDirection.Bottom);
expect(fakeFileElement.nativeElement.value).toBe('');
expect(anotherFakeFileElement.nativeElement.value).toBe('test');
expect(subject.isUploadingFile).toBeFalsy();
});

Expand Down

0 comments on commit 564539c

Please sign in to comment.