line-height-setting.test.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { screen, within, render } from '@testing-library/react'
  2. import { expect } from 'chai'
  3. import fetchMock from 'fetch-mock'
  4. import { EditorProviders } from '../../../helpers/editor-providers'
  5. import { SettingsModalProvider } from '@/features/ide-redesign/contexts/settings-modal-context'
  6. import LineHeightSetting from '@/features/settings/components/appearance-settings/line-height-setting'
  7. import userEvent from '@testing-library/user-event'
  8. const OPTIONS = [
  9. {
  10. label: 'Compact',
  11. value: 'compact',
  12. },
  13. {
  14. label: 'Normal',
  15. value: 'normal',
  16. },
  17. {
  18. label: 'Wide',
  19. value: 'wide',
  20. },
  21. ]
  22. describe('<LineHeightSetting />', function () {
  23. afterEach(function () {
  24. fetchMock.removeRoutes().clearHistory()
  25. })
  26. it('each option is shown and can be selected', async function () {
  27. render(
  28. <EditorProviders>
  29. <SettingsModalProvider>
  30. <LineHeightSetting />
  31. </SettingsModalProvider>
  32. </EditorProviders>
  33. )
  34. const select = screen.getByLabelText('Editor line height')
  35. const saveSettingsMock = fetchMock.post(
  36. 'express:/user/settings',
  37. {
  38. status: 200,
  39. },
  40. { delay: 0 }
  41. )
  42. for (const option of OPTIONS) {
  43. const optionElement = within(select).getByText(option.label)
  44. expect(optionElement.getAttribute('value')).to.equal(option.value)
  45. await userEvent.selectOptions(select, [optionElement])
  46. expect(
  47. saveSettingsMock.callHistory.called('/user/settings', {
  48. body: { lineHeight: option.value },
  49. })
  50. ).to.be.true
  51. }
  52. })
  53. })