file-view-refresh-button.test.jsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {
  2. screen,
  3. fireEvent,
  4. waitForElementToBeRemoved,
  5. } from '@testing-library/react'
  6. import fetchMock from 'fetch-mock'
  7. import FileViewRefreshButton from '@/features/file-view/components/file-view-refresh-button'
  8. import { renderWithEditorContext } from '../../../helpers/render-with-context'
  9. import { USER_ID } from '../../../helpers/editor-providers'
  10. describe('<FileViewRefreshButton />', function () {
  11. const projectFile = {
  12. name: 'example.tex',
  13. linkedFileData: {
  14. v1_source_doc_id: 'v1-source-id',
  15. source_project_id: 'source-project-id',
  16. source_entity_path: '/source-entity-path.ext',
  17. provider: 'project_file',
  18. importer_id: USER_ID,
  19. },
  20. created: new Date(2021, 1, 17, 3, 24).toISOString(),
  21. }
  22. beforeEach(function () {
  23. fetchMock.reset()
  24. })
  25. it('Changes text when the file is refreshing', async function () {
  26. fetchMock.post(
  27. 'express:/project/:project_id/linked_file/:file_id/refresh',
  28. {
  29. new_file_id: '5ff7418157b4e144321df5c4',
  30. }
  31. )
  32. renderWithEditorContext(<FileViewRefreshButton file={projectFile} />)
  33. fireEvent.click(screen.getByRole('button', { name: 'Refresh' }))
  34. await waitForElementToBeRemoved(() =>
  35. screen.getByText('Refreshing', { exact: false })
  36. )
  37. await screen.findByText('Refresh')
  38. })
  39. })