settings-spell-check-language.test.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { screen, within } from '@testing-library/dom'
  2. import { expect } from 'chai'
  3. import fetchMock from 'fetch-mock'
  4. import SettingsSpellCheckLanguage from '../../../../../../frontend/js/features/editor-left-menu/components/settings/settings-spell-check-language'
  5. import type { SpellCheckLanguage } from '../../../../../../types/project-settings'
  6. import { render } from '@testing-library/react'
  7. import { EditorProviders } from '../../../../helpers/editor-providers'
  8. import { EditorLeftMenuProvider } from '@/features/editor-left-menu/components/editor-left-menu-context'
  9. describe('<SettingsSpellCheckLanguage />', function () {
  10. const languages: SpellCheckLanguage[] = [
  11. {
  12. name: 'Lang 1',
  13. code: 'lang-1',
  14. dic: 'lang_1',
  15. },
  16. {
  17. name: 'Lang 2',
  18. code: 'lang-2',
  19. dic: 'lang_2',
  20. },
  21. ]
  22. beforeEach(function () {
  23. window.metaAttributesCache.set('ol-languages', languages)
  24. })
  25. afterEach(function () {
  26. fetchMock.reset()
  27. })
  28. it('shows correct menu', async function () {
  29. render(
  30. <EditorProviders>
  31. <EditorLeftMenuProvider>
  32. <SettingsSpellCheckLanguage />
  33. </EditorLeftMenuProvider>
  34. </EditorProviders>
  35. )
  36. const select = screen.getByLabelText('Spell check')
  37. const optionEmpty = within(select).getByText('Off')
  38. expect(optionEmpty.getAttribute('value')).to.equal('')
  39. for (const language of languages) {
  40. const option = within(select).getByText(language.name)
  41. expect(option.getAttribute('value')).to.equal(language.code)
  42. }
  43. })
  44. })