file-tree-toolbar.test.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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: { rootDocId: '123abc' }
  27. })
  28. screen.getByRole('button', { name: 'New File' })
  29. screen.getByRole('button', { name: 'New Folder' })
  30. screen.getByRole('button', { name: 'Upload' })
  31. screen.getByRole('button', { name: 'Rename' })
  32. screen.getByRole('button', { name: 'Delete' })
  33. })
  34. })