1import { describe, expect, it } from "vitest"
2
3import { computeCenterCrop } from "@/features/camera/crop"
4
5/* FR-05 dan FR-13: crop tengah dari sumber ke rasio slot. Nilai yang diuji
6 adalah nilai yang dipakai kamera dan pemuat foto galeri. */
7
8describe("computeCenterCrop", () => {
9 it("memotong sisi lebar saat sumber lebih lebar dari rasio slot", () => {
10 /* 1280 x 720 dipotong ke rasio slot strip-4 (528 / 372). */
11 const crop = computeCenterCrop(1280, 720, 528 / 372)
12
13 expect(crop.height).toBe(720)
14 expect(crop.width).toBe(Math.round(720 * (528 / 372)))
15 expect(crop.x).toBe(Math.round((1280 - crop.width) / 2))
16 expect(crop.y).toBe(0)
17 })
18
19 it("memotong sisi tinggi saat sumber lebih tinggi dari rasio slot", () => {
20 /* Foto potret 600 x 1200 ke rasio layar 16 / 9. */
21 const crop = computeCenterCrop(600, 1200, 16 / 9)
22
23 expect(crop.width).toBe(600)
24 expect(crop.height).toBe(Math.round(600 / (16 / 9)))
25 expect(crop.x).toBe(0)
26 expect(crop.y).toBe(Math.round((1200 - crop.height) / 2))
27 })
28
29 it("membiarkan sumber yang rasionya sudah pas", () => {
30 expect(computeCenterCrop(800, 600, 4 / 3)).toEqual({
31 x: 0,
32 y: 0,
33 width: 800,
34 height: 600,
35 })
36 })
37})
38