dictionary-modal-content.spec.jsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import DictionaryModal from '@/features/dictionary/components/dictionary-modal'
  2. import { EditorProviders } from '../../../helpers/editor-providers'
  3. import { learnedWords } from '@/features/source-editor/extensions/spelling/learned-words'
  4. describe('<DictionaryModalContent />', function () {
  5. let originalLearnedWords
  6. beforeEach(function () {
  7. cy.then(() => {
  8. originalLearnedWords = learnedWords.global
  9. })
  10. cy.interceptCompile()
  11. })
  12. afterEach(function () {
  13. cy.then(() => {
  14. learnedWords.global = originalLearnedWords
  15. })
  16. })
  17. it('list words', function () {
  18. cy.then(() => {
  19. learnedWords.global = new Set(['foo', 'bar'])
  20. })
  21. cy.mount(
  22. <EditorProviders>
  23. <DictionaryModal show handleHide={cy.stub()} />
  24. </EditorProviders>
  25. )
  26. cy.findByText('foo')
  27. cy.findByText('bar')
  28. })
  29. it('shows message when empty', function () {
  30. cy.then(() => {
  31. learnedWords.global = new Set([])
  32. })
  33. cy.mount(
  34. <EditorProviders>
  35. <DictionaryModal show handleHide={cy.stub()} />
  36. </EditorProviders>
  37. )
  38. cy.contains('Your custom dictionary is empty.')
  39. })
  40. it('removes words', function () {
  41. cy.intercept('/spelling/unlearn', { statusCode: 200 })
  42. cy.then(() => {
  43. learnedWords.global = new Set(['Foo', 'bar'])
  44. })
  45. cy.mount(
  46. <EditorProviders>
  47. <DictionaryModal show handleHide={cy.stub()} />
  48. </EditorProviders>
  49. )
  50. cy.findByText('Foo')
  51. cy.findByText('bar')
  52. cy.findAllByRole('button', {
  53. name: 'Remove from dictionary',
  54. })
  55. .eq(0)
  56. .click()
  57. cy.findByText('bar').should('not.exist')
  58. cy.findByText('Foo')
  59. })
  60. it('handles errors', function () {
  61. cy.intercept('/spelling/unlearn', { statusCode: 500 }).as('unlearn')
  62. cy.then(() => {
  63. learnedWords.global = new Set(['foo'])
  64. })
  65. cy.mount(
  66. <EditorProviders>
  67. <DictionaryModal show handleHide={cy.stub()} />
  68. </EditorProviders>
  69. )
  70. cy.findByText('foo')
  71. cy.findAllByRole('button', {
  72. name: 'Remove from dictionary',
  73. })
  74. .eq(0)
  75. .click()
  76. cy.wait('@unlearn')
  77. cy.findByText('Sorry, something went wrong')
  78. cy.findByText('foo')
  79. })
  80. })