Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-24 21:09:03 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-24 21:09:03 +0300
commitc59765a50abd6a235220fd895f5de78038c243a8 (patch)
tree6cacf61d1746e2d54149c028ecd3f187128cd7da /spec/frontend/static_site_editor
parent4c5468b40825debc2b7bbe08b975dedd2f7f1523 (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.js43
-rw-r--r--spec/frontend/static_site_editor/services/parse_source_file_spec.js92
2 files changed, 62 insertions, 73 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 1689da52322..11c5abf1b08 100644
--- a/spec/frontend/static_site_editor/components/edit_area_spec.js
+++ b/spec/frontend/static_site_editor/components/edit_area_spec.js
@@ -52,7 +52,7 @@ describe('~/static_site_editor/components/edit_area.vue', () => {
it('renders rich content editor', () => {
expect(findRichContentEditor().exists()).toBe(true);
- expect(findRichContentEditor().props('value')).toBe(body);
+ expect(findRichContentEditor().props('content')).toBe(body);
});
it('renders publish toolbar', () => {
@@ -76,6 +76,15 @@ describe('~/static_site_editor/components/edit_area.vue', () => {
return wrapper.vm.$nextTick();
});
+ it('updates parsedSource with new content', () => {
+ const newContent = 'New content';
+ const spySyncParsedSource = jest.spyOn(wrapper.vm.parsedSource, 'sync');
+
+ findRichContentEditor().vm.$emit('input', newContent);
+
+ expect(spySyncParsedSource).toHaveBeenCalledWith(newContent, true);
+ });
+
it('sets publish toolbar as saveable', () => {
expect(findPublishToolbar().props('saveable')).toBe(true);
});
@@ -103,35 +112,21 @@ describe('~/static_site_editor/components/edit_area.vue', () => {
});
it.each`
- initialMode | targetMode
- ${EDITOR_TYPES.wysiwyg} | ${EDITOR_TYPES.markdown}
- ${EDITOR_TYPES.markdown} | ${EDITOR_TYPES.wysiwyg}
- `('sets editorMode from $initialMode to $targetMode', ({ initialMode, targetMode }) => {
- setInitialMode(initialMode);
- findRichContentEditor().vm.$emit('modeChange', targetMode);
-
- expect(wrapper.vm.editorMode).toBe(targetMode);
- });
-
- it.each`
- syncFnName | initialMode | targetMode
- ${'syncBodyToRaw'} | ${EDITOR_TYPES.wysiwyg} | ${EDITOR_TYPES.markdown}
- ${'syncRawToBody'} | ${EDITOR_TYPES.markdown} | ${EDITOR_TYPES.wysiwyg}
+ initialMode | targetMode | resetValue
+ ${EDITOR_TYPES.wysiwyg} | ${EDITOR_TYPES.markdown} | ${content}
+ ${EDITOR_TYPES.markdown} | ${EDITOR_TYPES.wysiwyg} | ${body}
`(
- 'calls $syncFnName source before switching from $initialMode to $targetMode',
- ({ syncFnName, initialMode, targetMode }) => {
+ 'sets editorMode from $initialMode to $targetMode',
+ ({ initialMode, targetMode, resetValue }) => {
setInitialMode(initialMode);
- const spySyncSource = jest.spyOn(wrapper.vm, 'syncSource');
- const spySyncParsedSource = jest.spyOn(wrapper.vm.parsedSource, syncFnName);
+ const resetInitialValue = jest.fn();
+ findRichContentEditor().setMethods({ resetInitialValue });
findRichContentEditor().vm.$emit('modeChange', targetMode);
- expect(spySyncSource).toHaveBeenCalled();
- expect(spySyncParsedSource).toHaveBeenCalled();
-
- spySyncSource.mockReset();
- spySyncParsedSource.mockReset();
+ expect(resetInitialValue).toHaveBeenCalledWith(resetValue);
+ expect(wrapper.vm.editorMode).toBe(targetMode);
},
);
});
diff --git a/spec/frontend/static_site_editor/services/parse_source_file_spec.js b/spec/frontend/static_site_editor/services/parse_source_file_spec.js
index a6c148dfd02..4588548e614 100644
--- a/spec/frontend/static_site_editor/services/parse_source_file_spec.js
+++ b/spec/frontend/static_site_editor/services/parse_source_file_spec.js
@@ -1,64 +1,58 @@
-import {
- sourceContent as content,
- sourceContentHeader as header,
- sourceContentSpacing as spacing,
- sourceContentBody as body,
-} from '../mock_data';
+import { sourceContent as content, sourceContentBody as body } from '../mock_data';
import parseSourceFile from '~/static_site_editor/services/parse_source_file';
describe('parseSourceFile', () => {
- const contentSimple = content;
const contentComplex = [content, content, content].join('');
+ const complexBody = [body, content, content].join('');
+ const edit = 'and more';
+ const newContent = `${content} ${edit}`;
+ const newContentComplex = `${contentComplex} ${edit}`;
- describe('the editable shape and its expected values', () => {
+ describe('unmodified content', () => {
it.each`
- sourceContent | sourceHeader | sourceSpacing | sourceBody | desc
- ${contentSimple} | ${header} | ${spacing} | ${body} | ${'extracts header'}
- ${contentComplex} | ${header} | ${spacing} | ${[body, content, content].join('')} | ${'extracts body'}
- `('$desc', ({ sourceContent, sourceHeader, sourceSpacing, sourceBody }) => {
- const { editable } = parseSourceFile(sourceContent);
-
- expect(editable).toMatchObject({
- raw: sourceContent,
- header: sourceHeader,
- spacing: sourceSpacing,
- body: sourceBody,
- });
+ parsedSource
+ ${parseSourceFile(content)}
+ ${parseSourceFile(contentComplex)}
+ `('returns false by default', ({ parsedSource }) => {
+ expect(parsedSource.isModified()).toBe(false);
});
- it('returns the same front matter regardless of front matter duplication', () => {
- const parsedSourceSimple = parseSourceFile(contentSimple);
- const parsedSourceComplex = parseSourceFile(contentComplex);
-
- expect(parsedSourceSimple.editable.header).toBe(parsedSourceComplex.editable.header);
- });
- });
-
- describe('editable body to raw content default and changes', () => {
it.each`
- sourceContent | desc
- ${contentSimple} | ${'returns false by default for both raw and body'}
- ${contentComplex} | ${'returns false by default for both raw and body'}
- `('$desc', ({ sourceContent }) => {
- const parsedSource = parseSourceFile(sourceContent);
+ parsedSource | isBody | target
+ ${parseSourceFile(content)} | ${undefined} | ${content}
+ ${parseSourceFile(content)} | ${false} | ${content}
+ ${parseSourceFile(content)} | ${true} | ${body}
+ ${parseSourceFile(contentComplex)} | ${undefined} | ${contentComplex}
+ ${parseSourceFile(contentComplex)} | ${false} | ${contentComplex}
+ ${parseSourceFile(contentComplex)} | ${true} | ${complexBody}
+ `(
+ 'returns only the $target content when the `isBody` parameter argument is $isBody',
+ ({ parsedSource, isBody, target }) => {
+ expect(parsedSource.content(isBody)).toBe(target);
+ },
+ );
+ });
- expect(parsedSource.isModifiedRaw()).toBe(false);
- expect(parsedSource.isModifiedBody()).toBe(false);
- });
+ describe('modified content', () => {
+ const newBody = `${body} ${edit}`;
+ const newComplexBody = `${complexBody} ${edit}`;
it.each`
- sourceContent | editableKey | syncKey | isModifiedKey | desc
- ${contentSimple} | ${'body'} | ${'syncBodyToRaw'} | ${'isModifiedRaw'} | ${'returns true after modification and sync'}
- ${contentSimple} | ${'raw'} | ${'syncRawToBody'} | ${'isModifiedBody'} | ${'returns true after modification and sync'}
- ${contentComplex} | ${'body'} | ${'syncBodyToRaw'} | ${'isModifiedRaw'} | ${'returns true after modification and sync'}
- ${contentComplex} | ${'raw'} | ${'syncRawToBody'} | ${'isModifiedBody'} | ${'returns true after modification and sync'}
- `('$desc', ({ sourceContent, editableKey, syncKey, isModifiedKey }) => {
- const parsedSource = parseSourceFile(sourceContent);
- parsedSource.editable[editableKey] += 'Added content';
- parsedSource[syncKey]();
-
- expect(parsedSource[isModifiedKey]()).toBe(true);
- });
+ parsedSource | isModified | targetRaw | targetBody
+ ${parseSourceFile(content)} | ${false} | ${content} | ${body}
+ ${parseSourceFile(content)} | ${true} | ${newContent} | ${newBody}
+ ${parseSourceFile(contentComplex)} | ${false} | ${contentComplex} | ${complexBody}
+ ${parseSourceFile(contentComplex)} | ${true} | ${newContentComplex} | ${newComplexBody}
+ `(
+ 'returns $isModified after a $targetRaw sync',
+ ({ parsedSource, isModified, targetRaw, targetBody }) => {
+ parsedSource.sync(targetRaw);
+
+ expect(parsedSource.isModified()).toBe(isModified);
+ expect(parsedSource.content()).toBe(targetRaw);
+ expect(parsedSource.content(true)).toBe(targetBody);
+ },
+ );
});
});