isSlicedLibraryFile.test.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * The Print button must follow what the file is, not what it is called (#2993).
  3. *
  4. * A plate exported from Studio, or a print dispatched through the cloud, is a
  5. * fully sliced 3MF named `Foo.3mf`. Deciding from the extension hid the Print
  6. * button on files the backend was perfectly willing to print -- `library.py`
  7. * has always accepted either type on the G-code path.
  8. */
  9. import { describe, it, expect } from 'vitest';
  10. import { isSlicedLibraryFile } from '../../utils/libraryFiles';
  11. describe('isSlicedLibraryFile', () => {
  12. it('trusts file_type over a filename that disagrees', () => {
  13. // The reported file: sliced, named as a project.
  14. expect(isSlicedLibraryFile({ filename: 'Labyrinth.3mf', file_type: 'gcode.3mf' })).toBe(true);
  15. });
  16. it('leaves a genuine project alone', () => {
  17. expect(isSlicedLibraryFile({ filename: 'Labyrinth.3mf', file_type: '3mf' })).toBe(false);
  18. });
  19. it('accepts raw gcode', () => {
  20. expect(isSlicedLibraryFile({ filename: 'plate.gcode', file_type: 'gcode' })).toBe(true);
  21. });
  22. it('does not treat a model as printable', () => {
  23. expect(isSlicedLibraryFile({ filename: 'thing.stl', file_type: 'stl' })).toBe(false);
  24. });
  25. describe('the name answers where file_type does not', () => {
  26. it('with no file_type at all', () => {
  27. expect(isSlicedLibraryFile({ filename: 'Labyrinth.gcode.3mf' })).toBe(true);
  28. expect(isSlicedLibraryFile({ filename: 'plate.GCODE' })).toBe(true);
  29. expect(isSlicedLibraryFile({ filename: 'Labyrinth.3mf' })).toBe(false);
  30. });
  31. it('with an empty one', () => {
  32. expect(isSlicedLibraryFile({ filename: 'Labyrinth.gcode.3mf', file_type: '' })).toBe(true);
  33. expect(isSlicedLibraryFile({ filename: 'Labyrinth.gcode.3mf', file_type: null })).toBe(true);
  34. });
  35. it('and on a row stored before the backfill, where file_type is the stale half', () => {
  36. // Mirrors classify_file_type, which returns `gcode.3mf` for this name
  37. // without opening the file. Neither side may drop a Print button that
  38. // the other would keep.
  39. expect(isSlicedLibraryFile({ filename: 'Labyrinth.gcode.3mf', file_type: '3mf' })).toBe(true);
  40. });
  41. });
  42. });