draft-setting.test.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { screen, within, render } from '@testing-library/react'
  2. import { expect } from 'chai'
  3. import { SettingsModalProvider } from '@/features/settings/context/settings-modal-context'
  4. import {
  5. EditorProviders,
  6. projectDefaults,
  7. } from '../../../helpers/editor-providers'
  8. import userEvent from '@testing-library/user-event'
  9. import DraftSetting from '@/features/settings/components/compiler-settings/draft-setting'
  10. const OPTIONS = [
  11. {
  12. label: 'Normal',
  13. value: false,
  14. },
  15. {
  16. label: 'Fast [draft]',
  17. value: true,
  18. },
  19. ]
  20. describe('<DraftSetting />', function () {
  21. it('each option is shown and can be selected', async function () {
  22. render(
  23. <EditorProviders>
  24. <SettingsModalProvider>
  25. <DraftSetting />
  26. </SettingsModalProvider>
  27. </EditorProviders>
  28. )
  29. const select = screen.getByLabelText('Compile mode')
  30. for (const option of OPTIONS) {
  31. const optionElement = within(select).getByText(option.label)
  32. expect(optionElement.getAttribute('value')).to.equal(
  33. option.value.toString()
  34. )
  35. await userEvent.selectOptions(select, [optionElement])
  36. expect(!!localStorage.getItem(`draft:${projectDefaults._id}`)).to.equal(
  37. option.value
  38. )
  39. }
  40. })
  41. })