Files
supabase/apps/studio/tests/components/AuditLogs/OrgAuditLogs.utils.test.ts
Joshen Lim e3fec137fe Joshenlim/fe 4466 audit logs update organization logs as well (#50935)
## Context

Follows up from [this
PR](https://github.com/supabase/supabase/pull/50799) - updates the Audit
Logs UI for organization audit logs. Just differs from Account audit
logs slightly with added "Actor" + "Target" column

Reuses the same UI components from account audit logs so quite a bit of
code clean up 🙂
<img width="1451" height="955" alt="image"
src="https://github.com/user-attachments/assets/a1002cee-917f-4d9a-b977-3fab8ecd2d13"
/>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Organization audit logs now use a sortable table with row selection
and a resizable details panel.
* Actor details show a member’s username when available, otherwise the
actor’s email; a dash appears when neither is available.
* Logs can be filtered by users and projects, with separate messages for
no logs and no matching results.
* A refresh control and loading indicators help show audit-log updates.
* **Bug Fixes**
* Organization project lists stop loading when pagination totals are
unavailable.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-29 17:41:54 +08:00

84 lines
2.3 KiB
TypeScript

import dayjs from 'dayjs'
import { afterEach, describe, expect, test, vi } from 'vitest'
import { formatSelectedDateRange } from '@/components/interfaces/Organization/AuditLogs/AuditLogs.utils'
// Pin "now" to a fixed point so date comparisons are deterministic
const NOW = dayjs('2024-06-15T14:30:00')
afterEach(() => {
vi.useRealTimers()
})
function fakeNow() {
vi.setSystemTime(NOW.toDate())
}
describe('formatSelectedDateRange', () => {
test('two different dates: preserves current time on both ends', () => {
fakeNow()
const result = formatSelectedDateRange({
from: '2024-06-10',
to: '2024-06-14',
})
const from = dayjs(result.from)
const to = dayjs(result.to)
expect(from.date()).toBe(10)
expect(to.date()).toBe(14)
// Both should carry current H:M:S
expect(from.hour()).toBe(NOW.hour())
expect(to.hour()).toBe(NOW.hour())
})
test('single date matching today: from is set to 00:00:00', () => {
fakeNow()
const today = NOW.format('YYYY-MM-DD')
const result = formatSelectedDateRange({ from: today, to: today })
const from = dayjs(result.from)
expect(from.hour()).toBe(0)
expect(from.minute()).toBe(0)
expect(from.second()).toBe(0)
})
test('single date matching today: to keeps current time', () => {
fakeNow()
const today = NOW.format('YYYY-MM-DD')
const result = formatSelectedDateRange({ from: today, to: today })
const to = dayjs(result.to)
expect(to.hour()).toBe(NOW.hour())
expect(to.minute()).toBe(NOW.minute())
})
test('single date in the past: to is set to 23:59:59', () => {
fakeNow()
const result = formatSelectedDateRange({
from: '2024-06-01',
to: '2024-06-01',
})
const to = dayjs(result.to)
expect(to.hour()).toBe(23)
expect(to.minute()).toBe(59)
expect(to.second()).toBe(59)
})
test('single date in the past: from keeps current time', () => {
fakeNow()
const result = formatSelectedDateRange({
from: '2024-06-01',
to: '2024-06-01',
})
const from = dayjs(result.from)
expect(from.hour()).toBe(NOW.hour())
})
test('output is in UTC ISO format', () => {
fakeNow()
const result = formatSelectedDateRange({
from: '2024-06-10',
to: '2024-06-14',
})
expect(result.from).toMatch(/Z$/)
expect(result.to).toMatch(/Z$/)
})
})