jan/web/containers/ModelLabel/ModelLabel.test.tsx
Louis 83f090826e
feat: Jan Hub Revamp (#4491)
* feat: model hub revamp UI

* chore: model description - consistent markdown css

* chore: add model versions dropdown

* chore: integrate APIs - model sources

* chore: update model display name

* chore: lint fix

* chore: page transition animation

* feat: model search dropdown - deeplink

* chore: bump cortex version

* chore: add remote model sources

* chore: model download state

* chore: fix model metadata label

* chore: polish model detail page markdown

* test: fix test cases

* chore: initialize default Hub model sources

* chore: fix model stats

* chore: clean up click outside and inside hooks

* feat: change hub banner

* chore: lint fix

* chore: fix css long model id
2025-01-28 22:23:25 +07:00

61 lines
1.5 KiB
TypeScript

import React from 'react'
import { render, waitFor, screen } from '@testing-library/react'
import { useAtomValue } from 'jotai'
import { useActiveModel } from '@/hooks/useActiveModel'
import { useSettings } from '@/hooks/useSettings'
import ModelLabel from '@/containers/ModelLabel'
jest.mock('jotai', () => ({
useAtomValue: jest.fn(),
atom: jest.fn(),
}))
jest.mock('@/hooks/useActiveModel', () => ({
useActiveModel: jest.fn(),
}))
jest.mock('@/hooks/useSettings', () => ({
useSettings: jest.fn(),
}))
describe('ModelLabel', () => {
const mockUseAtomValue = useAtomValue as jest.Mock
const mockUseActiveModel = useActiveModel as jest.Mock
const mockUseSettings = useSettings as jest.Mock
const defaultProps: any = {
metadata: {
author: 'John Doe', // Add the 'author' property with a value
tags: ['8B'],
size: 100,
},
compact: false,
}
beforeEach(() => {
jest.clearAllMocks()
})
it('renders nothing when minimumRamModel is less than availableRam', () => {
mockUseAtomValue
.mockReturnValueOnce(100)
.mockReturnValueOnce(50)
.mockReturnValueOnce(0)
mockUseActiveModel.mockReturnValue({
activeModel: { metadata: { size: 0 } },
})
mockUseSettings.mockReturnValue({ settings: { run_mode: 'cpu' } })
const props = {
...defaultProps,
metadata: {
...defaultProps.metadata,
size: 10,
},
}
const { container } = render(<ModelLabel {...props} />)
expect(container.firstChild).toBeNull()
})
})