diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-29 12:09:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-29 12:09:33 +0300 |
commit | b4dc6516ae8662e23e6fd8331656a91f9e853417 (patch) | |
tree | dc661c605af627ea9306dc592433c40b9cc0e832 /spec/frontend/static_site_editor | |
parent | 3fa28959b9c657503c98caa0e535d39f51ad2c31 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/static_site_editor')
-rw-r--r-- | spec/frontend/static_site_editor/components/edit_area_spec.js | 35 | ||||
-rw-r--r-- | spec/frontend/static_site_editor/services/formatter_spec.js | 26 |
2 files changed, 56 insertions, 5 deletions
diff --git a/spec/frontend/static_site_editor/components/edit_area_spec.js b/spec/frontend/static_site_editor/components/edit_area_spec.js index 11c5abf1b08..6953a986444 100644 --- a/spec/frontend/static_site_editor/components/edit_area_spec.js +++ b/spec/frontend/static_site_editor/components/edit_area_spec.js @@ -15,8 +15,11 @@ import { returnUrl, } from '../mock_data'; +jest.mock('~/static_site_editor/services/formatter', () => jest.fn(str => `${str} formatted`)); + describe('~/static_site_editor/components/edit_area.vue', () => { let wrapper; + const formattedContent = `${content} formatted`; const savingChanges = true; const newBody = `new ${body}`; @@ -103,31 +106,53 @@ describe('~/static_site_editor/components/edit_area.vue', () => { }); describe('when the mode changes', () => { + let resetInitialValue; + const setInitialMode = mode => { wrapper.setData({ editorMode: mode }); }; + const buildResetInitialValue = () => { + resetInitialValue = jest.fn(); + findRichContentEditor().setMethods({ resetInitialValue }); + }; + afterEach(() => { setInitialMode(EDITOR_TYPES.wysiwyg); + resetInitialValue = null; }); it.each` initialMode | targetMode | resetValue - ${EDITOR_TYPES.wysiwyg} | ${EDITOR_TYPES.markdown} | ${content} - ${EDITOR_TYPES.markdown} | ${EDITOR_TYPES.wysiwyg} | ${body} + ${EDITOR_TYPES.wysiwyg} | ${EDITOR_TYPES.markdown} | ${formattedContent} + ${EDITOR_TYPES.markdown} | ${EDITOR_TYPES.wysiwyg} | ${`${body} formatted`} `( 'sets editorMode from $initialMode to $targetMode', ({ initialMode, targetMode, resetValue }) => { setInitialMode(initialMode); + buildResetInitialValue(); - const resetInitialValue = jest.fn(); - - findRichContentEditor().setMethods({ resetInitialValue }); findRichContentEditor().vm.$emit('modeChange', targetMode); expect(resetInitialValue).toHaveBeenCalledWith(resetValue); expect(wrapper.vm.editorMode).toBe(targetMode); }, ); + + it('should format the content', () => { + buildResetInitialValue(); + + findRichContentEditor().vm.$emit('modeChange', EDITOR_TYPES.markdown); + + expect(resetInitialValue).toHaveBeenCalledWith(formattedContent); + }); + }); + + describe('when content is submitted', () => { + it('should format the content', () => { + findPublishToolbar().vm.$emit('submit', content); + + expect(wrapper.emitted('submit')[0][0].content).toBe(formattedContent); + }); }); }); diff --git a/spec/frontend/static_site_editor/services/formatter_spec.js b/spec/frontend/static_site_editor/services/formatter_spec.js new file mode 100644 index 00000000000..b7600798db9 --- /dev/null +++ b/spec/frontend/static_site_editor/services/formatter_spec.js @@ -0,0 +1,26 @@ +import formatter from '~/static_site_editor/services/formatter'; + +describe('formatter', () => { + const source = `Some text +<br> + +And some more text + + +<br> + + +And even more text`; + const sourceWithoutBrTags = `Some text + +And some more text + + + + +And even more text`; + + it('removes extraneous <br> tags', () => { + expect(formatter(source)).toMatch(sourceWithoutBrTags); + }); +}); |