Intoduce vitest
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { Image, Button, Tooltip, Card, CardBody } from "@nextui-org/react";
|
import { Image, Button, Tooltip, Card, CardBody } from "@nextui-org/react";
|
||||||
import { AttachmentType, CaseMessages } from "@/types/case";
|
import { AttachmentType, CaseMessages } from "@/types/case";
|
||||||
import { Trash, ArrowDownToLine } from "lucide-react";
|
import { Trash, ArrowDownToLine } from "lucide-react";
|
||||||
|
import { isImage } from "./isImage";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
attachments: AttachmentType[];
|
attachments: AttachmentType[];
|
||||||
@@ -12,23 +13,6 @@ type Props = {
|
|||||||
messages: CaseMessages,
|
messages: CaseMessages,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function isImg(attachmentFile: AttachmentType) {
|
|
||||||
let path = attachmentFile.path;
|
|
||||||
let extension = path.substring(path.lastIndexOf(".") + 1).toLowerCase();
|
|
||||||
if (
|
|
||||||
extension === "png" ||
|
|
||||||
extension === "jpg" ||
|
|
||||||
extension === "jpeg" ||
|
|
||||||
extension === "gif" ||
|
|
||||||
extension === "bmp" ||
|
|
||||||
extension === "svg"
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function CaseAttachmentsEditor({
|
export default function CaseAttachmentsEditor({
|
||||||
attachments = [],
|
attachments = [],
|
||||||
onAttachmentDownload,
|
onAttachmentDownload,
|
||||||
@@ -39,8 +23,7 @@ export default function CaseAttachmentsEditor({
|
|||||||
let others = [];
|
let others = [];
|
||||||
|
|
||||||
attachments.forEach((attachment) => {
|
attachments.forEach((attachment) => {
|
||||||
const isImage = isImg(attachment)
|
if (isImage(attachment)) {
|
||||||
if (isImage) {
|
|
||||||
images.push(attachment);
|
images.push(attachment);
|
||||||
} else {
|
} else {
|
||||||
others.push(attachment);
|
others.push(attachment);
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { expect, test } from "vitest";
|
||||||
|
import { isImage } from "./isImage";
|
||||||
|
import { AttachmentType } from "@/types/case";
|
||||||
|
|
||||||
|
test("isImage", () => {
|
||||||
|
type CaseAttachmentType = {
|
||||||
|
createdAt: Date;
|
||||||
|
updatedAt: Date;
|
||||||
|
CaseId: number;
|
||||||
|
AttachmentId: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const sampleCaseAttachment: CaseAttachmentType = {
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
CaseId: 1,
|
||||||
|
AttachmentId: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
const sampleAttachment: AttachmentType = {
|
||||||
|
id: 1,
|
||||||
|
title: "",
|
||||||
|
detail: "",
|
||||||
|
path: "",
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
caseAttachments: sampleCaseAttachment,
|
||||||
|
};
|
||||||
|
|
||||||
|
sampleAttachment.path = "public/uploads/abc.png";
|
||||||
|
expect(isImage(sampleAttachment)).toBe(true);
|
||||||
|
|
||||||
|
sampleAttachment.path = "public/uploads/abc.mp3";
|
||||||
|
expect(isImage(sampleAttachment)).toBe(false);
|
||||||
|
});
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { AttachmentType } from "@/types/case";
|
||||||
|
|
||||||
|
function isImage(attachmentFile: AttachmentType) {
|
||||||
|
let path = attachmentFile.path;
|
||||||
|
let extension = path.substring(path.lastIndexOf(".") + 1).toLowerCase();
|
||||||
|
if (
|
||||||
|
extension === "png" ||
|
||||||
|
extension === "jpg" ||
|
||||||
|
extension === "jpeg" ||
|
||||||
|
extension === "gif" ||
|
||||||
|
extension === "bmp" ||
|
||||||
|
extension === "svg"
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { isImage };
|
||||||
Reference in New Issue
Block a user