settings-document.test.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { screen, within } from '@testing-library/dom'
  2. import { expect } from 'chai'
  3. import sinon from 'sinon'
  4. import fetchMock from 'fetch-mock'
  5. import SettingsDocument from '../../../../../../frontend/js/features/editor-left-menu/components/settings/settings-document'
  6. import * as isValidTeXFileModule from '../../../../../../frontend/js/main/is-valid-tex-file'
  7. import { Folder } from '../../../../../../types/folder'
  8. import { EditorLeftMenuProvider } from '@/features/editor-left-menu/components/editor-left-menu-context'
  9. import { render } from '@testing-library/react'
  10. import { EditorProviders } from '../../../../helpers/editor-providers'
  11. describe('<SettingsDocument />', function () {
  12. let isValidTeXFileStub: sinon.SinonStub
  13. const rootFolder: Folder = {
  14. _id: 'root-folder-id',
  15. name: 'rootFolder',
  16. docs: [
  17. {
  18. _id: '123abc',
  19. name: 'main.tex',
  20. },
  21. ],
  22. fileRefs: [],
  23. folders: [],
  24. }
  25. beforeEach(function () {
  26. isValidTeXFileStub = sinon
  27. .stub(isValidTeXFileModule, 'default')
  28. .returns(true)
  29. })
  30. afterEach(function () {
  31. fetchMock.reset()
  32. isValidTeXFileStub.restore()
  33. })
  34. it('shows correct menu', async function () {
  35. render(
  36. <EditorProviders rootFolder={[rootFolder as any]}>
  37. <EditorLeftMenuProvider>
  38. <SettingsDocument />
  39. </EditorLeftMenuProvider>
  40. </EditorProviders>
  41. )
  42. const select = screen.getByLabelText('Main document')
  43. const optionOn = within(select).getByText('main.tex')
  44. expect(optionOn.getAttribute('value')).to.equal('123abc')
  45. })
  46. })