FilamentSlotCircle.test.tsx 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Tests for the FilamentSlotCircle component.
  3. */
  4. import { describe, it, expect } from 'vitest';
  5. import { screen } from '@testing-library/react';
  6. import { render } from '../utils';
  7. import { FilamentSlotCircle } from '../../components/FilamentSlotCircle';
  8. /**
  9. * JSDOM normalizes some CSS color values (e.g. #000 → rgb(0, 0, 0)),
  10. * so we compare against both hex and rgb forms.
  11. */
  12. function expectColor(actual: string, hex: string, rgb: string) {
  13. expect([hex, rgb]).toContain(actual);
  14. }
  15. describe('FilamentSlotCircle', () => {
  16. it('renders the slot number', () => {
  17. render(<FilamentSlotCircle trayColor="FF0000" trayType="PLA" isEmpty={false} slotNumber={1} />);
  18. expect(screen.getByText('1')).toBeInTheDocument();
  19. });
  20. it('renders slot number for empty slot', () => {
  21. render(<FilamentSlotCircle isEmpty={true} slotNumber={3} />);
  22. expect(screen.getByText('3')).toBeInTheDocument();
  23. });
  24. it('uses dashed border for empty slots', () => {
  25. const { container } = render(
  26. <FilamentSlotCircle isEmpty={true} slotNumber={1} />
  27. );
  28. const circle = container.firstChild as HTMLElement;
  29. expect(circle.style.borderStyle).toBe('dashed');
  30. });
  31. it('uses solid border for filled slots', () => {
  32. const { container } = render(
  33. <FilamentSlotCircle trayColor="FF0000" isEmpty={false} slotNumber={1} />
  34. );
  35. const circle = container.firstChild as HTMLElement;
  36. expect(circle.style.borderStyle).toBe('solid');
  37. });
  38. it('sets background color from trayColor', () => {
  39. const { container } = render(
  40. <FilamentSlotCircle trayColor="00FF00" trayType="PLA" isEmpty={false} slotNumber={2} />
  41. );
  42. const circle = container.firstChild as HTMLElement;
  43. expectColor(circle.style.backgroundColor, '#00FF00', 'rgb(0, 255, 0)');
  44. });
  45. it('uses dark background when trayType is set but no color', () => {
  46. const { container } = render(
  47. <FilamentSlotCircle trayType="PLA" isEmpty={false} slotNumber={1} />
  48. );
  49. const circle = container.firstChild as HTMLElement;
  50. expectColor(circle.style.backgroundColor, '#333', 'rgb(51, 51, 51)');
  51. });
  52. it('uses transparent background when empty and no type', () => {
  53. const { container } = render(
  54. <FilamentSlotCircle isEmpty={true} slotNumber={1} />
  55. );
  56. const circle = container.firstChild as HTMLElement;
  57. expect(circle.style.backgroundColor).toBe('transparent');
  58. });
  59. it('uses black text on light filament colors', () => {
  60. // White filament (FFFFFF) is light
  61. render(<FilamentSlotCircle trayColor="FFFFFF" isEmpty={false} slotNumber={1} />);
  62. const text = screen.getByText('1');
  63. expectColor(text.style.color, '#000', 'rgb(0, 0, 0)');
  64. });
  65. it('uses white text on dark filament colors', () => {
  66. // Black filament (000000) is dark
  67. render(<FilamentSlotCircle trayColor="000000" isEmpty={false} slotNumber={1} />);
  68. const text = screen.getByText('1');
  69. expectColor(text.style.color, '#fff', 'rgb(255, 255, 255)');
  70. });
  71. it('uses white text when no tray color', () => {
  72. render(<FilamentSlotCircle isEmpty={true} slotNumber={1} />);
  73. const text = screen.getByText('1');
  74. expectColor(text.style.color, '#fff', 'rgb(255, 255, 255)');
  75. });
  76. });