settings-document.test.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 { renderWithEditorContext } from '../../../../helpers/render-with-context'
  8. import type { MainDocument } from '../../../../../../types/project-settings'
  9. describe('<SettingsDocument />', function () {
  10. let isValidTeXFileStub: sinon.SinonStub
  11. const docs: MainDocument[] = [
  12. {
  13. path: 'main.tex',
  14. doc: {
  15. name: 'main.tex',
  16. id: '123abc',
  17. type: 'doc',
  18. selected: false,
  19. } as MainDocument['doc'],
  20. },
  21. ]
  22. beforeEach(function () {
  23. isValidTeXFileStub = sinon
  24. .stub(isValidTeXFileModule, 'default')
  25. .returns(true)
  26. })
  27. afterEach(function () {
  28. fetchMock.reset()
  29. isValidTeXFileStub.restore()
  30. })
  31. it('shows correct menu', async function () {
  32. renderWithEditorContext(<SettingsDocument />, {
  33. scope: {
  34. docs,
  35. },
  36. })
  37. const select = screen.getByLabelText('Main document')
  38. const optionOn = within(select).getByText('main.tex')
  39. expect(optionOn.getAttribute('value')).to.equal('123abc')
  40. })
  41. })