diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/frontend/static_site_editor/services/parse_source_file_spec.js | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
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.js | 92 |
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); + }, + ); }); }); |