file-tree-toolbar.test.js 1.6 KB

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