Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
TaylorJ76 committed Nov 25, 2024
1 parent 573056c commit 7cfca1b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
5 changes: 1 addition & 4 deletions libs/components/src/lib/file-picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ Some examples of valid values are:
If the user tries to upload a file that does not match the accepted files, the file picker displays an error message.

```html preview 230px
<vwc-file-picker
helper-text=".jpg, .jpeg types only"
accept=".jpg, .jpeg"
>
<vwc-file-picker helper-text=".jpg, .jpeg types only" accept=".jpg, .jpeg">
Drag & Drop or click to upload
</vwc-file-picker>
```
Expand Down
17 changes: 10 additions & 7 deletions libs/components/src/lib/file-picker/file-picker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@ describe('vwc-file-picker', () => {

it('should show a custom error message (when supplied) for files larger than maxFileSize', async function () {
element.maxFileSize = 1; // 1 MB
element.fileTooBigError = 'File size of {{filesize}}MB is too big. Limit is {{maxFilesize}}MB.';
element.fileTooBigError =
'File size of {{filesize}}MB is too big. Limit is {{maxFilesize}}MB.';
const file = await generateFile('london.png', 2);
addFiles([file]);

expect(getErrorMessage(0)).toBe('File size of 2MB is too big. Limit is 1MB.');
expect(getErrorMessage(0)).toBe(
'File size of 2MB is too big. Limit is 1MB.'
);
});
});

Expand All @@ -157,7 +160,7 @@ describe('vwc-file-picker', () => {
await generateFile('london.png', 1),
await generateFile('london.png', 1),
]);

expect(getErrorMessage(0)).toBe('');
expect(getErrorMessage(1)).toBe("You can't select any more files.");
});
Expand All @@ -166,14 +169,14 @@ describe('vwc-file-picker', () => {
element.maxFiles = 1;
element.maxFilesExceededError = 'Max files exceeded.';
await elementUpdated(element);

addFiles([
await generateFile('london.png', 1),
await generateFile('london.png', 1),
]);

expect(getErrorMessage(0)).toBe('');
expect(getErrorMessage(1)).toBe("Max files exceeded.");
expect(getErrorMessage(1)).toBe('Max files exceeded.');
});
});

Expand Down Expand Up @@ -284,7 +287,7 @@ describe('vwc-file-picker', () => {
await generateFile('london.txt', 1, 'text/plain'),
]);

expect(getErrorMessage(3)).toBe("File type not allowed.");
expect(getErrorMessage(3)).toBe('File type not allowed.');
});
});

Expand Down
23 changes: 16 additions & 7 deletions libs/components/src/lib/file-picker/file-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ export class FilePicker extends FormAssociatedFilePicker {
return;

Check warning on line 153 in libs/components/src/lib/file-picker/file-picker.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/lib/file-picker/file-picker.ts#L153

Added line #L153 was not covered by tests
}

this.#dropzone.options.dictInvalidFileType = newValue || this.locale.filePicker.invalidFileTypeError;
this.#dropzone.options.dictInvalidFileType =
newValue || this.locale.filePicker.invalidFileTypeError;
}

/**
Expand All @@ -163,13 +164,15 @@ export class FilePicker extends FormAssociatedFilePicker {
* @remarks
* HTML Attribute: max-files-exceeded-error
*/
@attr({ attribute: 'max-files-exceeded-error' }) maxFilesExceededError?: string;
@attr({ attribute: 'max-files-exceeded-error' })
maxFilesExceededError?: string;
maxFilesExceededErrorChanged(_oldValue: string, newValue: string): void {
if (!this.#dropzone) {
return;

Check warning on line 171 in libs/components/src/lib/file-picker/file-picker.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/lib/file-picker/file-picker.ts#L171

Added line #L171 was not covered by tests
}

this.#dropzone.options.dictMaxFilesExceeded = newValue || this.locale.filePicker.maxFilesExceededError;
this.#dropzone.options.dictMaxFilesExceeded =
newValue || this.locale.filePicker.maxFilesExceededError;
}

/**
Expand All @@ -185,7 +188,8 @@ export class FilePicker extends FormAssociatedFilePicker {
return;

Check warning on line 188 in libs/components/src/lib/file-picker/file-picker.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/lib/file-picker/file-picker.ts#L188

Added line #L188 was not covered by tests
}

this.#dropzone.options.dictFileTooBig = newValue || this.locale.filePicker.fileTooBigError;
this.#dropzone.options.dictFileTooBig =
newValue || this.locale.filePicker.fileTooBigError;
}

override nameChanged(previous: string, next: string) {
Expand Down Expand Up @@ -292,9 +296,14 @@ export class FilePicker extends FormAssociatedFilePicker {
previewsContainer: previewList,
createImageThumbnails: false,
previewTemplate: generateFilePreviewTemplate(this.buttonTag, this.locale),
dictInvalidFileType: this.invalidFileTypeError || this.locale.filePicker.invalidFileTypeError,
dictMaxFilesExceeded: this.maxFilesExceededError || this.locale.filePicker.maxFilesExceededError,
dictFileTooBig: this.fileTooBigError || this.locale.filePicker.fileTooBigError,
dictInvalidFileType:
this.invalidFileTypeError ||
this.locale.filePicker.invalidFileTypeError,
dictMaxFilesExceeded:
this.maxFilesExceededError ||
this.locale.filePicker.maxFilesExceededError,
dictFileTooBig:
this.fileTooBigError || this.locale.filePicker.fileTooBigError,
error: this.#localizeErrorMessage,
});

Expand Down

0 comments on commit 7cfca1b

Please sign in to comment.