mirror of
https://github.com/langgenius/dify.git
synced 2026-06-18 13:27:00 +08:00
fix(web): use generated account-profile contracts (#36927)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { renderHook } from '@testing-library/react'
|
||||
import { createAccountProfileQueryWrapper } from '@/test/account-profile-query'
|
||||
import useTimestamp from './use-timestamp'
|
||||
|
||||
vi.mock('@/context/app-context', () => ({
|
||||
@@ -23,7 +24,7 @@ vi.mock('@/context/app-context', () => ({
|
||||
describe('useTimestamp', () => {
|
||||
describe('formatTime', () => {
|
||||
it('should format unix timestamp correctly', () => {
|
||||
const { result } = renderHook(() => useTimestamp())
|
||||
const { result } = renderHook(() => useTimestamp(), { wrapper: createAccountProfileQueryWrapper() })
|
||||
const timestamp = 1704132000
|
||||
|
||||
expect(result.current.formatTime(timestamp, 'YYYY-MM-DD HH:mm:ss'))
|
||||
@@ -31,7 +32,7 @@ describe('useTimestamp', () => {
|
||||
})
|
||||
|
||||
it('should format with different patterns', () => {
|
||||
const { result } = renderHook(() => useTimestamp())
|
||||
const { result } = renderHook(() => useTimestamp(), { wrapper: createAccountProfileQueryWrapper() })
|
||||
const timestamp = 1704132000
|
||||
|
||||
expect(result.current.formatTime(timestamp, 'MM/DD/YYYY'))
|
||||
@@ -44,7 +45,7 @@ describe('useTimestamp', () => {
|
||||
|
||||
describe('formatDate', () => {
|
||||
it('should format date string correctly', () => {
|
||||
const { result } = renderHook(() => useTimestamp())
|
||||
const { result } = renderHook(() => useTimestamp(), { wrapper: createAccountProfileQueryWrapper() })
|
||||
const dateString = '2024-01-01T12:00:00Z'
|
||||
|
||||
expect(result.current.formatDate(dateString, 'YYYY-MM-DD HH:mm:ss'))
|
||||
@@ -52,7 +53,7 @@ describe('useTimestamp', () => {
|
||||
})
|
||||
|
||||
it('should format with different patterns', () => {
|
||||
const { result } = renderHook(() => useTimestamp())
|
||||
const { result } = renderHook(() => useTimestamp(), { wrapper: createAccountProfileQueryWrapper() })
|
||||
const dateString = '2024-01-01T12:00:00Z'
|
||||
|
||||
expect(result.current.formatDate(dateString, 'MM/DD/YYYY'))
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
'use client'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import dayjs from 'dayjs'
|
||||
import timezone from 'dayjs/plugin/timezone'
|
||||
import utc from 'dayjs/plugin/utc'
|
||||
import { useCallback } from 'react'
|
||||
import { useAppContext } from '@/context/app-context'
|
||||
import { userProfileQueryOptions } from '@/features/account-profile/client'
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
const useTimestamp = () => {
|
||||
const { userProfile: { timezone } } = useAppContext()
|
||||
const { data: timezone } = useQuery({
|
||||
...userProfileQueryOptions(),
|
||||
select: data => data.profile.timezone ?? undefined,
|
||||
})
|
||||
|
||||
const formatTime = useCallback((value: number, format: string) => {
|
||||
return dayjs.unix(value).tz(timezone).format(format)
|
||||
|
||||
Reference in New Issue
Block a user