QueueItemPlateThumbnail.test.tsx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * A queued plate shows that plate's picture everywhere it is listed.
  3. *
  4. * The queue list asked for the plate thumbnail, but the timeline and the
  5. * compact history row asked for the file's, which is plate 1: two plates of
  6. * one file queued side by side looked like the same job.
  7. */
  8. import { describe, it, expect } from 'vitest';
  9. import { render } from '@testing-library/react';
  10. import { QueueTimelineView } from '../../components/QueueTimelineView';
  11. import { CompactHistoryRow } from '../../components/CompactHistoryRow';
  12. import type { PrintQueueItem, Printer } from '../../api/client';
  13. const printers = [{ id: 1, name: 'Workshop X1C', model: 'X1C' }] as unknown as Printer[];
  14. const item = (over: Partial<PrintQueueItem>) =>
  15. ({
  16. id: 1,
  17. printer_id: 1,
  18. status: 'printing',
  19. position: 0,
  20. archive_name: 'Two plates',
  21. print_time_seconds: 3600,
  22. started_at: new Date(Date.now() - 30 * 60 * 1000).toISOString(),
  23. scheduled_time: null,
  24. manual_start: false,
  25. waiting_reason: null,
  26. plate_id: 4,
  27. ...over,
  28. }) as unknown as PrintQueueItem;
  29. const fromArchive = { archive_id: 7, archive_thumbnail: 'thumb.png' };
  30. const fromLibrary = { archive_id: null, archive_thumbnail: null, library_file_id: 9, library_file_thumbnail: 'thumb.png' };
  31. function timelineImages(queued: PrintQueueItem): string[] {
  32. const { container, unmount } = render(
  33. <QueueTimelineView
  34. queueItems={[queued]}
  35. printers={printers}
  36. printerStatuses={{ 1: { progress: 50, remaining_time: 30, state: 'RUNNING' } }}
  37. sjfEnabled={false}
  38. onItemClick={() => {}}
  39. t={(key: string) => key}
  40. />,
  41. );
  42. const srcs = Array.from(container.querySelectorAll('img')).map((img) => img.getAttribute('src') ?? '');
  43. unmount();
  44. return srcs;
  45. }
  46. function historyImages(done: PrintQueueItem): string[] {
  47. const { container, unmount } = render(
  48. <CompactHistoryRow
  49. item={done}
  50. onRequeue={() => {}}
  51. onRemove={() => {}}
  52. hasPermission={() => true}
  53. canModify={() => true}
  54. t={(key: string) => key}
  55. />,
  56. );
  57. const srcs = Array.from(container.querySelectorAll('img')).map((img) => img.getAttribute('src') ?? '');
  58. unmount();
  59. return srcs;
  60. }
  61. describe('queued plate thumbnail', () => {
  62. it.each([
  63. ['an archive', fromArchive, '/archives/7/plate-thumbnail/4'],
  64. ['a library file', fromLibrary, '/library/files/9/plate-thumbnail/4'],
  65. ])('the timeline shows the plate of %s', (_, source, url) => {
  66. const srcs = timelineImages(item(source));
  67. expect(srcs.length).toBeGreaterThan(0);
  68. for (const src of srcs) expect(src).toContain(url);
  69. });
  70. it.each([
  71. ['an archive', fromArchive, '/archives/7/plate-thumbnail/4'],
  72. ['a library file', fromLibrary, '/library/files/9/plate-thumbnail/4'],
  73. ])('a history row shows the plate of %s', (_, source, url) => {
  74. const srcs = historyImages(item({ ...source, status: 'completed', completed_at: new Date().toISOString() }));
  75. expect(srcs.length).toBeGreaterThan(0);
  76. for (const src of srcs) expect(src).toContain(url);
  77. });
  78. it('a single-plate job keeps the file thumbnail', () => {
  79. for (const src of timelineImages(item({ ...fromArchive, plate_id: null }))) {
  80. expect(src).toContain('/archives/7/thumbnail');
  81. }
  82. });
  83. });