* feat(model): add Rated At field - #4653 Signed-off-by: zacaj <zacaj@zacaj.com> * fix(ui): ignore empty dates in rating/love tooltips - #4653 * refactor(ui): add isDateSet util function Signed-off-by: zacaj <zacaj@zacaj.com> * feat: add tests for isDateSet and rated_at sort mappings Added comprehensive tests for isDateSet and urlValidate functions in ui/src/utils/validations.test.js covering falsy values, Go zero date handling, valid date strings, Date objects, and edge cases. Added rated_at sort mapping to album, artist, and mediafile repositories, following the same pattern as starred_at (sorting by rating first, then by timestamp). This enables proper sorting by rating date in the UI. --------- Signed-off-by: zacaj <zacaj@zacaj.com> Co-authored-by: zacaj <zacaj@zacaj.com> Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { isDateSet, urlValidate } from './validations'
|
||||
|
||||
describe('urlValidate', () => {
|
||||
it('returns undefined for valid URLs', () => {
|
||||
expect(urlValidate('https://example.com')).toBeUndefined()
|
||||
expect(urlValidate('http://localhost:3000')).toBeUndefined()
|
||||
expect(urlValidate('ftp://files.example.com')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('returns undefined for empty values', () => {
|
||||
expect(urlValidate('')).toBeUndefined()
|
||||
expect(urlValidate(null)).toBeUndefined()
|
||||
expect(urlValidate(undefined)).toBeUndefined()
|
||||
})
|
||||
|
||||
it('returns error for invalid URLs', () => {
|
||||
expect(urlValidate('not-a-url')).toEqual('ra.validation.url')
|
||||
expect(urlValidate('example.com')).toEqual('ra.validation.url')
|
||||
expect(urlValidate('://missing-protocol')).toEqual('ra.validation.url')
|
||||
})
|
||||
})
|
||||
|
||||
describe('isDateSet', () => {
|
||||
describe('with falsy values', () => {
|
||||
it('returns false for null', () => {
|
||||
expect(isDateSet(null)).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false for undefined', () => {
|
||||
expect(isDateSet(undefined)).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false for empty string', () => {
|
||||
expect(isDateSet('')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with Go zero date string', () => {
|
||||
it('returns false for Go zero date', () => {
|
||||
expect(isDateSet('0001-01-01T00:00:00Z')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with valid date strings', () => {
|
||||
it('returns true for ISO date strings', () => {
|
||||
expect(isDateSet('2024-01-15T10:30:00Z')).toBe(true)
|
||||
expect(isDateSet('2023-12-25T00:00:00Z')).toBe(true)
|
||||
})
|
||||
|
||||
it('returns true for other date formats', () => {
|
||||
expect(isDateSet('2024-01-15')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with Date objects', () => {
|
||||
it('returns true for valid Date objects', () => {
|
||||
expect(isDateSet(new Date())).toBe(true)
|
||||
expect(isDateSet(new Date('2024-01-15T10:30:00Z'))).toBe(true)
|
||||
})
|
||||
|
||||
// Note: Date objects representing Go zero date would return true because
|
||||
// toISOString() adds milliseconds (0001-01-01T00:00:00.000Z).
|
||||
// In practice, dates from the API come as strings, not Date objects,
|
||||
// so this edge case doesn't occur.
|
||||
})
|
||||
|
||||
describe('with other truthy values', () => {
|
||||
it('returns true for non-date truthy values', () => {
|
||||
expect(isDateSet(123)).toBe(true)
|
||||
expect(isDateSet({})).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user