file-tree-toolbar.test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { expect } from 'chai'
  2. import { screen } from '@testing-library/react'
  3. import renderWithContext from '../helpers/render-with-context'
  4. import FileTreeToolbar from '../../../../../frontend/js/features/file-tree/components/file-tree-toolbar'
  5. describe('<FileTreeToolbar/>', function () {
  6. beforeEach(function () {
  7. global.localStorage.clear()
  8. })
  9. it('without selected files', function () {
  10. renderWithContext(<FileTreeToolbar />)
  11. screen.getByRole('button', { name: 'New File' })
  12. screen.getByRole('button', { name: 'New Folder' })
  13. screen.getByRole('button', { name: 'Upload' })
  14. expect(screen.queryByRole('button', { name: 'Rename' })).to.not.exist
  15. expect(screen.queryByRole('button', { name: 'Delete' })).to.not.exist
  16. })
  17. it('read-only', function () {
  18. renderWithContext(<FileTreeToolbar />, {
  19. contextProps: { hasWritePermissions: false },
  20. })
  21. expect(screen.queryByRole('button')).to.not.exist
  22. })
  23. it('with one selected file', function () {
  24. renderWithContext(<FileTreeToolbar />, {
  25. contextProps: {
  26. rootDocId: '456def',
  27. rootFolder: [
  28. {
  29. _id: 'root-folder-id',
  30. docs: [{ _id: '456def', name: 'main.tex' }],
  31. folders: [],
  32. fileRefs: [],
  33. },
  34. ],
  35. },
  36. })
  37. screen.getByRole('button', { name: 'New File' })
  38. screen.getByRole('button', { name: 'New Folder' })
  39. screen.getByRole('button', { name: 'Upload' })
  40. screen.getByRole('button', { name: 'Rename' })
  41. screen.getByRole('button', { name: 'Delete' })
  42. })
  43. })