summaryrefslogtreecommitdiff
path: root/spec/frontend/static_site_editor/services/parse_source_file_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/static_site_editor/services/parse_source_file_spec.js')
-rw-r--r--spec/frontend/static_site_editor/services/parse_source_file_spec.js92
1 files changed, 43 insertions, 49 deletions
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 fe99c4f5334..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'} | ${'syncRaw'} | ${'isModifiedRaw'} | ${'returns true after modification and sync'}
- ${contentSimple} | ${'raw'} | ${'syncBody'} | ${'isModifiedBody'} | ${'returns true after modification and sync'}
- ${contentComplex} | ${'body'} | ${'syncRaw'} | ${'isModifiedRaw'} | ${'returns true after modification and sync'}
- ${contentComplex} | ${'raw'} | ${'syncBody'} | ${'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);
+ },
+ );
});
});