Skip to content

Commit

Permalink
add ignore case to regex creation for uploading document, add test ca…
Browse files Browse the repository at this point in the history
…se for uppercase file extension
  • Loading branch information
Josh-HMCTS committed Feb 7, 2025
1 parent 5bd16af commit 8695d8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,21 @@ describe('WriteDocumentFieldComponent', () => {
expect(component.fileUploadMessages).toEqual('Document format is not supported');
});

it('should allow user to upload file ignoring file extension case', () => {
const allowedFileTypes = '.pdf,.txt,.doc,.dot,.docx,.rtf,.xls,.xlt,.xla,.xlsx,.xltx,.xlsb,.ppt,.pot,.pps,.ppa,.pptx,.potx,.ppsx,.jpg,.jpeg,.bmp,.tif,.tiff,.png,.csv';
const blobParts: BlobPart[] = ['some contents for blob'];
const file: File = new File(blobParts, 'test.PDF');
const dummyEvent = {
target: {
files: [
file
]
}
};
component.fileChangeEvent(dummyEvent, allowedFileTypes);
expect(component.fileUploadMessages).toEqual('Uploading...');
});

it('should allow user to upload if there is no file types specified', () => {
spyOn(component, 'invalidFileFormat');
const allowedFileTypes = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ export class WriteDocumentFieldComponent extends AbstractFieldWriteComponent imp

public fileChangeEvent(fileInput: any, allowedRegex?: string): void {
let fileTypeRegex;
if (allowedRegex){
fileTypeRegex = new RegExp(`(${allowedRegex.replace(/,/g, '|')})`);
if (allowedRegex) {
fileTypeRegex = new RegExp(`(${allowedRegex.replace(/,/g, '|')})`, 'i');
}
if (fileInput.target?.files[0] && !fileInput.target?.files[0]?.name.toLowerCase()?.match(fileTypeRegex)){
if (fileInput.target?.files[0] && !fileInput.target?.files[0]?.name?.match(fileTypeRegex)){
this.invalidFileFormat();
} else if (fileInput.target.files[0]) {
this.selectedFile = fileInput.target.files[0];
Expand Down

0 comments on commit 8695d8d

Please sign in to comment.