-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Communication: Allow users to paste images from the clipboard (#9637)
- Loading branch information
Showing
9 changed files
with
239 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/test/javascript/spec/component/shared/http/file-uploader.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { provideHttpClient } from '@angular/common/http'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { FileUploaderService } from 'app/shared/http/file-uploader.service'; | ||
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; | ||
import { MAX_FILE_SIZE, MAX_FILE_SIZE_COMMUNICATION } from '../../../../../../main/webapp/app/shared/constants/input.constants'; | ||
|
||
describe('FileUploaderService', () => { | ||
let service: FileUploaderService; | ||
let httpMock: HttpTestingController; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [], | ||
providers: [provideHttpClient(), provideHttpClientTesting()], | ||
}); | ||
|
||
service = TestBed.inject(FileUploaderService); | ||
httpMock = TestBed.inject(HttpTestingController); | ||
}); | ||
|
||
it('should upload a regular file for the markdown editor', async () => { | ||
const file = new File([''], 'test.pdf', { type: 'application/pdf' }); | ||
const expectedResponse = { path: 'some-path' }; | ||
const promise = service.uploadMarkdownFile(file); | ||
|
||
const request = httpMock.expectOne({ method: 'POST', url: '/api/markdown-file-upload' }); | ||
request.flush(expectedResponse); | ||
|
||
httpMock.verify(); | ||
await expect(promise).resolves.toEqual(expectedResponse); | ||
}); | ||
|
||
it('should upload a regular file for communication', async () => { | ||
const file = new File([''], 'test.pdf', { type: 'application/pdf' }); | ||
const expectedResponse = { path: 'some-path' }; | ||
const promise = service.uploadMarkdownFileInCurrentMetisConversation(file, 1, 2); | ||
|
||
const request = httpMock.expectOne({ method: 'POST', url: '/api/files/courses/1/conversations/2' }); | ||
request.flush(expectedResponse); | ||
|
||
httpMock.verify(); | ||
await expect(promise).resolves.toEqual(expectedResponse); | ||
}); | ||
|
||
it('should reject if the course for communication is not specified', async () => { | ||
const file = new File([''], 'test.pdf', { type: 'application/pdf' }); | ||
await expect(service.uploadMarkdownFileInCurrentMetisConversation(file, undefined, 2)).rejects.toThrow(Error); | ||
}); | ||
|
||
it('should reject if the conversation for communication is not specified', async () => { | ||
const file = new File([''], 'test.pdf', { type: 'application/pdf' }); | ||
await expect(service.uploadMarkdownFileInCurrentMetisConversation(file, 1, undefined)).rejects.toThrow(Error); | ||
}); | ||
|
||
it('should reject files with unsupported extensions', async () => { | ||
const file = new File([''], 'test.docx', { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }); | ||
await expect(service.uploadMarkdownFile(file)).rejects.toThrow(Error); | ||
}); | ||
|
||
it('should reject files that are too large (general)', async () => { | ||
const largeFile = new File([''], 'test.pdf', { type: 'application/pdf' }); | ||
// Overwrite the size property to be larger than the maximum allowed size | ||
Object.defineProperty(largeFile, 'size', { value: MAX_FILE_SIZE + 1 }); | ||
await expect(service.uploadMarkdownFile(largeFile)).rejects.toThrow(Error); | ||
}); | ||
|
||
it('should reject files that are too large (communication)', async () => { | ||
const largeFile = new File([''], 'test.pdf', { type: 'application/pdf' }); | ||
// Overwrite the size property to be larger than the maximum allowed size | ||
Object.defineProperty(largeFile, 'size', { value: MAX_FILE_SIZE_COMMUNICATION + 1 }); | ||
await expect(service.uploadMarkdownFileInCurrentMetisConversation(largeFile, 1, 2)).rejects.toThrow(Error); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
src/test/javascript/spec/helpers/mocks/service/mock-clipboard-item.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
export class MockClipboardItem {} | ||
export class MockClipboardItem { | ||
types: string[]; | ||
|
||
getType(_type: string): Promise<Blob> { | ||
return Promise.resolve(new Blob()); | ||
} | ||
} |