printer.test.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * Tests for getPrinterImage — model → printer card image resolver.
  3. *
  4. * X2D support (#988): both the display name "X2D" and the internal SSDP
  5. * code "N6" must resolve to /img/printers/x2d.png so the Printers page
  6. * and PrinterInfoModal show the correct artwork instead of falling back
  7. * to default.png.
  8. */
  9. import { describe, it, expect } from 'vitest';
  10. import { getPrinterImage } from '../../utils/printer';
  11. describe('getPrinterImage', () => {
  12. describe('X2D (#988)', () => {
  13. it('resolves display name "X2D" to x2d.png', () => {
  14. expect(getPrinterImage('X2D')).toBe('/img/printers/x2d.png');
  15. });
  16. it('resolves case-insensitive variants', () => {
  17. expect(getPrinterImage('x2d')).toBe('/img/printers/x2d.png');
  18. expect(getPrinterImage(' X2D ')).toBe('/img/printers/x2d.png');
  19. });
  20. it('resolves the internal SSDP code "N6" to x2d.png', () => {
  21. expect(getPrinterImage('N6')).toBe('/img/printers/x2d.png');
  22. });
  23. it('does not match X2D on unrelated model strings', () => {
  24. // Regression guard: a hypothetical future "X2" model must not
  25. // silently pick up x2d.png until it's explicitly mapped.
  26. expect(getPrinterImage('X2E')).toBe('/img/printers/default.png');
  27. });
  28. });
  29. describe('regression: existing families unchanged', () => {
  30. it('X1C → x1c.png', () => {
  31. expect(getPrinterImage('X1C')).toBe('/img/printers/x1c.png');
  32. });
  33. it('X1E → x1e.png', () => {
  34. expect(getPrinterImage('X1E')).toBe('/img/printers/x1e.png');
  35. });
  36. it('H2D → h2d.png', () => {
  37. expect(getPrinterImage('H2D')).toBe('/img/printers/h2d.png');
  38. });
  39. it('H2D Pro → h2dpro.png', () => {
  40. expect(getPrinterImage('H2D Pro')).toBe('/img/printers/h2dpro.png');
  41. });
  42. it('P2S → p1s.png (shared with P1S)', () => {
  43. // Pre-existing behaviour: P2S currently reuses the P1S artwork. Not
  44. // changed by the X2D diff; asserted to catch accidental regressions.
  45. expect(getPrinterImage('P2S')).toBe('/img/printers/p1s.png');
  46. });
  47. it('A1 Mini → a1mini.png (not a1.png)', () => {
  48. // The "a1mini" branch must run before the generic "a1" branch —
  49. // the X2D branch was inserted above both and must not break order.
  50. expect(getPrinterImage('A1 Mini')).toBe('/img/printers/a1mini.png');
  51. });
  52. it('null / undefined → default.png', () => {
  53. expect(getPrinterImage(null)).toBe('/img/printers/default.png');
  54. expect(getPrinterImage(undefined)).toBe('/img/printers/default.png');
  55. });
  56. it('unknown model → default.png', () => {
  57. expect(getPrinterImage('SomeFuturePrinter')).toBe(
  58. '/img/printers/default.png',
  59. );
  60. });
  61. });
  62. });