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

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. },
  13. {
  14. name: 'Lang 2',
  15. code: 'lang-2',
  16. },
  17. ]
  18. beforeEach(function () {
  19. window.metaAttributesCache.set('ol-languages', languages)
  20. })
  21. afterEach(function () {
  22. fetchMock.reset()
  23. window.metaAttributesCache = new Map()
  24. })
  25. it('shows correct menu', async function () {
  26. renderWithEditorContext(<SettingsSpellCheckLanguage />)
  27. const select = screen.getByLabelText('Spell check')
  28. const optionEmpty = within(select).getByText('Off')
  29. expect(optionEmpty.getAttribute('value')).to.equal('')
  30. for (const language of languages) {
  31. const option = within(select).getByText(language.name)
  32. expect(option.getAttribute('value')).to.equal(language.code)
  33. }
  34. })
  35. })