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

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 { renderWithEditorContext } from '../../../../helpers/render-with-context'
  7. describe('<SettingsSpellCheckLanguage />', function () {
  8. const languages: SpellCheckLanguage[] = [
  9. {
  10. name: 'Lang 1',
  11. code: 'lang-1',
  12. dic: 'lang_1',
  13. },
  14. {
  15. name: 'Lang 2',
  16. code: 'lang-2',
  17. dic: 'lang_2',
  18. },
  19. ]
  20. beforeEach(function () {
  21. window.metaAttributesCache.set('ol-languages', languages)
  22. })
  23. afterEach(function () {
  24. fetchMock.reset()
  25. })
  26. it('shows correct menu', async function () {
  27. renderWithEditorContext(<SettingsSpellCheckLanguage />)
  28. const select = screen.getByLabelText('Spell check')
  29. const optionEmpty = within(select).getByText('Off')
  30. expect(optionEmpty.getAttribute('value')).to.equal('')
  31. for (const language of languages) {
  32. const option = within(select).getByText(language.name)
  33. expect(option.getAttribute('value')).to.equal(language.code)
  34. }
  35. })
  36. })