dictionary-modal-content.spec.jsx 2.4 KB

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