Files
xenia-pos-local/manager_dashboard/tests/media.test.mjs
T
bonaminandClaude Opus 5.5 e09056a7a4 feat(manager): Media page, photo field for products and categories (platform-v2 step 5.2)
- Management → Media (src/pages/media/): every picture and video, search,
  pictures / videos, batch upload (many files or drop on the page) with a
  result per file, details (preview, display name, kind, resolution, length,
  file size, uploaded file, when / who, the sizes made, what uses it, delete
  off while used).
- MediaField: upload on the spot (into the library and set at once), pick
  from the library (MediaPicker, which can also upload), remove; after an
  upload on the spot "Name it after the product / category" renames it in
  Latin letters. Used by the product editor and the category dialog.
- nav: `anyPerm` (any of the keys that manage pictures); the route guard uses
  the same rule. Product rows have test ids.
- @xenia/i18n: latin() (Greek to Latin, the way venues write it) + tests.
- tests: manager media.test.mjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 15:57:50 +02:00

40 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The media library's helpers and its nav rule (plan step 5.2).
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { duration, fileSize, imageOf, queueFrom, queueSummary, resolution } from '../src/pages/media/mediaLogic.js'
import { canSee, pageFor } from '../src/shell/nav.js'
test('sizes, resolutions and lengths for people', () => {
assert.equal(fileSize(512), '512 B')
assert.equal(fileSize(250_000), '244 KB')
assert.equal(fileSize(3.4 * 1024 * 1024, (n, o) => n.toFixed(o.maxDecimals)), '3.4 MB')
assert.equal(fileSize(null), '')
assert.equal(resolution(1920, 1080), '1920 × 1080')
assert.equal(resolution(null, 5), '')
assert.equal(duration(12_500), '0:13')
assert.equal(duration(3_909_000), '1:05:09')
})
test('a library item as the picture an app shows', () => {
const item = { id: 4, kind: 'image', name: 'Gyros', urls: { thumb: '/t', card: '/c', full: '/f', original: '/o' } }
assert.deepEqual(imageOf(item), { id: 4, name: 'Gyros', thumb: '/t', card: '/c', full: '/f' })
assert.equal(imageOf({ ...item, kind: 'video' }), null)
assert.equal(imageOf(null), null)
})
test('a batch upload queue and its summary', () => {
const q = queueFrom([{ name: 'a.jpg' }, { name: 'b.jpg' }], 3)
assert.deepEqual(q.map(x => [x.key, x.status]), [['3:a.jpg', 'waiting'], ['4:b.jpg', 'waiting']])
assert.equal(queueSummary(q).busy, true)
const done = [{ ...q[0], status: 'added' }, { ...q[1], status: 'existing' }, { key: 'x', status: 'failed' }]
assert.deepEqual(queueSummary(done), { total: 3, added: 1, existing: 1, failed: 1, busy: false })
})
test('the Media page is for anyone who manages something with pictures', () => {
const page = pageFor('/management/media')
const access = keys => ({ modules: new Set(['core']), permissions: new Set(keys) })
assert.equal(canSee(page, access(['customer_display.manage'])), true)
assert.equal(canSee(page, access(['catalog.menu.manage'])), true)
assert.equal(canSee(page, access(['core.dashboard.access'])), false)
})