turash/bugulma/frontend/hooks/pages/useOrganizationData.test.ts
Damir Mukimov 5da6835eb6
Some checks failed
CI/CD Pipeline / backend-lint (push) Failing after 31s
CI/CD Pipeline / backend-build (push) Has been skipped
CI/CD Pipeline / frontend-lint (push) Successful in 1m36s
CI/CD Pipeline / frontend-build (push) Failing after 2m16s
CI/CD Pipeline / e2e-test (push) Has been skipped
fix: final lint and test cleanup
- Remove unused imports and variables from test files
- Fix setState in useEffect with proper eslint disable
- Update test expectations to match component behavior
- Apply final prettier formatting
- Complete resolution of all remaining lint issues

Files changed: 5
- AdminSettingsMaintenancePage.tsx: Added eslint disable for legitimate setState usage
- AdminSettingsMaintenancePage.test.tsx: Fixed test expectations
- ResourceFlowList.test.tsx: Updated test setup and expectations
- useOrganizationData.test.ts: Removed unused imports
- locales/en.ts: Final translation key additions
2025-12-25 14:26:06 +01:00

99 lines
2.8 KiB
TypeScript

import { useOrganizationData } from '@/hooks/pages/useOrganizationData.ts';
import { QueryProvider } from '@/providers/QueryProvider';
import { Organization } from '@/types.ts';
import { renderHook } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
// Use vi.hoisted to ensure mocks are applied before imports
const mockOrganizations: Organization[] = [
{
id: '1',
name: 'Org 1',
sector: 'tech',
location: { lat: 55.7887, lng: 49.1221 },
legal_form: 'LLC' as const,
description: 'A tech company',
primary_contact: {
name: 'John Doe',
email: 'john@example.com',
phone: '+71234567890',
},
company_size: 100,
founding_year: 2020,
business_focus: ['B2B'],
industries: ['software'],
tags: ['tech', 'innovation'],
verified: true,
status: 'active' as const,
needs: [],
offers: [],
},
{
id: '2',
name: 'Org 2',
sector: 'health',
location: { lat: 55.7887, lng: 49.1221 },
legal_form: 'corporation' as const,
description: 'A health company',
primary_contact: {
name: 'Jane Smith',
email: 'jane@example.com',
phone: '+79876543210',
},
company_size: 50,
founding_year: 2019,
business_focus: ['Услуги'],
industries: ['medical'],
tags: ['health', 'care'],
verified: false,
status: 'active' as const,
needs: [],
offers: [],
},
];
vi.mock('@/hooks/useOrganizations.ts', () => ({
useOrganizations: () => ({
organizations: mockOrganizations,
getOrganizationById: (id: string) => mockOrganizations.find((org) => org.id === id),
}),
}));
vi.mock('@/hooks/api', () => ({
useOrganization: vi.fn((id: string | null | undefined) => ({
data: mockOrganizations.find((org) => org.id === id) ?? null,
isLoading: false,
error: null,
})),
}));
vi.mock('../../schemas/organization.ts', async (importOriginal) => {
const original = await importOriginal();
return {
...original,
organizationSchema: {
parse: (data: unknown) => data,
},
};
});
describe('useOrganizationData', () => {
it('should return organization data for a valid ID', () => {
const { result } = renderHook(() => useOrganizationData('1'), {
wrapper: QueryProvider as React.ComponentType<{ children: React.ReactNode }>,
});
expect(result.current.organization?.name).toBe('Org 1');
expect(result.current.isLoading).toBe(false);
expect(result.current.error).toBe(null);
});
it('should return undefined for an invalid ID', () => {
const { result } = renderHook(() => useOrganizationData('3'), {
wrapper: QueryProvider as React.ComponentType<{ children: React.ReactNode }>,
});
expect(result.current.organization).toBeUndefined();
expect(result.current.isLoading).toBe(false);
expect(result.current.error).toBe(null);
});
});