mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
fix(admin): show when users were last active and keep the list current
The column showed the last sign-in, which a renewing cookie leaves weeks behind for someone using TREK daily. It now shows the later of the sign-in and the last request. Saving an edit no longer blanks the row's avatar, activity and online dot, and the list refreshes every 30 seconds while open.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// FE-ADMMODEL-001 to -005: the invite status both admin user views show.
|
||||
// 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 { inviteStatus } from './adminModel';
|
||||
import { formatLastActive, inviteStatus, mergeSavedUser, type AdminUser } from './adminModel';
|
||||
|
||||
const NOW = new Date('2026-10-09T12:00:00Z');
|
||||
|
||||
@@ -47,3 +47,40 @@ describe('inviteStatus', () => {
|
||||
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',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user