mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-03 19:05:32 -05:00
24c8629cd4
GitOrigin-RevId: c4d0d9e06fe0cc9d7cb7a058fd0768eb024e44f5
100 lines
2.4 KiB
JavaScript
100 lines
2.4 KiB
JavaScript
import DictionaryModal from '@/features/dictionary/components/dictionary-modal'
|
|
import { EditorProviders } from '../../../helpers/editor-providers'
|
|
|
|
describe('<DictionaryModalContent />', function () {
|
|
beforeEach(function () {
|
|
cy.interceptCompile()
|
|
})
|
|
|
|
afterEach(function () {
|
|
cy.window().then(win => {
|
|
win.dispatchEvent(new CustomEvent('learnedWords:doreset'))
|
|
})
|
|
})
|
|
|
|
it('list words', function () {
|
|
cy.window().then(win => {
|
|
win.metaAttributesCache.set('ol-learnedWords', ['foo', 'bar'])
|
|
win.dispatchEvent(new CustomEvent('learnedWords:doreset'))
|
|
})
|
|
|
|
cy.mount(
|
|
<EditorProviders>
|
|
<DictionaryModal show handleHide={cy.stub()} />
|
|
</EditorProviders>
|
|
)
|
|
|
|
cy.findByText('foo')
|
|
cy.findByText('bar')
|
|
})
|
|
|
|
it('shows message when empty', function () {
|
|
cy.window().then(win => {
|
|
win.metaAttributesCache.set('ol-learnedWords', [])
|
|
win.dispatchEvent(new CustomEvent('learnedWords:doreset'))
|
|
})
|
|
|
|
cy.mount(
|
|
<EditorProviders>
|
|
<DictionaryModal show handleHide={cy.stub()} />
|
|
</EditorProviders>
|
|
)
|
|
|
|
cy.contains('Your custom dictionary is empty.')
|
|
})
|
|
|
|
it('removes words', function () {
|
|
cy.intercept('/spelling/unlearn', { statusCode: 200 })
|
|
|
|
cy.window().then(win => {
|
|
win.metaAttributesCache.set('ol-learnedWords', ['Foo', 'bar'])
|
|
win.dispatchEvent(new CustomEvent('learnedWords:doreset'))
|
|
})
|
|
|
|
cy.mount(
|
|
<EditorProviders>
|
|
<DictionaryModal show handleHide={cy.stub()} />
|
|
</EditorProviders>
|
|
)
|
|
|
|
cy.findByText('Foo')
|
|
cy.findByText('bar')
|
|
|
|
cy.findAllByRole('button', {
|
|
name: 'Remove from dictionary',
|
|
})
|
|
.eq(0)
|
|
.click()
|
|
|
|
cy.findByText('bar').should('not.exist')
|
|
cy.findByText('Foo')
|
|
})
|
|
|
|
it('handles errors', function () {
|
|
cy.intercept('/spelling/unlearn', { statusCode: 500 }).as('unlearn')
|
|
|
|
cy.window().then(win => {
|
|
win.metaAttributesCache.set('ol-learnedWords', ['foo'])
|
|
win.dispatchEvent(new CustomEvent('learnedWords:doreset'))
|
|
})
|
|
|
|
cy.mount(
|
|
<EditorProviders>
|
|
<DictionaryModal show handleHide={cy.stub()} />
|
|
</EditorProviders>
|
|
)
|
|
|
|
cy.findByText('foo')
|
|
|
|
cy.findAllByRole('button', {
|
|
name: 'Remove from dictionary',
|
|
})
|
|
.eq(0)
|
|
.click()
|
|
|
|
cy.wait('@unlearn')
|
|
|
|
cy.findByText('Sorry, something went wrong')
|
|
cy.findByText('foo')
|
|
})
|
|
})
|