mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-06 04:20:59 +08:00
- Delete llm/ dead code (3 files, zero references) - Split mcp/ into sub-packages: mcp/provider/ (8 providers) and mcp/payment/ (4 payment clients) with registry pattern - Export Client internal fields and ClientHooks interface for sub-package access - Split api/server.go (3892 lines) into 8 domain-specific handler files - Split trader/auto_trader.go (2296 lines) into 5 focused files - Reorganize web/src/components/ flat files into auth/, charts/, trader/, common/, modals/, backtest/ subdirectories - Update all consumer imports to use registry-based provider creation
104 lines
3.3 KiB
TypeScript
104 lines
3.3 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { render, screen, fireEvent } from '@testing-library/react'
|
|
import { RegistrationDisabled } from './RegistrationDisabled'
|
|
import { LanguageProvider } from '../../contexts/LanguageContext'
|
|
|
|
// Mock useLanguage hook
|
|
vi.mock('../../contexts/LanguageContext', async () => {
|
|
const actual = await vi.importActual('../../contexts/LanguageContext')
|
|
return {
|
|
...actual,
|
|
useLanguage: () => ({ language: 'en' }),
|
|
}
|
|
})
|
|
|
|
/**
|
|
* RegistrationDisabled Component Tests
|
|
*
|
|
* Tests the component that displays when registration is disabled
|
|
* This is part of the registration toggle feature
|
|
*/
|
|
describe('RegistrationDisabled Component', () => {
|
|
const renderComponent = () => {
|
|
return render(
|
|
<LanguageProvider>
|
|
<RegistrationDisabled />
|
|
</LanguageProvider>
|
|
)
|
|
}
|
|
|
|
describe('Rendering', () => {
|
|
it('should render the component without errors', () => {
|
|
const { container } = renderComponent()
|
|
expect(container).toBeTruthy()
|
|
})
|
|
|
|
it('should display the NoFx logo', () => {
|
|
renderComponent()
|
|
const logo = screen.getByAltText('NoFx Logo')
|
|
expect(logo).toBeTruthy()
|
|
expect(logo.getAttribute('src')).toBe('/icons/nofx.svg')
|
|
})
|
|
|
|
it('should display registration closed heading', () => {
|
|
renderComponent()
|
|
const heading = screen.getByText('Registration Closed')
|
|
expect(heading).toBeTruthy()
|
|
})
|
|
|
|
it('should display registration closed message', () => {
|
|
renderComponent()
|
|
const message = screen.getByText(/User registration is currently disabled/i)
|
|
expect(message).toBeTruthy()
|
|
})
|
|
|
|
it('should display back to login button', () => {
|
|
renderComponent()
|
|
const button = screen.getByRole('button', { name: /back to login/i })
|
|
expect(button).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
describe('Navigation', () => {
|
|
it('should navigate to login page when button is clicked', () => {
|
|
const pushStateSpy = vi.spyOn(window.history, 'pushState')
|
|
const dispatchEventSpy = vi.spyOn(window, 'dispatchEvent')
|
|
|
|
renderComponent()
|
|
const button = screen.getByRole('button', { name: /back to login/i })
|
|
|
|
fireEvent.click(button)
|
|
|
|
expect(pushStateSpy).toHaveBeenCalledWith({}, '', '/login')
|
|
expect(dispatchEventSpy).toHaveBeenCalled()
|
|
|
|
pushStateSpy.mockRestore()
|
|
dispatchEventSpy.mockRestore()
|
|
})
|
|
})
|
|
|
|
describe('Styling', () => {
|
|
it('should have correct background color', () => {
|
|
const { container } = renderComponent()
|
|
const mainDiv = container.firstChild as HTMLElement
|
|
// Browser converts hex to rgb
|
|
expect(mainDiv.style.background).toMatch(/rgb\(11,\s*14,\s*17\)|#0B0E11/i)
|
|
})
|
|
|
|
it('should have correct text color', () => {
|
|
const { container } = renderComponent()
|
|
const mainDiv = container.firstChild as HTMLElement
|
|
// Browser converts hex to rgb
|
|
expect(mainDiv.style.color).toMatch(/rgb\(234,\s*236,\s*239\)|#EAECEF/i)
|
|
})
|
|
|
|
it('should have centered layout', () => {
|
|
const { container } = renderComponent()
|
|
const mainDiv = container.firstChild as HTMLElement
|
|
expect(mainDiv.className).toContain('flex')
|
|
expect(mainDiv.className).toContain('items-center')
|
|
expect(mainDiv.className).toContain('justify-center')
|
|
})
|
|
})
|
|
})
|