diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-14 00:15:31 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-14 00:15:31 +0300 |
commit | 5699348c8235e2e4382859be94e5676d39db9401 (patch) | |
tree | 57c28de6b58dfd78df2c4129ca6922fb203171dc /spec/frontend/vue_shared/components/markdown | |
parent | 7b7bc31c5ba07eebe62e2f2582f111ce24285cd4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_shared/components/markdown')
-rw-r--r-- | spec/frontend/vue_shared/components/markdown/markdown_editor_spec.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/frontend/vue_shared/components/markdown/markdown_editor_spec.js b/spec/frontend/vue_shared/components/markdown/markdown_editor_spec.js index 51afb7c499f..e4f72226844 100644 --- a/spec/frontend/vue_shared/components/markdown/markdown_editor_spec.js +++ b/spec/frontend/vue_shared/components/markdown/markdown_editor_spec.js @@ -1,4 +1,5 @@ import axios from 'axios'; +import Autosize from 'autosize'; import MockAdapter from 'axios-mock-adapter'; import { nextTick } from 'vue'; import { mountExtended } from 'helpers/vue_test_utils_helper'; @@ -10,8 +11,10 @@ import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue'; import MarkdownField from '~/vue_shared/components/markdown/field.vue'; import { stubComponent } from 'helpers/stub_component'; import { useLocalStorageSpy } from 'helpers/local_storage_helper'; +import waitForPromises from 'helpers/wait_for_promises'; jest.mock('~/emoji'); +jest.mock('autosize'); describe('vue_shared/component/markdown/markdown_editor', () => { useLocalStorageSpy(); @@ -107,6 +110,35 @@ describe('vue_shared/component/markdown/markdown_editor', () => { }); }); + describe('autosize', () => { + it('autosizes the textarea when the value changes', async () => { + buildWrapper(); + await findTextarea().setValue('Lots of newlines\n\n\n\n\n\n\nMore content\n\n\nand newlines'); + + expect(Autosize.update).toHaveBeenCalled(); + }); + + it('autosizes the textarea when the value changes from outside the component', async () => { + buildWrapper(); + wrapper.setProps({ value: 'Lots of newlines\n\n\n\n\n\n\nMore content\n\n\nand newlines' }); + + await nextTick(); + await waitForPromises(); + expect(Autosize.update).toHaveBeenCalled(); + }); + + it('does not autosize the textarea if markdown editor is disabled', async () => { + buildWrapper(); + findMarkdownField().vm.$emit('enableContentEditor'); + + wrapper.setProps({ value: 'Lots of newlines\n\n\n\n\n\n\nMore content\n\n\nand newlines' }); + + await nextTick(); + await waitForPromises(); + expect(Autosize.update).not.toHaveBeenCalled(); + }); + }); + describe('autosave', () => { it('automatically saves the textarea value to local storage if autosaveKey is defined', () => { buildWrapper({ propsData: { autosaveKey: 'issue/1234', value: 'This is **markdown**' } }); |