compiler-setting.test.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { screen, within, render } from '@testing-library/react'
  2. import { expect } from 'chai'
  3. import fetchMock from 'fetch-mock'
  4. import { SettingsModalProvider } from '@/features/ide-redesign/contexts/settings-modal-context'
  5. import {
  6. EditorProviders,
  7. projectDefaults,
  8. } from '../../../helpers/editor-providers'
  9. import CompilerSetting from '@/features/settings/components/compiler-settings/compiler-setting'
  10. import userEvent from '@testing-library/user-event'
  11. const OPTIONS = [
  12. {
  13. label: 'pdfLaTeX',
  14. value: 'pdflatex',
  15. },
  16. {
  17. label: 'LaTeX',
  18. value: 'latex',
  19. },
  20. {
  21. label: 'XeLaTeX',
  22. value: 'xelatex',
  23. },
  24. {
  25. label: 'LuaLaTeX',
  26. value: 'lualatex',
  27. },
  28. ]
  29. describe('<CompilerSetting />', function () {
  30. afterEach(function () {
  31. fetchMock.removeRoutes().clearHistory()
  32. })
  33. it('each option is shown and can be selected', async function () {
  34. render(
  35. <EditorProviders>
  36. <SettingsModalProvider>
  37. <CompilerSetting />
  38. </SettingsModalProvider>
  39. </EditorProviders>
  40. )
  41. const saveSettingsMock = fetchMock.post(
  42. `express:/project/:projectId/settings`,
  43. {
  44. status: 200,
  45. },
  46. { delay: 0 }
  47. )
  48. const select = screen.getByLabelText('Compiler')
  49. // Reverse order so we test changing to each option
  50. for (const option of OPTIONS.reverse()) {
  51. const optionElement = within(select).getByText(option.label)
  52. expect(optionElement.getAttribute('value')).to.equal(option.value)
  53. await userEvent.selectOptions(select, [optionElement])
  54. expect(
  55. saveSettingsMock.callHistory.called(
  56. `/project/${projectDefaults._id}/settings`,
  57. {
  58. body: { compiler: option.value },
  59. }
  60. )
  61. ).to.be.true
  62. }
  63. })
  64. })