1
0
Fork 0
fahrPool/web/lib/auftraege/fotos.test.ts

62 lines
3.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { sortiereUndBeschrifteFotos } from "./fotos";
describe("sortiereUndBeschrifteFotos", () => {
it("sortiert Pflichtfotos in der festen Positions-Reihenfolge, unabhaengig von der Eingabe-Reihenfolge", () => {
const fotos = [
{ position: "heck", storage_path: "a/heck.jpg", uploaded_at: "2026-01-01T10:00:00Z", beschreibung: null },
{ position: "front", storage_path: "a/front.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null },
];
const result = sortiereUndBeschrifteFotos(fotos);
expect(result.map((f) => f.position)).toEqual(["front", "heck"]);
});
it("beschriftet Pflichtfotos mit Leerzeichen statt Unterstrich", () => {
const fotos = [
{ position: "seitlich_rechts", storage_path: "a/seitlich_rechts.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null },
];
const result = sortiereUndBeschrifteFotos(fotos);
expect(result[0].label).toBe("seitlich rechts");
});
it("laesst fehlende Pflicht-Positionen einfach weg", () => {
const fotos = [{ position: "front", storage_path: "a/front.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null }];
const result = sortiereUndBeschrifteFotos(fotos);
expect(result).toHaveLength(1);
expect(result[0].position).toBe("front");
});
it("beschriftet ein einzelnes Schadensfoto ohne Nummer", () => {
const fotos = [{ position: "schaden", storage_path: "a/schaden-1.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null }];
const result = sortiereUndBeschrifteFotos(fotos);
expect(result[0].label).toBe("Schaden");
});
it("nummeriert mehrere Schadensfotos nach Upload-Zeitpunkt, unabhaengig von der Eingabe-Reihenfolge", () => {
const fotos = [
{ position: "schaden", storage_path: "a/schaden-2.jpg", uploaded_at: "2026-01-01T10:00:00Z", beschreibung: null },
{ position: "schaden", storage_path: "a/schaden-1.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null },
];
const result = sortiereUndBeschrifteFotos(fotos);
expect(result.map((f) => f.storage_path)).toEqual(["a/schaden-1.jpg", "a/schaden-2.jpg"]);
expect(result.map((f) => f.label)).toEqual(["Schaden 1", "Schaden 2"]);
});
it("stellt Pflichtfotos vor Schadensfotos, unabhaengig von der Eingabe-Reihenfolge", () => {
const fotos = [
{ position: "schaden", storage_path: "a/schaden.jpg", uploaded_at: "2026-01-01T08:00:00Z", beschreibung: null },
{ position: "front", storage_path: "a/front.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: null },
];
const result = sortiereUndBeschrifteFotos(fotos);
expect(result.map((f) => f.position)).toEqual(["front", "schaden"]);
});
it("reicht die Schadensbeschreibung unveraendert durch", () => {
const fotos = [
{ position: "schaden", storage_path: "a/schaden-1.jpg", uploaded_at: "2026-01-01T09:00:00Z", beschreibung: "Kratzer hintere Stossstange" },
];
const result = sortiereUndBeschrifteFotos(fotos);
expect(result[0].beschreibung).toBe("Kratzer hintere Stossstange");
});
});