Merge pull request #2 from kimatata/seed

Seed
This commit is contained in:
Takeshi Kimata
2024-05-16 10:24:30 +09:00
committed by GitHub
5 changed files with 1669 additions and 32 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,9 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"test": "vitest",
"coverage": "vitest run --coverage"
},
"dependencies": {
"@nextui-org/react": "^2.2.9",
@@ -34,5 +36,9 @@
"tailwind-variants": "^0.1.18",
"tailwindcss": "3.3.5",
"typescript": "5.0.4"
},
"devDependencies": {
"@vitest/coverage-v8": "^1.6.0",
"vitest": "^1.6.0"
}
}

View File

@@ -1,6 +1,7 @@
import { Image, Button, Tooltip, Card, CardBody } from "@nextui-org/react";
import { AttachmentType, CaseMessages } from "@/types/case";
import { Trash, ArrowDownToLine } from "lucide-react";
import { isImage } from "./isImage";
type Props = {
attachments: AttachmentType[];
@@ -22,16 +23,7 @@ export default function CaseAttachmentsEditor({
let others = [];
attachments.forEach((attachment) => {
let path = attachment.path;
let extension = path.substring(path.lastIndexOf(".") + 1).toLowerCase();
if (
extension === "png" ||
extension === "jpg" ||
extension === "jpeg" ||
extension === "gif" ||
extension === "bmp" ||
extension === "svg"
) {
if (isImage(attachment)) {
images.push(attachment);
} else {
others.push(attachment);

View File

@@ -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);
});

View File

@@ -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 };