mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
31859651d7
Every help screen checked against the v5 redesign. Tours is documented for the first time, as a screen of its own with twelve screens under it, and notifications get help of their own. All pictures are taken again on a realistic demo trip, with short loops where a still cannot show the motion. The English is plain and every language is written naturally rather than word for word. The switcher shows two levels at most, a screen's overview lists its sub-screens as cards above its guides, each wiki page is linked once, and the help sidebar is wider. Fixes found along the way: Save to Collection keeps a tour's route, a track dropped on the places column opens the Tours import, tour Share on desktop, the unsaved tour draft lives on the account, a route click no longer adds an end point, Trip places leaves the trip's tours out, Escape closes a stage's day menu, confirms before destructive deletes, DWD warnings sharing one id kept apart, a booking's date moves with it, and smaller fixes across notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and the admin screens.
109 lines
4.3 KiB
TypeScript
109 lines
4.3 KiB
TypeScript
// FE-ADMMODEL-001 to -005: the invite status both admin user views show; -010 to -012 the users list.
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
import { formatLastActive, inviteMeta, inviteStatus, mergeSavedUser, type AdminUser } from './adminModel';
|
|
|
|
const NOW = new Date('2026-10-09T12:00:00Z');
|
|
|
|
describe('inviteStatus', () => {
|
|
it('FE-ADMMODEL-001: an unexpired invite with uses left is active', () => {
|
|
expect(inviteStatus({ expires_at: '2026-10-10T00:00:00Z', max_uses: 3, used_count: 2 }, NOW)).toEqual({
|
|
isExpired: false,
|
|
isUsedUp: false,
|
|
isActive: true,
|
|
labelKey: 'admin.invite.active',
|
|
});
|
|
});
|
|
|
|
it('FE-ADMMODEL-002: no expiry and unlimited uses (max_uses 0) stays active', () => {
|
|
expect(inviteStatus({ expires_at: null, max_uses: 0, used_count: 99 }, NOW).isActive).toBe(true);
|
|
expect(inviteStatus({ max_uses: 0, used_count: 0 }, NOW).labelKey).toBe('admin.invite.active');
|
|
expect(inviteStatus({ expires_at: '', max_uses: 1, used_count: 0 }, NOW).isExpired).toBe(false);
|
|
});
|
|
|
|
it('FE-ADMMODEL-003: a past expiry is expired', () => {
|
|
expect(inviteStatus({ expires_at: '2026-10-09T11:59:59Z', max_uses: 5, used_count: 0 }, NOW)).toEqual({
|
|
isExpired: true,
|
|
isUsedUp: false,
|
|
isActive: false,
|
|
labelKey: 'admin.invite.expired',
|
|
});
|
|
});
|
|
|
|
it('FE-ADMMODEL-004: reaching max_uses is used up, and used up wins over expired in the label', () => {
|
|
expect(inviteStatus({ expires_at: null, max_uses: 2, used_count: 2 }, NOW)).toEqual({
|
|
isExpired: false,
|
|
isUsedUp: true,
|
|
isActive: false,
|
|
labelKey: 'admin.invite.usedUp',
|
|
});
|
|
const both = inviteStatus({ expires_at: '2026-01-01T00:00:00Z', max_uses: 1, used_count: 1 }, NOW);
|
|
expect(both.isExpired).toBe(true);
|
|
expect(both.labelKey).toBe('admin.invite.usedUp');
|
|
});
|
|
|
|
it('FE-ADMMODEL-005: defaults to the current time', () => {
|
|
expect(inviteStatus({ expires_at: '2000-01-01T00:00:00Z', max_uses: 0, used_count: 0 }).isExpired).toBe(true);
|
|
expect(inviteStatus({ expires_at: '2999-01-01T00:00:00Z', max_uses: 0, used_count: 0 }).isActive).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('formatLastActive', () => {
|
|
it('FE-ADMMODEL-010: a dash for never, the year only once it is not this one', () => {
|
|
expect(formatLastActive(null, 'en-GB', false, NOW)).toBe('—');
|
|
const thisYear = formatLastActive('2026-03-04T10:30:00Z', 'en-GB', false, NOW);
|
|
const lastYear = formatLastActive('2025-03-04T10:30:00Z', 'en-GB', false, NOW);
|
|
expect(thisYear).not.toContain('2026');
|
|
expect(lastYear).toContain('2025');
|
|
});
|
|
|
|
it('FE-ADMMODEL-011: follows the 12 and 24 hour setting', () => {
|
|
expect(formatLastActive('2026-03-04T15:30:00Z', 'en-US', true, NOW)).toMatch(/PM/i);
|
|
expect(formatLastActive('2026-03-04T15:30:00Z', 'en-US', false, NOW)).not.toMatch(/PM/i);
|
|
});
|
|
});
|
|
|
|
describe('mergeSavedUser', () => {
|
|
it('FE-ADMMODEL-012: takes the account fields from the reply and keeps the rest of the row', () => {
|
|
const row: AdminUser = {
|
|
id: 2,
|
|
username: 'old',
|
|
email: 'old@e.com',
|
|
role: 'user',
|
|
created_at: '2026-01-01T00:00:00Z',
|
|
last_login: '2026-10-01T08:00:00Z',
|
|
last_active: '2026-10-08T17:30:00Z',
|
|
online: true,
|
|
avatar_url: '/a.jpg',
|
|
};
|
|
expect(mergeSavedUser(row, { username: 'new', email: 'new@e.com', role: 'admin' })).toEqual({
|
|
...row,
|
|
username: 'new',
|
|
email: 'new@e.com',
|
|
role: 'admin',
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('inviteMeta', () => {
|
|
const t = (key: string, params?: Record<string, string | number>) => (params ? `${key} ${params.trip}` : key);
|
|
|
|
it('FE-ADMMODEL-020: joins uses, expiry, trip and creator with commas, never a middle dot', () => {
|
|
const meta = inviteMeta(
|
|
{ used_count: 1, max_uses: 5, expires_at: '2026-10-10T00:00:00Z', trip_title: 'Rome', created_by_name: 'alice' },
|
|
t,
|
|
'en-US'
|
|
);
|
|
expect(meta).toBe(
|
|
'1/5 admin.invite.uses, admin.invite.expiresAt 10/10/2026, admin.invite.boundTo Rome, admin.invite.createdBy alice'
|
|
);
|
|
expect(meta).not.toContain('·');
|
|
});
|
|
|
|
it('FE-ADMMODEL-021: leaves out the expiry and the trip when the invite has none, and shows unlimited uses as infinity', () => {
|
|
expect(inviteMeta({ used_count: 2, max_uses: 0, created_by_name: 'bob' }, t, 'en-US')).toBe(
|
|
'2/∞ admin.invite.uses, admin.invite.createdBy bob'
|
|
);
|
|
});
|
|
});
|