auto-compile-setting.test.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { screen, render } from '@testing-library/react'
  2. import { expect } from 'chai'
  3. import fetchMock from 'fetch-mock'
  4. import { SettingsModalProvider } from '@/features/settings/context/settings-modal-context'
  5. import {
  6. EditorProviders,
  7. projectDefaults,
  8. } from '../../../helpers/editor-providers'
  9. import AutoCompileSetting from '@/features/settings/components/compiler-settings/auto-compile-setting'
  10. import localStorage from '@/infrastructure/local-storage'
  11. import userEvent from '@testing-library/user-event'
  12. describe('<AutoCompileSetting />', function () {
  13. afterEach(function () {
  14. fetchMock.removeRoutes().clearHistory()
  15. })
  16. it('can toggle', async function () {
  17. render(
  18. <EditorProviders>
  19. <SettingsModalProvider>
  20. <AutoCompileSetting />
  21. </SettingsModalProvider>
  22. </EditorProviders>
  23. )
  24. const toggle = screen.getByLabelText('Autocompile')
  25. const startingCheckedValue = (toggle as HTMLInputElement).checked
  26. // Toggle the checkbox
  27. await userEvent.click(toggle)
  28. expect((toggle as HTMLInputElement).checked).to.equal(!startingCheckedValue)
  29. expect(
  30. localStorage.getItem(`autocompile_enabled:${projectDefaults._id}`)
  31. ).to.equal(!startingCheckedValue)
  32. // Toggle back to original value
  33. await userEvent.click(toggle)
  34. expect((toggle as HTMLInputElement).checked).to.equal(startingCheckedValue)
  35. expect(
  36. !!localStorage.getItem(`autocompile_enabled:${projectDefaults._id}`)
  37. ).to.equal(startingCheckedValue)
  38. })
  39. })