chore: Minor fix
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { fileNameWithEllipsis } from 'shared/helpers/FileHelper';
|
||||
import { fileNameWithEllipsis } from '@chatwoot/utils';
|
||||
|
||||
import Button from 'dashboard/components-next/button/Button.vue';
|
||||
|
||||
@@ -69,7 +69,7 @@ const removeAttachment = id => {
|
||||
<div
|
||||
v-for="attachment in filteredNonImageAttachments"
|
||||
:key="attachment.id"
|
||||
class="max-w-[300px] inline-flex items-center h-8 min-w-0 bg-n-solid-3 rounded-lg gap-3 ltr:pl-3 rtl:pr-3 ltr:pr-2 rtl:pl-2"
|
||||
class="max-w-[300px] inline-flex items-center h-8 min-w-0 bg-n-alpha-2 dark:bg-n-solid-3 rounded-lg gap-3 ltr:pl-3 rtl:pr-3 ltr:pr-2 rtl:pl-2"
|
||||
>
|
||||
<span class="text-sm font-medium text-n-slate-11">
|
||||
{{ fileNameWithEllipsis(attachment.resource) }}
|
||||
|
||||
@@ -19,19 +19,3 @@ export const checkFileSizeLimit = (file, maximumUploadLimit) => {
|
||||
const fileSizeInMB = fileSizeInMegaBytes(fileSize);
|
||||
return fileSizeInMB <= maximumUploadLimit;
|
||||
};
|
||||
|
||||
export const fileNameWithEllipsis = (file, maxLength = 26, ellipsis = '…') => {
|
||||
const fullName = file?.filename ?? file?.name ?? 'Untitled';
|
||||
|
||||
const dotIndex = fullName.lastIndexOf('.');
|
||||
if (dotIndex === -1) return fullName;
|
||||
|
||||
const [name, extension] = [
|
||||
fullName.slice(0, dotIndex),
|
||||
fullName.slice(dotIndex),
|
||||
];
|
||||
|
||||
if (name.length <= maxLength) return fullName;
|
||||
|
||||
return `${name.slice(0, maxLength)}${ellipsis}${extension}`;
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@ import {
|
||||
formatBytes,
|
||||
fileSizeInMegaBytes,
|
||||
checkFileSizeLimit,
|
||||
fileNameWithEllipsis,
|
||||
} from '../FileHelper';
|
||||
|
||||
describe('#File Helpers', () => {
|
||||
@@ -36,51 +35,4 @@ describe('#File Helpers', () => {
|
||||
expect(checkFileSizeLimit({ file: { size: 199154 } }, 40)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fileNameWithEllipsis', () => {
|
||||
it('should return original filename if name length is within limit', () => {
|
||||
const file = { name: 'document.pdf' };
|
||||
expect(fileNameWithEllipsis(file)).toBe('document.pdf');
|
||||
});
|
||||
|
||||
it('should truncate filename if it exceeds max length', () => {
|
||||
const file = { name: 'very-long-filename-that-needs-truncating.pdf' };
|
||||
expect(fileNameWithEllipsis(file)).toBe(
|
||||
'very-long-filename-that-ne….pdf'
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle files without extension', () => {
|
||||
const file = { name: 'README' };
|
||||
expect(fileNameWithEllipsis(file)).toBe('README');
|
||||
});
|
||||
|
||||
it('should handle files with multiple dots', () => {
|
||||
const file = { name: 'archive.tar.gz' };
|
||||
expect(fileNameWithEllipsis(file)).toBe('archive.tar.gz');
|
||||
});
|
||||
|
||||
it('should handle hidden files', () => {
|
||||
const file = { name: '.gitignore' };
|
||||
expect(fileNameWithEllipsis(file)).toBe('.gitignore');
|
||||
});
|
||||
|
||||
it('should handle both filename and name properties', () => {
|
||||
const file = {
|
||||
filename: 'from-filename.pdf',
|
||||
name: 'from-name.pdf',
|
||||
};
|
||||
expect(fileNameWithEllipsis(file)).toBe('from-filename.pdf');
|
||||
});
|
||||
|
||||
it('should handle special characters', () => {
|
||||
const file = { name: 'résumé-2023_final-version.doc' };
|
||||
expect(fileNameWithEllipsis(file)).toBe('résumé-2023_final-version.doc');
|
||||
});
|
||||
|
||||
it('should handle very short filenames', () => {
|
||||
const file = { name: 'a.txt' };
|
||||
expect(fileNameWithEllipsis(file)).toBe('a.txt');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user