AdditionalSection.test.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import React from 'react';
  2. import { describe, it, expect, vi } from 'vitest';
  3. import { screen } from '@testing-library/react';
  4. import { render } from '../utils';
  5. import { AdditionalSection } from '../../components/spool-form/AdditionalSection';
  6. import { defaultFormData } from '../../components/spool-form/types';
  7. vi.mock('react-i18next', () => ({
  8. useTranslation: () => ({
  9. t: (key: string) => key,
  10. }),
  11. }));
  12. const baseProps = {
  13. formData: defaultFormData,
  14. updateField: vi.fn(),
  15. spoolCatalog: [],
  16. currencySymbol: '$',
  17. availableCategories: [],
  18. globalLowStockThreshold: 20,
  19. };
  20. describe('AdditionalSection', () => {
  21. it('renders SpoolWeightPicker when spoolmanMode is false', () => {
  22. render(<AdditionalSection {...baseProps} spoolmanMode={false} />);
  23. // SpoolWeightPicker renders the 'inventory.coreWeight' label
  24. expect(screen.getByText('inventory.coreWeight')).toBeTruthy();
  25. // Info notice must NOT be present
  26. expect(screen.queryByText('inventory.spoolWeightManagedBySpoolman')).toBeNull();
  27. });
  28. it('hides SpoolWeightPicker and shows info notice when spoolmanMode is true', () => {
  29. render(<AdditionalSection {...baseProps} spoolmanMode={true} />);
  30. // Info notice must appear
  31. expect(screen.getByText('inventory.spoolWeightManagedBySpoolman')).toBeTruthy();
  32. // SpoolWeightPicker must NOT be rendered
  33. expect(screen.queryByText('inventory.coreWeight')).toBeNull();
  34. });
  35. it('defaults to spoolmanMode=false when prop is omitted', () => {
  36. render(<AdditionalSection {...baseProps} />);
  37. // SpoolWeightPicker present by default
  38. expect(screen.getByText('inventory.coreWeight')).toBeTruthy();
  39. });
  40. });